Package org.apache.camel.http.common
Class HttpHelper
- java.lang.Object
-
- org.apache.camel.http.common.HttpHelper
-
public final class HttpHelper extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
appendHeader(Map<String,Object> headers, String key, Object value)
Appends the key/value to the headers.static HttpMethods
createMethod(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload)
Creates the HttpMethod to use to call the remote server, often either its GET or POST.static URI
createURI(org.apache.camel.Exchange exchange, String url, HttpCommonEndpoint endpoint)
Creates the URI to invoke.static String
createURL(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint)
Creates the URL to invoke.static Object
deserializeJavaObjectFromStream(InputStream is)
Deprecated.Camel 3.0 Please use the one which has the parameter of camel contextstatic Object
deserializeJavaObjectFromStream(InputStream is, org.apache.camel.CamelContext context)
Deserializes the input stream to a Java objectstatic Object
extractHttpParameterValue(String value)
Extracts the parameter value.static String
getCharsetFromContentType(String contentType)
static boolean
isSecureConnection(String uri)
static boolean
isStatusCodeOk(int statusCode, String okStatusCodeRange)
Checks whether the given http status code is within the ok rangestatic int[]
parserHttpVersion(String s)
static Object
readRequestBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange)
Reads the request body from the given input stream.static Object
readRequestBodyFromServletRequest(javax.servlet.http.HttpServletRequest request, org.apache.camel.Exchange exchange)
Reads the request body from the given http servlet request.static Object
readResponseBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange)
Reads the response body from the given input stream.static void
setCharsetFromContentType(String contentType, org.apache.camel.Exchange exchange)
static void
writeObjectToServletResponse(javax.servlet.ServletResponse response, Object target)
Writes the given object as response body to the servlet responsestatic void
writeObjectToStream(OutputStream stream, Object target)
Writes the given object as response body to the output stream
-
-
-
Method Detail
-
isSecureConnection
public static boolean isSecureConnection(String uri)
-
parserHttpVersion
public static int[] parserHttpVersion(String s) throws ProtocolException
- Throws:
ProtocolException
-
setCharsetFromContentType
public static void setCharsetFromContentType(String contentType, org.apache.camel.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 toHttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT
- Parameters:
response
- servlet responsetarget
- 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 streamtarget
- object to write- Throws:
IOException
- is thrown if error writing
-
deserializeJavaObjectFromStream
@Deprecated public static Object deserializeJavaObjectFromStream(InputStream is) throws ClassNotFoundException, IOException
Deprecated.Camel 3.0 Please use the one which has the parameter of camel contextDeserializes 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 foundIOException
- can be thrown
-
deserializeJavaObjectFromStream
public static Object deserializeJavaObjectFromStream(InputStream is, org.apache.camel.CamelContext context) throws ClassNotFoundException, IOException
Deserializes the input stream to a Java object- Parameters:
is
- input stream for the Java objectcontext
- the camel context which could help us to apply the customer classloader- Returns:
- the java object, or null if input stream was null
- Throws:
ClassNotFoundException
- is thrown if class not foundIOException
- can be thrown
-
readRequestBodyFromServletRequest
public static Object readRequestBodyFromServletRequest(javax.servlet.http.HttpServletRequest request, org.apache.camel.Exchange exchange) throws IOException
Reads the request body from the given http servlet request.- Parameters:
request
- http servlet requestexchange
- the exchange- Returns:
- the request body, can be null if no body
- Throws:
IOException
- is thrown if error reading request body
-
readRequestBodyFromInputStream
public static Object readRequestBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange) throws IOException
Reads the request body from the given input stream.- Parameters:
is
- the input streamexchange
- the exchange- Returns:
- the request body, can be null if no body
- Throws:
IOException
- is thrown if error reading request body
-
readResponseBodyFromInputStream
public static Object readResponseBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange) throws IOException
Reads the response body from the given input stream.- Parameters:
is
- the input streamexchange
- 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(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint)
Creates the URL to invoke.- Parameters:
exchange
- the exchangeendpoint
- the endpoint- Returns:
- the URL to invoke
-
createURI
public static URI createURI(org.apache.camel.Exchange exchange, String url, HttpCommonEndpoint endpoint) throws URISyntaxException
Creates the URI to invoke.- Parameters:
exchange
- the exchangeurl
- the url to invokeendpoint
- the endpoint- Returns:
- the URI to invoke
- Throws:
URISyntaxException
-
appendHeader
public static void appendHeader(Map<String,Object> 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 aList
that contains the multiple values.- Parameters:
headers
- headerskey
- the keyvalue
- 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 aList
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.
-
createMethod
public static HttpMethods createMethod(org.apache.camel.Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException
Creates the HttpMethod to use to call the remote server, often either its GET or POST.- Parameters:
exchange
- the exchange- Returns:
- the created method
- Throws:
URISyntaxException
-
isStatusCodeOk
public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange)
Checks whether the given http status code is within the ok range- Parameters:
statusCode
- the status codeokStatusCodeRange
- the ok range (inclusive)- Returns:
- true if ok, false otherwise
-
-