Secure iNet Factory

com.jscape.inet.http
Class Http

java.lang.Object
  extended by com.jscape.inet.http.Http
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Https, HttpSsh

public class Http
extends java.lang.Object
implements java.io.Serializable

Implements the basic functionality of a HTTP client.

Example Usage:

 Http http = new Http();
 
 // build HTTP request
 HttpRequest request = new HttpRequest("http://www.myserver.com");
 
 // get HTTP response
 try
 {
   HttpResponse response = http.getResponse(request);
   System.out.println(new String(response.getBody()));
 }
 catch(Exception e)
 {
   System.out.println(e);
 }
 

See Also:
Serialized Form

Constructor Summary
Http()
          Constructs a new Http instance.
 
Method Summary
 void addHttpListener(HttpListener listener)
          Adds an event listener for events implemented by HttpListener interface.
 void clearProxySettings()
          Clears proxy server values.
 java.io.PrintStream getDebugStream()
          Gets PrintStream used in reporting debug statements.
 int getReadBlockSize()
          Gets the number of bytes read in each block of data read from server
 HttpResponse getResponse(HttpFileUpload request)
          Gets response to HTTP request.
 HttpResponse getResponse(HttpRequest request)
          Gets response to HTTP request.
 HttpResponse getResponseToFile(HttpRequest request, java.io.File file)
          Gets response to HTTP request and writes contents to file.
 int getTimeout()
          Gets the timeout used when opening a HTTP connection.
 int getWriteBlockSize()
          Gets number of bytes written in each block to server
 boolean isDebug()
          Gets debug level of HTTP session.
 void removeHttpListener(HttpListener listener)
          Removes instance of HttpListener.
 void setDebug(boolean debug)
          Sets debugging state.
 void setDebugStream(java.io.PrintStream debugStream)
          Sets PrintStream used in reporting debug statements.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the username and password to use when for authentication with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this connection.
 void setReadBlockSize(int i)
          Sets the number of bytes read in each block of data read from server
 void setTimeout(int timeout)
          Sets the timeout for opening a HTTP connection.
 void setWriteBlockSize(int i)
          Sets number of bytes written in each block to server
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Http

public Http()
Constructs a new Http instance.

Method Detail

addHttpListener

public void addHttpListener(HttpListener listener)
Adds an event listener for events implemented by HttpListener interface.

Parameters:
listener - an HttpListener
See Also:
HttpListener

removeHttpListener

public void removeHttpListener(HttpListener listener)
Removes instance of HttpListener.

Parameters:
listener - an HttpListener
See Also:
HttpListener

getResponse

public HttpResponse getResponse(HttpFileUpload request)
                         throws HttpException
Gets response to HTTP request.

Parameters:
request - the HttpFileUpload to perform
Returns:
an HttpResponse
Throws:
HttpException - thrown if an I/O or HTTP related error occurs
See Also:
HttpResponse, HttpException

getResponse

public HttpResponse getResponse(HttpRequest request)
                         throws HttpException
Gets response to HTTP request.

Parameters:
request - the HttpRequest to perform
Returns:
an HttpResponse
Throws:
HttpException - thrown if an I/O or HTTP related error occurs
See Also:
HttpResponse, HttpException

getResponseToFile

public HttpResponse getResponseToFile(HttpRequest request,
                                      java.io.File file)
                               throws HttpException
Gets response to HTTP request and writes contents to file.

Parameters:
request - the HttpRequest to perform
file - the file to write the response to
Returns:
the HttpResponse written to file
Throws:
HttpException - thrown if an I/O or HTTP related error occurs
See Also:
HttpResponse, HttpException

getDebugStream

public java.io.PrintStream getDebugStream()
Gets PrintStream used in reporting debug statements. Default PrintStream is System.out

Returns:
the PrintStream used for debug statements
See Also:
PrintStream

setDebugStream

public void setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements. Default PrintStream is System.out

Parameters:
debugStream - the PrintStream to send debug statements to
See Also:
PrintStream

setDebug

public void setDebug(boolean debug)
Sets debugging state. All debug statements are reported to debug stream. Default debug stream is System.out

Parameters:
debug - true to turn debugging on
See Also:
setDebugStream(java.io.PrintStream)

isDebug

public boolean isDebug()
Gets debug level of HTTP session. Debug messages are reported to debug stream. Default debug stream is System.out

Returns:
true if debugging is on
See Also:
setDebugStream(java.io.PrintStream)

setTimeout

public void setTimeout(int timeout)
Sets the timeout for opening a HTTP connection. Default of 0ms uses natural timeout of socket.

Parameters:
timeout - in milliseconds

getTimeout

public int getTimeout()
Gets the timeout used when opening a HTTP connection. Default of 0ms uses natural timeout of socket.

Returns:
timeout in milliseconds

getWriteBlockSize

public int getWriteBlockSize()
Gets number of bytes written in each block to server

Returns:
block size

setWriteBlockSize

public void setWriteBlockSize(int i)
Sets number of bytes written in each block to server

Parameters:
i - block size

getReadBlockSize

public int getReadBlockSize()
Gets the number of bytes read in each block of data read from server

Returns:
block size

setReadBlockSize

public void setReadBlockSize(int i)
Sets the number of bytes read in each block of data read from server

Parameters:
i - block size

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the #clearProxySettings method.

Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this connection. To clear these settings invoke the #clearProxySettings method.

Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.

Parameters:
proxyType - The proxy type. Valid values: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.


Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved