Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-99

Exception when creating XMLStreamReader from AxiomSoapMessage.getPayloadSource with Woodstox

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0 M3
    • Fix Version/s: 1.0 RC1
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Axiom 1.2.2
      Woodstox 3.2.0
      message factory: org.springframework.ws.soap.axiom.AxiomSoapMessageFactory

      Description

      I'm trying to create a javax.xml.stream.XMLStreamReader from WebServiceMessage.getPayloadSource(). I'm using Axiom to create web service messages and Woodstox as a StaX parser. The following code is throwing the following exception with Axiom but works fine with Saaj:
      javax.xml.stream.XMLStreamException: Can not create StAX reader for the Source passed – neither reader, input stream nor system id was accessible; can not use other types of sources (like embedded SAX streams)

      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      XMLStreamReader parser = inputFactory.createXMLStreamReader(message.getPayloadSource());

      To reproduce the exception, modify the echo sample as follows:
      1- Add Axiom jars to the classpath
      2- Add Woodstox to the classpath
      3- Add <bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory"/> to spring-ws-servlet.xml
      4- Add the following endpoint interceptor:

      package org.springframework.ws.samples.echo.ws;

      import javax.xml.stream.XMLInputFactory;
      import javax.xml.stream.XMLStreamReader;

      import org.springframework.ws.WebServiceMessage;
      import org.springframework.ws.context.MessageContext;
      import org.springframework.ws.server.EndpointInterceptor;

      public class StaxEndpointInterceptor implements EndpointInterceptor {

      public boolean handleRequest(MessageContext messageContext, Object endpoint)
      throws Exception

      { WebServiceMessage message = messageContext.getRequest(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader parser = inputFactory.createXMLStreamReader(message.getPayloadSource()); return true; }

      public boolean handleResponse(MessageContext messageContext, Object endpoint)
      throws Exception

      { return true; }

      }

      5 - configure it in spring-ws-servlet.xml:
      <bean id="staxEndpointInterceptor" class="org.springframework.ws.samples.echo.ws.StaxEndpointInterceptor"/>
      and
      <ref local="staxEndpointInterceptor"/>

      Calling echo now will throw the following exception:

      javax.xml.stream.XMLStreamException: Can not create StAX reader for the Source passed – neither reader, input stream nor system id was accessible; can not use other types of sources (like embedded SAX streams)
      at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:756)
      at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:329)
      at org.springframework.ws.samples.echo.ws.StaxEndpointInterceptor.handleRequest(StaxEndpointInterceptor.java:16)
      at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:197)
      at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:166)
      at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handle(WebServiceMessageReceiverObjectSupport.java:78)
      at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:60)
      at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:125)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:360)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Unknown Source)

        Activity

        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Unfortunately, I cannot fix this, since it is Woodstox issue rather than a SWS issue. Woodstox can only handle StreamSource implementations, or SAXSource implementations that have a proper InputSource (i.e. either InputStream or Writer must be set).

        A common trick while dealing with StAX and TrAX is to create a "fake" SAXSource that has its own custom XMLReader and an empty InputSource. Reading from the XMLReader will result in a read from the underlying XMLStreamReader or XMLEventReader. Look at org.springframework.xml.transform.StaxSource to see how this is done.

        Woodstox cannot deal with this trick, so I have another one up my sleeve: create a buffer, write the source to that buffer, and read from that (see org.springframework.ws.server.endpoint.AbstractStaxStreamPayloadEndpoint#getStreamReader(Source)). Slow, but it works.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Unfortunately, I cannot fix this, since it is Woodstox issue rather than a SWS issue. Woodstox can only handle StreamSource implementations, or SAXSource implementations that have a proper InputSource (i.e. either InputStream or Writer must be set). A common trick while dealing with StAX and TrAX is to create a "fake" SAXSource that has its own custom XMLReader and an empty InputSource. Reading from the XMLReader will result in a read from the underlying XMLStreamReader or XMLEventReader. Look at org.springframework.xml.transform.StaxSource to see how this is done. Woodstox cannot deal with this trick, so I have another one up my sleeve: create a buffer, write the source to that buffer, and read from that (see org.springframework.ws.server.endpoint.AbstractStaxStreamPayloadEndpoint#getStreamReader(Source)). Slow, but it works.
        Hide
        arjen.poutsma Arjen Poutsma added a comment -

        Closing RC1 issues.

        Show
        arjen.poutsma Arjen Poutsma added a comment - Closing RC1 issues.

          People

          • Assignee:
            arjen.poutsma Arjen Poutsma
            Reporter:
            tareq Tareq Abedrabbo
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: