org.deegree.commons.utils.net
Class HttpUtils

java.lang.Object
  extended by org.deegree.commons.utils.net.HttpUtils

public class HttpUtils
extends java.lang.Object

HttpUtils Example use from rhino: var u = org.deegree.commons.utils.net.HttpUtils u.retrieve(u.UTF8STRING, "http://demo.deegree.org/deegree-wms/services?request=capabilities&service=WMS")

Version:
$Revision: 25762 $, $Date: 2010-08-09 15:24:20 +0200 (Mo, 09. Aug 2010) $
Author:
Andreas Schmitz, last edited by: $Author: aschmitz $

Nested Class Summary
static interface HttpUtils.Worker<T>
          Worker is used to specify how to return the stream from the remote location.
 
Field Summary
static HttpUtils.Worker<java.awt.image.BufferedImage> IMAGE
          Returns a BufferedImage.
static HttpUtils.Worker<java.io.InputStream> STREAM
          Directly returns the stream.
static HttpUtils.Worker<java.lang.String> UTF8STRING
          Returns a decoded String.
static HttpUtils.Worker<XMLAdapter> XML
          Returns streaming XMLAdapter.
static HttpUtils.Worker<XMLStreamReaderWrapper> XML_STREAM
          Returns streaming XMLAdapter.
 
Constructor Summary
HttpUtils()
           
 
Method Summary
static org.apache.commons.httpclient.HttpClient enableProxyUsage(org.apache.commons.httpclient.HttpClient client, DURL url)
          reads proxyHost and proxyPort from system parameters and sets them to the passed HttpClient instance
static
<T> T
get(HttpUtils.Worker<T> worker, java.lang.String url, java.util.Map<java.lang.String,java.lang.String> headers)
          Performs an HTTP-Get request and provides typed access to the response.
static HttpUtils.Worker<java.lang.String> getStringWorker(java.lang.String encoding)
           
static
<T> T
post(HttpUtils.Worker<T> worker, java.lang.String url, java.io.InputStream postBody, java.util.Map<java.lang.String,java.lang.String> headers)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> T
retrieve(HttpUtils.Worker<T> worker, DURL url)
           
static
<T> T
retrieve(HttpUtils.Worker<T> worker, java.lang.String url)
           
static
<T> T
retrieve(HttpUtils.Worker<T> worker, java.lang.String url, java.util.Map<java.lang.String,java.lang.String> map)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STREAM

public static final HttpUtils.Worker<java.io.InputStream> STREAM
Directly returns the stream.


XML

public static final HttpUtils.Worker<XMLAdapter> XML
Returns streaming XMLAdapter.


XML_STREAM

public static final HttpUtils.Worker<XMLStreamReaderWrapper> XML_STREAM
Returns streaming XMLAdapter.


UTF8STRING

public static final HttpUtils.Worker<java.lang.String> UTF8STRING
Returns a decoded String.


IMAGE

public static final HttpUtils.Worker<java.awt.image.BufferedImage> IMAGE
Returns a BufferedImage.

Constructor Detail

HttpUtils

public HttpUtils()
Method Detail

getStringWorker

public static HttpUtils.Worker<java.lang.String> getStringWorker(java.lang.String encoding)
Parameters:
encoding -
Returns:
a string producer for a specific encoding

retrieve

public static <T> T retrieve(HttpUtils.Worker<T> worker,
                             DURL url)
                  throws java.io.IOException
Type Parameters:
T -
Parameters:
worker -
url - must be valid
Returns:
some object from the url
Throws:
java.io.IOException

retrieve

public static <T> T retrieve(HttpUtils.Worker<T> worker,
                             java.lang.String url)
                  throws java.net.MalformedURLException,
                         java.io.IOException
Type Parameters:
T -
Parameters:
worker -
url -
Returns:
some object from the url
Throws:
java.net.MalformedURLException
java.io.IOException

retrieve

public static <T> T retrieve(HttpUtils.Worker<T> worker,
                             java.lang.String url,
                             java.util.Map<java.lang.String,java.lang.String> map)
                  throws java.net.MalformedURLException,
                         java.io.IOException
Type Parameters:
T -
Parameters:
worker -
url -
map -
Returns:
some object from the url, null, if url is not valid
Throws:
java.io.IOException
java.net.MalformedURLException

post

public static <T> T post(HttpUtils.Worker<T> worker,
                         java.lang.String url,
                         java.io.InputStream postBody,
                         java.util.Map<java.lang.String,java.lang.String> headers)
              throws org.apache.commons.httpclient.HttpException,
                     java.io.IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
postBody -
headers -
Returns:
some object from the url
Throws:
org.apache.commons.httpclient.HttpException
java.io.IOException

get

public static <T> T get(HttpUtils.Worker<T> worker,
                        java.lang.String url,
                        java.util.Map<java.lang.String,java.lang.String> headers)
             throws org.apache.commons.httpclient.HttpException,
                    java.io.IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
headers -
Returns:
some object from the url, null, if url is not valid
Throws:
org.apache.commons.httpclient.HttpException
java.io.IOException

enableProxyUsage

public static org.apache.commons.httpclient.HttpClient enableProxyUsage(org.apache.commons.httpclient.HttpClient client,
                                                                        DURL url)
reads proxyHost and proxyPort from system parameters and sets them to the passed HttpClient instance

Parameters:
client -
url - must be valid
Returns:
HttpClient with proxy configuration
See Also:
of the passed, HttpClient


Copyright © 2011. All Rights Reserved.