【问题标题】:JAXB Unmarshalling with MTOM使用 MTOM 进行 JAXB 解组
【发布时间】:2014-04-07 07:38:47
【问题描述】:

我在为 RetrieveDocumentSetResponse 解组 MTOM 时遇到问题,它是 XDS 的一部分。

在我生成的 JAXB 文件中,我只有一个元素文档,它是 byte[]。 在我执行通常的unmarshalling 步骤后:

final JAXBContext jc = JAXBContext.newInstance(RetrieveDocumentSetResponseType.class);
final Unmarshaller u = jc.createUnmarshaller();

final JAXBElement<RetrieveDocumentSetResponseType> rdsJaxb = u.unmarshal(
                    soapResponse.getSOAPBody().getElementsByTagNameNS("urn:ihe:iti:xds-b:2007", "RetrieveDocumentSetResponse").item(0),
                    RetrieveDocumentSetResponseType.class);
final RetrieveDocumentSetResponseType rdsResp = rdsJaxb.getValue();

我的文档是空的:rdsResp.getDocument().length == 0

在与TCPMonitor 核对时,我看到文档正在通过线路发送,因此错误一定是在解组中的某个地方。

我尝试使用 DataHandler 代替 byte[] 并使用 @XMLMimeType 注释来注释文档变量,但无济于事。我使用 TomEE 作为我的部署目标,我相信它使用 RI 版本的 JAXB。

我还在为 Web 服务调用使用常规调度,确保启用 MTOM:

final Service repoService;
final QName repoPort = new QName(XdsProperties.XDS_REPOSITORY_NAMESPACE, XdsProperties.XDS_REPOSITORY_PORT);
        if (XdsProperties.XDS_REPOSITORY_WSDL == null) {
            repoService = Service.create(new QName(XdsProperties.XDS_REPOSITORY_NAMESPACE, XdsProperties.XDS_REPOSITORY_SERVICE));
        } else {
            repoService = Service.create(XdsProperties.XDS_REPOSITORY_WSDL, new QName(XdsProperties.XDS_REPOSITORY_NAMESPACE,
                    XdsProperties.XDS_REPOSITORY_SERVICE));
        }
        repoService.addPort(repoPort, SOAPBinding.SOAP12HTTP_MTOM_BINDING, XdsProperties.XDS_REPOSITORY_ENDPOINT);
final MTOMFeature mtomFt = new MTOMFeature(true);
REPOSITORY_DISPATCH = repoService.createDispatch(repoPort, SOAPMessage.class, Service.Mode.MESSAGE, addrFt, mtomFt);

我什至会这样做:

REPOSITORY_DISPATCH.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, soapAction);       
final SOAPBinding binding = (SOAPBinding) REPOSITORY_DISPATCH.getBinding();         
binding.setMTOMEnabled(true);

我真的不确定出了什么问题或者我应该做什么,因为没有抛出异常,文档总是空的。

【问题讨论】:

    标签: jaxb unmarshalling mtom apache-tomee


    【解决方案1】:

    为了在 JAXB 解组期间解析附件,需要在 Unmarshaller 上设置 AttachmentUnmarshaller

    当 JAX-WS 在后台使用 JAXB 时,这会自动处理。如果您直接与 XML 交互,您将需要自己实现和设置 AttachmentUnmarshaller。下面是一个有用的示例链接:

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 2014-02-10
      • 2013-11-19
      • 1970-01-01
      • 2013-04-13
      相关资源
      最近更新 更多