Announcement Announcement Module
Collapse
No announcement yet.
Setting http custom headers in outbound-gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting http custom headers in outbound-gateway

    Hi guys,

    I'm trying to implement a Rest "router", using inbound and outbound-gateway, which receives requests and decides which rest service to call based some header values, and finally returns the rest results to the original caller with all the message headers it is expecting.
    I'm having problem in this last part, returning the custom headers to the caller. I found the problem lies in HttpRequestHandlingEndpointSupport class, which always returns the standard headers discarding any custom header present in the rest result.
    In HttpRequestHandlingEndpointSupport javadoc:

    To customize the mapping of request headers to the MessageHeaders, provide a reference to a {@link HeaderMapper
    * HeaderMapper<HttpHeaders>} implementation to the {@link #setHeaderMapper(HeaderMapper)} method.


    but I found no examples on how to do that.
    Could you please give a light?

    Here is the relevant part of my xml configuration:
    <int-http:outbound-gateway
    request-channel="requestChannel"
    reply-channel="replyChannel"
    header-mapper="headerMapper"
    url="[my.rest.service.url]"
    expected-response-type="org.springframework.http.ResponseEntity"
    extract-request-payload="true"
    charset="UTF-8">
    </int-http:outbound-gateway>

    <bean id="headerMapper" class="com.xxx.RestDefaultHttpHeaderMapper">
    <property name="userDefinedHeaderPrefix" value=""/>
    <property name="inboundHeaderNames" value="[some custom headers]"/>
    <property name="outboundHeaderNames" value="[some custom headers]"/>
    </bean>

  • #2
    Hi,

    I've just solved my issue:
    I've put the header-mapper attribute also in the inbound-gateway configuration tag.
    I thought this wasn't possible...
    Thanks anyway.

    Comment


    • #3
      Just be aware that inboundHeaderNames and outboundHeaderNames have the opposite sense for an inbound Vs. and outbound gateway.

      Obviously not a problem if the lists are the same.

      Comment

      Working...
      X