如何使用Spring-WS直接传输SOAP? [英] How to use direct streaming for SOAP with Spring-WS?

查看:198
本文介绍了如何使用Spring-WS直接传输SOAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望在Web服务端点中启用有效负载的直接流式传输。我们必须处理大量数据,并希望在处理时流式传输数据。

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.

我们在版本2.0.0中使用spring-ws-core并使用 PayloadRootQNameEndpointMapping 作为端点映射器。作为消息工厂,我们使用 AxiomSoapMessageFactory 。我们实现 StreamingPayload 和相应的 writeTo(XMLStreamWriter writer)方法,我们用它来编写有效负载(根据春天的JIRA门票, SWS-352 )。

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.

writer.writeStartElement("exampleResponse")

10000.times
{
    writer.writeStartElement("example")
    writer.writeEndElement()    
}

writer.writeEndElement()

我们假设这将直接流式传输到消费者/客户端,因此soap标头是已写入我们的编写器并在端点完成后关闭。不幸的是,这是不可能的,流不能直接使用!该流包含在一个 ByteArrayInputStream 中,在spring-ws源代码中找到。

We assumed that this will be directly streamed to the consumer/client, so the soap header is already 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.

<$ c的实现$ c> StreamingOMDataSource 显示了这一点(可以在 spring FishEye )。 StreamingOMDataSource 调用您的StreamingPayload实现并为您提供一个编写器。

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

方法 #serialize()使用 ByteArrayOutputStream 创建 XMLStreamWriter 并调用有效负载以启用写入,如上所述。

The method #serialize() creates the XMLStreamWriter with the ByteArrayOutputStream and 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);
   }
   serialize(streamWriter);
}

public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
   payload.writeTo(xmlWriter);
   xmlWriter.flush();
}

所以这对我来说无法使用。是否有可能实现直接流媒体?有什么想法吗?提前谢谢!

So this is not usable for me. Is it possible to achieve direct streaming? Any ideas for this? Thank you in advance!

更新:我终于创建了 Spring WS的JIRA票证(SWS-704)。如果你想看到它实现,请考虑在JIRA页面上观看/投票。希望我们至少得到一个有用的答复。

Update: I finally created a JIRA ticket (SWS-704) for Spring WS. If you want to see it implemented consider watching/voting it on the JIRA page. Hopefully we get at least an useful reply.

推荐答案

您还必须禁用有效负载缓存:

You have also to disable the payload caching:

<bean id="messageFactory" 
      class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
     <property name="payloadCaching" value="false"/>
</bean> 

通过此设置,我们终于可以使用Spring WS为SOAP执行直接流式传输!

With this setting we are finally able to perform direct streaming for SOAP with Spring WS!

这篇关于如何使用Spring-WS直接传输SOAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆