org.deegree.commons.utils.net
Class HttpUtils

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

public class HttpUtils
extends 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: 32163 $, $Date: 2011-10-19 10:03:01 +0200 (Wed, 19 Oct 2011) $
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<BufferedImage> IMAGE
          Returns a BufferedImage.
static HttpUtils.Worker<com.google.gson.JsonElement> JSON
           
static HttpUtils.Worker<InputStream> STREAM
          Directly returns the stream.
static HttpUtils.Worker<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.http.impl.client.DefaultHttpClient enableProxyUsage(org.apache.http.impl.client.DefaultHttpClient 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, String url, Map<String,String> headers)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> T
get(HttpUtils.Worker<T> worker, String url, Map<String,String> headers, String user, String pass)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> Pair<T,org.apache.http.HttpResponse>
getFullResponse(HttpUtils.Worker<T> worker, String url, Map<String,String> headers, String user, String pass)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> Pair<T,org.apache.http.HttpResponse>
getFullResponse(HttpUtils.Worker<T> worker, String url, Map<String,String> headers, String user, String pass, int readTimeout)
           
static HttpUtils.Worker<String> getStringWorker(String encoding)
           
static
<T> T
post(HttpUtils.Worker<T> worker, String url, File postBody, Map<String,String> headers, String user, String pass)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> T
post(HttpUtils.Worker<T> worker, String url, InputStream postBody, Map<String,String> headers)
          Performs an HTTP-Get request and provides typed access to the response.
static
<T> T
post(HttpUtils.Worker<T> worker, String url, Map<String,String> params, Map<String,String> headers, int readTimeout)
           
static
<T> Pair<T,org.apache.http.HttpResponse>
postFullResponse(HttpUtils.Worker<T> worker, String url, Map<String,String> params, Map<String,String> headers, int readTimeout)
           
static
<T> T
retrieve(HttpUtils.Worker<T> worker, DURL url)
           
static
<T> T
retrieve(HttpUtils.Worker<T> worker, String url)
           
static
<T> T
retrieve(HttpUtils.Worker<T> worker, String url, Map<String,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<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<String> UTF8STRING
Returns a decoded String.


JSON

public static final HttpUtils.Worker<com.google.gson.JsonElement> JSON

IMAGE

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

Constructor Detail

HttpUtils

public HttpUtils()
Method Detail

getStringWorker

public static HttpUtils.Worker<String> getStringWorker(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 IOException
Type Parameters:
T -
Parameters:
worker -
url - must be valid
Returns:
some object from the url
Throws:
IOException

retrieve

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

retrieve

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

post

public static <T> T post(HttpUtils.Worker<T> worker,
                         String url,
                         InputStream postBody,
                         Map<String,String> headers)
              throws IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
postBody -
headers - may be null
Returns:
some object from the url
Throws:
IOException

post

public static <T> T post(HttpUtils.Worker<T> worker,
                         String url,
                         Map<String,String> params,
                         Map<String,String> headers,
                         int readTimeout)
              throws IOException
Type Parameters:
T -
Parameters:
worker -
url -
params - KVP parameter map to set in the post body
headers -
Returns:
some object from the url
Throws:
IOException

postFullResponse

public static <T> Pair<T,org.apache.http.HttpResponse> postFullResponse(HttpUtils.Worker<T> worker,
                                                                        String url,
                                                                        Map<String,String> params,
                                                                        Map<String,String> headers,
                                                                        int readTimeout)
                                                             throws IOException
Type Parameters:
T -
Parameters:
worker -
url -
params - KVP parameter map to set in the post body
headers -
Returns:
some object from the url and the http response object for complete inspection
Throws:
IOException

post

public static <T> T post(HttpUtils.Worker<T> worker,
                         String url,
                         File postBody,
                         Map<String,String> headers,
                         String user,
                         String pass)
              throws IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
postBody -
headers - may be null
user - optional username for HTTP basic authentication
pass - optional password for HTTP basic authentication
Returns:
some object from the url
Throws:
IOException

get

public static <T> T get(HttpUtils.Worker<T> worker,
                        String url,
                        Map<String,String> headers)
             throws IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
headers - may be null
Returns:
some object from the url, null, if url is not valid
Throws:
IOException

get

public static <T> T get(HttpUtils.Worker<T> worker,
                        String url,
                        Map<String,String> headers,
                        String user,
                        String pass)
             throws IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
headers - may be null
user - optional username for HTTP basic authentication
pass - optional password for HTTP basic authentication
Returns:
some object from the url, null, if url is not valid
Throws:
IOException

getFullResponse

public static <T> Pair<T,org.apache.http.HttpResponse> getFullResponse(HttpUtils.Worker<T> worker,
                                                                       String url,
                                                                       Map<String,String> headers,
                                                                       String user,
                                                                       String pass)
                                                            throws IOException
Performs an HTTP-Get request and provides typed access to the response.

Type Parameters:
T -
Parameters:
worker -
url -
headers - may be null
user - optional username for HTTP basic authentication
pass - optional password for HTTP basic authentication
Returns:
some object from the url, null, if url is not valid
Throws:
IOException

getFullResponse

public static <T> Pair<T,org.apache.http.HttpResponse> getFullResponse(HttpUtils.Worker<T> worker,
                                                                       String url,
                                                                       Map<String,String> headers,
                                                                       String user,
                                                                       String pass,
                                                                       int readTimeout)
                                                            throws IOException
Throws:
IOException

enableProxyUsage

public static org.apache.http.impl.client.DefaultHttpClient enableProxyUsage(org.apache.http.impl.client.DefaultHttpClient 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:
HttpClient


Copyright © 2011. All Rights Reserved.