Spring + SOAPExceptionImpl: Error during saving a multipart message

半城伤御伤魂 提交于 2019-11-28 10:11:46

问题


I have a spring web application with jsp pages that calls different web services and displays the results in a jsp page. The spring web application has username/login spring security attached to it.

I am adding a call to a web service that handles security. For the WebServiceGateway, I added a security interceptor. (See below)

<bean id="securityInterceptor"
    class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
    <property name="securementActions" value="UsernameToken Timestamp" />
    <property name="securementUsername" value="Bert" />
    <property name="securementPassword" value="Ernie" />
    <property name="timestampPrecisionInMilliseconds" value="true" />
</bean>

When I added the wss4j into my pom file, I now get the following error on the web service side:

[28-13:46:26]DEBUG: org.springframework.web.servlet.FrameworkServlet.processRequest(): Could not complete request [http-8080-2]
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
    at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:163)
    at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:172)
    at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:88)
    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 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:128)
    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:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:619)
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1124)
    at org.springframework.ws.soap.saaj.Saaj13Implementation.writeTo(Saaj13Implementation.java:268)
    at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:159)
    ... 20 more
Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to get header stream in saveChanges: 
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1101)
    ... 22 more
Caused by: 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:295)
    at com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl.output(EnvelopeImpl.java:306)
    at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getContentAsStream(SOAPPartImpl.java:302)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getHeaderBytes(MessageImpl.java:945)
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1096)
    ... 22 more

回答1:


It may be a bit too late, but you seem to be suffering from what is described here. The Xerces implementation in Java 6 is apparently not compatible with Spring Web Services. Their solution is to start messing with endorsed libs, but this is something I would like to avoid. I have not yet found a good solution that does not involve modifying the JVM installation.

Arjen Poutsma seems to have another solution. He removed all the Xerces and Xalan dependencies. Then it works. Unless you need features from Xerces/Xalan in some other part of you web service application you could try this. The relevant ticket is SWS-175.




回答2:


I got exact same issue wherein spring client of soap web service was working absolutely fine when tested on tomcat and was giving following exception when tested on jboss:

org.springframework.ws.soap.saaj.SaajSoapMessageException: Could not write message to OutputStream: Error during saving a multipart message; nested exception is com.sun.xml.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message

With the answer given above, I changed jboss-deployment-structure file as follows and added activation, xerces and xalan in exclusion:

<exclusions>
     <module name="org.apache.commons.logging" />
     <module name="org.apache.log4j" />
     <module name="org.jboss.logging" />
     <module name="org.jboss.logging.jul-to-slf4j-stub" />
     <module name="org.jboss.logmanager" />
     <module name="org.jboss.logmanager.log4j" />
     <module name="org.slf4j" />
     <module name="org.slf4j.impl" />
     <module name="javaee.api"/> 
     <module name="javax.ws.rs.api"/>
     <module name="org.apache.xalan"/>
     <module name="org.apache.xerces"/>
     <module name="javax.activation.api"/>
</exclusions>

This resolved the issue on jboss.




回答3:


I faced the same problem today. Tried all the possible ways and finally removed Xalan.jar and xerces.jar. In fact not only Xalan and Xerces JARS but XercesImpl.jar and all versions of Xalan JARS as well.

Now it's working completely fine.



来源:https://stackoverflow.com/questions/1638986/spring-soapexceptionimpl-error-during-saving-a-multipart-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!