【问题标题】:JAX-WS: OutOfMemory with large attachments + ChainHandlerJAX-WS:带有大型附件的 OutOfMemory + ChainHandler
【发布时间】:2013-10-07 15:55:17
【问题描述】:

我的问题类似于: JAX-WS SoapHandler with large messages: 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
        ...

在第一个链接中,Ahmed 写道 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.,但他没有为此提供代码 sn-p。

我尝试过的事情:

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

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

还有其他使用其他提供程序/运行时的可能性吗?如果没有,我该如何覆盖JDK7的AbstractMessageImpl#readAsSOAPMessage

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

在此先感谢你的克拉皮

【问题讨论】:

    标签: tomcat soap jax-ws out-of-memory mtom


    【解决方案1】:

    此问题也可以在此处的工单报告中找到:https://java.net/jira/browse/WSIT-1081

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

    网络服务创建

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

    由于没有提供方法创建标头,因此 JAXB 用于复杂的标头类型。

    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 支持的情况下使用胖客户端)

    【讨论】:

      猜你喜欢
      • 2020-03-07
      • 2013-03-05
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多