org.deegree_impl.tools
Class NetWorker

java.lang.Object
  extended byorg.deegree_impl.tools.NetWorker

public class NetWorker
extends java.lang.Object

Performs a HTTP request using the service URL submitted to the constructor

Version:
$Revision: 1.11 $
Author:
Andreas Poth

Field Summary
private  java.lang.String contentType
           
private  java.lang.String encoding
           
private static int GET
           
private static int POST
           
private  int reqType
           
private  java.lang.String request
           
private  java.net.URL url
           
 
Constructor Summary
NetWorker(java.lang.String encoding, java.net.URL url)
          constructor for initializing a HTTP GET connection with a user defined encoding
NetWorker(java.lang.String encoding, java.net.URL url, java.lang.String request)
          constructor for initializing a HTTP POST connection with a user defined encoding
NetWorker(java.net.URL url)
          constructor for initializing a HTTP GET connection with UTF-8 as character encoding
NetWorker(java.net.URL url, java.lang.String request)
          constructor for initializing a HTTP POST connection with UTF-8 as character encoding
 
Method Summary
static boolean existsURL(java.net.URL url)
          returns true if a connection to the submitted URL can be opend
 java.lang.String getContentType()
          returns the content type of the response from the connected net resource.
 byte[] getDataAsByteArr(int expectedDataSize)
          performs the request and returns the result as a byte array.
 java.io.InputStream getInputStream()
          returns an InputStream from the et resource
 void sendRequest()
          sends the request that have been passed to the constructor without expecting to receive a response.
static java.lang.String url2String(java.net.URL url)
          Returns the original form of a URL as as String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET

private static final int GET
See Also:
Constant Field Values

POST

private static final int POST
See Also:
Constant Field Values

contentType

private java.lang.String contentType

request

private java.lang.String request

url

private java.net.URL url

reqType

private int reqType

encoding

private java.lang.String encoding
Constructor Detail

NetWorker

public NetWorker(java.net.URL url)
constructor for initializing a HTTP GET connection with UTF-8 as character encoding

Parameters:
url - URL to the net resource containing the URI

NetWorker

public NetWorker(java.lang.String encoding,
                 java.net.URL url)
constructor for initializing a HTTP GET connection with a user defined encoding

Parameters:
encoding - desired character encoding
url - URL to the net resource containing the URI

NetWorker

public NetWorker(java.net.URL url,
                 java.lang.String request)
constructor for initializing a HTTP POST connection with UTF-8 as character encoding

Parameters:
url - URL to the net resource (without URI parameters)
request - request that shall be posted to the net resource

NetWorker

public NetWorker(java.lang.String encoding,
                 java.net.URL url,
                 java.lang.String request)
constructor for initializing a HTTP POST connection with a user defined encoding

Parameters:
encoding - desired character encoding
url - URL to the net resource (without URI parameters)
request - request that shall be posted to the net resource
Method Detail

getContentType

public java.lang.String getContentType()
returns the content type of the response from the connected net resource. this method shall be called after getInputStream or getDataAsByteArr has been called.


sendRequest

public void sendRequest()
                 throws java.io.IOException
sends the request that have been passed to the constructor without expecting to receive a response.

Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
returns an InputStream from the et resource

Returns:
InputStream accessing the net resource
Throws:
java.io.IOException

getDataAsByteArr

public byte[] getDataAsByteArr(int expectedDataSize)
                        throws java.io.IOException
performs the request and returns the result as a byte array.

Parameters:
expectedDataSize - size a the data in bytes expected to be returned from the net resource. this value will be replaced if the resource is able to return the available data size.
Returns:
a byte array containing the content of the net resource
Throws:
java.io.IOException

url2String

public static java.lang.String url2String(java.net.URL url)
Returns the original form of a URL as as String. Handles local filenames correctly, C:/foo is formatted as file:///C:/foo (and not as file:/C:/foo as returned by the toString () method of the object.

Parameters:
url - URL to be converted
Returns:
String representation of the given URL

existsURL

public static boolean existsURL(java.net.URL url)
returns true if a connection to the submitted URL can be opend