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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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
      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
      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.
      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
      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.
      void writeResponse​(org.apache.camel.Exchange exchange, javax.servlet.http.HttpServletResponse response)
      Writes the exchange to the servlet response.
    • Method Detail

      • readRequest

        void readRequest​(javax.servlet.http.HttpServletRequest request,
                         HttpMessage message)
        Strategy to read the given request and bindings it to the given message.
        Parameters:
        request - the request
        message - the message to populate with data from request
      • 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 exchange
        response - 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 occurred
        response - 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 message
        response - the http response
        exchange - 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 message
        response - the http response
        exchange - 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:
        for more details
      • setUseReaderForPayload

        void setUseReaderForPayload​(boolean useReaderForPayload)
        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.

        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 use HttpHeaderFilterStrategy

        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

        void setFileNameExtWhitelist​(String fileNameExtWhitelist)
        Whitelist of accepted filename extensions for accepting uploaded files.

        Multiple extensions can be separated by comma, such as txt,xml.