Results 1 to 8 of 8

Thread: support for URL Expression for Http Outbound adapter/gateway for Post call

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    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".

  3. #3
    Join Date
    Dec 2012
    Posts
    4

    Default

    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 at 04:57 AM.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Dec 2012
    Posts
    4

    Default

    Hey Gary


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


    Any suggestions on how to do that??

  6. #6
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    Use an expression...

    Code:
    <int:header-enricher input-channel="in" output-channel="out">
    	<int:header name="foo" expression="payload.someProperty"/>
    </int:header-enricher>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  7. #7
    Join Date
    Dec 2012
    Posts
    4

    Default

    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

  8. #8
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    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();
    }
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •