DCT Lightfoot v3 API specification

com.dctl.j2me.io.http
Class BaseHttpConnection

java.lang.Object
  |
  +--com.dctl.j2me.io.BaseConnection
        |
        +--com.dctl.j2me.io.http.BaseHttpConnection
All Implemented Interfaces:
Connection
Direct Known Subclasses:
Connection, HttpServerSocket

public abstract class BaseHttpConnection
extends BaseConnection

This is the base for http server and client connections


Field Summary
protected static java.lang.String ACCEPT_PROPERTY
          The accept property
protected static java.lang.String ACCEPT_VALUE
          The accept value
protected static int ASCTIME
           
protected static java.lang.String CHUNKED_ENCODING
          The chunked encoding value
protected static int CLOSED
          Closed.
protected static java.lang.String COLON_SPACE
          This separates property names from values
protected static int COMMA
           
protected static java.lang.String CONNECTION_CLOSE
          Close a connection
protected static java.lang.String CONNECTION_KEEP_ALIVE
          The default connection value
protected static java.lang.String CONNECTION_PROPERTY
          The connection property
protected static java.lang.String CONTENT_ENCODING_PROPERTY
          The content encoding property
protected static java.lang.String CONTENT_LENGTH_PROPERTY
          The content length property
protected static java.lang.String CONTENT_TYPE_PROPERTY
          The content type property
protected static java.lang.String CRLF
          This ends lines
protected static int DASH
           
protected static java.lang.String DATE_PROPERTY
          The date property
protected static int DAY
           
protected static java.lang.String EXPIRES_PROPERTY
          The expires property
protected static int[] FIELDS
           
protected  int handle
          The handle to the TCP socket
protected static java.lang.String HOST_PROPERTY
          The host property string
protected static int HOUR
           
protected  Vector inputNames
          The vector of response names that is only created if required
protected  Hashtable inputProperties
          The hashtable of output properties
protected  com.dctl.j2me.io.http.InputStream is
          The input stream
protected static java.lang.String LAST_MODIFIED_PROPERTY
          The last modified property
protected  java.lang.String method
          The method we are using
protected static int MIN
           
protected static int MONTH
           
protected static java.lang.String[] MONTH_STRING
           
protected  int opens
          The number of streams open on the connection plus one if the connection is open
protected  com.dctl.j2me.io.http.OutputStream os
          The output stream
protected  Hashtable outputProperties
          The hashtable of input properties
protected static java.lang.String PROTOCOL
          The protocol we are doing
protected static int RECEIVING
          Receiving.
protected  int responseCode
          The response code
protected  java.lang.String responseMessage
          The response message
protected static int RFC1123
           
protected static int RFC850
           
protected static int SEC
           
protected static int SENDING
          Sending.
protected static int SETUP
          Setup.
protected static int SPACE
           
protected  int state
          The current state
protected static java.lang.String TRANSFER_ENCODING_PROPERTY
          The transfer encoding property
protected static java.lang.String USER_AGENT_PROPERTY
          The user agent property
protected static java.lang.String USER_AGENT_VALUE
          Default user agent value
protected static java.lang.String VERSION
          The version of HTTP we are using
protected static int YEAR
           
 
Fields inherited from class com.dctl.j2me.io.BaseConnection
protocol
 
Constructor Summary
BaseHttpConnection()
           
 
Method Summary
 void close()
          Close the connection if the reference count gets to zero
protected abstract  java.lang.String generateFirstOutput()
          Get the first line to output
 long getFieldDate(Hashtable table, java.lang.String name, long defaultValue)
          Get a field parsed as a date value
 int getFieldInt(Hashtable table, java.lang.String name, int defaultValue)
          Get a field parsed as a number
 java.lang.String getFile()
          Get the file portion of the URL
 java.lang.String getHost()
          Get the host to connect to
 java.lang.String getInputFieldKey(int index)
          Get the header field key at the index
 int getPort()
          Get the port of the URL
 java.lang.String getProtocol()
          Get the protocol used for the connection
 java.lang.String getQuery()
          Get the query portion of the URL - after the last question mark
 java.lang.String getRef()
          Get the ref portion of the URL
 java.lang.String getRequestMethod()
          Get the request method
 java.lang.String getURL()
          Get the URL
protected abstract  boolean handleFirstInput(java.lang.String line)
          handle the first input line
protected  void invalidState()
           
protected abstract  void openConnection()
          Open the connection
 java.io.DataInputStream openDataInputStream()
          Open a data input stream
 java.io.DataOutputStream openDataOutputStream()
          Open a data output stream
 InputStream openInputStream()
          Open an input stream
 OutputStream openOutputStream()
          Open an output stream if it was not already open.
protected  void parseInput()
          Parse the input stream
 void recycle()
          Recycle the connection
protected  void sendOutput()
          Send the request and transition the state
 void setRequestMethod(java.lang.String method)
          Set the request method - only valid until the request has been got
 
Methods inherited from class com.dctl.j2me.io.BaseConnection
setParameters
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

method

protected java.lang.String method
The method we are using


PROTOCOL

protected static final java.lang.String PROTOCOL
The protocol we are doing

See Also:
Constant Field Values

VERSION

protected static final java.lang.String VERSION
The version of HTTP we are using

See Also:
Constant Field Values

CRLF

protected static final java.lang.String CRLF
This ends lines

See Also:
Constant Field Values

COLON_SPACE

protected static final java.lang.String COLON_SPACE
This separates property names from values

See Also:
Constant Field Values

HOST_PROPERTY

protected static final java.lang.String HOST_PROPERTY
The host property string

See Also:
Constant Field Values

USER_AGENT_PROPERTY

protected static final java.lang.String USER_AGENT_PROPERTY
The user agent property

See Also:
Constant Field Values

USER_AGENT_VALUE

protected static final java.lang.String USER_AGENT_VALUE
Default user agent value

See Also:
Constant Field Values

ACCEPT_PROPERTY

protected static final java.lang.String ACCEPT_PROPERTY
The accept property

See Also:
Constant Field Values

ACCEPT_VALUE

protected static final java.lang.String ACCEPT_VALUE
The accept value

See Also:
Constant Field Values

CONNECTION_PROPERTY

protected static final java.lang.String CONNECTION_PROPERTY
The connection property

See Also:
Constant Field Values

CONNECTION_KEEP_ALIVE

protected static final java.lang.String CONNECTION_KEEP_ALIVE
The default connection value

See Also:
Constant Field Values

CONNECTION_CLOSE

protected static final java.lang.String CONNECTION_CLOSE
Close a connection

See Also:
Constant Field Values

DATE_PROPERTY

protected static final java.lang.String DATE_PROPERTY
The date property

See Also:
Constant Field Values

EXPIRES_PROPERTY

protected static final java.lang.String EXPIRES_PROPERTY
The expires property

See Also:
Constant Field Values

LAST_MODIFIED_PROPERTY

protected static final java.lang.String LAST_MODIFIED_PROPERTY
The last modified property

See Also:
Constant Field Values

CONTENT_TYPE_PROPERTY

protected static final java.lang.String CONTENT_TYPE_PROPERTY
The content type property

See Also:
Constant Field Values

CONTENT_ENCODING_PROPERTY

protected static final java.lang.String CONTENT_ENCODING_PROPERTY
The content encoding property

See Also:
Constant Field Values

CONTENT_LENGTH_PROPERTY

protected static final java.lang.String CONTENT_LENGTH_PROPERTY
The content length property

See Also:
Constant Field Values

TRANSFER_ENCODING_PROPERTY

protected static final java.lang.String TRANSFER_ENCODING_PROPERTY
The transfer encoding property

See Also:
Constant Field Values

CHUNKED_ENCODING

protected static final java.lang.String CHUNKED_ENCODING
The chunked encoding value

See Also:
Constant Field Values

SETUP

protected static final int SETUP
Setup. we are created but have not sent the request

See Also:
Constant Field Values

SENDING

protected static final int SENDING
Sending. we have sent the headers and can send other stuff

See Also:
Constant Field Values

RECEIVING

protected static final int RECEIVING
Receiving. we have received the response headers and can read from server

See Also:
Constant Field Values

CLOSED

protected static final int CLOSED
Closed. nothing really works

See Also:
Constant Field Values

outputProperties

protected Hashtable outputProperties
The hashtable of input properties


inputProperties

protected Hashtable inputProperties
The hashtable of output properties


inputNames

protected Vector inputNames
The vector of response names that is only created if required


responseCode

protected int responseCode
The response code


responseMessage

protected java.lang.String responseMessage
The response message


state

protected int state
The current state


is

protected com.dctl.j2me.io.http.InputStream is
The input stream


os

protected com.dctl.j2me.io.http.OutputStream os
The output stream


handle

protected int handle
The handle to the TCP socket


opens

protected int opens
The number of streams open on the connection plus one if the connection is open


YEAR

protected static final int YEAR
See Also:
Constant Field Values

MONTH

protected static final int MONTH
See Also:
Constant Field Values

DAY

protected static final int DAY
See Also:
Constant Field Values

HOUR

protected static final int HOUR
See Also:
Constant Field Values

MIN

protected static final int MIN
See Also:
Constant Field Values

SEC

protected static final int SEC
See Also:
Constant Field Values

FIELDS

protected static final int[] FIELDS

MONTH_STRING

protected static final java.lang.String[] MONTH_STRING

RFC1123

protected static final int RFC1123
See Also:
Constant Field Values

RFC850

protected static final int RFC850
See Also:
Constant Field Values

ASCTIME

protected static final int ASCTIME
See Also:
Constant Field Values

COMMA

protected static final int COMMA
See Also:
Constant Field Values

SPACE

protected static final int SPACE
See Also:
Constant Field Values

DASH

protected static final int DASH
See Also:
Constant Field Values
Constructor Detail

BaseHttpConnection

public BaseHttpConnection()
Method Detail

recycle

public void recycle()
Recycle the connection


setRequestMethod

public void setRequestMethod(java.lang.String method)
                      throws IOException
Set the request method - only valid until the request has been got

Parameters:
method - The request method
Throws:
IOException - if the request has already been sent or the method is not valid

invalidState

protected final void invalidState()
                           throws IOException
IOException

generateFirstOutput

protected abstract java.lang.String generateFirstOutput()
Get the first line to output

Returns:
the line

openConnection

protected abstract void openConnection()
                                throws IOException
Open the connection

Throws:
IOException - if there is an error

sendOutput

protected final void sendOutput()
                         throws IOException
Send the request and transition the state

Throws:
IOException - if there is an error

handleFirstInput

protected abstract boolean handleFirstInput(java.lang.String line)
                                     throws IOException
handle the first input line

Parameters:
line - The first input line
Returns:
true if the line parsed ok, false if another line is requried
Throws:
IOException - if the line is incorrect

parseInput

protected final void parseInput()
                         throws IOException
Parse the input stream

Throws:
IOException - if there is an error

close

public void close()
           throws IOException
Close the connection if the reference count gets to zero

Throws:
IOException - if there is an I/O error

getFile

public java.lang.String getFile()
Get the file portion of the URL

Returns:
the file portion of the URL

getURL

public java.lang.String getURL()
Get the URL

Returns:
the url

getProtocol

public java.lang.String getProtocol()
Get the protocol used for the connection

Returns:
the protocol

getHost

public java.lang.String getHost()
Get the host to connect to

Returns:
the host name or IP address

getRef

public java.lang.String getRef()
Get the ref portion of the URL

Returns:
the ref

getQuery

public java.lang.String getQuery()
Get the query portion of the URL - after the last question mark

Returns:
the query

getPort

public int getPort()
Get the port of the URL

Returns:
the port or default 80 if none specified

getRequestMethod

public java.lang.String getRequestMethod()
Get the request method

Returns:
the request method

getFieldInt

public int getFieldInt(Hashtable table,
                       java.lang.String name,
                       int defaultValue)
                throws IOException
Get a field parsed as a number

Parameters:
table - The table to get the field from
name - The name of the field
defaultValue - The default value to use if the field cannot be parsed or if it does not exist
Returns:
the value of the field or the default value if it cannot be parsed
Throws:
IOException - if there is an error

getFieldDate

public long getFieldDate(Hashtable table,
                         java.lang.String name,
                         long defaultValue)
                  throws IOException
Get a field parsed as a date value

Parameters:
table - The table to get the field from
name - Thename of the field
defaultValue - The default value to use if the field cannot be parsed or if it does not exist
Returns:
the value of the field or the default value if it cannot be parsed
Throws:
IOException - if there is an error

getInputFieldKey

public java.lang.String getInputFieldKey(int index)
                                  throws IOException
Get the header field key at the index

Parameters:
index - the index
Returns:
the header field name at the index or null if it is out of range
Throws:
IOException - if there is an error

openInputStream

public InputStream openInputStream()
                            throws IOException
Open an input stream

Returns:
the input stream
Throws:
IOException - if there is an error

openDataInputStream

public java.io.DataInputStream openDataInputStream()
                                            throws IOException
Open a data input stream

Returns:
the data input stream
Throws:
IOException - if there is an error

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Open an output stream if it was not already open.

Returns:
the output stream
Throws:
IOException - if there is an error

openDataOutputStream

public java.io.DataOutputStream openDataOutputStream()
                                              throws IOException
Open a data output stream

Returns:
the data output stream
Throws:
IOException - if there is an error

DCT Lightfoot v3 API specification

DCT Lightfoot v3 API specification