Spring-ws -Problem从tomcat 6请求webservice

时间:2011-05-13 19:28:05

标签: java web-services spring jsp spring-ws

我已经实现了某个spring-ws服务,当我发送一条肥皂消息时,我收到了春季webapplication 1(在tomcat 6.0.32上运行):

请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gen="http://www.foo.com/bar/webservice/generated">
   <soapenv:Header/>
   <soapenv:Body>
      <gen:GetAllPanelWSRequest/>
   </soapenv:Body>
</soapenv:Envelope>

响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns2:GetAllPanelWSResponse xmlns:ns2="http://www.foo.com/bar/webservice/generated">
         <ns2:PanelWS ns2:Id="5">
            <ns2:name>all</ns2:name>
            <ns2:code>all</ns2:code>
         </ns2:PanelWS>
         <ns2:PanelWS ns2:Id="9">
            <ns2:name>test</ns2:name>
            <ns2:code>test1</ns2:code>
         </ns2:PanelWS>         
      </ns2:GetAllPanelWSResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

到目前为止没问题。从webappliction 2(不使用spring MVC等)我创建了一个函数,当我运行这个函数时,它可以工作:

Main.java

...
public class Main {
    public static void main(String[] args) {
        List<PanelWS> panelWSs = CallServices.getPanelWSs();
        for (PanelWS p : panelWSs) {
            System.out.println("\t" + makeString(p));
        }
    }
...

CallServices.java

public static List<PanelWS> getPanelWSs() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        PanelClient client = (PanelClient) ctx.getBean("client");
        PanelWS panelWS = null;

        // Get all panelWS
        System.out.println("Get all panels...");
        List<PanelWS> panelWSs = client.getAllPanelWS();
        return panelWSs;
    }

输出:

Get all panels...
    [id=5, name=all, code=all]
    [id=9, name=test, code=test1]

所以这很有效并且符合预期。但是当我想调用函数

    <%
        List<PanelWS> panelWSs = CallServices.getPanelWSs();
    %>

在JSP(在同一个tomcat服务器上运行)或简单类中我得到以下错误:

服务器

13-mei-2011 17:57:37 com.sun.xml.internal.messaging.saaj.soap.MessageImpl saveChanges
SEVERE: SAAJ0539: Unable to get header stream in saveChanges
13-mei-2011 17:57:37 com.sun.xml.internal.messaging.saaj.soap.MessageImpl saveChanges
SEVERE: SAAJ0540: Error during saving a multipart message

客户端:

  

org.springframework.ws.soap.saaj.SaajSoapMessageException:无法将消息写入OutputStream:保存多部分消息时出错;嵌套异常是com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:保存多部分消息时出错

我正在使用以下Java版本指向myeclipse和tomcat(运行):

* JDK 1.6.0_13 *

  • xercesImpl-2.9.1.jar
  • 的Xalan-2.7.1.jar
  • 串行 - 2.7.1.jar
  • 弹簧-WS-1.5.9-all.jar在
  • spring.jar(2.5.6)
  • xml-apis-1.3.04.jar
  • XML的API-EXT-1.3.04.jar

客户端的完整堆栈跟踪

Message:    org.springframework.ws.soap.saaj.SaajSoapMessageException: Could not write message to OutputStream: Error during saving a multipart message; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
Error ID:   #9yb3mzb7
Stack trace:    org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:169)
org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:580)
org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:549)
org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:502)
org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:351)
org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:345)
org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:337)
com.foo.bar.webservice.client.PanelMGMClientImpl.getAllPanelWS(PanelMGMClientImpl.java:22)
com.foo.bar.webservice.client.CallServices.getPanelWSs(CallServices.java:22)
org.apache.jsp.workspace.aclusers_jsp._jspService(aclusers_jsp.java:786)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

服务器的Fullstacktrace **

**SEVERE: Servlet.service() for servlet spring-ws threw exception
java.io.IOException: org.apache.xml.serializer.ToXMLSAXHandler cannot be cast to org.apache.xml.serializer.SerializationHandler
    at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:298)
    at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:309)
    at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:305)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:947)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1098)
    at org.springframework.ws.soap.saaj.Saaj13Implementation.writeTo(Saaj13Implementation.java:268)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:165)
    at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:45)
    at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:97)
    at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
    at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:230)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    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 com.foo.bar.support.gzip.CompressionFilter.doFilter(CompressionFilter.java:30)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
    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.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:168)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    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:298)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
    at java.lang.Thread.run(Thread.java:619)
16-mei-2011 14:20:12 com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope
SEVERE: SAAJ0511: Unable to create envelope from given source**

**

希望这是解决问题的足够信息。我发现了一些消息和错误指向我需要从项目中删除一些Jars(xalan,xercesImpl和serializer)并将这些jar添加到jdk\lib\endorsed\文件夹并向tomcat添加参数:{{1 }}。这有效,但我无法做到这一点,因为应用程序已经在几台服务器上运行。

提前谢谢

替代解决方案

在客户端上使用Apache CXF时解决了这个问题。并且服务器上的弹簧为1.5.9 ......显然弹簧很糟糕,jdk&gt; 1.5

3 个答案:

答案 0 :(得分:6)

也许你应该尝试考虑更新到xerces-2.10.x,问题可能是在jdk6(rt.jar)中有一个com.sun.org.apache.xerces包似乎包含一个jaxp 1.4实现, xerces 2.10 +:

也是如此
  

“它还包含一个实现   JAXP的解析器相关部分   1.4"

来自here

您是否正在构建包含jsp的二进制文件作为单独的进程,或者您正在构建所有内容?如果它是分开的,你可以尝试从该包的构建路径中删除xerces和xalan吗? - 如果你不能,尝试升级也许它会帮助。

仍然认为让一个服务调用你的ws并且你从jsp调用该服务会更好,这样你可以单独测试它,但也许你不能出于某种原因这样做。

如果这两个都失败了,你可以发布一个完整的堆栈跟踪b)如果你删除xerces和xalan一起出现的一些错误吗?

答案 1 :(得分:3)

现在使用客户端上的Apache CXF 2.4.0解决它。并且服务器上的弹簧为1.5.9 ......显然弹簧很糟糕,jdk&gt; 1.5

答案 2 :(得分:2)

这是Spring-WS和Java 6的已知问题,请参阅ticket SWS-175。根据此票据,解决方案是从您的webapp类路径中删除Xalan和Xerces。