代码之家  ›  专栏  ›  技术社区  ›  springbootlearner

saajsoapmessagefactory是否支持客户端的mtom resonse

  •  0
  • springbootlearner  · 技术社区  · 6 年前

    我正在编写一个spring webservice客户端,它调用一个soap服务,它返回一个带有附件的soap响应(响应中包含mtom->xop标记)。

    在我当前的客户机代码中,我正在使用saajsoapmessagefactory,并在我的webservicetemplate中注入了相同的代码,而且我在marshaller中将mtomenabled设置为true。

    使用此设置,当我调用soap服务时,我的客户端代码可以读取soap响应体,但响应体中的附件部分是空的。对于soap ui中的相同请求,我可以获取附件。

    客户端的saajsoapmessagefactory是否支持mtom响应?

    1 回复  |  直到 6 年前
        1
  •  0
  •   springbootlearner    6 年前

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