Announcement Announcement Module
Collapse
No announcement yet.
http:outbound-gateway - Resttemplate method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • http:outbound-gateway - Resttemplate method

    I am trying to invoke a rest service from SI using http:outbound-gateway. When I look at the source code of SI, I believe that it in turn using RestTemplate.exchange method in org.springframework.integration.http.HttpRequestEx ecutingMessageHandler class.

    There is an issue with the 3rd party rest service. When I try to execute using resttemplate exchage method with http method "GET", it give an http page as response, instead of the xml response. However, if I use Resttemplate getForObject method, it worked properly and gave proper xml response. The same html response is getting returned if I use SI because it uses Resttemplate exchange method.
    Is there any work around in SI? Can I somehow ask SI to use Resttemplate getForObbject method in http:outbound-gateway?

    Or Is there any way to change the resttemplate method that is use in http:outbound-gateway?

    Thanks.

  • #2
    Could you please post the gateway configuration?
    Also, when executing RestTemplate.exchange(..) method what type of 'responseType' type you provide?

    Comment


    • #3
      Below is my gateway configuration:
      <int-http:outbound-gateway id="example" request-channel="requests" url="http://localhost/test" http-method="GET" expected-response-type="java.lang.String"
      reply-channel="replies"/>

      Is there any way to change the Resttemplate method getting invoke?

      Comment


      • #4
        When you invoke getForObject() method what 'responseType' do you provide?

        Comment


        • #5
          Yes. This is the method that I invoked from RestTemplate class
          public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables)

          Comment


          • #6
            PLease read my question again since you did not answer it. What is the type of the 'responseType' you are providing to the above method?

            Comment


            • #7
              It is the same java.lang.String only

              Comment


              • #8
                Hi!
                Which "Content-Type" are you getting from Response?
                And maybe you are sending some "Accept" from you SI-flow...
                Can you DEBUG both scenarios (SI and direct Resttemplate) and say us what's going on? Where Spring Integration is not right .
                And which version of Spring Integration & Spring Web do you use?

                Take care,
                Artem

                Comment


                • #9
                  As I mentioned earlier, I have used Resttemplate directly for debugging. When I invoke using RestTemplate.exchange, it returned the client request html page. I have tried with all kind of content-type and accept in the header.
                  Now I have invoked using RestTemplate.getForObject method, I get the proper xml response. So, I believe the resttemplate.exchange is not working properly for my rest service.

                  So my question is, as SI used RestTemplate.exchange method in http:outbound-gateway, is it possible to invoke some other method provided by RestTemplate class in SI? If not, then do you not think that you should provide this, as RestTemplate class has in turned so many public methods?

                  I am using spring integration 2.1.0 version.
                  Last edited by Mission; Dec 5th, 2012, 11:18 AM.

                  Comment


                  • #10
                    So, I believe the resttemplate.exchange is not working properly for my rest service.
                    Well, there is some difference between 'getForObject' & 'exchange': AcceptHeaderRequestCallback for first one and HttpEntityRequestCallback for other.
                    So, that's why I ask you to debug it.
                    And I believe you're sending some headers to the service by which he means that he should send you back HTML instead of XML...

                    Comment

                    Working...
                    X