Announcement Announcement Module
No announcement yet.
Call a REST web service from Spring Integration Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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.


  • #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.



    • #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?


      • #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.



        • #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.


          • #6

            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.

            Could you please help me in fixing my problem.


            Avinash Munaga.


            • #7
              There are many samples available here
              The one you should probably look at is

              You can also look at the more complex sample here were the REST call is made to Google finance service to enrich the message.


              • #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");
                This is the error message while sending request in both the cases.

                WARNING: POST request for "" resulted in 400 (Bad Request); invoking error handler
                Exception in thread "main" org.springframework.integration.MessageHandlingExc eption: HTTP request execution failed for URI []
                at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(
                at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A
                at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch( :114)
                at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch( 01)
                at bscribableChannel.doSend(AbstractSubscribableChann
                at ssageChannel.send(
                at ssageChannel.send(
                at blog.HTTPDemo.main(
                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(
                at org.springframework.web.client.RestTemplate.doExec ute(
                at org.springframework.web.client.RestTemplate.execut e(
                at org.springframework.web.client.RestTemplate.exchan ge(
                at org.springframework.integration.http.outbound.Http RequestExecutingMessageHandler.handleRequestMessag e(
                ... 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="" />

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

                Thanks in Advance!!!


                • #9
                  The example i included are both working samples.
                  You are getting HTTP 400 error,so something is wrong with your request. See more