spring - SaajSoapMessageFactory 是否在客户端支持 Mtom 响应
问题描述
我正在编写一个调用 SOAP 服务的 Spring Web 服务客户端,它返回一个带有附件的 SOAP 响应(MTOM-> XOP 在响应中包含标记)。
在我当前的客户端代码中,我使用 SaajSoapMessageFactory 并在我的 WebServiceTemplate 中注入了相同的内容,我还在我的编组器中将 MtomEnabled 设置为 true。
通过此设置,当我调用 SOAP 服务时,我的客户端代码可以读取 SOAP 响应正文,但响应正文中的附件部分为空。对于 SOAP UI 中的相同请求,我可以获得附件。
客户端中的 SaajSoapMessageFactory 是否支持 MTOM 响应?
解决方案
我已经用 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;
}
推荐阅读
- css - angularjs将括号添加到数组值输出
- python - PyQt5 鼠标悬停功能
- node.js - 如何访问写在 docker 容器卷上的文件并使用 NGINX 将 URL 共享给客户端
- javascript - 在用户选择旁边显示一个菜单
- android - recycler view Items之间如何通信
- python - 从规则冻结集中提取字符串
- java - Spock 使用 spring-boot-starter 1.5.16.RELEASE 测试问题
- python - 使用 Python 进行主成分分析
- python - 反向累积以获取 Pandas 中的逐月数据
- nginx - 如何在 Nginx 中拒绝包含点点斜杠(相对路径)的路径?