我正在编写一个Spring Web服务客户端,该客户端调用一个SOAP服务,它返回带有附件(MTOM-> XOP响应标签中的标签)的SOAP响应。
在我当前的客户端代码中,我正在使用SaajSoapMessageFactory并将其注入到WebServiceTemplate中,并且在编组器中将MtomEnabled设置为true。
通过这种设置,当我调用SOAP服务时,我的客户端代码可以读取SOAP响应正文,但是Response正文中的附件部分为空。对于SOAP UI中的相同请求,我可以获取附件。
客户端的SaajSoapMessageFactory是否支持MTOM响应?
答案 0 :(得分:0)
我已经用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;
}