2014-03-05 84 views
1

我有一个问题解组MTX为RetrieveDocumentSetResponse,这是XDS的一部分。JAXB解组与MTOM

在我生成的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作为我的部署目标,我使用JAXB的RI版本。

我还使用定期调度的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); 

我真的不知道这是怎么回事错误的或者我应该做的事情,因为没有任何异常被抛出,文档总是空的。

回答

0

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

当JAXB在幕后通过JAX-WS杠杆这是自动处理。如果您直接与XML交互,则需要实现并设置您自己的AttachmentUnmarshaller。下面是一个例子的链接,这将有助于: