10

I have implement a certain spring-ws service and when I sent a soap message I receive in spring webapplication 1 (running on tomcat 6.0.32):

Request:

<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>

Response

<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>

So far no problem. From a webappliction 2 (not using spring MVC etc.) I made a function and when I run this function it works:

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;
    }

Output:

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

So this works great and as expected. But when I want to call the function

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

within a JSP (runnning on the same tomcat server) or a simple class I get the following error:

Server:

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

Client:

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

I'm using the following Java version pointing to myeclipse and tomcat (runs on):

*JDK 1.6.0_13*

Jars:

  • xercesImpl-2.9.1.jar
  • xalan-2.7.1.jar
  • serializer-2.7.1.jar
  • spring-ws-1.5.9-all.jar
  • spring.jar(2.5.6)
  • xml-apis-1.3.04.jar
  • xml-apis-ext-1.3.04.jar

Full stacktrace of client

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 of server **

**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**

**

hopefully this is enough information to solve the problem. I found some messages and bugs the pointing to the fact that I need to delete some Jars (xalan,xercesImpl and serializer) from the projects and add these jars to the jdk\lib\endorsed\ folder and add to tomcat the argument: -Djava.endorsed.dirs=. This works but I can't do this because the applications is running on several servers already.

Thx in advance

Alternative solution

Solved It for now while using the Apache CXF on the client. And spring-ws 1.5.9 on the server... apparently spring-ws sucks with jdk > 1.5

Michel
  • 9,220
  • 13
  • 44
  • 59
  • Can't answer but some comments/questions: A) I suggest not to use the spring.jar, use only the jars you need. B) use a dependency management system (maven/ivy) C) why do you want to call a webservice from a jsp? – abalogh May 13 '11 at 21:07
  • A) I need spring.jar because WebServiceGatewaySupport need some Spring classes B) Not possible, it is a huge project can't set Maven on it for the moment (because of project structure) C) This is the easiest way. because I can immediately print out the results. And it should work anyway D) Thanks for your comment – Michel May 14 '11 at 06:41
  • Are you using ant for building then? If so, you can probably add Ivy in without much difficulty. (Maven's method of “their way or the highway” is OK if you buy into it, but can be a pain to convert to. Ivy seems to be designed to work within ant, with all that implies.) – Donal Fellows May 16 '11 at 06:51

3 Answers3

6

Maybe you should try considering updating to xerces-2.10.x, the problem can be that in jdk6 (rt.jar) there is a com.sun.org.apache.xerces package which seem to contain a jaxp 1.4 implementation, so does xerces 2.10+:

"It also contains an implementation of the parser related portions of JAXP 1.4"

quote from here.

Are you building the binary containing the jsp as a separate process or you are building everything together? If it's separated, you can try to remove xerces and xalan from the buildpath of that package only? - If you cannot, try upgrading maybe it'll help.

Still think it would be better to have a service calling your ws and you'd invoke that service from the jsp, that way you could test it separately, but perhaps you can't do that for some reason.

If both of these fail, can you post a) full stacktrace b) some of the errors which appear if you remove xerces and xalan alltogether?

abalogh
  • 8,239
  • 2
  • 34
  • 49
  • I have added the full stack trace and added xercesImpl-2.11.0.jar. but no new results – Michel May 16 '11 at 10:56
  • 1
    do you have an activation.jar on your classpath? Have you tried capturing network traffic and see if you have the same request sent when using CallServices and the jsp? – abalogh May 16 '11 at 11:01
  • Added full stacktraces/ activation.jar is on the classpath of the client. I don't have looked in the request with a sniffer. Server and client are running on the same server atm – Michel May 16 '11 at 13:12
  • Even running a simple class deployed on the tomcat server results in the same error... I'm stuck I guess – Michel May 16 '11 at 14:19
  • 1
    Which java version are you running on? What happens if you remove dependencies: xerces, xalan and xml-api? – abalogh May 16 '11 at 14:29
  • I mean using the small testcase which is able to reproduce the problem. – abalogh May 16 '11 at 14:29
  • 1
    I think I need to look for another solution than spring-ws, because I only get it working when defining the endorsed folder as argument to tomcat 6 and put the libraries xalan,xercesImpl and serializer to the jdk/lib/endorsed folder... If I delete the jars from the project I get problems with several function. for example: TransformerFactoryImpl – Michel May 16 '11 at 15:17
  • Well I'm sure these classpath/config issues could be easily solved with a dependency management system, but I understand you cannot include one in your project. Maybe check out Apache CXF. (btw the error in your last comment didn't come through, add it to the question perhaps) – abalogh May 16 '11 at 15:29
  • One more idea, can you use SWS 2.0 instead of 1.5? – abalogh May 16 '11 at 16:16
  • I tried to switch from SWS 1.5 to SWS 2.0 on the client (needs spring 3.0) but than I get exactly the same error. – Michel May 17 '11 at 09:46
  • Solved It for now while using the Apache CXF on the client. And spring-ws 1.5.9 on the server... apparently spring-ws sucks with jdk > 1.5 – Michel May 17 '11 at 15:39
3

Solved It for now using the Apache CXF 2.4.0 on the client. And spring-ws 1.5.9 on the server... apparently spring-ws sucks with jdk > 1.5

Michel
  • 9,220
  • 13
  • 44
  • 59
2

This is a known issue with Spring-WS and Java 6, see ticket SWS-175. According to this ticket the solution is to remove Xalan and Xerces from your webapp classpath.

Richard Kettelerij
  • 2,049
  • 14
  • 17
  • 2
    Also this problem was discussed earlier on StackOverflow, see http://stackoverflow.com/questions/1638986/spring-soapexceptionimpl-error-during-saving-a-multipart-message – Richard Kettelerij May 22 '11 at 20:49
  • As you can read in my question this isn't possible. The impact of removing Xalan and Xerces is to big. But beyond that, the application already running on different servers(tomcat 5.5 and tomcat 6.0) with different jdk's (also 1.5) – Michel May 22 '11 at 21:18