spring - Spring ws - Swaref 的数据处理程序仍然为空
问题描述
我使用 Spring Boot 启动器 Web 服务开发了一个带有附件服务的 SOAP。
由于未知原因,附件未解组。使用了 Jaxb Unmarshaller,但内部的属性 AttachmentUnmarshaller 为“null” ...所以可能是 DataHandler 解组未完成的原因?
与在 JEE 环境中一样,附件Unmarshaller 由 jaxws 处理。如何在独立进程中配置它,例如在 tomcat 上的 spring boot ?
Java 版本:8_0_191
春季启动版本:2.1
解决方案
我遇到了类似的问题,但有编组。
Jaxb2Marshaller 有自己的AttachmentMarshaller
和实现AttachmentUnarshaller
。但是为了使这些工作,mtomEnabled
属性应该设置为 true。如果不是,将使用未实例化的默认值。
尝试setMtomEnabled(true)
在您的 Jaxb2Marshaller 上进行设置。这可能会解决您的问题。
对于遇到相同编组问题的人来说 - 它有点复杂。Jaxb2AttachmentMarshaller
没有按照 WS-I Attachment Profile 1.0 正确实现 - http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#Example_Attachment_Description_Using_swaRef
您将不得不覆盖Jaxb2Marshaller
当时的编组行为。
注意:此解决方案假定 MTOM 始终处于禁用状态。
@Configuration
class SOAPConfiguration {
@Bean
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller() {
@Override
public void marshal(Object graph, Result result, @Nullable MimeContainer mimeContainer) throws XmlMappingException {
try {
javax.xml.bind.Marshaller marshaller = createMarshaller();
if (mimeContainer != null) {
marshaller.setAttachmentMarshaller(
new SwaRefAttachmentMarshaller(mimeContainer)
);
marshaller.marshal(graph, result);
} else {
super.marshal(graph, result, null);
}
} catch (JAXBException ex) {
throw convertJaxbException(ex);
}
}
};
marshaller.setPackagesToScan("my.package");
marshaller.setMtomEnabled(false);
return marshaller;
}
private class SwaRefAttachmentMarshaller extends AttachmentMarshaller {
private final MimeContainer mimeContainer;
private SwaRefAttachmentMarshaller(MimeContainer mimeContainer) {
this.mimeContainer = mimeContainer;
}
@Override
public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) {
return null;
}
@Override
public String addMtomAttachment(byte[] data, int offset, int length, String mimeType, String elementNamespace, String elementLocalName) {
return null;
}
@Override
public String addSwaRefAttachment(DataHandler data) {
String attachmentId = UUID.randomUUID().toString();
mimeContainer.addAttachment("<" + attachmentId + ">", data);
return "cid:" + attachmentId;
}
}
}
推荐阅读
- ios - Xcode 11 的功能中不提供应用内购买
- css - 带有过滤器的 DT::datatable 中的列宽
- kubernetes - 如何使用本地开发 minikube 进入 Kubernetes 中的 postgres
- perl - 无法在 /usr/local/share/perl/5.22.1/RRDTool/OO.pm 创建临时文件
- python - 当还使用组数据计算前一个值时,如何在熊猫数据框中使用前一行值
- java - Websphere 服务器中的静态网站托管
- python - 简单的 TensorFlow 2 分类器不会学习
- javascript - 导入在 Typeorm 中给出未定义
- python - python中的动态类对象日志记录
- java - 从文本文件中读取工单数据