You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by manjuljaiswal <ma...@gmail.com> on 2013/12/06 17:09:32 UTC

Re: Attachments for Dispatch not supported?

I came across this thread when I ended up in the same issue as mentioned in
this thread. I have a situation where I have to send an attachment (using
MTOM) from client to the webservice as well as recieve an attachment back
from the service. with jaxws.sun.com as my webservice provider my JAXWS
dispatch code works fine but with CXF as my webservice provider I am not
able to send the attachments from the client(they are simply not sent). I
have tried everything mentioned in this thread.

The code below does not work with CXF and I get an error "A data handler was
not found for content id cid:attachment-1"

Map<String, DataHandler> attachments = new HashMap<String, DataHandler>();
ByteArrayDataSource rawData= new ByteArrayDataSource(bytearray,
"application/octet-stream");
DataHandler data= new DataHandler(rawData);
attachments.put("attachment-1", data);
dispatch.getRequestContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
attachments);
....
Object response = dispatch.invoke(request);

I also tried the below ways of doing it. (using CXF API for Attachment and
AttachmentImpl)

List<Attachment> attachments = new ArrayList<Attachment>(); 
ByteArrayDataSource rawData= new ByteArrayDataSource(bytearray,
"application/octet-stream");
    	
InternetHeaders headers = new InternetHeaders(); 
headers.addHeader("Content-Type", "application/octet-stream"); 
headers.addHeader("Content-ID", "attachment-1");
Attachment attach =
AttachmentUtil.createAttachment(rawData.getInputStream(), headers);
attachments.add(attach);
dispatch.getRequestContext().put(Message.ATTACHMENTS, attachments);

AND 

AttachmentImpl attachment = new AttachmentImpl("attachment-1");
DataHandler dataHandler = new DataHandler(new
ByteDataSource(mtomAttachment.getBytes(), "application/octet-stream"));
attachment.setDataHandler(dataHandler);
attachments.add(attachment);
dispatch.getRequestContext().put(Message.ATTACHMENTS, attachments);

but with these I am getting  org.apache.cxf.attachment.AttachmentImpl cannot
be cast to org.apache.cxf.message.Attachment which does not make any sense
to me.

Please can someone help me with how this can be made to work.

Thanks.



--
View this message in context: http://cxf.547215.n5.nabble.com/Attachments-for-Dispatch-not-supported-tp5729017p5737475.html
Sent from the cxf-user mailing list archive at Nabble.com.