Class DefaultHttpHeaderMapper

java.lang.Object
org.springframework.integration.http.support.DefaultHttpHeaderMapper
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean, org.springframework.integration.mapping.HeaderMapper<org.springframework.http.HttpHeaders>

public class DefaultHttpHeaderMapper
extends java.lang.Object
implements org.springframework.integration.mapping.HeaderMapper<org.springframework.http.HttpHeaders>, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean
Default HeaderMapper implementation for HTTP.
Since:
2.0
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String CONTENT_MD5  
    protected static java.time.format.DateTimeFormatter[] DATE_FORMATS  
    static java.lang.String HTTP_REQUEST_HEADER_NAME_PATTERN  
    static java.lang.String HTTP_RESPONSE_HEADER_NAME_PATTERN  
    protected org.apache.commons.logging.Log logger  
    static java.lang.String REFRESH  
  • Constructor Summary

    Constructors 
    Constructor Description
    DefaultHttpHeaderMapper()  
  • Method Summary

    Modifier and Type Method Description
    void afterPropertiesSet()  
    protected static boolean containsElementIgnoreCase​(java.lang.String[] headerNames, java.lang.String name)  
    protected java.lang.String convertToString​(java.lang.Object value)  
    void fromHeaders​(org.springframework.messaging.MessageHeaders headers, org.springframework.http.HttpHeaders target)
    Map from the integration MessageHeaders to an HttpHeaders instance.
    protected org.springframework.beans.factory.BeanFactory getBeanFactory()  
    protected static long getFirstDate​(java.lang.String headerValue, java.lang.String headerName)  
    protected java.lang.Object getHttpHeader​(org.springframework.http.HttpHeaders source, java.lang.String name)  
    static DefaultHttpHeaderMapper inboundMapper()
    Factory method for creating a basic inbound mapper instance.
    static DefaultHttpHeaderMapper outboundMapper()
    Factory method for creating a basic outbound mapper instance.
    void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)  
    void setExcludedInboundStandardResponseHeaderNames​(java.lang.String... excludedInboundStandardResponseHeaderNames)
    Provide header names from the list of standard headers that should be suppressed when mapping inbound endpoint response headers.
    void setExcludedOutboundStandardRequestHeaderNames​(java.lang.String... excludedOutboundStandardRequestHeaderNames)
    Provide header names from the list of standard headers that should be suppressed when mapping outbound endpoint request headers.
    void setInboundHeaderNames​(java.lang.String... inboundHeaderNamesArg)
    Provide the header names that should be mapped from an HTTP request (for inbound adapters) or HTTP response (for outbound adapters) to a Spring Integration Message's headers.
    void setOutboundHeaderNames​(java.lang.String... outboundHeaderNames)
    Provide the header names that should be mapped to an HTTP request (for outbound adapters) or HTTP response (for inbound adapters) from a Spring Integration Message's headers.
    protected static void setupDefaultInboundMapper​(DefaultHttpHeaderMapper mapper)
    Subclasses can call this from a static inboundMapper() method to set up standard header mappings for an inbound mapper.
    protected static void setupDefaultOutboundMapper​(DefaultHttpHeaderMapper mapper)
    Subclasses can call this from a static outboundMapper() method to set up standard header mappings for an outbound mapper.
    void setUserDefinedHeaderPrefix​(java.lang.String userDefinedHeaderPrefix)
    Sets the prefix to use with user-defined (non-standard) headers.
    protected boolean shouldMapInboundHeader​(java.lang.String headerName)  
    java.util.Map<java.lang.String,​java.lang.Object> toHeaders​(org.springframework.http.HttpHeaders source)
    Map from an HttpHeaders instance to integration MessageHeaders.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • setBeanFactory

      public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • getBeanFactory

      protected org.springframework.beans.factory.BeanFactory getBeanFactory()
    • setOutboundHeaderNames

      public void setOutboundHeaderNames​(java.lang.String... outboundHeaderNames)
      Provide the header names that should be mapped to an HTTP request (for outbound adapters) or HTTP response (for inbound adapters) from a Spring Integration Message's headers. The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.

      Any non-standard headers will be prefixed with the value specified by setUserDefinedHeaderPrefix(String). The default is 'X-'.

      Parameters:
      outboundHeaderNames - The outbound header names.
    • setInboundHeaderNames

      public void setInboundHeaderNames​(java.lang.String... inboundHeaderNamesArg)
      Provide the header names that should be mapped from an HTTP request (for inbound adapters) or HTTP response (for outbound adapters) to a Spring Integration Message's headers. The values can also contain simple wildcard patterns (e.g. "foo*" or "*foo") to be matched.

      This will match the header name directly or, for non-standard HTTP headers, it will match the header name prefixed with the value specified by setUserDefinedHeaderPrefix(String). The default for that is an empty String.

      Parameters:
      inboundHeaderNamesArg - The inbound header names.
    • setExcludedOutboundStandardRequestHeaderNames

      public void setExcludedOutboundStandardRequestHeaderNames​(java.lang.String... excludedOutboundStandardRequestHeaderNames)
      Provide header names from the list of standard headers that should be suppressed when mapping outbound endpoint request headers.
      Parameters:
      excludedOutboundStandardRequestHeaderNames - the excludedStandardRequestHeaderNames to set
    • setExcludedInboundStandardResponseHeaderNames

      public void setExcludedInboundStandardResponseHeaderNames​(java.lang.String... excludedInboundStandardResponseHeaderNames)
      Provide header names from the list of standard headers that should be suppressed when mapping inbound endpoint response headers.
      Parameters:
      excludedInboundStandardResponseHeaderNames - the excludedStandardResponseHeaderNames to set
    • setUserDefinedHeaderPrefix

      public void setUserDefinedHeaderPrefix​(java.lang.String userDefinedHeaderPrefix)
      Sets the prefix to use with user-defined (non-standard) headers. The default is an empty string.
      Parameters:
      userDefinedHeaderPrefix - The user defined header prefix.
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • fromHeaders

      public void fromHeaders​(org.springframework.messaging.MessageHeaders headers, org.springframework.http.HttpHeaders target)
      Map from the integration MessageHeaders to an HttpHeaders instance. Depending on which type of adapter is using this mapper, the HttpHeaders might be for an HTTP request (outbound adapter) or for an HTTP response (inbound adapter).
      Specified by:
      fromHeaders in interface org.springframework.integration.mapping.HeaderMapper<org.springframework.http.HttpHeaders>
    • toHeaders

      public java.util.Map<java.lang.String,​java.lang.Object> toHeaders​(org.springframework.http.HttpHeaders source)
      Map from an HttpHeaders instance to integration MessageHeaders. Depending on which type of adapter is using this mapper, the HttpHeaders might be from an HTTP request (inbound adapter) or from an HTTP response (outbound adapter).
      Specified by:
      toHeaders in interface org.springframework.integration.mapping.HeaderMapper<org.springframework.http.HttpHeaders>
    • getHttpHeader

      protected java.lang.Object getHttpHeader​(org.springframework.http.HttpHeaders source, java.lang.String name)
    • shouldMapInboundHeader

      protected final boolean shouldMapInboundHeader​(java.lang.String headerName)
    • convertToString

      @Nullable protected java.lang.String convertToString​(java.lang.Object value)
    • containsElementIgnoreCase

      protected static boolean containsElementIgnoreCase​(java.lang.String[] headerNames, java.lang.String name)
    • getFirstDate

      protected static long getFirstDate​(java.lang.String headerValue, java.lang.String headerName)
    • outboundMapper

      public static DefaultHttpHeaderMapper outboundMapper()
      Factory method for creating a basic outbound mapper instance. This will map all standard HTTP request headers when sending an HTTP request, and it will map all standard HTTP response headers when receiving an HTTP response.
      Returns:
      The default outbound mapper.
    • setupDefaultOutboundMapper

      protected static void setupDefaultOutboundMapper​(DefaultHttpHeaderMapper mapper)
      Subclasses can call this from a static outboundMapper() method to set up standard header mappings for an outbound mapper.
      Parameters:
      mapper - the mapper.
    • inboundMapper

      public static DefaultHttpHeaderMapper inboundMapper()
      Factory method for creating a basic inbound mapper instance. This will map all standard HTTP request headers when receiving an HTTP request, and it will map all standard HTTP response headers when sending an HTTP response.
      Returns:
      The default inbound mapper.
    • setupDefaultInboundMapper

      protected static void setupDefaultInboundMapper​(DefaultHttpHeaderMapper mapper)
      Subclasses can call this from a static inboundMapper() method to set up standard header mappings for an inbound mapper.
      Parameters:
      mapper - the mapper.