Class DefaultHttpHeaderMapper

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

public class DefaultHttpHeaderMapper extends Object implements HeaderMapper<HttpHeaders>, BeanFactoryAware, InitializingBean
Default HeaderMapper implementation for HTTP.
Since:
2.0
Author:
Mark Fisher, Jeremy Grelle, Oleg Zhurakousky, Gunnar Hillert, Gary Russell, Artem Bilan
  • Field Details

  • Constructor Details

    • DefaultHttpHeaderMapper

      public DefaultHttpHeaderMapper()
  • Method Details

    • setBeanFactory

      public void setBeanFactory(BeanFactory beanFactory) throws BeansException
      Specified by:
      setBeanFactory in interface BeanFactoryAware
      Throws:
      BeansException
    • getBeanFactory

      protected BeanFactory getBeanFactory()
    • setOutboundHeaderNames

      public void setOutboundHeaderNames(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(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(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(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(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 InitializingBean
    • fromHeaders

      public void fromHeaders(MessageHeaders headers, 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 HeaderMapper<HttpHeaders>
    • toHeaders

      public Map<String,Object> toHeaders(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 HeaderMapper<HttpHeaders>
    • getHttpHeader

      protected Object getHttpHeader(HttpHeaders source, String name)
    • shouldMapInboundHeader

      protected final boolean shouldMapInboundHeader(String headerName)
    • convertToString

      @Nullable protected String convertToString(Object value)
    • containsElementIgnoreCase

      protected static boolean containsElementIgnoreCase(String[] headerNames, String name)
    • getFirstDate

      protected static long getFirstDate(String headerValue, 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.