我有一个带有jsp页面的spring web应用程序,它调用不同的Web服务并在jsp页面中显示结果。 spring web应用程序附带了用户名/登录spring security。
我正在添加一个处理安全性的Web服务的调用。对于WebServiceGateway,我添加了一个安全拦截器。 (见下文)
<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>
当我将wss4j添加到我的pom文件中时,我现在在Web服务端出现以下错误:
[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
答案 0 :(得分:6)
可能有点太晚了,但你似乎正在遭遇here所描述的内容。 Java 6中的Xerces实现显然与Spring Web Services不兼容。 他们的解决方案是开始搞乱已经认可的库,但这是我想避免的。我还没有找到一个不涉及修改JVM安装的好解决方案。
Arjen Poutsma似乎有另一种解决方案。他删除了所有Xerces和Xalan依赖项。然后它工作。除非您在Web服务应用程序的其他部分需要Xerces / Xalan的功能,否则您可以尝试这样做。相关票证为SWS-175。
答案 1 :(得分:0)
我遇到完全相同的问题,其中soap web服务的spring客户端在tomcat上测试时工作得非常好,并且在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
通过上面给出的答案,我按如下方式更改了jboss-deployment-structure文件,并在排除中添加了激活,xerces和xalan:
<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>
这解决了jboss上的问题。
答案 2 :(得分:-1)
我今天遇到了同样的问题。尝试了所有可能的方法,最后删除了Xalan.jar和xerces.jar。事实上,不仅Xalan和Xerces JARS,还有XercesImpl.jar和Xalan JARS的所有版本。
现在它工作得很好。