Package org.apache.camel.http.common
Interface HttpBinding
- All Known Implementing Classes:
DefaultHttpBinding
public interface HttpBinding
A pluggable strategy for configuring the http binding so reading request and writing response can be customized using
the Java Servlet API.
This is also used by the camel-jetty component in the JettyHttpConsumer class.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
doWriteExceptionResponse
(Throwable exception, javax.servlet.http.HttpServletResponse response) Strategy method that writes the response to the http response stream when an exception occurredvoid
doWriteFaultResponse
(org.apache.camel.Message message, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) Strategy method that writes the response to the http response stream for a fault messagevoid
doWriteResponse
(org.apache.camel.Message message, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) Strategy method that writes the response to the http response stream for an OUT messageWhitelist of accepted filename extensions for accepting uploaded files.org.apache.camel.spi.HeaderFilterStrategy
Gets the header filter strategyboolean
Whether to allow java serialization when a request uses context-type=application/x-java-serialized-objectboolean
Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present.boolean
Whether to allow Exchange Body HTTP mappingboolean
Whether to allow Exchange Form URL Encoded Body HTTP mappingboolean
Whether to allow Exchange Headers HTTP mappingboolean
If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace.boolean
If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or Servlet Camel components).boolean
Should reader by used instead of input stream.parseBody
(javax.servlet.http.HttpServletRequest request, org.apache.camel.Message message) Parses the body from servlet requestvoid
readRequest
(javax.servlet.http.HttpServletRequest request, org.apache.camel.Message message) Strategy to read the given request and bindings it to the given message.void
setAllowJavaSerializedObject
(boolean allowJavaSerializedObject) Whether to allow java serialization when a request uses context-type=application/x-java-serialized-objectvoid
setEagerCheckContentAvailable
(boolean eagerCheckContentAvailable) Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present.void
setFileNameExtWhitelist
(String fileNameExtWhitelist) Whitelist of accepted filename extensions for accepting uploaded files.void
setHeaderFilterStrategy
(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy) Sets the header filter strategy to use.void
setMapHttpMessageBody
(boolean mapHttpMessageBody) Whether to allow Exchange Body HTTP mappingvoid
setMapHttpMessageFormUrlEncodedBody
(boolean mapHttpMessageFormUrlEncodedBody) Whether to allow Exchange Form URL Encoded Body HTTP mappingvoid
setMapHttpMessageHeaders
(boolean mapHttpMessageHeaders) Whether to allow Exchange Headers HTTP mappingvoid
setMuteException
(boolean muteException) If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace.void
setTransferException
(boolean transferException) If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or Servlet Camel components).void
setUseReaderForPayload
(boolean useReaderForPayload) Should theServletRequest.getReader()
be exposed as the payload of input messages in the CamelMessage.getBody()
or not.void
writeResponse
(org.apache.camel.Exchange exchange, javax.servlet.http.HttpServletResponse response) Writes the exchange to the servlet response.
-
Method Details
-
readRequest
void readRequest(javax.servlet.http.HttpServletRequest request, org.apache.camel.Message message) Strategy to read the given request and bindings it to the given message.- Parameters:
request
- the requestmessage
- the message to populate with data from request
-
parseBody
Object parseBody(javax.servlet.http.HttpServletRequest request, org.apache.camel.Message message) throws IOException Parses the body from servlet request- Parameters:
request
- the requestmessage
- the message- Returns:
- the parsed body returned as either a
InputStream
or aReader
depending on thesetUseReaderForPayload(boolean)
property. - Throws:
IOException
- can be thrown
-
writeResponse
void writeResponse(org.apache.camel.Exchange exchange, javax.servlet.http.HttpServletResponse response) throws IOException Writes the exchange to the servlet response. Default implementation will delegate to the following methods depending on the status of the exchange- doWriteResponse - processing returns a OUT message
- doWriteFaultResponse - processing returns a fault message
- doWriteResponse - processing returns an exception and status code 500
- Parameters:
exchange
- the exchangeresponse
- the http response- Throws:
IOException
- can be thrown from http response
-
doWriteExceptionResponse
void doWriteExceptionResponse(Throwable exception, javax.servlet.http.HttpServletResponse response) throws IOException Strategy method that writes the response to the http response stream when an exception occurred- Parameters:
exception
- the exception occurredresponse
- the http response- Throws:
IOException
- can be thrown from http response
-
doWriteFaultResponse
void doWriteFaultResponse(org.apache.camel.Message message, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException Strategy method that writes the response to the http response stream for a fault message- Parameters:
message
- the fault messageresponse
- the http responseexchange
- the exchange to provide context for header filtering- Throws:
IOException
- can be thrown from http response
-
doWriteResponse
void doWriteResponse(org.apache.camel.Message message, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException Strategy method that writes the response to the http response stream for an OUT message- Parameters:
message
- the OUT messageresponse
- the http responseexchange
- the exchange to provide context for header filtering- Throws:
IOException
- can be thrown from http response
-
isUseReaderForPayload
boolean isUseReaderForPayload()Should reader by used instead of input stream.- Returns:
- true if reader should be used
- See Also:
-
setUseReaderForPayload
void setUseReaderForPayload(boolean useReaderForPayload) Should theServletRequest.getReader()
be exposed as the payload of input messages in the CamelMessage.getBody()
or not. If false then theServletRequest.getInputStream()
will be exposed. Is default false.- Parameters:
useReaderForPayload
- whether to use reader or not
-
isTransferException
boolean isTransferException()If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk. -
isMuteException
boolean isMuteException()If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace. -
isAllowJavaSerializedObject
boolean isAllowJavaSerializedObject()Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk. -
isEagerCheckContentAvailable
boolean isEagerCheckContentAvailable()Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. This can be turned on in case HTTP clients do not send streamed data. -
isMapHttpMessageBody
boolean isMapHttpMessageBody()Whether to allow Exchange Body HTTP mapping -
isMapHttpMessageHeaders
boolean isMapHttpMessageHeaders()Whether to allow Exchange Headers HTTP mapping -
isMapHttpMessageFormUrlEncodedBody
boolean isMapHttpMessageFormUrlEncodedBody()Whether to allow Exchange Form URL Encoded Body HTTP mapping -
setEagerCheckContentAvailable
void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present. This can be turned on in case HTTP clients do not send streamed data. -
setTransferException
void setTransferException(boolean transferException) If enabled and an Exchange failed processing on the consumer side, and if the caused Exception was send back serialized in the response as a application/x-java-serialized-object content type (for example using Jetty or Servlet Camel components). On the producer side the exception will be deserialized and thrown as is, instead of the HttpOperationFailedException. The caused exception is required to be serialized. This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk. -
setMuteException
void setMuteException(boolean muteException) If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace. -
setAllowJavaSerializedObject
void setAllowJavaSerializedObject(boolean allowJavaSerializedObject) Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object This is by default turned off. If you enable this then be aware that Java will deserialize the incoming data from the request to Java and that can be a potential security risk.- Parameters:
allowJavaSerializedObject
- true to allow serializing java objects
-
getHeaderFilterStrategy
org.apache.camel.spi.HeaderFilterStrategy getHeaderFilterStrategy()Gets the header filter strategy- Returns:
- the strategy
-
setHeaderFilterStrategy
void setHeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy) Sets the header filter strategy to use. Will default useHttpHeaderFilterStrategy
- Parameters:
headerFilterStrategy
- the custom strategy
-
setMapHttpMessageBody
void setMapHttpMessageBody(boolean mapHttpMessageBody) Whether to allow Exchange Body HTTP mapping This is by default turned on. If you disable this then be aware that the Exchange body won't be mapped to HTTP -
setMapHttpMessageHeaders
void setMapHttpMessageHeaders(boolean mapHttpMessageHeaders) Whether to allow Exchange Headers HTTP mapping This is by default turned on. If you disable this then be aware that the Exchange headers won't be mapped to HTTP -
setMapHttpMessageFormUrlEncodedBody
void setMapHttpMessageFormUrlEncodedBody(boolean mapHttpMessageFormUrlEncodedBody) Whether to allow Exchange Form URL Encoded Body HTTP mapping This is by default turned on. If you disable this then be aware that the Exchange Form URL Encoded Body won't be mapped to HTTP -
getFileNameExtWhitelist
String getFileNameExtWhitelist()Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml. -
setFileNameExtWhitelist
Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml.
-