2013-10-03 46 views
0

我想編寫一個簡單的Spring-ws服務器。我不知道我在做什麼錯,但是我從SoapUI初始化的請求永遠不會到達我的服務器。在調試器下運行,我永遠不會在我的服務器中獲得控制權。該錯誤表示無效的內容類型,但我不確定這是來自響應。返回的響應是我的應用程序的jsp錯誤頁面。
我相信servlet配置正確。我設置了一個僞造的test.wsdl,正如你看到的配置如下。這工作正常。我只是無法從SoapUI獲取到我的服務器代碼的請求。未達到Spring-ws端點,錯誤表示無效的內容類型:application/xml

我的服務器的代碼是:
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; 
} 

}

這裏是我的servlet的配置。這個文件是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> 

這是來自SoapUI的原始請求。我用小提琴手得到這個:

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> 

下面是從日誌中的錯誤堆棧:

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) 

以下是錯誤堆棧我切換服務器支持SOAP 1.2,所以我不相信它後是一個SOAP版本問題:

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. 

有沒有人有關於如何調試的建議?非常感謝!

回答

1

看起來您的Web服務是SOAP 1.1,並且您的SoapUI請求是SOAP 1.2,因此由於此衝突您正在收到錯誤。這個thread可能會幫你解決這個問題。在SOAP 1.2中,MIME類型是「application/soap + xml」。這就是爲什麼我認爲它是SOAP 1.2(純粹是一種猜測)

+0

羅伯特,我感謝您的建議,我調查這個堆棧中的類也清楚地表明這是SOAP 1.1你怎麼看,我的SOAP請求。是版本1.2? –

+0

我切換了我的服務器以支持SOAP 1.2,並且我得到了同樣的錯誤,所以我不確定是否這是問題: –

+0

當我切換到SOAP 1.2時添加了錯誤堆棧 –

0

問題是我沒有發送正確的肥皂請求。我想Soap UI在我的請求周圍添加了SOAP Envelope和Body,但我錯了。 :-(我用下面的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> 
相關問題