Announcement Announcement Module
Collapse
No announcement yet.
support for URL Expression for Http Outbound adapter/gateway for Post call Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • support for URL Expression for Http Outbound adapter/gateway for Post call

    https://jira.springsource.org/browse/INT-2570 explains the scenario in case of Get call.

    thats is

    <int-http:outbound-gateway url="{url}" request-channel="vmwChannel" reply-channel="replyChannel"
    expected-response-type="java.lang.String" http-method="GET">
    <int-http:uri-variable name="url" expression="payload" encode="false"/>
    </int-http:outbound-gateway>

    How do we handle when we have a Post call with a request body and a dynamic url
    If i try putting both(string url , object ) in the payload it gives me an error - Cannot add 2 objects in payload.

    I also read some where I can add the dynamic url into the header. But how to add values in header when I am using Spring integration and NOT USING Rest Template object

    Please suggest how do I handle Post calls

  • #2
    You can put the URL (or better yet just the part(s) you need to be dynamic) into one or more Message headers. Then for the expression use "headers.someName" instead of "payload". The payload itself should be what you want converted into the request body. Of course, you also need to change the "http-method" attribute's value to "POST".

    Comment


    • #3
      Hi Mark
      I am unable to add Headers

      I tried 2 approaches---->

      Firstly

      I defined a header-mapper
      In the file ShoppingListHeaderMapper I extended DefaultHttpHeaderMapper and added the headers
      given below code for your reference

      <!-- Defining HTTP outbound Gateway Interface -->
      <bean id="jsonHeaderMapper" class="com.coupons.nextgen.notification.ShoppingLi stHeaderMapper"/>


      <int-http:outbound-gateway request-channel="requestChannel1"
      header-mapper="jsonHeaderMapper"
      reply-channel="replyChannel1" url-expression="headers.url"
      extract-request-payload="true" expected-response-type="java.lang.String" http-method="POST" charset="UTF-8"/>

      public class ShoppingListHeaderMapper extends DefaultHttpHeaderMapper {

      @Override
      public void fromHeaders(MessageHeaders headers, HttpHeaders httpHeaders) {

      httpHeaders.add("CONTENT-TYPE","application/xml");
      httpHeaders.add("ACCEPT","application/xml");

      headers.put("url",{url});
      super.fromHeaders(headers, httpHeaders);
      System.out.println(super.toString());
      }

      }

      But the header url Did not get added

      Secondly

      on the inteface of my gateway I added @header
      as described http://forum.springsource.org/showth...essage+headers

      but got " Message headers is immutable" error .


      Can you please suggest how do i add headers??
      Last edited by Dheerja; Dec 20th, 2012, 04:57 AM.

      Comment


      • #4
        http://static.springsource.org/sprin...eader-enricher

        Comment


        • #5
          Hey Gary


          I have to add headers that are dynamically determined from the content .


          Any suggestions on how to do that??

          Comment


          • #6
            Use an expression...

            Code:
            <int:header-enricher input-channel="in" output-channel="out">
            	<int:header name="foo" expression="payload.someProperty"/>
            </int:header-enricher>

            Comment


            • #7
              Hey Gary

              I cant use Payload.
              I have my request body in payload
              Its a Post call with a Dynamic Url
              I wanted to put the url in the headers from my code so that i can fetch the value in the spring integration file

              Comment


              • #8
                Well, your payload could be a wrapper class that contains the data for your headers as well as the request body in another property; after the header enricher, add a transformer (expression=payload.requestBody).

                If you don't want to do that, and want to manipulate the headers directly, write a @Transformer

                Code:
                @Transformer
                public Message<?> transform(Message<?> message) {
                      return MessageBuilder.fromMessage(message)
                        .setHeader("foo", "bar")
                        .setHeader("baz", "qux")
                        .build();
                }

                Comment

                Working...
                X