Package org.apache.camel.http.common
Class DefaultHttpBinding
java.lang.Object
org.apache.camel.http.common.DefaultHttpBinding
- All Implemented Interfaces:
HttpBinding
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultHttpBinding
(HttpCommonEndpoint endpoint) Deprecated.DefaultHttpBinding
(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
checkChunked
(org.apache.camel.Message message, org.apache.camel.Exchange exchange) protected boolean
convertDateAndLocaleLocally
(org.apache.camel.Exchange exchange) protected String
convertHeaderValueToString
(org.apache.camel.Exchange exchange, Object headerValue) protected int
copyStream
(InputStream is, OutputStream os, int bufferSize) protected void
doWriteDirectResponse
(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) void
doWriteExceptionResponse
(Throwable exception, jakarta.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, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) Strategy method that writes the response to the http response stream for a fault messageprotected void
doWriteGZIPResponse
(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) void
doWriteResponse
(org.apache.camel.Message message, jakarta.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 strategyprotected static SimpleDateFormat
boolean
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
If enabled and an Exchange failed processing on the consumer side the exception's stack trace will be logged when the exception stack trace is not sent in the response's body.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.protected boolean
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
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) Parses the body from servlet requestprotected void
populateAttachments
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) protected void
populateRequestParameters
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) protected void
readBody
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) protected void
readFormUrlEncodedBody
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) protected void
readHeaders
(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) void
readRequest
(jakarta.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
setLogException
(boolean logException) If enabled and an Exchange failed processing on the consumer side the exception's stack trace will be logged when the exception stack trace is not sent in the response's body.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.protected static String
toHttpDate
(Date date) protected static String
toHttpLanguage
(Locale locale) void
writeResponse
(org.apache.camel.Exchange exchange, jakarta.servlet.http.HttpServletResponse response) Writes the exchange to the servlet response.
-
Field Details
-
DATE_LOCALE_CONVERSION
Whether Date/Locale should be converted to String types (enabled by default)- See Also:
-
DATE_FORMAT
The data format used for storing java.util.Date instances as a String value.- See Also:
-
-
Constructor Details
-
DefaultHttpBinding
public DefaultHttpBinding() -
DefaultHttpBinding
@Deprecated public DefaultHttpBinding(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy) Deprecated. -
DefaultHttpBinding
Deprecated.
-
-
Method Details
-
readRequest
public void readRequest(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) Description copied from interface:HttpBinding
Strategy to read the given request and bindings it to the given message.- Specified by:
readRequest
in interfaceHttpBinding
- Parameters:
request
- the requestmessage
- the message to populate with data from request
-
readHeaders
protected void readHeaders(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) -
readBody
protected void readBody(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) -
populateRequestParameters
protected void populateRequestParameters(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) -
readFormUrlEncodedBody
protected void readFormUrlEncodedBody(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
populateAttachments
protected void populateAttachments(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) -
writeResponse
public void writeResponse(org.apache.camel.Exchange exchange, jakarta.servlet.http.HttpServletResponse response) throws IOException Description copied from interface:HttpBinding
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
- Specified by:
writeResponse
in interfaceHttpBinding
- Parameters:
exchange
- the exchangeresponse
- the http response- Throws:
IOException
- can be thrown from http response
-
doWriteExceptionResponse
public void doWriteExceptionResponse(Throwable exception, jakarta.servlet.http.HttpServletResponse response) throws IOException Description copied from interface:HttpBinding
Strategy method that writes the response to the http response stream when an exception occurred- Specified by:
doWriteExceptionResponse
in interfaceHttpBinding
- Parameters:
exception
- the exception occurredresponse
- the http response- Throws:
IOException
- can be thrown from http response
-
doWriteFaultResponse
public void doWriteFaultResponse(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException Description copied from interface:HttpBinding
Strategy method that writes the response to the http response stream for a fault message- Specified by:
doWriteFaultResponse
in interfaceHttpBinding
- 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
public void doWriteResponse(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException Description copied from interface:HttpBinding
Strategy method that writes the response to the http response stream for an OUT message- Specified by:
doWriteResponse
in interfaceHttpBinding
- Parameters:
message
- the OUT messageresponse
- the http responseexchange
- the exchange to provide context for header filtering- Throws:
IOException
- can be thrown from http response
-
convertHeaderValueToString
-
convertDateAndLocaleLocally
protected boolean convertDateAndLocaleLocally(org.apache.camel.Exchange exchange) -
isText
-
copyStream
- Throws:
IOException
-
doWriteDirectResponse
protected void doWriteDirectResponse(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException - Throws:
IOException
-
checkChunked
protected boolean checkChunked(org.apache.camel.Message message, org.apache.camel.Exchange exchange) -
doWriteGZIPResponse
protected void doWriteGZIPResponse(org.apache.camel.Message message, jakarta.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange) throws IOException - Throws:
IOException
-
parseBody
public Object parseBody(jakarta.servlet.http.HttpServletRequest request, org.apache.camel.Message message) throws IOException Description copied from interface:HttpBinding
Parses the body from servlet request- Specified by:
parseBody
in interfaceHttpBinding
- Parameters:
request
- the requestmessage
- the message- Returns:
- the parsed body returned as either a
InputStream
or aReader
depending on theHttpBinding.setUseReaderForPayload(boolean)
property. - Throws:
IOException
- can be thrown
-
isUseReaderForPayload
public boolean isUseReaderForPayload()Description copied from interface:HttpBinding
Should reader by used instead of input stream.- Specified by:
isUseReaderForPayload
in interfaceHttpBinding
- Returns:
- true if reader should be used
- See Also:
-
setUseReaderForPayload
public void setUseReaderForPayload(boolean useReaderForPayload) Description copied from interface:HttpBinding
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.- Specified by:
setUseReaderForPayload
in interfaceHttpBinding
- Parameters:
useReaderForPayload
- whether to use reader or not
-
isEagerCheckContentAvailable
public boolean isEagerCheckContentAvailable()Description copied from interface:HttpBinding
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.- Specified by:
isEagerCheckContentAvailable
in interfaceHttpBinding
-
setEagerCheckContentAvailable
public void setEagerCheckContentAvailable(boolean eagerCheckContentAvailable) Description copied from interface:HttpBinding
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.- Specified by:
setEagerCheckContentAvailable
in interfaceHttpBinding
-
isTransferException
public boolean isTransferException()Description copied from interface:HttpBinding
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.- Specified by:
isTransferException
in interfaceHttpBinding
-
setTransferException
public void setTransferException(boolean transferException) Description copied from interface:HttpBinding
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.- Specified by:
setTransferException
in interfaceHttpBinding
-
isMuteException
public boolean isMuteException()Description copied from interface:HttpBinding
If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace.- Specified by:
isMuteException
in interfaceHttpBinding
-
setMuteException
public void setMuteException(boolean muteException) Description copied from interface:HttpBinding
If enabled and an Exchange failed processing on the consumer side the response's body won't contain the exception's stack trace.- Specified by:
setMuteException
in interfaceHttpBinding
-
isLogException
public boolean isLogException()Description copied from interface:HttpBinding
If enabled and an Exchange failed processing on the consumer side the exception's stack trace will be logged when the exception stack trace is not sent in the response's body.- Specified by:
isLogException
in interfaceHttpBinding
-
setLogException
public void setLogException(boolean logException) Description copied from interface:HttpBinding
If enabled and an Exchange failed processing on the consumer side the exception's stack trace will be logged when the exception stack trace is not sent in the response's body.- Specified by:
setLogException
in interfaceHttpBinding
-
isAllowJavaSerializedObject
public boolean isAllowJavaSerializedObject()Description copied from interface:HttpBinding
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.- Specified by:
isAllowJavaSerializedObject
in interfaceHttpBinding
-
setAllowJavaSerializedObject
public void setAllowJavaSerializedObject(boolean allowJavaSerializedObject) Description copied from interface:HttpBinding
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.- Specified by:
setAllowJavaSerializedObject
in interfaceHttpBinding
- Parameters:
allowJavaSerializedObject
- true to allow serializing java objects
-
getHeaderFilterStrategy
public org.apache.camel.spi.HeaderFilterStrategy getHeaderFilterStrategy()Description copied from interface:HttpBinding
Gets the header filter strategy- Specified by:
getHeaderFilterStrategy
in interfaceHttpBinding
- Returns:
- the strategy
-
setHeaderFilterStrategy
public void setHeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy) Description copied from interface:HttpBinding
Sets the header filter strategy to use. Will default useHttpHeaderFilterStrategy
- Specified by:
setHeaderFilterStrategy
in interfaceHttpBinding
- Parameters:
headerFilterStrategy
- the custom strategy
-
isMapHttpMessageBody
public boolean isMapHttpMessageBody()Description copied from interface:HttpBinding
Whether to allow Exchange Body HTTP mapping- Specified by:
isMapHttpMessageBody
in interfaceHttpBinding
-
setMapHttpMessageBody
public void setMapHttpMessageBody(boolean mapHttpMessageBody) Description copied from interface:HttpBinding
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- Specified by:
setMapHttpMessageBody
in interfaceHttpBinding
-
isMapHttpMessageHeaders
public boolean isMapHttpMessageHeaders()Description copied from interface:HttpBinding
Whether to allow Exchange Headers HTTP mapping- Specified by:
isMapHttpMessageHeaders
in interfaceHttpBinding
-
setMapHttpMessageHeaders
public void setMapHttpMessageHeaders(boolean mapHttpMessageHeaders) Description copied from interface:HttpBinding
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- Specified by:
setMapHttpMessageHeaders
in interfaceHttpBinding
-
isMapHttpMessageFormUrlEncodedBody
public boolean isMapHttpMessageFormUrlEncodedBody()Description copied from interface:HttpBinding
Whether to allow Exchange Form URL Encoded Body HTTP mapping- Specified by:
isMapHttpMessageFormUrlEncodedBody
in interfaceHttpBinding
-
setMapHttpMessageFormUrlEncodedBody
public void setMapHttpMessageFormUrlEncodedBody(boolean mapHttpMessageFormUrlEncodedBody) Description copied from interface:HttpBinding
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- Specified by:
setMapHttpMessageFormUrlEncodedBody
in interfaceHttpBinding
-
getFileNameExtWhitelist
Description copied from interface:HttpBinding
Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml.- Specified by:
getFileNameExtWhitelist
in interfaceHttpBinding
-
setFileNameExtWhitelist
Description copied from interface:HttpBinding
Whitelist of accepted filename extensions for accepting uploaded files. Multiple extensions can be separated by comma, such as txt,xml.- Specified by:
setFileNameExtWhitelist
in interfaceHttpBinding
-
getHttpDateFormat
-
toHttpDate
-
toHttpLanguage
-