Package org.apache.camel.http.common
Class HttpHelper
java.lang.Object
org.apache.camel.http.common.HttpHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Appends the key/value to the headers.static Object
cacheResponseBodyFromInputStream
(InputStream is, org.apache.camel.Exchange exchange) Caches the response body from the given input stream, which is needed byPollingConsumer
.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
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[]
static Object
readRequestBodyFromServletRequest
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Exchange exchange) Reads the request body from the given http servlet request.static String[]
sanitizeLog
(String[] input) Sanitize log: it removes any new line and carriage return in order to avoid third party integrations with logging system to suffer potential log injection.static void
setCharsetFromContentType
(String contentType, org.apache.camel.Exchange exchange) static void
writeObjectToServletResponse
(jakarta.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 Details
-
isSecureConnection
-
parserHttpVersion
- Throws:
ProtocolException
-
setCharsetFromContentType
public static void setCharsetFromContentType(String contentType, org.apache.camel.Exchange exchange) -
getCharsetFromContentType
-
writeObjectToServletResponse
public static void writeObjectToServletResponse(jakarta.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
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(jakarta.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
-
cacheResponseBodyFromInputStream
public static Object cacheResponseBodyFromInputStream(InputStream is, org.apache.camel.Exchange exchange) throws IOException Caches the response body from the given input stream, which is needed byPollingConsumer
.- Parameters:
is
- the input streamexchange
- the exchange- Returns:
- the cached response body
- Throws:
IOException
- is thrown if error reading response body
-
createURL
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
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
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
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
-
sanitizeLog
Sanitize log: it removes any new line and carriage return in order to avoid third party integrations with logging system to suffer potential log injection.- Parameters:
input
- the log trace- Returns:
- a sanitized log trace
-