Announcement Announcement Module
Collapse
No announcement yet.
Call a REST web service from Spring Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call a REST web service from Spring Integration

    I am trying to call a REST web service through Spring Integration, i.e. Spring Integration will act as my client to the REST web service. However, whenever I invoke this REST web service, I am getting a missing SOAP envelope error message. Looks like Spring Integration is expecting the Web Service returns the response as a a SOAP message. How do I call a REST WS from Spring Integration? Is it supported? Or do I have to use a different library?

    Please advise.

    Hitesh

  • #2
    For invocation of REST services, you should be able to use the HTTP adapters rather than the "ws" adapters.

    Check out that section of the reference manual, and post back here if you have any more questions.

    By the way, in the 2.0 timeframe, Spring Integration's HTTP adapters will be refactored to use the Spring 3.0 RestTemplate and/or underlying HTTP client API, so if you encounter any limitations with the current implementation, please do provide feedback so that it can be considered during that refactoring.

    Thanks,
    Mark

    Comment


    • #3
      Is RESTTemplate supported for outbound?

      Not sure if RESTTemplate support has been added to the outbound channel? Please advice when we can expect this to be added? Is there any plan to integrate Jersey as well inbound and outbound channels?

      Comment


      • #4
        We are working on the RestTemplate now. It will be included in the upcoming M5 release (probably available within a couple weeks).

        Have you been using the existing HTTP outbound adapter already? If so, I'd be interested in any limitations you've experienced so that we can consider that in the new RestTemplate-based implementation.

        Thanks,
        Mark

        Comment


        • #5
          Did not find any limitation yet, will post if I find any.

          We have just started the integrations effort with 3rd party vendors, need to deploy within next 2 weeks, will post my experience if I find any limitations.

          Comment


          • #6
            Hi,

            Did you find a way to call a REST service from Spring Integration. If so, please revert back to me. I am also facing problems with invoking REST services from Spring Integration.

            Mark,
            Could you please help me in fixing my problem.

            Thanks!!!

            Regards,
            Avinash Munaga.

            Comment


            • #7
              There are many samples available here https://github.com/SpringSource/spri...ation-samples/
              The one you should probably look at is https://github.com/SpringSource/spri...ter/basic/http

              You can also look at the more complex sample here https://github.com/olegz/s12gx.2011/...ation/enricher were the REST call is made to Google finance service to enrich the message.

              Comment


              • #8
                Hi Oleg,

                Thanks for your reply.

                I have gone through the basic example before starting my integration work.

                After viewing your example on gihub tried sending request like this.

                ApplicationContext context = new ClassPathXmlApplicationContext("config-http.xml");
                JSONObject json = new JSONObject();
                //creating JSON
                Message<?> message = MessageBuilder.withPayload(json.toString()).build( );
                context.getBean("requestChannel", MessageChannel.class).send(message);
                But, it's not working. Even tried sending request to integration in a different way like this:

                ApplicationContext context = new ClassPathXmlApplicationContext("config-http.xml");
                JSONObject json = new JSONObject();
                //creating JSON
                Message<?> message = MessageBuilder.withPayload(json.toString()).build( );
                ChannelResolver resolver = new BeanFactoryChannelResolver(context);
                MessageChannel channel = resolver.resolveChannelName("requestChannel");
                channel.send(message);
                This is the error message while sending request in both the cases.

                WARNING: POST request for "https://login.salesforce.com/services/oauth2/token" resulted in 400 (Bad Request); invoking error handler
                Exception in thread "main" org.springframework.integration.MessageHandlingExc eption: HTTP request execution failed for URI [https://login.salesforce.com/services/oauth2/token]
                at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(HttpRequestExecutingMessageHandler.java:284)
                at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:97)
                at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
                at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
                at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
                at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
                at blog.HTTPDemo.main(HTTPDemo.java:59)
                Caused by: org.springframework.web.client.HttpClientErrorExce ption: 400 Bad Request
                at org.springframework.web.client.DefaultResponseErro rHandler.handleError(DefaultResponseErrorHandler.j ava:76)
                at org.springframework.web.client.RestTemplate.handle ResponseError(RestTemplate.java:486)
                at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:443)
                at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:409)
                at org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:384)
                at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(HttpRequestExecutingMessageHandler.java:258)
                ... 8 more
                and this is my configuration file.

                <http:outbound-gateway id="outboundGateway"
                request-channel="requestChannel" reply-channel="httpResponseChannel"
                http-method="POST" auto-startup="true"
                url="https://login.salesforce.com/services/oauth2/token" />

                <int:channel id="httpResponseChannel">
                <int:queue capacity="10" />
                </int:channel>
                Is there something I am doing wrong.

                Thanks in Advance!!!

                Comment


                • #9
                  The example i included are both working samples.
                  You are getting HTTP 400 error,so something is wrong with your request. See more http://www.checkupdown.com/status/E400.html

                  Comment

                  Working...
                  X