com.universaldevices.soap
Class AbstractHTTPRequest

java.lang.Object
  extended by com.universaldevices.soap.AbstractHTTPRequest
Direct Known Subclasses:
UDHTTPRequest, UDHTTPSRequest

public abstract class AbstractHTTPRequest
extends java.lang.Object

AbstractHTTPRequest class encapsulates an HTTP request to ISY. This class may also be used for other types of HTTP request and it's the superclass to UDSOAPRequest

Author:
UD Architect
See Also:
UDSOAPRequest

Field Summary
protected  java.net.InetSocketAddress address
          The address segment of the URL (includes the port)
protected  java.io.ByteArrayOutputStream ba
          The output stream encapsulated in a ByteArrayOutputStream
protected  boolean closed
          The status of the socket: true if close, false otherwise
protected  java.lang.String credentials
           
protected  java.io.InputStream is
          The input stream
protected  java.lang.String method
          The method which is either a GET or a POST
protected  java.io.OutputStream os
          The output stream
protected  java.nio.channels.SocketChannel sc
           
protected static int SEND_BUFFER_SIZE
           
 java.lang.String url_path
          The path segment of the URL (such as /web/nodescnf.xml)
 
Constructor Summary
protected AbstractHTTPRequest(java.net.InetSocketAddress address, java.lang.String url_path)
          Constructor
protected AbstractHTTPRequest(java.net.InetSocketAddress address, java.lang.String method, java.lang.String url_path)
          Constructor
 
Method Summary
abstract  void close(int status)
          Releases all the resources
static AbstractHTTPRequest create(boolean isSSL, java.net.InetSocketAddress address, java.lang.String url_path, java.lang.String httpCredentials)
          UDHTTPRequest and UDHTTPSRequest factory method
static AbstractHTTPRequest create(boolean isSSL, java.net.InetSocketAddress address, java.lang.String method, java.lang.String url_path, java.lang.String httpCredentials)
          UDHTTPRequest and UDHTTPSRequest factory method
static AbstractHTTPRequest create(java.lang.String url, java.lang.String httpCredentials)
          UDHTTPRequest and UDHTTPSRequest factory method
 java.lang.String get()
          Issues a GET request to the URL pointed to by this object.
 java.lang.String getFile()
           
 java.lang.StringBuffer getHeader(int body_length, boolean terminate_header)
          Returns the HTTP header for this request
 java.lang.String getHost()
          Returns the String representation of the host segment of the URL for this request
 java.lang.StringBuffer getHostAndPort()
          Returns the host:port combination for the URL for this request
 int getPort()
          Returns the port segment of the URL for this request
abstract  java.lang.String getProtocol()
           
 UDHTTPResponse getServerResponse(java.lang.StringBuffer header, java.lang.StringBuffer body, boolean keep_alive)
          Issues the request to the server and returns the response in UDHTTPResponse object
abstract  UDHTTPResponse getServerResponse(java.lang.StringBuffer header, java.lang.StringBuffer body, boolean keep_alive, java.lang.Object device)
          Issues the request to the server and returns the response
abstract  java.net.Socket getSocket()
           
 int getSocketTimeoutMillis()
          Returns the number of milliseconds before the socket times out.
 java.lang.String getURL()
          Returns the String representation of the URL for this request
abstract  boolean isSSL()
           
 UDHTTPResponse post(byte[] body, boolean keep_alive, IUpdaterClient view)
          Simple post
abstract  UDHTTPResponse post(java.lang.StringBuffer header, byte[] body, boolean keep_alive, java.lang.Object device, IUpdaterClient view)
          Simple post
static void setSendBufferSize(boolean isLarge)
           
 void setSocketTimeoutMillis(int v)
          Sets the number of milliseconds before the socket times out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEND_BUFFER_SIZE

protected static int SEND_BUFFER_SIZE

url_path

public java.lang.String url_path
The path segment of the URL (such as /web/nodescnf.xml)


address

protected java.net.InetSocketAddress address
The address segment of the URL (includes the port)


method

protected java.lang.String method
The method which is either a GET or a POST


is

protected java.io.InputStream is
The input stream


os

protected java.io.OutputStream os
The output stream


closed

protected boolean closed
The status of the socket: true if close, false otherwise


ba

protected java.io.ByteArrayOutputStream ba
The output stream encapsulated in a ByteArrayOutputStream


sc

protected java.nio.channels.SocketChannel sc

credentials

protected java.lang.String credentials
Constructor Detail

AbstractHTTPRequest

protected AbstractHTTPRequest(java.net.InetSocketAddress address,
                              java.lang.String method,
                              java.lang.String url_path)
Constructor

Parameters:
address - - the address segment of the URL including port
method - - the method either GET or POST
url_path - - the path segment of the URL (i.e. /web/nodescnf.xml)

AbstractHTTPRequest

protected AbstractHTTPRequest(java.net.InetSocketAddress address,
                              java.lang.String url_path)
Constructor

Note: the method is defaulted to "GET"

Parameters:
address - - the address segment of the URL including port
url_path - - the path segment of the URL (i.e. /web/nodescnf.xml)
Method Detail

getSocketTimeoutMillis

public int getSocketTimeoutMillis()
Returns the number of milliseconds before the socket times out.

Returns:
Returns the number of milliseconds before the socket times out.

setSocketTimeoutMillis

public void setSocketTimeoutMillis(int v)
Sets the number of milliseconds before the socket times out.


getURL

public java.lang.String getURL()
Returns the String representation of the URL for this request

Returns:
- the String representation of the URL for this request

getHost

public java.lang.String getHost()
Returns the String representation of the host segment of the URL for this request

Returns:
- the String representation of the host segment of the URL for this request (i.e. 192.168.0.150)

getPort

public int getPort()
Returns the port segment of the URL for this request

Returns:
- the port segment of the URL for this request

getFile

public java.lang.String getFile()
Returns:
- the path segment of the URL for this request

getHostAndPort

public java.lang.StringBuffer getHostAndPort()
Returns the host:port combination for the URL for this request

Returns:
- the host:port combination for the URL for this request

getHeader

public java.lang.StringBuffer getHeader(int body_length,
                                        boolean terminate_header)
Returns the HTTP header for this request

Parameters:
body_length - - the length of the body for this request. Content-Length is used only for POST method
terminate_header - - whether or not to terminate the header with a \r\n; this
parameter should be used if no other header fields are to be added by subclasses such as UDSOAPRequest
Returns:
- the HTTP header for this request

getServerResponse

public UDHTTPResponse getServerResponse(java.lang.StringBuffer header,
                                        java.lang.StringBuffer body,
                                        boolean keep_alive)
Issues the request to the server and returns the response in UDHTTPResponse object

Parameters:
header - - the header for the request
body - - the body for the request if any (in case of POST)
keep_alive - - whether or not the connection should be kept alive
Returns:
- the response from the server encapsulated in UDHTTPResponse
See Also:
UDHTTPResponse

getServerResponse

public abstract UDHTTPResponse getServerResponse(java.lang.StringBuffer header,
                                                 java.lang.StringBuffer body,
                                                 boolean keep_alive,
                                                 java.lang.Object device)
Issues the request to the server and returns the response

The response is of type UDHTTPResponse
Use this method to encapuslate requests to ISY

Parameters:
header - - the header for the request
body - - the body for the request if any (in case of POST)
keep_alive - - whether or not the connection should be kept alive
device - - the UDProxyDevice object
Returns:
- the response from the server encapsulated in UDHTTPResponse
See Also:
UDHTTPResponse, UDProxyDevice

post

public UDHTTPResponse post(byte[] body,
                           boolean keep_alive,
                           IUpdaterClient view)
Simple post

Parameters:
body - - the body for the request if any (in case of POST)
keep_alive - - whether or not the connection should be kept alive
view - - updates the progress bar
Returns:
- the response from the server encapsulated in UDHTTPResponse
See Also:
UDHTTPResponse

post

public abstract UDHTTPResponse post(java.lang.StringBuffer header,
                                    byte[] body,
                                    boolean keep_alive,
                                    java.lang.Object device,
                                    IUpdaterClient view)
Simple post

The response is of type UDHTTPResponse
Use this method to encapuslate requests to ISY

Parameters:
header - - the header for the request
body - - the body for the request if any (in case of POST)
keep_alive - - whether or not the connection should be kept alive
device - - the UDProxyDevice object
Returns:
- the response from the server encapsulated in UDHTTPResponse
See Also:
UDHTTPResponse, UDProxyDevice

get

public java.lang.String get()
Issues a GET request to the URL pointed to by this object.

Does not work with any content except text/xml/html

Returns:
- the content of the URL in String format.

close

public abstract void close(int status)
Releases all the resources

Releases all resources and closes all the connection which this object holds

Parameters:
status - - @depracated

getProtocol

public abstract java.lang.String getProtocol()
Returns:
- the protocol: http or https

getSocket

public abstract java.net.Socket getSocket()
Returns:
- returns the socket

isSSL

public abstract boolean isSSL()
Returns:
- whether or not this request is SSL based

create

public static AbstractHTTPRequest create(boolean isSSL,
                                         java.net.InetSocketAddress address,
                                         java.lang.String method,
                                         java.lang.String url_path,
                                         java.lang.String httpCredentials)

UDHTTPRequest and UDHTTPSRequest factory method

Parameters:
isSSL - - whether or not to return UDHTTPRequest or UDHTTPSRequest
address - - the address segment of the URL including port
method - - the method either GET or POST
url_path - - the path segment of the URL (i.e. /web/nodescnf.xml)
httpCredentials - - Complete HTTP Authorization header
Returns:
- if SSL, then UDHTTPSRequest otherwise UDHTTPRequest

create

public static AbstractHTTPRequest create(boolean isSSL,
                                         java.net.InetSocketAddress address,
                                         java.lang.String url_path,
                                         java.lang.String httpCredentials)

UDHTTPRequest and UDHTTPSRequest factory method

Note: the method is defaulted to "GET"

Parameters:
isSSL - - whether or not to return UDHTTPRequest or UDHTTPSRequest
address - - the address segment of the URL including port
url_path - - the path segment of the URL (i.e. /web/nodescnf.xml)
httpCredentials - - Complete HTTP Authorization header
Returns:
- if SSL, then UDHTTPSRequest otherwise UDHTTPRequest

create

public static AbstractHTTPRequest create(java.lang.String url,
                                         java.lang.String httpCredentials)

UDHTTPRequest and UDHTTPSRequest factory method

Creates a request based on a String representation of an URL

Parameters:
url - - the URL
Returns:
- if SSL, then UDHTTPSRequest otherwise UDHTTPRequest

setSendBufferSize

public static void setSendBufferSize(boolean isLarge)