JAXWS Soap Handler大型MTOM附件 [英] JAXWS Soap Handler Large MTOM Attachments

查看:119
本文介绍了JAXWS Soap Handler大型MTOM附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IBM SOAP 7和8中的JAXWS实现在肥皂处理程序和大型MTOM附件方面似乎存在一些问题。当在SOAPMessageContext对象上调用getMessage()时,似乎将整个消息(包括所有附件二进制内容)读入内存。这很容易导致JVM耗尽可用内存。

The JAXWS implementation within IBM WebSphere 7 and 8 appears to have some problems when it comes to soap handlers and large MTOM attachments. It appears that the entire message, including all attachment binary content, is read into memory when getMessage() is invoked on the SOAPMessageContext object. This can very easily cause the JVM to run out of available memory.

@Override
public boolean handleMessage(SOAPMessageContext context) {
    SOAPMessage soapMsg = context.getMessage();

    ...
}

在上面的代码片段中如果传入的请求附件大于JVM中可用的可用内存量,context.getMessage()可能导致内存不足。

In the above code snippet, context.getMessage() can result in out of memory exceptions if the incoming request attachments are larger than the amount of free memory available in the JVM.

我怎样才能获得访问SoapHeader元素而不会触发这种不受欢迎的功能?我看到SOAPMessageContext类有一个getHeaders(...)方法,但我不确定如何使用它。我特别不确定要为JAXBContext传递什么。任何人都可以提供一个例子或解释如何使用这种方法吗?

How can I get access to the SoapHeader elements without triggering this undesired functionality? I see that the SOAPMessageContext class has a getHeaders(...) method but I'm not sure how to use it exactly. I'm specifically unsure what to pass in for the JAXBContext. Can anybody provide an example or explanation how to use this method?

这是另一篇相关的stackoverflow文章:带有大消息的JAX-WS SoapHandler:OutOfMemoryError

Here's another related stackoverflow article : JAX-WS SoapHandler with large messages: OutOfMemoryError

推荐答案

以下是如何在不使用WebSphere内置JAX-WS实现读取整个消息的情况下访问标头。

Here is how to access the headers without reading the entire message using the WebSphere built-in JAX-WS implementation.

public boolean handleMessage(SOAPMessageContext context) {

    AttributedURI messageIdURI = (AttributedURI)context.get("com.ibm.wsspi.wsaddressing.inbound.MessageID");
    String messageId = "";
    if (messageIdURI != null && messageIdURI.getURI() != null) {
        messageId = messageIdURI.getURI().toString();
    }
    EndpointReference fromApplicationEPR = (EndpointReference)context.get("com.ibm.wsspi.wsaddressing.inbound.FromEPR");
    String fromApplication = "";
    if (fromApplicationEPR != null && fromApplicationEPR.getAddress() != null &&
        fromApplicationEPR.getAddress().getURI() != null) {
        fromApplication = fromApplicationEPR.getAddress().getURI().toString();
    }

    ...

    return true;
}

请注意,这取决于精确的JAX-WS实现。当我有机会时,我将通过Apache CXF发布如何做到这一点。以下是上述代码所需的导入:

Note that this differs based on the precise JAX-WS implementation. I'll post how to do this via Apache CXF when I get a chance. Here are the needed imports for the above code:

import com.ibm.ws.wsaddressing.AttributedURI;
import com.ibm.ws.wsaddressing.EndpointReference;

这篇关于JAXWS Soap Handler大型MTOM附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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