You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by dolanp <do...@gmail.com> on 2015/12/18 00:38:36 UTC

Reading the MTOM/XOP attachment

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.

Re: Reading the MTOM/XOP attachment

Posted by dolanp <do...@gmail.com>.
Hey there. Glad to hear I'm not the only one. No, unfortunately I never found
a way around it so the synchronous approach was what I used. I believe this
is probably some sort of CXF bug when combining MTOM/XOP and WSS4J.



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

Re: Reading the MTOM/XOP attachment

Posted by JordiCA <jo...@puck.eu>.
Hi,

I happen to be integrating exactly the same third-party service (the name of
the classes gave me the right clue) and found the same issue. The
DataHandler is not properly returning the binary file in the attachment,
that as you did, I confirmed it's being received in the logs.

First of all, THANK YOU SO MUCH for providing the 'squirrelly' work-around
to access the attachment. I was getting desperate trying to make this work
and already started thinking of dirtier solutions like accessing the
attachments through the logging system...
From your comments I understand that as long as the requests to this service
are done in a synchronous way accessing the response context should be safe
enough. I did a few tests and that seems to be the case... Could you
confirm?

Which solution did you finally apply? Did you manage to get the attachments
directly from the DataHandler?

in any case, thanks a lot!



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