|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.autonomy.utilities.AutnHttpURLConnection
This class is intended to simulate some aspects of java.net.HttpURLConnection
while allowing the user to set
a timeout on the underlying socket's read operations. This class only impliments the HTTP protocol, trying to construct
an AutnHttpURLConnection
object using another protocol (e.g. AutnHttpURLConnection("ftp://host:21/")
will throw a MalformedURLException
).
Usage:
AutnHttpURLConnection conn = new AutnHttpURLConnection(sURL);
if(bPost)
{
conn.setRequestMethod("POST");
conn.setBody(sData);
}
conn.setTimeout(cm_nTimeout);
conn.connect();
conn.skipResponseHeaders();
bReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
// ... read from input
conn.disconnect();
Since this class represents an HTTP connection, port 80 is used if no port number is given in the URL.
HttpURLConnection
Constructor Summary | |
AutnHttpURLConnection(java.lang.String sURL)
Construct an AutnHttpURLConnection object to communicate with the given URL. |
|
AutnHttpURLConnection(java.lang.String sHost,
int nPort,
java.lang.String sResource)
Construct an AutnHttpURLConnection object to communicate with the given host, port and resource. |
|
AutnHttpURLConnection(java.net.URL uURL)
Construct an AutnHttpURLConnection object to communicate with the given URL . |
Method Summary | |
void |
addHeader(java.lang.String sKey,
java.lang.String sValue)
Add a header line to the HTTP request as sKey: sValue. |
void |
allowSlackHTTP()
Enables use of \n\n to detect the end of the response header section (as opposed to correct \r\n\r\n ) |
void |
connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. |
void |
disconnect()
Disconnect from the underlying socket, close the io streams and set them to null. |
java.lang.String |
getBody()
Returns the content of this message. |
java.lang.String |
getHeaderField(int n)
Returns the value for the nth header field. |
java.lang.String |
getHeaderField(java.lang.String sKey)
Returns the value for the header field called sKey. |
java.lang.String |
getHeaderFieldKey(int n)
Returns the name for the nth header field. |
java.io.InputStream |
getInputStream()
Returns an input stream that reads from this open connection. |
int |
getNumHeaders()
Returns the number of headers in this request |
java.io.OutputStream |
getOutputStream()
Returns an output stream that writes to this connection. |
java.lang.String |
getRequestMethod()
Get the request method |
int |
getResponseCode()
Gets HTTP response status. |
java.lang.String |
getResponseMessage()
Gets the HTTP response message, if any, returned along with the response code from a server. |
int |
getTimeout()
Returns setting for SO_TIMEOUT. |
java.net.URL |
getURL()
Gets the URL this connection is using. |
java.lang.String |
getVersion()
Returns the HTTP version being used |
void |
setBody(java.lang.String sBody)
Set the content to be sent with this message. |
void |
setContentType(java.lang.String sContentType)
Set the Content-Type header value. |
void |
setEncoding(java.lang.String sSendEncoding,
java.lang.String sRecvEncoding)
Set the encoding used to write data to the socket. Setting any of these to null will uses the JVM's default encoding |
void |
setHeader(java.lang.String sKey,
java.lang.String sValue)
Add a header line to the HTTP request as sKey: sValue. |
void |
setRequestMethod(java.lang.String sMethod)
Set the method for the URL request, one of: GET POST are legal, subject to protocol restrictions. |
void |
setTimeout(int nTimeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
void |
setVersion(java.lang.String sVersion)
Sets the HTTP version to use. |
void |
skipResponseHeaders()
Moves the input stream past initial response line and headers so response body is next to be read. |
java.lang.String |
toString()
Constructs the string buffer to send as this HTTP request |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public AutnHttpURLConnection(java.net.URL uURL) throws java.net.MalformedURLException
AutnHttpURLConnection
object to communicate with the given URL
.
uURL
- the URL to connect to.public AutnHttpURLConnection(java.lang.String sURL) throws java.net.MalformedURLException
AutnHttpURLConnection
object to communicate with the given URL.
sURL
- the URL to connect to.public AutnHttpURLConnection(java.lang.String sHost, int nPort, java.lang.String sResource)
AutnHttpURLConnection
object to communicate with the given host, port and resource.
sHost
- the server host to connect to.nPort
- the port on which the server is listening.sResource
- the host resource.Method Detail |
public void allowSlackHTTP()
\n\n
to detect the end of the response header section (as opposed to correct \r\n\r\n
)
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public void setRequestMethod(java.lang.String sMethod)
sMethod
- method string (upper- or lowercase)
java.net.ProtocolException
- - if the method cannot be reset or if the requested method isn't valid for HTTP.public java.lang.String getRequestMethod()
public void setVersion(java.lang.String sVersion)
public void setEncoding(java.lang.String sSendEncoding, java.lang.String sRecvEncoding)
sSendEncoding
- String used to represent encoding used to send the request, eg. 8859_7public java.lang.String getVersion()
public void setTimeout(int nTimeout)
public int getTimeout()
public void setBody(java.lang.String sBody)
sBody
- request content as a string. Can be null,public java.lang.String getBody()
public void setContentType(java.lang.String sContentType)
sContentType
- the string value of the content type header.public void setHeader(java.lang.String sKey, java.lang.String sValue)
sKey: sValue. If a header with the given header name exists it is overwritten. Can only be called while disconnected.
sKey
- the header namesValue
- the header value. Is allowed to be nullpublic void addHeader(java.lang.String sKey, java.lang.String sValue)
sKey: sValue. If a header with the given header name exists, a second entry is created using the given value. Can only be called while disconnected.
sKey
- the header namesValue
- the header value. Is allowed to be null.public java.lang.String getHeaderField(int n)
n
- an header index (0 <= n < getNumHeaders()).
public java.lang.String getHeaderField(java.lang.String sKey)
public java.lang.String getHeaderFieldKey(int n)
n
- an header index(0 <= n < getNumHeaders()).
public int getNumHeaders()
public int getResponseCode()
public java.lang.String getResponseMessage()
public java.net.URL getURL()
URL
this connection is using.
URL
this connection is using.public void connect() throws java.io.IOException
java.io.IOException
- - if an I/O error occurs while opening the connection.public void disconnect()
public void skipResponseHeaders() throws java.io.IOException
java.io.IOException
- if there is a problem reading from the socket InputStream - likely to be InterruptedIOException.public java.lang.String toString()
toString
in class java.lang.Object
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |