Spring-ws Endpoint is not reached, error indicates invalid content type: application/xml

StackOverflow https://stackoverflow.com/questions/19169599

  •  30-06-2022
  •  | 
  •  

Pregunta

I am trying to code a simple Spring-ws server. I am not sure what I am doing wrong but the request I initial from SoapUI never reaches my server. Running under a debugger I never get control in my server. The error indicates an invalid content type, but I'm not sure this is from the response. The response being returned is my jsp error page for the application.
I believe the servlet is configured correctly. I setup a bogus test.wsdl and as you see configured below. This worked correctly. I just cannot get the request from SoapUI to my server code.

The code for my server is:
package com.tester;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.starstandard.star.x5.ItemIdDescriptionDocument;

@Endpoint   
public class EndpointTest {


@PayloadRoot(localPart="ItemIdDescription", namespace = "http://www.starstandard.org/STAR/5")
@ResponsePayload
public ItemIdDescriptionDocument handleItemIdDescription(@RequestPayload  ItemIdDescriptionDocument request){

    String description = request.getItemIdDescription().getStringValue();

    return request;
}

}

Here is the configuration for my servlet. This file is WEB-INF/spring-ws-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

<context:component-scan base-package="com.tester" />
<sws:annotation-driven />
<bean
  class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
  <property name="marshaller" ref="marshaller" />
  <property name="unmarshaller" ref="marshaller" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"></bean>
<sws:static-wsdl id="test" location="/WEB-INF/test.wsdl"/>
</beans>

Here is the raw request from SoapUI. I used Fiddler to get this:

POST http://localhost:8080/webroot/eservices HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/xml
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8080
Connection: Keep-Alive
Content-Length: 146

<ItemIdDescription xmlns:oagis="http://www.openapplications.org/oagis/9"
 xmlns="http://www.starstandard.org/STAR/5">Test</ItemIdDescription>

Here is the error stack from the logs:

Oct 3, 2013 4:54:55 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet spring-ws threw exception
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-    Type:application/xml. Is this an error message instead of a SOAP response?
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:602)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(MessageImpl.java:275)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl.<init>(Message1_1Impl.java:67)
at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl.createMessage(SOAPMessageFactory1_1Impl.java:61)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:184)
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60)
at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:90)
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:86)
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:59)
at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:239)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

Here is the error stack after I switched the server to support SOAP 1.2 so I do not believe it is a SOAP version issue:

SEVERE: Servlet.service() for servlet spring-ws threw exception
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:application/xml. Is this an error message instead of a SOAP response
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(MessageImpl.java:602)
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.<init>(MessageImpl.java:275)
at com.sun.xml.internal.messaging.saaj.soap.ver1_2.Message1_2Impl.<init>(Message1_2Impl.java:60)
at com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl.createMessage(SOAPMessageFactory1_2Impl.java:61)
... the rest of the stack is the same.

Does anyone have suggestions on how to debug this? Much thanks!

¿Fue útil?

Solución

Looks like your web service is SOAP 1.1 and where as your SoapUI request is SOAP 1.2 and hence due to this conflict you are getting the error. This thread might help you regarding this matter. In SOAP 1.2 MIME type is "application/soap+xml". That's why I thought it's SOAP 1.2(purely a speculation)

Otros consejos

The issue was I was not sending a correct soap request. I thought Soap UI added the SOAP Envelope and Body around my request but I was wrong. :-( I correct it with the following XML:

<SOAP-ENV:Envelope 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <war:ItemIdDescription xmlns:oagis="http://www.openapplications.org/oagis/9"
         xmlns:war="http://www.starstandard.org/STAR/5">Test</war:ItemIdDescription>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I ran into this issue when running an integration test on my SOAP webservice. I solved it by setting the content-type header of my soap call to "text/xml" instead of "application/xml".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top