Announcement Announcement Module
Collapse
No announcement yet.
Stuck with an error while implementing Spring Integration using HTTP-outbound gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stuck with an error while implementing Spring Integration using HTTP-outbound gateway

    Hi All,

    I am developing a web application which calls a web-service that provides HttpBinding to implement it. So, I thought of using <http:outboundgateway> in my config file.

    But, when I call the service I am getting this error -
    "Caused by: org.springframework.web.client.HttpClientErrorExce ption: 415 Cannot process the message because the content type 'text/plain;charset=UTF-8' was not the expected type 'text/xml; charset=utf-8'."

    This is my config file.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans:beans xmlns="http://www.springframework.org/schema/integration"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:int="http://www.springframework.org/schema/integration"
    	xmlns:stream="http://www.springframework.org/schema/integration/stream"
    	xmlns:ws="http://www.springframework.org/schema/integration/ws"
    	xmlns:int-http="http://www.springframework.org/schema/integration/http"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    		http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/integration
    		http://www.springframework.org/schema/integration/spring-integration.xsd
    		http://www.springframework.org/schema/integration/stream
    		http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
    		http://www.springframework.org/schema/integration/ws
    		http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
    		http://www.springframework.org/schema/integration/http
    		http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
    
    	<int-http:outbound-gateway id="example" request-channel="input_userdetails"
    				url="http://xxxxxxxx/AuthenticationService/Service1.svc?wsdl"
    				http-method="POST" expected-response-type="java.lang.String"
    				charset="UTF-8" reply-channel="output_sessiontoken"/>
    
    	<!-- The response from the service is logged to the console. -->
    	<stream:stdout-channel-adapter id="output_sessiontoken" />
    	
    </beans:beans>
    Also, this is my class calling the service.

    Code:
    public class UserSessionID_RiskMaster {
    
    	public static void main(String[] args) {
    		ClassPathXmlApplicationContext context = 
                                        new ClassPathXmlApplicationContext("blog/authenticate-config.xml");
    		ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
    
    		// Compose the XML message according to the server's schema
    
    		String requestXml = "<GetUserSessionID>" +
    				"   <struserInfo>" +
    				"      <Message><Call><Function>LoginAdaptor.Authorization</Function>" +
    				"         </Call><Document><Authorization><UserInfo><UserName>csc</UserName>" +
    				"	  <DSNName>RMXR7_MOBILE_FEB16</DSNName</UserInfo></Authorization>" +
    				"      </Document></Message>" +
    				"   </struserInfo> " +
    				"</GetUserSessionID>";
    		// Create the Message object
    		Message<String> message = MessageBuilder.withPayload(requestXml).build();
    
    		// Send the Message to the handler's input channel
    		MessageChannel channel = channelResolver
    				.resolveChannelName("input_userdetails");
    		System.out.println("Headers : " + message.getHeaders());
    		channel.send(message);
    
    	}
    }
    The error here is that, what ever the input I am giving to the URL is going in a text/plain format. But, the service is expecting a text/xml format. So, can any one provide me information of where to change/append in my code so, that the xml I am sending to the service will be an XML instead of plain text.

    Awaiting for some help as it is really necessary.

    Thanks in Advance.

    Regards,
    Avinash Munaga

  • #2
    When creating the Spring Integration Message, set the "content-type" header to "text/xml".

    HTH,
    Mark

    Comment


    • #3
      You can set 'Content-Type' as Message header
      Code:
      Message<String> message = MessageBuilder.withPayload(requestXml).setHeader("Content-Type", "text/xml").build();
      Since 'Content-Type' is a standard HTTP header it will be copied from SI Headers to HTTP headers.

      Comment


      • #4
        Originally posted by oleg.zhurakousky View Post
        You can set 'Content-Type' as Message header
        Code:
        Message<String> message = MessageBuilder.withPayload(requestXml).setHeader("Content-Type", "text/xml").build();
        Since 'Content-Type' is a standard HTTP header it will be copied from SI Headers to HTTP headers.
        Thanks for your reply. This error is resolved.

        Now, after changing my xml as
        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        
        <beans:beans xmlns="http://www.springframework.org/schema/integration"
        	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        	xmlns:beans="http://www.springframework.org/schema/beans"
        	xmlns:int="http://www.springframework.org/schema/integration"
        	xmlns:stream="http://www.springframework.org/schema/integration/stream"
        	xmlns:ws="http://www.springframework.org/schema/integration/ws"
        	xmlns:int-http="http://www.springframework.org/schema/integration/http"
        	xsi:schemaLocation="http://www.springframework.org/schema/beans
        		http://www.springframework.org/schem...ring-beans.xsd
        		http://www.springframework.org/schema/integration
        		http://www.springframework.org/schem...ntegration.xsd
        		http://www.springframework.org/schem...gration/stream
        		http://www.springframework.org/schem...ion-stream.xsd
        		http://www.springframework.org/schema/integration/ws
        		http://www.springframework.org/schem...gration-ws.xsd
        		http://www.springframework.org/schema/integration/http
        		http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
                <int:chain input-channel="input_userdetails" output-channel="output_sessiontoken">
        		<ws:header-enricher>
        			<ws:soap-action value="http://tempuri.org/GetUserSessionID" />
        		</ws:header-enricher>
        	</int:chain>
        	<int-http:outbound-gateway id="example" request-channel="input_userdetails"
        				url="http://xxxxxxxx/AuthenticationService/Service1.svc?wsdl"
        				http-method="POST" expected-response-type="java.lang.String"
        				charset="UTF-8" reply-channel="output_sessiontoken"/>
        
        	<!-- The response from the service is logged to the console. -->
        	<stream:stdout-channel-adapter id="output_sessiontoken" />
        	
        </beans:beans>
        I am getting output same as my input.

        Can any one help me with this as I am not able to figure out the cause of this.

        Comment


        • #5
          Hello.

          Why don't you use
          Code:
          <ws:outbound-gateway/>
          ?
          And why do you make request to WSDL-URL:
          url="http://xxxxxxxx/AuthenticationService/Service1.svc?wsdl"
          ?

          Artem Bilan

          Comment


          • #6
            Originally posted by Cleric View Post
            Hello.

            Why don't you use
            Code:
            <ws:outbound-gateway/>
            ?
            And why do you make request to WSDL-URL:
            ?

            Artem Bilan
            Got my problem solved. Sorry for not updating. Used <ws:outbound-gateway/> and I got the response from the web service. And about WSDL, I have to use this URL to fetch information from the web service.

            Thanks for the response.

            Comment


            • #7
              Could you explain uri value for the int-ws:outbound-gateway

              The below is my code , i am getting an exception. Is the WSDL referance to the url attribute is correct , if not how do i find right uri value from wsdl file, please help ..

              <int:chain input-channel="httpOutboundSenderChannel" output-channel="fnoResponseChannel" >
              <int:header-enricher>
              <int:header name="SoapAction" value="urn:createEntitlement"/>
              </int:header-enricher>
              <int-ws:outbound-gateway uri="http://abcccer04:8080/abcService/services/someservice?wsdl" />
              </int:chain>

              Comment


              • #8
                if not how do i find right uri value from wsdl file
                Service ULR should be in the end of WDL:
                HTML Code:
                <wsdl:service name="SomeService">
                   <wsdl:port name="SomeService-ServiceHttpPort" binding="tns:SomeService-ServiceHttpBinding">
                      <wsdlsoap:address location="http://host:port/Service-URL"/>
                   </wsdl:port>
                </wsdl:service>

                Comment


                • #9
                  Thanks for the responce. I am having trouble use operation in the WSDL file. My wsdl contains multiple operations . i only need to invoke one operation, kindly explain how do i do that

                  WS input channel name: httpOutboundSenderChannel , this channel carries the XML payload- for the webservice call.

                  WS output channel name: fnoResponseChannel , this channel i use to receive webservice responce after invoking the WS.


                  I only need to invoke one operation since WSDL contains mutiple operations. Please help..

                  Thanks
                  Vibin
                  Last edited by vibin12; Feb 16th, 2012, 10:07 AM.

                  Comment


                  • #10
                    H-m...

                    Vibin, maybe you should study what is SOAP at first?
                    And then please read this: http://static.springsource.org/sprin...tml/index.html.
                    Right now it seems like you have some gaps in the theory...
                    And also Soap-UI is for you to help.

                    And one more: https://github.com/SpringSource/spri...tbound-gateway

                    Take care,
                    Artem

                    Comment


                    • #11
                      Thanks for your help , i am going through the webservce documentation you have sent. however i am getting this error when i invoke the service in the chain, please advise , do i need to change the integration components , just curious wheather i am following a wrong path or not.

                      this is my webservice outbound-gateway cofuguration.


                      <int:chain input-channel="httpOutboundSenderChannel" output-channel="fnoResponseChannel" >
                      <int:header-enricher>
                      <int:header name="springintegration_ws_soapAction" value="urn:createEntitlement" />
                      </int:header-enricher>
                      <int-ws:outbound-gateway uri="http://10.254.175.153:8080/PoeticToFNOTranslationService/services/PoeticToFNOTranslationService.PoeticToFNOTranslati onServiceHttpSoap12Endpoint/" />
                      </int:chain>


                      This below is the exception message :
                      org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:79)
                      org.springframework.integration.handler.MessageHan dlerChain$1.send(MessageHandlerChain.java:154)
                      org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
                      org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendMessage(AbstractRep lyProducingMessageHandler.java:175)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendReplyMessage(Abstra ctReplyProducingMessageHandler.java:159)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.produceReply(AbstractRe plyProducingMessageHandler.java:124)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleResult(AbstractRe plyProducingMessageHandler.java:118)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:100)
                      org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                      org.springframework.integration.handler.MessageHan dlerChain.handleMessageInternal(MessageHandlerChai n.java:137)
                      org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
                      org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
                      org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
                      org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
                      org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
                      org.springframework.integration.router.AbstractMes sageRouter.handleMessageInternal(AbstractMessageRo uter.java:128)
                      org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
                      org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
                      org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
                      org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
                      org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
                      org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendMessage(AbstractRep lyProducingMessageHandler.java:175)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendReplyMessage(Abstra ctReplyProducingMessageHandler.java:159)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.produceReply(AbstractRe plyProducingMessageHandler.java:124)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleResult(AbstractRe plyProducingMessageHandler.java:118)
                      org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:100)
                      org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :114)
                      org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 01)
                      org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
                      org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
                      org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
                      org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
                      org.springframework.integration.core.MessagingTemp late.convertAndSend(MessagingTemplate.java:189)
                      org.springframework.integration.gateway.MessagingG atewaySupport.send(MessagingGatewaySupport.java:18 3)
                      org.springframework.integration.http.inbound.HttpR equestHandlingEndpointSupport.doHandleRequest(Http RequestHandlingEndpointSupport.java:393)
                      org.springframework.integration.http.inbound.HttpR equestHandlingMessagingGateway.handleRequest(HttpR equestHandlingMessagingGateway.java:95)
                      org.springframework.web.servlet.mvc.HttpRequestHan dlerAdapter.handle(HttpRequestHandlerAdapter.java: 49)
                      org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
                      org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
                      org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:669)
                      org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:585)
                      javax.servlet.http.HttpServlet.service(HttpServlet .java:641)
                      javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
                      org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:304)
                      org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:210)
                      org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:224)
                      org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
                      org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:472)
                      org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:164)
                      org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:100)
                      org.apache.catalina.valves.AccessLogValve.invoke(A ccessLogValve.java:929)
                      org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:118)
                      com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.traceNextVa lve(HttpRequestOperationCollectionValve.java:112)
                      com.springsource.insight.collection.tcserver.reque st.HttpRequestOperationCollectionValve.invoke(Http RequestOperationCollectionValve.java:94)
                      org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:405)
                      org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:279)
                      org.apache.coyote.AbstractProtocol$AbstractConnect ionHandler.process(AbstractProtocol.java:515)
                      org.apache.tomcat.util.net.JIoEndpoint$SocketProce ssor.run(JIoEndpoint.java:300)
                      java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
                      java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
                      java.lang.Thread.run(Unknown Source)


                      <int-stream:stdout-channel-adapter id="fnoResponseChannel"/>

                      When i invoke this iam getting the below exception. however when i invoke the outbound-gateway as stand alone , no exception is thrown ..

                      Please help

                      Comment


                      • #12
                        It's not full stackTrace...

                        Can you attache it entire?

                        Comment


                        • #13
                          I modified my implimentation as below:

                          <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMe ssageFactory"/>

                          <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServi ceTemplate">
                          <constructor-arg ref="messageFactory"/>
                          <property name="messageSender">
                          <bean class="org.springframework.ws.transport.http.Commo nsHttpMessageSender">
                          <property name="credentials">
                          <bean class="org.apache.commons.httpclient.UsernamePassw ordCredentials">
                          <constructor-arg value=""/>
                          <constructor-arg value=""/>
                          </bean>
                          </property>
                          </bean>
                          </property>
                          <property name="defaultUri" value="http://some server:8015/abc/services/TranslationService.fnoTranslationServiceHttpSoap12 Endpoint/"/>
                          </bean>


                          Now I am able to sent SOAP request to the end point and gives a falt response back, the issue is SOAP message is getting constructed is not based on the namespace mentioned in the WSDL.

                          Below is the SOAP request constructed my client:

                          <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body>
                          <createEntitlement>

                          </createEntitlement>
                          </SOAP-ENV:Body>

                          </SOAP-ENV:Envelope>


                          When I tested with SoapPUI tool - it generates SOAP request as below: Elements are prrifixed with a namespace link. But my client generated request are not prifixed, how do i resolve this issue ..Please help

                          <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.act.emc.com" xmlns:xsd="http://ws.act.emc.com/xsd">
                          <soap:Header/>
                          <soap:Body>
                          <ws:createEntitlement>
                          <xsdoeticResponse>?</xsdoeticResponse>
                          <!--Optional:-->
                          <xsd:userName>?</xsd:userName>
                          </wsaram0>
                          </ws:createEntitlement>
                          </soap:Body>
                          </soap:Envelope>


                          Plese help

                          Comment


                          • #14
                            Hello.

                            Your client build SOAP-Request with empty body...
                            How do you do that?
                            In the Spring Integration we have two ways:
                            1. Build body manualy from string payload. It should be XML-string
                            2. Use marshaler, when your payload is POJO with some OXM specification, e.g. JAXB

                            Comment


                            • #15
                              I get XML from a string payload from spring integration channel.
                              Last edited by vibin12; Feb 17th, 2012, 08:09 AM.

                              Comment

                              Working...
                              X