deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.framework.util
Class NetWorker

java.lang.Object
  extended by org.deegree.framework.util.NetWorker

public class NetWorker
extends java.lang.Object

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

Version:
$Revision: 18195 $
Author:
Andreas Poth

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 with default 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)
           
 java.lang.String getContentType()
           
 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
 

Constructor Detail

NetWorker

public NetWorker(java.net.URL url)
constructor for initializing a HTTP GET connection with with default 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)
Parameters:
url -
Returns:
true if a connection to the submitted URL can be opend

deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org