Announcement Announcement Module
Collapse
No announcement yet.
WS Client using JAXB for marshalling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WS Client using JAXB for marshalling

    Hello guys,

    First time using Spring-WS. I am trying to get my WS client to return me objects using JAXB marshalling.

    When I access the WS, this is the Exception I get:

    Code:
    org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
    	at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:171)
    	at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:86)
    	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:552)
    	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:501)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:350)
    	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:344)
    	at com.b2w.service.SynonymWordsServiceClient.getSynonymWords(SynonymWordsServiceClient.java:23)
    	at com.b2w.service.SynonymWordsServiceTest.testGetSynonymWords(SynonymWordsServiceTest.java:14)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runManaged(AbstractJUnit38SpringContextTests.java:307)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.access$000(AbstractJUnit38SpringContextTests.java:94)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests$1.run(AbstractJUnit38SpringContextTests.java:193)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTest(AbstractJUnit38SpringContextTests.java:270)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTestTimed(AbstractJUnit38SpringContextTests.java:228)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runBare(AbstractJUnit38SpringContextTests.java:191)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
    	at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:605)
    	at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(MessageImpl.java:278)
    	at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(Message1_1Impl.java:68)
    	at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(SOAPMessageFactory1_1Impl.java:62)
    	at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:154)
    	... 30 more
    I know the WS is working fine as I can access it via Soap UI.

    That's my unit test context:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:jndi="http://www.springframework.org/schema/jee"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd ">
    
    	<bean id="synonymWordsService"
    		class="com.b.service.SynonymWordsServiceClient">
    		<property name="template" ref="synonymWebServiceTemplate" />
    	</bean>
    
    	<bean id="synonymWebServiceTemplate"
    		class="org.springframework.ws.client.core.WebServiceTemplate">
    		<property name="defaultUri"
    			value="http://host:port/SMW" />
    		<property name="messageFactory" ref="messageFactory" />
    		<property name="marshaller" ref="synonymMarshaller" />
    		<property name="unmarshaller" ref="synonymMarshaller" />
    	</bean>
    
    	<bean id="synonymMarshaller"
    		class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPath"
    			value="com.b.xml.getsynonymwords" />
    	</bean>
    
    	<bean id="messageFactory"
    		class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
    
    </beans>
    And that's my client code:
    Code:
    package com.b.service;
    
    import java.util.Collection;
    
    import org.springframework.ws.WebServiceMessage;
    import org.springframework.ws.client.core.WebServiceMessageCallback;
    import org.springframework.ws.client.core.WebServiceTemplate;
    import org.springframework.ws.soap.SoapMessage;
    
    import com.b.xml.getsynonymwords.GetSynonymWordsRequest;
    import com.b.xml.getsynonymwords.SynonymWordsInfo;
    import com.b.xml.getsynonymwords.SynonymWordsInfoListInfo;
    
    public class SynonymWordsServiceClient {
    	
    	private static final String BRAND_ID = "03";
    	protected static final String SOAP_ACTION = "getSynonymWords";
    	private WebServiceTemplate template;
    	
    	public Collection<SynonymWordsInfo> getSynonymWords() {
    		GetSynonymWordsRequest request = new GetSynonymWordsRequest();
    		request.setBrandId(BRAND_ID);
    		SynonymWordsInfoListInfo result = (SynonymWordsInfoListInfo)template.marshalSendAndReceive(request, new WebServiceMessageCallback() {
    	        public void doWithMessage(WebServiceMessage message) {
    	            ((SoapMessage)message).setSoapAction(SOAP_ACTION);
    	        }
    	    });
    		return null;
    	}
    
    	public WebServiceTemplate getTemplate() {
    		return template;
    	}
    
    	public void setTemplate(WebServiceTemplate template) {
    		this.template = template;
    	}
    	
    }
    I simply don't get what this Exception means. If anyone knows what I am doing wrong, I would be gratefull :-)

  • #2
    It looks like you are getting an html-page back. Probably an error page.

    When you work with web services, always use a tcp sniffer, for example tcpmon. Install one and let us know what the response is.

    It is easy to get name spaces etc. wrong when you create a web service. The client you have been using to test your service might not be as strict as jaxb.

    Cheers

    G
    Last edited by Goran; Dec 15th, 2008, 02:55 PM.

    Comment


    • #3
      Hm,

      I don't believe that's the problem, because this is the response body:
      Code:
      <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
         <env:Header/>
         <env:Body>
            <m:getSynonymWordsResponse xmlns:m="http://com/b/sm/jws">
               <get:getSynonymWordsResponse xmlns:get="http://www.b.com/getSynonymWords">
                  <synonymWordsInfo/>
               </get:getSynonymWordsResponse>
            </m:getSynonymWordsResponse>
         </env:Body>
      </env:Envelope>
      These are the headers:
      Code:
      Transfer-Encoding	chunked
      Date	Mon, 15 Dec 2008 21:38:26 GMT
      #status#	HTTP/1.1 200 OK
      SOAPAction	""
      Set-Cookie	JSESSIONID=N2xjJGTSQj3fmjmhtJMdSWBJt4fSgRfrsTyV8DFmWzgQDvgxN8n9!599367006; path=/
      Content-Type	text/xml; charset="utf-8"
      X-Powered-By	Servlet/2.5 JSP/2.1
      Cache-Control	no-cache="set-cookie"
      As you can see, the content type is text/xml

      Comment


      • #4
        The error message says - Invalid Content-Type:text/html. Even though the response is in proper format, the client detects it as text/html instead of text/xml. Not sure if things going wrong after or before marshaling. Need to see your server configuration code - application-context.

        However, can you try adding this additional property to your synonymWebServiceTemplate ?

        <property name="messageSender">
        <bean
        class="org.springframework.ws.transport.http.Commo nsHttpMessageSender">
        </bean>

        If it does not work, you can find a step by step tutorial for building the Spring-WS at http://justcompiled.blogspot.com/201...spring-ws.html
        and
        client tutorial at http://justcompiled.blogspot.com/201...spring-ws.html

        Hope it helps.

        Comment

        Working...
        X