Hello,

I am developing a WS client for a third-party service (client is
auto-generated from their WSDL using wsdl4java).

The service works fine but I am having difficulty with a download method on
one of the services because it uses MTOM/XOP in order to send the binary
data to the client. 

I create the service like so:
        JaxWsProxyFactoryBean proxyFactoryBean = new
JaxWsProxyFactoryBean();
        Map<String, Object> properties = new HashMap<>();
        properties.put("mtom-enabled", Boolean.TRUE);
        proxyFactoryBean.setProperties(properties);
        proxyFactoryBean.setServiceClass(AIMSLServicePortType.class);
        proxyFactoryBean.setAddress("http://service_url";);
        proxyFactoryBean.setBindingId(SOAPBinding.SOAP11HTTP_MTOM_BINDING);
// tried with and without this
        proxyFactoryBean.getInInterceptors().add(new
LoggingInInterceptor());
        proxyFactoryBean.getOutInterceptors().add(new
LoggingOutInterceptor());

        AIMSLServicePortType aimslService =
(AIMSLServicePortType)proxyFactoryBean.create();

That service has a download method invoked like so:
       Document document = aimslService.pamsDownload(id);

The Document has a property down in there that is mapped to a DataHandler as
I would expect, since the original XSD for that element is as follows:
<xs:element minOccurs="0" name="filecontent" type="xs:base64Binary"
              xmime:expectedContentTypes="application/octet-stream" />

However, after fetching the Document object, the DataHandler's InputStream
is always empty. I've tried all manner of flipping switches in CXF (and
WSS4J because I'm using that too, maybe related) but have not been able to
get that piece to work. I also have WSS4JOutInterceptor in the chain for
doing client signatures but not on the inbound (tried both with and without
with no change).

The attachments are coming through correctly using XOP, I can see them in
the log and if I debug in the AttachmentInInterceptor I can see that it is
being parsed out.

The only way I've successfully been able to get to the DataHandler is by
doing this squirrelly business after calling the 'download' method above:
Collection<Attachment> attachments = (Collection<Attachment>)
                            ((BindingProvider)
aimslService).getResponseContext()
                                    .get(Message.ATTACHMENTS);

However, as the getResponseContext() documentation says, this just returns
the results of the most recent synchronous operation and is going to get
clobbered if some other thread comes in and makes another request.

So my question is... what is the right way to read the attachment? Either to
cleanly access the Message or Attachment in such a way that it's scoped only
to the thread.. or to get the automatic MTOM mapping to the DataHandler to
work right. All the documentation and posts I've read seem to indicate it
should just work with the mtom-enabled flag set to true. I feel like I'm
missing something obvious.

I've also tried this during service configuration but it produces the same
effect:
((SOAPBinding)((BindingProvider)
aimslService).getBinding()).setMTOMEnabled(true); 



--
View this message in context: 
http://cxf.547215.n5.nabble.com/Reading-the-MTOM-XOP-attachment-tp5764160.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to