Page 1 of 2 12 LastLast
Results 1 to 10 of 17

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

  1. #1
    Join Date
    Dec 2011
    Location
    Hyderabad, India
    Posts
    16

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

    Default

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

    HTH,
    Mark

  3. #3
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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.

  4. #4
    Join Date
    Dec 2011
    Location
    Hyderabad, India
    Posts
    16

    Default

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

  5. #5
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    645

    Default

    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

  6. #6
    Join Date
    Dec 2011
    Location
    Hyderabad, India
    Posts
    16

    Default

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

  7. #7
    Join Date
    Feb 2012
    Location
    US
    Posts
    9

    Default 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>

  8. #8
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    645

    Default

    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>

  9. #9
    Join Date
    Feb 2012
    Location
    US
    Posts
    9

    Default

    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 at 10:07 AM.

  10. #10
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    645

    Default

    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

Tags for this Thread

Posting Permissions

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