Announcement Announcement Module
No announcement yet.
How to use direct streaming for SOAP with Spring-WS? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use direct streaming for SOAP with Spring-WS?

    We want to enable direct streaming of our payload in webservice endpoints. We have to process a large amount of data and want to stream the data while processing.

    We use spring-ws-core, in version 2.0.0 and use the PayloadRootQNameEndpointMapping as endpoint mapper. As message factory we are using the AxiomSoapMessageFactory. We implement the StreamingPayload and the corresponding writeTo(XMLStreamWriter writer) method, which we use to write our payload (According to the spring-ws JIRA ticket, SWS-352).

    This works fine without any errors, but we wanted to stream directly! This is apparently not possible. We made an easy test where we streamed some data to evaluate the behaviour.

    We assumed that this will be directly streamed to the consumer/client, so the soap header is already be written to our writer and closes after the endpoint is completed. Unfortunately this is not possible, the stream can not be used directly! The stream is wrapped in a ByteArrayInputStream, found in the spring-ws source.

    The implementation of StreamingOMDataSource shows this (can be viewed in springs FishEye). The StreamingOMDataSource calls your StreamingPayload implementation and gives you a writer for this.

    public XMLStreamReader getReader() throws XMLStreamException {
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       serialize(bos, null);
       ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
       return StAXUtils.createXMLStreamReader(bis);
    The method #serialize() creates the XMLStreamWriter with the ByteArrayOutputStreamand calls the payload to enable writing, as described above.

    public void serialize(OutputStream output, OMOutputFormat format) 
           throws XMLStreamException
       XMLStreamWriter streamWriter;
       if ([...]) {
          // Create stream writer with defined charset
       else {
           streamWriter = StAXUtils.createXMLStreamWriter(output);
    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
    So this is not usable for me, is it possible to achieve direct streaming? Any ideas for this? Thank you in advance!

  • #2
    I assume due to no repsonses, this is impossible to achieve? Is something like this planned or is a workaround known?


    • #3
      Well actually, spring ws streaming is like the
      One piece
      everyone want to find it but nobody has ever seen it.

      Even if it is working, your NEED to use AxiomSoapMessageFactory. It will may be ok for a new spring ws project but not if your have already a huge stack of ws & custom interceptors based on SaajSoapMessageFactory. You cant switch so easily.

      Unless you declare an new MessageDispatcherServlet.

      We are still waiting for a real example written by WhiteBeard.. Arjen
      Last edited by mada; Mar 25th, 2011, 03:32 AM.