【问题标题】:Is SaajSoapMessageFactory support Mtom resonse in Client sideSaajSoapMessageFactory 是否支持客户端的 Mtom 响应
【发布时间】:2019-05-03 06:24:00
【问题描述】:

我正在编写一个调用 SOAP 服务的 Spring Web 服务客户端,它返回一个带有附件的 SOAP 响应(MTOM->XOP 在响应中包含标记)。

在我当前的客户端代码中,我使用 SaajSoapMessageFactory 并在我的 WebServiceTemplate 中注入了相同的内容,我还在我的编组器中将 MtomEnabled 设置为 true。

通过此设置,当我调用我的 SOAP 服务时,我的客户端代码可以读取 SOAP 响应正文,但响应正文中的附件部分为空。对于 SOAP UI 中的相同请求,我可以获取附件。

客户端的 SaajSoapMessageFactory 是否支持 MTOM 响应?

【问题讨论】:

  • 也许添加一些代码来显示您如何使用 WebServiceTemplate 以及您如何尝试获取附件。
  • @AndreasVeithen 我已经更新了我的答案。请查看并建议我们是否可以提取其他附件

标签: spring spring-ws mtom saaj


【解决方案1】:

我已经用 SaajSoapMessageFactory 提取了附件

@SuppressWarnings("rawtypes")
public class MtomContentRespExtractor implements WebServiceMessageExtractor {


    private static final Logger logger = LoggerFactory.getLogger(MtomContentRespExtractor.class);

    private JAXBContext jaxbContext = null;
    private Class<MyContentResponse> responseType;

    public MtomContentRespExtractor(JAXBContext jaxbContext,
                       Class<MyContentResponse> responseType) {
        this.jaxbContext  = jaxbContext;
        this.responseType = responseType;

    }

    @Override
    public Object extractData(WebServiceMessage webServiceMsg) throws IOException, TransformerException {


        JAXBElement<MyContentResponse> jaxbElement = null;
        MyContentResponse myContResp = null;


        try {

            jaxbElement = jaxbContext.createUnmarshaller()
                          .unmarshal(webServiceMsg.getPayloadSource(), responseType);

            Attachment attachment = (Attachment) ((SaajSoapMessage) webServiceMsg).getAttachments().next();
            myContResp =    (MyContentResponse) jaxbElement.getValue();
                        attachment.getInputStream()

            //Logic for response


        } catch (JAXBException e) {
            logger.error(e.getMessage());
        }


        return myContResp;
    }

【讨论】:

    猜你喜欢
    • 2019-05-17
    • 2021-02-08
    • 2012-07-23
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 2011-06-26
    • 2010-10-25
    相关资源
    最近更新 更多