Class DefaultHttpBinding

java.lang.Object
org.apache.camel.http.common.DefaultHttpBinding
All Implemented Interfaces:
HttpBinding

public class DefaultHttpBinding extends Object implements HttpBinding
Binding between HttpMessage and HttpServletResponse.

Uses by default the HttpHeaderFilterStrategy

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The data format used for storing java.util.Date instances as a String value.
    static final String
    Whether Date/Locale should be converted to String types (enabled by default)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Deprecated.
    DefaultHttpBinding(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy)
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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 occurred
    void
    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 message
    protected 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 message
    Whitelist of accepted filename extensions for accepting uploaded files.
    org.apache.camel.spi.HeaderFilterStrategy
    Gets the header filter strategy
    protected static SimpleDateFormat
     
    boolean
    Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object
    boolean
    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 mapping
    boolean
    Whether to allow Exchange Form URL Encoded Body HTTP mapping
    boolean
    Whether to allow Exchange Headers HTTP mapping
    boolean
    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
    isText(String contentType)
     
    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 request
    protected 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-object
    void
    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 mapping
    void
    setMapHttpMessageFormUrlEncodedBody(boolean mapHttpMessageFormUrlEncodedBody)
    Whether to allow Exchange Form URL Encoded Body HTTP mapping
    void
    setMapHttpMessageHeaders(boolean mapHttpMessageHeaders)
    Whether to allow Exchange Headers HTTP mapping
    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.
    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 the ServletRequest.getReader() be exposed as the payload of input messages in the Camel Message.getBody() or not.
    protected static String
     
    protected static String
     
    void
    writeResponse(org.apache.camel.Exchange exchange, jakarta.servlet.http.HttpServletResponse response)
    Writes the exchange to the servlet response.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DATE_LOCALE_CONVERSION

      public static final String DATE_LOCALE_CONVERSION
      Whether Date/Locale should be converted to String types (enabled by default)
      See Also:
    • DATE_FORMAT

      public static final String 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 public DefaultHttpBinding(HttpCommonEndpoint endpoint)
      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 interface HttpBinding
      Parameters:
      request - the request
      message - 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 interface HttpBinding
      Parameters:
      exchange - the exchange
      response - 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 interface HttpBinding
      Parameters:
      exception - the exception occurred
      response - 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 interface HttpBinding
      Parameters:
      message - the fault message
      response - the http response
      exchange - 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 interface HttpBinding
      Parameters:
      message - the OUT message
      response - the http response
      exchange - the exchange to provide context for header filtering
      Throws:
      IOException - can be thrown from http response
    • convertHeaderValueToString

      protected String convertHeaderValueToString(org.apache.camel.Exchange exchange, Object headerValue)
    • convertDateAndLocaleLocally

      protected boolean convertDateAndLocaleLocally(org.apache.camel.Exchange exchange)
    • isText

      protected boolean isText(String contentType)
    • copyStream

      protected int copyStream(InputStream is, OutputStream os, int bufferSize) throws IOException
      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 interface HttpBinding
      Parameters:
      request - the request
      message - the message
      Returns:
      the parsed body returned as either a InputStream or a Reader depending on the HttpBinding.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 interface HttpBinding
      Returns:
      true if reader should be used
      See Also:
    • setUseReaderForPayload

      public void setUseReaderForPayload(boolean useReaderForPayload)
      Description copied from interface: HttpBinding
      Should the ServletRequest.getReader() be exposed as the payload of input messages in the Camel Message.getBody() or not. If false then the ServletRequest.getInputStream() will be exposed.

      Is default false.

      Specified by:
      setUseReaderForPayload in interface HttpBinding
      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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
    • 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 interface HttpBinding
      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 interface HttpBinding
      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 use HttpHeaderFilterStrategy

      Specified by:
      setHeaderFilterStrategy in interface HttpBinding
      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 interface HttpBinding
    • 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 interface HttpBinding
    • isMapHttpMessageHeaders

      public boolean isMapHttpMessageHeaders()
      Description copied from interface: HttpBinding
      Whether to allow Exchange Headers HTTP mapping
      Specified by:
      isMapHttpMessageHeaders in interface HttpBinding
    • 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 interface HttpBinding
    • isMapHttpMessageFormUrlEncodedBody

      public boolean isMapHttpMessageFormUrlEncodedBody()
      Description copied from interface: HttpBinding
      Whether to allow Exchange Form URL Encoded Body HTTP mapping
      Specified by:
      isMapHttpMessageFormUrlEncodedBody in interface HttpBinding
    • 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 interface HttpBinding
    • getFileNameExtWhitelist

      public String 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 interface HttpBinding
    • setFileNameExtWhitelist

      public void setFileNameExtWhitelist(String fileNameExtWhitelist)
      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 interface HttpBinding
    • getHttpDateFormat

      protected static SimpleDateFormat getHttpDateFormat()
    • toHttpDate

      protected static String toHttpDate(Date date)
    • toHttpLanguage

      protected static String toHttpLanguage(Locale locale)