Class DefaultHttpBinding

    • Field Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      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, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange)  
      void doWriteExceptionResponse​(Throwable exception, javax.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, javax.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, javax.servlet.http.HttpServletResponse response, org.apache.camel.Exchange exchange)  
      void 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 message
      String getFileNameExtWhitelist()
      Whitelist of accepted filename extensions for accepting uploaded files.
      org.apache.camel.spi.HeaderFilterStrategy getHeaderFilterStrategy()
      Gets the header filter strategy
      protected static SimpleDateFormat getHttpDateFormat()  
      boolean isAllowJavaSerializedObject()
      Whether to allow java serialization when a request uses context-type=application/x-java-serialized-object
      boolean isEagerCheckContentAvailable()
      Whether to eager check whether the HTTP requests has content if the content-length header is 0 or not present.
      boolean isMapHttpMessageBody()
      Whether to allow Exchange Body HTTP mapping
      boolean isMapHttpMessageFormUrlEncodedBody()
      Whether to allow Exchange Form URL Encoded Body HTTP mapping
      boolean isMapHttpMessageHeaders()
      Whether to allow Exchange Headers HTTP mapping
      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.
      protected boolean isText​(String contentType)  
      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).
      boolean isUseReaderForPayload()
      Should reader by used instead of input stream.
      Object parseBody​(HttpMessage httpMessage)
      Parses the body from a HttpMessage
      protected void populateAttachments​(javax.servlet.http.HttpServletRequest request, HttpMessage message)  
      protected void populateRequestParameters​(javax.servlet.http.HttpServletRequest request, HttpMessage message)  
      protected void readBody​(javax.servlet.http.HttpServletRequest request, HttpMessage message)  
      protected void readFormUrlEncodedBody​(javax.servlet.http.HttpServletRequest request, HttpMessage message)  
      protected void readHeaders​(javax.servlet.http.HttpServletRequest request, HttpMessage message)  
      void readRequest​(javax.servlet.http.HttpServletRequest request, HttpMessage 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 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 toHttpDate​(Date date)  
      protected static String toHttpLanguage​(Locale locale)  
      void writeResponse​(org.apache.camel.Exchange exchange, javax.servlet.http.HttpServletResponse response)
      Writes the exchange to the servlet response.
    • Field Detail

      • DATE_LOCALE_CONVERSION

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

        public static final String DATE_FORMAT
        The data format used for storing java.util.Date instances as a String value.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultHttpBinding

        public DefaultHttpBinding()
      • DefaultHttpBinding

        @Deprecated
        public DefaultHttpBinding​(org.apache.camel.spi.HeaderFilterStrategy headerFilterStrategy)
        Deprecated.
    • Method Detail

      • readRequest

        public void readRequest​(javax.servlet.http.HttpServletRequest request,
                                HttpMessage 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​(javax.servlet.http.HttpServletRequest request,
                                   HttpMessage message)
      • readBody

        protected void readBody​(javax.servlet.http.HttpServletRequest request,
                                HttpMessage message)
      • populateRequestParameters

        protected void populateRequestParameters​(javax.servlet.http.HttpServletRequest request,
                                                 HttpMessage message)
      • populateAttachments

        protected void populateAttachments​(javax.servlet.http.HttpServletRequest request,
                                           HttpMessage message)
      • writeResponse

        public void writeResponse​(org.apache.camel.Exchange exchange,
                                  javax.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,
                                             javax.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,
                                         javax.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,
                                    javax.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)
      • doWriteDirectResponse

        protected void doWriteDirectResponse​(org.apache.camel.Message message,
                                             javax.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,
                                           javax.servlet.http.HttpServletResponse response,
                                           org.apache.camel.Exchange exchange)
                                    throws IOException
        Throws:
        IOException
      • 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
      • 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
      • 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
      • toHttpDate

        protected static String toHttpDate​(Date date)
      • toHttpLanguage

        protected static String toHttpLanguage​(Locale locale)