org.apache.camel.component.http4.helper
Class HttpHelper

java.lang.Object
  extended by org.apache.camel.component.http4.helper.HttpHelper

public final class HttpHelper
extends Object


Method Summary
static void appendHeader(Map headers, String key, Object value)
          Appends the key/value to the headers.
static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload)
          Creates the HttpMethod to use to call the remote server, often either its GET or POST.
static String createURL(Exchange exchange, HttpEndpoint endpoint)
          Creates the URL to invoke.
static Object deserializeJavaObjectFromStream(InputStream is)
          Deserializes the input stream to a Java object
static Object extractHttpParameterValue(String value)
          Extracts the parameter value.
static boolean isSecureConnection(String uri)
           
static org.apache.http.HttpVersion parserHttpVersion(String s)
           
static Object readResponseBodyFromInputStream(InputStream is, Exchange exchange)
          Reads the response body from the given input stream.
static Object readResponseBodyFromServletRequest(javax.servlet.http.HttpServletRequest request, Exchange exchange)
          Reads the response body from the given http servlet request.
static void setCharsetFromContentType(String contentType, Exchange exchange)
           
static void writeObjectToServletResponse(javax.servlet.ServletResponse response, Object target)
          Writes the given object as response body to the servlet response

The content type will be set to HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT

static void writeObjectToStream(OutputStream stream, Object target)
          Writes the given object as response body to the output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setCharsetFromContentType

public static void setCharsetFromContentType(String contentType,
                                             Exchange exchange)

writeObjectToServletResponse

public static void writeObjectToServletResponse(javax.servlet.ServletResponse response,
                                                Object target)
                                         throws IOException
Writes the given object as response body to the servlet response

The content type will be set to HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT

Parameters:
response - servlet response
target - object to write
Throws:
IOException - is thrown if error writing

writeObjectToStream

public static void writeObjectToStream(OutputStream stream,
                                       Object target)
                                throws IOException
Writes the given object as response body to the output stream

Parameters:
stream - output stream
target - object to write
Throws:
IOException - is thrown if error writing

deserializeJavaObjectFromStream

public static Object deserializeJavaObjectFromStream(InputStream is)
                                              throws ClassNotFoundException,
                                                     IOException
Deserializes the input stream to a Java object

Parameters:
is - input stream for the Java object
Returns:
the java object, or null if input stream was null
Throws:
ClassNotFoundException - is thrown if class not found
IOException - can be thrown

readResponseBodyFromServletRequest

public static Object readResponseBodyFromServletRequest(javax.servlet.http.HttpServletRequest request,
                                                        Exchange exchange)
                                                 throws IOException
Reads the response body from the given http servlet request.

Parameters:
request - http servlet request
exchange - the exchange
Returns:
the response body, can be null if no body
Throws:
IOException - is thrown if error reading response body

readResponseBodyFromInputStream

public static Object readResponseBodyFromInputStream(InputStream is,
                                                     Exchange exchange)
                                              throws IOException
Reads the response body from the given input stream.

Parameters:
is - the input stream
exchange - the exchange
Returns:
the response body, can be null if no body
Throws:
IOException - is thrown if error reading response body

createURL

public static String createURL(Exchange exchange,
                               HttpEndpoint endpoint)
Creates the URL to invoke.

Parameters:
exchange - the exchange
endpoint - the endpoint
Returns:
the URL to invoke

createMethod

public static HttpMethods createMethod(Exchange exchange,
                                       HttpEndpoint endpoint,
                                       boolean hasPayload)
Creates the HttpMethod to use to call the remote server, often either its GET or POST.

Parameters:
exchange - the exchange
Returns:
the created method

parserHttpVersion

public static org.apache.http.HttpVersion parserHttpVersion(String s)
                                                     throws org.apache.http.ProtocolException
Throws:
org.apache.http.ProtocolException

isSecureConnection

public static boolean isSecureConnection(String uri)

appendHeader

public static void appendHeader(Map headers,
                                String key,
                                Object value)
Appends the key/value to the headers.

This implementation supports keys with multiple values. In such situations the value will be a List that contains the multiple values.

Parameters:
headers - headers
key - the key
value - the value

extractHttpParameterValue

public static Object extractHttpParameterValue(String value)
Extracts the parameter value.

This implementation supports HTTP multi value parameters which is based on the syntax of [value1, value2, value3] by returning a List containing the values.

If the value is not a HTTP mulit value the value is returned as is.

Parameters:
value - the parameter value
Returns:
the extracted parameter value, see more details in javadoc.


Apache CAMEL