1

我的问题类似于: 带有大消息的 JAX-WS SoapHandler:OutOfMemoryErrorJAXWS Soap Handler Large MTOM Attachments

我正在使用 tomcat,即 Metro-Runtime-Configuration,当我想在其中添加标头时,HandlerChain它给了我一个OutOfMemory例外。

public boolean handleMessage(SOAPMessageContext smc) {
    if (Boolean.TRUE.equals(smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {
        SOAPMessage sm = smc.getMessage(); // <- OutOfMemory
        ...

在第一个链接中,艾哈迈德写道,I was able to write code that handles the raw data stream in 3 out of the 4 cases. Fortunately the three cases included the two we were mostly interested in: to/from the server.但他没有为此提供代码片段。

我尝试过的事情:

OutOfMemory发生在AbstractMessageImpl#readAsSOAPMessage我无法覆盖的JDK7中。是否可以使用自定义引导程序覆盖该类?以及如何做到这一点?我能够“覆盖” Integer-class,但AbstractMessageImpl没有被采纳。

将运行时更改为 Apache CXF 不适用于我生成的 JAX-WS RI 客户端 ( Cannot create a secure XMLInputFactory)

是否有另一种使用另一个提供程序/运行时的可能性?如果没有,我怎样才能覆盖 JDK7 的AbstractMessageImpl#readAsSOAPMessage

或者:是否可以配置 MTOM 和处理程序链的顺序?MTOM 的消息不应该引发 OutOfMemory,对吗?

在此先感谢克拉皮

4

1 回答 1

2

此处的票证报告中也发现了此问题:https ://java.net/jira/browse/WSIT-1081

我通过不使用处理程序但在创建这样的端口时添加标头来解决此问题:

Web服务创建

WebServiceEndpoint endpoint = w.getWebServiceEndpointPort(new MTOMFeature());
Map<String, Object> ctxt = ((BindingProvider) endpoint).getRequestContext();
// Enable HTTP chunking mode, otherwise HttpURLConnection buffers
ctxt.put("com.sun.xml.ws.transport.http.client.streaming.chunk.size", 8192);
WSBindingProvider bp = (WSBindingProvider) endpoint;
bp.setOutboundHeaders(Headers.create(JAXBContext.newInstance(WSSecurityHeader.class), 
                      new WSSecurityHeader()));

由于方法不提供 Header-creation,因此 JAXB 用于复杂的 header 类型。

WSSecurityHeader.java

@XmlRootElement(name = "Security")
public class WSSecurityHeader {

    @XmlElement(name = "UsernameToken")
    public WSSecurityUsernameToken usernameToken = new WSSecurityUsernameToken();
    ...
}

缺点

客户端需要此代码正在运行的许多库:JAXB、JAX-WS、StreamBuffer、Policy、Stax-Ex、gmbal-api-only,这对于仅添加标头来说是可怕的。(特别是如果您正在与没有 maven 支持的胖客户端一起工作)

于 2013-10-08T12:25:22.157 回答