Spring ws - 带有 Swaref 的数据处理程序仍然为空 [英] Spring ws - Datahandler with Swaref still null

查看:28
本文介绍了Spring ws - 带有 Swaref 的数据处理程序仍然为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring boot starter Web 服务来开发带有附件服务的 SOAP.

I used the Spring boot starter web services to develop a SOAP with attachment service.

由于未知原因,附件未解组.. 使用了 Jaxb Unmarshaller 但里面的属性 AttachmentUnmarshaller 为null"...所以可能是 DataHandler 解组未完成的原因??

For an unknown reason attachments aren't unmarshalled.. Jaxb Unmarshaller is used but the property AttachmentUnmarshaller inside is "null" ...so probably the reason why DataHandler unmarshalling isn't done ??

在 JEE 环境中,attachmentUnmarshaller 由 jaxws 处理..如何在独立进程中配置它,如 tomcat 上的 spring boot ??

As in a JEE environment the attachmentUnmarshaller is handle by jaxws .. how configure it in a standalone process like spring boot on tomcat ??

Java 版本:8_0_191

Java version : 8_0_191

Spring 启动版本:2.1

Spring boot version : 2.1

推荐答案

我遇到了类似的问题,但需要编组.

I faced similar issue, but with marshalling.

Jaxb2Marshaller 有自己的 AttachmentMarshallerAttachmentUnarshaller 实现.但是为了让这些工作,mtomEnabled 属性应该设置为 true.如果不是,将使用默认值,不会实例化.

Jaxb2Marshaller has its own implementations of AttachmentMarshaller and AttachmentUnarshaller. But for these to work, mtomEnabled property should be set to true. If it's not, defaults will be used, which are not instantiated.

尝试在您的 Jaxb2Marshaller 上设置 setMtomEnabled(true).这可能会解决您的问题.

Try setting setMtomEnabled(true) on your Jaxb2Marshaller. This will probably solve your issue.

对于在编组方面遇到相同问题的人 - 这有点复杂.Jaxb2 AttachmentMarshaller 没有按照 WS-I 附件配置文件 1.0 正确实现 - http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#Example_Attachment_Description_Using_swaRef

For people, who encounter same issue with marshalling - it's a bit more complicated. Jaxb2 AttachmentMarshaller is not correctly implemented as per WS-I Attachment Profile 1.0 - http://www.ws-i.org/Profiles/AttachmentsProfile-1.0.html#Example_Attachment_Description_Using_swaRef

然后,您将必须覆盖 Jaxb2Marshaller 的编组行为.

You will have to override marshalling behavior of Jaxb2Marshaller then.

注意:此解决方案假定 MTOM 始终处于禁用状态.

Notice: this solution assumes that MTOM is always disabled.

@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;
        }
    }
}

这篇关于Spring ws - 带有 Swaref 的数据处理程序仍然为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆