首页 > 解决方案 > SaajSoapMessageFactory 是否在客户端支持 Mtom 响应

问题描述

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

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

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

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

标签: springspring-wsmtomsaaj

解决方案


我已经用 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;
    }

推荐阅读