我使用Spring boot starter Web服务来开发带有附件服务的SOAP。
由于未知原因,附件没有被解组。.使用了Jaxb Unmarshaller,但是内部的AttachmentUnmarshaller属性为“ null” ...所以可能是未完成DataHandler解组的原因??
与在JEE环境中一样,attachmentUnmarshaller由jaxws处理。如何在独立进程(如tomcat中的spring boot)上配置它?
Java版本:8_0_191
春季启动版本:2.1
答案 0 :(得分:2)
我也遇到过类似的问题,但是要进行编组。
Jaxb2Marshaller具有自己的AttachmentMarshaller
和AttachmentUnarshaller
实现。但是,为了使它们起作用,应将mtomEnabled
属性设置为true。如果不是,则将使用默认值,该默认值不会被实例化。
尝试在Jaxb2Marshaller上设置setMtomEnabled(true)
。
这可能会解决您的问题。
对于在编组过程中遇到相同问题的人来说,这有点复杂。根据WS-I附件配置文件1.0-http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#Example_Attachment_Description_Using_swaRef
,未正确实现Jaxb2AttachmentMarshaller
然后,您将不得不覆盖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;
}
}
}