You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Dennis Sosnoski <dm...@sosnoski.com> on 2013/06/09 04:41:17 UTC

Attachments for Dispatch not supported?

I've been trying to use attachments with the Dispatch api, and haven't 
been able to make it work. After digging through the code I couldn't see 
anywhere that it was even trying to make it work. Is this just not 
supported?

Attachments work without any problems on the Provider side.

Here's a sample for Dispatch:

         // create and configure the dispatch object with actual service 
endpoint address
         Service service = Service.create(new 
QName("http://cxf.apache.org", "attachmentService"));
         QName portQName = new QName("http://cxf.apache.org", 
"attachmentPort");
         service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING, 
args[0]);
         Dispatch<Source> dispatch = service.createDispatch(portQName, 
Source.class, Service.Mode.PAYLOAD,
             new AddressingFeature(true));
         SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
         binding.setMTOMEnabled(true);

         // configure logging to view messages being exchanged
         ...

         // set attachment to be sent
         Map<String, Object> requestContext = dispatch.getRequestContext();
         Map<String, DataHandler> attachments = (Map<String, 
DataHandler>)requestContext.
             get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
         if (attachments == null) {
             attachments = new HashMap<String, DataHandler>();
requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, 
attachments);
         }
         byte[] bytes = new byte[1024];
         for (int i = 0; i < bytes.length; i++) {
             bytes[i] = (byte)i;
         }
         attachments.put("attachment-1", new DataHandler(new 
ByteArrayDataSource(bytes)));

         // configure the WS-Addressing Action to select operation
         ...

         // execute the request
         Source response = dispatch.invoke(new StreamSource(new 
ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
         System.out.println("Success");

The request gets sent using mime, but without the attachment. Here's the 
Provider code that works:

@MTOM(threshold = 0, enabled = true)
@WebServiceProvider(
   portName = AttachConstants.PORT_LOCALNAME,
   serviceName = AttachConstants.SERVICE_LOCALNAME,
   targetNamespace = AttachConstants.SERVICE_NAMESPACE)
@ServiceMode(value = Service.Mode.PAYLOAD)
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class AttachProvider implements Provider<StreamSource>
{
     /** Injected context for invocations. */
     @Resource
     private WebServiceContext serviceContext;

     private void setAttachment(DataHandler handler) {
         Map<String, DataHandler> attachments = new HashMap<String, 
DataHandler>();
         attachments.put(AttachConstants.OUT_ATTACH_ID, handler);
serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, 
attachments);
     }

     public StreamSource invoke(StreamSource request) {
         ...
            byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
             for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
                 bytes[i] = (byte)i;
             }
             setAttachment(new DataHandler(new ByteArrayDataSource(bytes)));

Has anyone else gotten Dispatch attachments to work?

Thanks,

   - Dennis

-- 

Dennis M. Sosnoski
Java SOA and Web Services Consulting <http://www.sosnoski.com/consult.html>
CXF and Web Services Security Training 
<http://www.sosnoski.com/training.html>
Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>


Re: Attachments for Dispatch not supported?

Posted by manjuljaiswal <ma...@gmail.com>.
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.

Re: Attachments for Dispatch not supported?

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Thanks, Aki. I was going to do this myself, but have been wrapped up in 
other issues.

Just for anyone else catching this thread, the JAX-WS technique 
currently works for attachments returned by the service (on both service 
and client side), but not for attachments sent by the client.

   - Dennis


On 06/27/2013 10:39 PM, Aki Yoshida wrote:
> I created CXF-5095 to allow adding attachments using jaxws
> attachments<https://issues.apache.org/jira/browse/CXF-5095> and
> mentioned there two approaches that I tried and of which, I prefer option 2.
>
>
>
> 2013/6/11 Daniel Kulp <dk...@apache.org>
>
>> This SHOULD be handled in the WrappedMessageContext, but it looks
>> potentially incomplete.  The "put" is certainly not wired in for the
>> MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS key.   However, it looks like
>> the get should have returned a viable Map.  I guess the suggestion is to
>> breakpoint in the AttachmentOutInterceptor and see if it's managed to see
>> if an attachment is there or not.
>>
>> Dan
>>
>>
>>
>> On Jun 8, 2013, at 10:41 PM, Dennis Sosnoski <dm...@sosnoski.com> wrote:
>>
>>> I've been trying to use attachments with the Dispatch api, and haven't
>> been able to make it work. After digging through the code I couldn't see
>> anywhere that it was even trying to make it work. Is this just not
>> supported?
>>> Attachments work without any problems on the Provider side.
>>>
>>> Here's a sample for Dispatch:
>>>
>>>         // create and configure the dispatch object with actual service
>> endpoint address
>>>         Service service = Service.create(new QName("http://cxf.apache.org",
>> "attachmentService"));
>>>         QName portQName = new QName("http://cxf.apache.org",
>> "attachmentPort");
>>>         service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING,
>> args[0]);
>>>         Dispatch<Source> dispatch = service.createDispatch(portQName,
>> Source.class, Service.Mode.PAYLOAD,
>>>             new AddressingFeature(true));
>>>         SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
>>>         binding.setMTOMEnabled(true);
>>>
>>>         // configure logging to view messages being exchanged
>>>         ...
>>>
>>>         // set attachment to be sent
>>>         Map<String, Object> requestContext = dispatch.getRequestContext();
>>>         Map<String, DataHandler> attachments = (Map<String,
>> DataHandler>)requestContext.
>>>             get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
>>>         if (attachments == null) {
>>>             attachments = new HashMap<String, DataHandler>();
>>> requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
>> attachments);
>>>         }
>>>         byte[] bytes = new byte[1024];
>>>         for (int i = 0; i < bytes.length; i++) {
>>>             bytes[i] = (byte)i;
>>>         }
>>>         attachments.put("attachment-1", new DataHandler(new
>> ByteArrayDataSource(bytes)));
>>>         // configure the WS-Addressing Action to select operation
>>>         ...
>>>
>>>         // execute the request
>>>         Source response = dispatch.invoke(new StreamSource(new
>> ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
>>>         System.out.println("Success");
>>>
>>> The request gets sent using mime, but without the attachment. Here's the
>> Provider code that works:
>>> @MTOM(threshold = 0, enabled = true)
>>> @WebServiceProvider(
>>>   portName = AttachConstants.PORT_LOCALNAME,
>>>   serviceName = AttachConstants.SERVICE_LOCALNAME,
>>>   targetNamespace = AttachConstants.SERVICE_NAMESPACE)
>>> @ServiceMode(value = Service.Mode.PAYLOAD)
>>> @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
>>> public class AttachProvider implements Provider<StreamSource>
>>> {
>>>     /** Injected context for invocations. */
>>>     @Resource
>>>     private WebServiceContext serviceContext;
>>>
>>>     private void setAttachment(DataHandler handler) {
>>>         Map<String, DataHandler> attachments = new HashMap<String,
>> DataHandler>();
>>>         attachments.put(AttachConstants.OUT_ATTACH_ID, handler);
>>>
>> serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
>> attachments);
>>>     }
>>>
>>>     public StreamSource invoke(StreamSource request) {
>>>         ...
>>>            byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
>>>             for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
>>>                 bytes[i] = (byte)i;
>>>             }
>>>             setAttachment(new DataHandler(new
>> ByteArrayDataSource(bytes)));
>>> Has anyone else gotten Dispatch attachments to work?
>>>
>>> Thanks,
>>>
>>>   - Dennis
>>>
>>> --
>>>
>>> Dennis M. Sosnoski
>>> Java SOA and Web Services Consulting <
>> http://www.sosnoski.com/consult.html>
>>> CXF and Web Services Security Training <
>> http://www.sosnoski.com/training.html>
>>> Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
>>>
>> --
>> Daniel Kulp
>> dkulp@apache.org - http://dankulp.com/blog
>> Talend Community Coder - http://coders.talend.com
>>
>>


Re: Attachments for Dispatch not supported?

Posted by Aki Yoshida <el...@gmail.com>.
I created CXF-5095 to allow adding attachments using jaxws
attachments<https://issues.apache.org/jira/browse/CXF-5095> and
mentioned there two approaches that I tried and of which, I prefer option 2.



2013/6/11 Daniel Kulp <dk...@apache.org>

>
> This SHOULD be handled in the WrappedMessageContext, but it looks
> potentially incomplete.  The "put" is certainly not wired in for the
> MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS key.   However, it looks like
> the get should have returned a viable Map.  I guess the suggestion is to
> breakpoint in the AttachmentOutInterceptor and see if it's managed to see
> if an attachment is there or not.
>
> Dan
>
>
>
> On Jun 8, 2013, at 10:41 PM, Dennis Sosnoski <dm...@sosnoski.com> wrote:
>
> > I've been trying to use attachments with the Dispatch api, and haven't
> been able to make it work. After digging through the code I couldn't see
> anywhere that it was even trying to make it work. Is this just not
> supported?
> >
> > Attachments work without any problems on the Provider side.
> >
> > Here's a sample for Dispatch:
> >
> >        // create and configure the dispatch object with actual service
> endpoint address
> >        Service service = Service.create(new QName("http://cxf.apache.org",
> "attachmentService"));
> >        QName portQName = new QName("http://cxf.apache.org",
> "attachmentPort");
> >        service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING,
> args[0]);
> >        Dispatch<Source> dispatch = service.createDispatch(portQName,
> Source.class, Service.Mode.PAYLOAD,
> >            new AddressingFeature(true));
> >        SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
> >        binding.setMTOMEnabled(true);
> >
> >        // configure logging to view messages being exchanged
> >        ...
> >
> >        // set attachment to be sent
> >        Map<String, Object> requestContext = dispatch.getRequestContext();
> >        Map<String, DataHandler> attachments = (Map<String,
> DataHandler>)requestContext.
> >            get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
> >        if (attachments == null) {
> >            attachments = new HashMap<String, DataHandler>();
> > requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
> attachments);
> >        }
> >        byte[] bytes = new byte[1024];
> >        for (int i = 0; i < bytes.length; i++) {
> >            bytes[i] = (byte)i;
> >        }
> >        attachments.put("attachment-1", new DataHandler(new
> ByteArrayDataSource(bytes)));
> >
> >        // configure the WS-Addressing Action to select operation
> >        ...
> >
> >        // execute the request
> >        Source response = dispatch.invoke(new StreamSource(new
> ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
> >        System.out.println("Success");
> >
> > The request gets sent using mime, but without the attachment. Here's the
> Provider code that works:
> >
> > @MTOM(threshold = 0, enabled = true)
> > @WebServiceProvider(
> >  portName = AttachConstants.PORT_LOCALNAME,
> >  serviceName = AttachConstants.SERVICE_LOCALNAME,
> >  targetNamespace = AttachConstants.SERVICE_NAMESPACE)
> > @ServiceMode(value = Service.Mode.PAYLOAD)
> > @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
> > public class AttachProvider implements Provider<StreamSource>
> > {
> >    /** Injected context for invocations. */
> >    @Resource
> >    private WebServiceContext serviceContext;
> >
> >    private void setAttachment(DataHandler handler) {
> >        Map<String, DataHandler> attachments = new HashMap<String,
> DataHandler>();
> >        attachments.put(AttachConstants.OUT_ATTACH_ID, handler);
> >
> serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
> attachments);
> >    }
> >
> >    public StreamSource invoke(StreamSource request) {
> >        ...
> >           byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
> >            for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
> >                bytes[i] = (byte)i;
> >            }
> >            setAttachment(new DataHandler(new
> ByteArrayDataSource(bytes)));
> >
> > Has anyone else gotten Dispatch attachments to work?
> >
> > Thanks,
> >
> >  - Dennis
> >
> > --
> >
> > Dennis M. Sosnoski
> > Java SOA and Web Services Consulting <
> http://www.sosnoski.com/consult.html>
> > CXF and Web Services Security Training <
> http://www.sosnoski.com/training.html>
> > Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
> >
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>

RE: Attachments for Dispatch not supported?

Posted by Jesse Pangburn <Je...@infor.com>.
I use Dispatch and got attachments to work inbound/outbound for it.  For outbound, it's basically these steps (carving the relevant lines from my code, leaving out the rest):

Collection<Attachment> attachments = new LinkedList<Attachment>();
// do a loop here to create your attachments
	String id = attachmentEntry.getKey();
	AttachmentImpl newAttachment = new AttachmentImpl(id);
	attachments.add(newAttachment);
	// do a loop to set any headers you have
		newAttachment.setHeader(headerName, headerValue);
	// there are a couple ways to provide the data for an attachment, I use a couple of them, but here's the easiest one
	byte[] attachmentContent = // your byte content
	dataHandler = new DataHandler(new ByteDataSource(attachmentContent, contentType));
	newAttachment.setDataHandler(dataHandler);
// attach that list to your message
dispatch.getRequestContext().put(Message.ATTACHMENTS, attachments);

Do this as about the last thing before you send the message, I recall some sort of ordering trouble with attachments although maybe that was on the response.

Good luck,
Jesse

-----Original Message-----
From: Daniel Kulp [mailto:dkulp@apache.org] 
Sent: Tuesday, June 11, 2013 10:50 AM
To: users@cxf.apache.org; Dennis Sosnoski
Subject: Re: Attachments for Dispatch not supported?


This SHOULD be handled in the WrappedMessageContext, but it looks potentially incomplete.  The "put" is certainly not wired in for the MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS key.   However, it looks like the get should have returned a viable Map.  I guess the suggestion is to breakpoint in the AttachmentOutInterceptor and see if it's managed to see if an attachment is there or not.   

Dan



On Jun 8, 2013, at 10:41 PM, Dennis Sosnoski <dm...@sosnoski.com> wrote:

> I've been trying to use attachments with the Dispatch api, and haven't been able to make it work. After digging through the code I couldn't see anywhere that it was even trying to make it work. Is this just not supported?
> 
> Attachments work without any problems on the Provider side.
> 
> Here's a sample for Dispatch:
> 
>        // create and configure the dispatch object with actual service endpoint address
>        Service service = Service.create(new QName("http://cxf.apache.org", "attachmentService"));
>        QName portQName = new QName("http://cxf.apache.org", "attachmentPort");
>        service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING, args[0]);
>        Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD,
>            new AddressingFeature(true));
>        SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
>        binding.setMTOMEnabled(true);
> 
>        // configure logging to view messages being exchanged
>        ...
> 
>        // set attachment to be sent
>        Map<String, Object> requestContext = dispatch.getRequestContext();
>        Map<String, DataHandler> attachments = (Map<String, DataHandler>)requestContext.
>            get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
>        if (attachments == null) {
>            attachments = new HashMap<String, DataHandler>(); 
> requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachments);
>        }
>        byte[] bytes = new byte[1024];
>        for (int i = 0; i < bytes.length; i++) {
>            bytes[i] = (byte)i;
>        }
>        attachments.put("attachment-1", new DataHandler(new 
> ByteArrayDataSource(bytes)));
> 
>        // configure the WS-Addressing Action to select operation
>        ...
> 
>        // execute the request
>        Source response = dispatch.invoke(new StreamSource(new ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
>        System.out.println("Success");
> 
> The request gets sent using mime, but without the attachment. Here's the Provider code that works:
> 
> @MTOM(threshold = 0, enabled = true)
> @WebServiceProvider(
>  portName = AttachConstants.PORT_LOCALNAME,  serviceName = 
> AttachConstants.SERVICE_LOCALNAME,
>  targetNamespace = AttachConstants.SERVICE_NAMESPACE)
> @ServiceMode(value = Service.Mode.PAYLOAD)
> @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
> public class AttachProvider implements Provider<StreamSource> {
>    /** Injected context for invocations. */
>    @Resource
>    private WebServiceContext serviceContext;
> 
>    private void setAttachment(DataHandler handler) {
>        Map<String, DataHandler> attachments = new HashMap<String, DataHandler>();
>        attachments.put(AttachConstants.OUT_ATTACH_ID, handler); 
> serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachments);
>    }
> 
>    public StreamSource invoke(StreamSource request) {
>        ...
>           byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
>            for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
>                bytes[i] = (byte)i;
>            }
>            setAttachment(new DataHandler(new 
> ByteArrayDataSource(bytes)));
> 
> Has anyone else gotten Dispatch attachments to work?
> 
> Thanks,
> 
>  - Dennis
> 
> --
> 
> Dennis M. Sosnoski
> Java SOA and Web Services Consulting 
> <http://www.sosnoski.com/consult.html>
> CXF and Web Services Security Training 
> <http://www.sosnoski.com/training.html>
> Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
> 

--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com


Re: Attachments for Dispatch not supported?

Posted by Daniel Kulp <dk...@apache.org>.
This SHOULD be handled in the WrappedMessageContext, but it looks potentially incomplete.  The "put" is certainly not wired in for the MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS key.   However, it looks like the get should have returned a viable Map.  I guess the suggestion is to breakpoint in the AttachmentOutInterceptor and see if it's managed to see if an attachment is there or not.   

Dan



On Jun 8, 2013, at 10:41 PM, Dennis Sosnoski <dm...@sosnoski.com> wrote:

> I've been trying to use attachments with the Dispatch api, and haven't been able to make it work. After digging through the code I couldn't see anywhere that it was even trying to make it work. Is this just not supported?
> 
> Attachments work without any problems on the Provider side.
> 
> Here's a sample for Dispatch:
> 
>        // create and configure the dispatch object with actual service endpoint address
>        Service service = Service.create(new QName("http://cxf.apache.org", "attachmentService"));
>        QName portQName = new QName("http://cxf.apache.org", "attachmentPort");
>        service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING, args[0]);
>        Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD,
>            new AddressingFeature(true));
>        SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
>        binding.setMTOMEnabled(true);
> 
>        // configure logging to view messages being exchanged
>        ...
> 
>        // set attachment to be sent
>        Map<String, Object> requestContext = dispatch.getRequestContext();
>        Map<String, DataHandler> attachments = (Map<String, DataHandler>)requestContext.
>            get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
>        if (attachments == null) {
>            attachments = new HashMap<String, DataHandler>();
> requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachments);
>        }
>        byte[] bytes = new byte[1024];
>        for (int i = 0; i < bytes.length; i++) {
>            bytes[i] = (byte)i;
>        }
>        attachments.put("attachment-1", new DataHandler(new ByteArrayDataSource(bytes)));
> 
>        // configure the WS-Addressing Action to select operation
>        ...
> 
>        // execute the request
>        Source response = dispatch.invoke(new StreamSource(new ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
>        System.out.println("Success");
> 
> The request gets sent using mime, but without the attachment. Here's the Provider code that works:
> 
> @MTOM(threshold = 0, enabled = true)
> @WebServiceProvider(
>  portName = AttachConstants.PORT_LOCALNAME,
>  serviceName = AttachConstants.SERVICE_LOCALNAME,
>  targetNamespace = AttachConstants.SERVICE_NAMESPACE)
> @ServiceMode(value = Service.Mode.PAYLOAD)
> @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
> public class AttachProvider implements Provider<StreamSource>
> {
>    /** Injected context for invocations. */
>    @Resource
>    private WebServiceContext serviceContext;
> 
>    private void setAttachment(DataHandler handler) {
>        Map<String, DataHandler> attachments = new HashMap<String, DataHandler>();
>        attachments.put(AttachConstants.OUT_ATTACH_ID, handler);
> serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, attachments);
>    }
> 
>    public StreamSource invoke(StreamSource request) {
>        ...
>           byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
>            for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
>                bytes[i] = (byte)i;
>            }
>            setAttachment(new DataHandler(new ByteArrayDataSource(bytes)));
> 
> Has anyone else gotten Dispatch attachments to work?
> 
> Thanks,
> 
>  - Dennis
> 
> -- 
> 
> Dennis M. Sosnoski
> Java SOA and Web Services Consulting <http://www.sosnoski.com/consult.html>
> CXF and Web Services Security Training <http://www.sosnoski.com/training.html>
> Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>
> 

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Attachments for Dispatch not supported?

Posted by Jaiyasree <ja...@gmail.com>.
 I am trying to send attachments from client to server. I tried setting in
both the ways Message.Attachments and
MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS.

Both are not working. It throws Attachment of type class <requestobject> are
not supported in SwAOutInterceptor itself.
Is there any way I can solve this issue.

Thanks,
Jai



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

Re: Attachments for Dispatch not supported?

Posted by Jaiyasree <ja...@gmail.com>.
I am not able to instantiate WrappedAttachments even after including
frontend-jaxws jar in my project



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

RE: Attachments for Dispatch not supported?

Posted by Andrei Shakirin <as...@talend.com>.
Hi Dennis,

The following code works for me with Dispatch interface:

...
Dispatch<SOAPMessage> dispatch = service1.createDispatch(portName1,  SOAPMessage.class, Mode.MESSAGE);
Map<String, DataHandler> attachments = buildAttachments();
dispatch.getRequestContext().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
                        attachments);
...

Regards,
Andrei

> -----Original Message-----
> From: Dennis Sosnoski [mailto:dms@sosnoski.com]
> Sent: Sonntag, 9. Juni 2013 04:41
> To: users@cxf.apache.org
> Subject: Attachments for Dispatch not supported?
> 
> I've been trying to use attachments with the Dispatch api, and haven't been
> able to make it work. After digging through the code I couldn't see anywhere
> that it was even trying to make it work. Is this just not supported?
> 
> Attachments work without any problems on the Provider side.
> 
> Here's a sample for Dispatch:
> 
>          // create and configure the dispatch object with actual service endpoint
> address
>          Service service = Service.create(new QName("http://cxf.apache.org",
> "attachmentService"));
>          QName portQName = new QName("http://cxf.apache.org",
> "attachmentPort");
>          service.addPort(portQName, SOAPBinding.SOAP12HTTP_BINDING,
> args[0]);
>          Dispatch<Source> dispatch = service.createDispatch(portQName,
> Source.class, Service.Mode.PAYLOAD,
>              new AddressingFeature(true));
>          SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
>          binding.setMTOMEnabled(true);
> 
>          // configure logging to view messages being exchanged
>          ...
> 
>          // set attachment to be sent
>          Map<String, Object> requestContext = dispatch.getRequestContext();
>          Map<String, DataHandler> attachments = (Map<String,
> DataHandler>)requestContext.
>              get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
>          if (attachments == null) {
>              attachments = new HashMap<String, DataHandler>();
> requestContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
> attachments);
>          }
>          byte[] bytes = new byte[1024];
>          for (int i = 0; i < bytes.length; i++) {
>              bytes[i] = (byte)i;
>          }
>          attachments.put("attachment-1", new DataHandler(new
> ByteArrayDataSource(bytes)));
> 
>          // configure the WS-Addressing Action to select operation
>          ...
> 
>          // execute the request
>          Source response = dispatch.invoke(new StreamSource(new
> ByteArrayInputStream("<test/>".getBytes("UTF-8"))));
>          System.out.println("Success");
> 
> The request gets sent using mime, but without the attachment. Here's the
> Provider code that works:
> 
> @MTOM(threshold = 0, enabled = true)
> @WebServiceProvider(
>    portName = AttachConstants.PORT_LOCALNAME,
>    serviceName = AttachConstants.SERVICE_LOCALNAME,
>    targetNamespace = AttachConstants.SERVICE_NAMESPACE)
> @ServiceMode(value = Service.Mode.PAYLOAD)
> @BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
> public class AttachProvider implements Provider<StreamSource> {
>      /** Injected context for invocations. */
>      @Resource
>      private WebServiceContext serviceContext;
> 
>      private void setAttachment(DataHandler handler) {
>          Map<String, DataHandler> attachments = new HashMap<String,
> DataHandler>();
>          attachments.put(AttachConstants.OUT_ATTACH_ID, handler);
> serviceContext.getMessageContext().put(MessageContext.OUTBOUND_MESSA
> GE_ATTACHMENTS,
> attachments);
>      }
> 
>      public StreamSource invoke(StreamSource request) {
>          ...
>             byte[] bytes = new byte[AttachConstants.ATTACHMENT_SIZE];
>              for (int i = 0; i < AttachConstants.ATTACHMENT_SIZE; i++) {
>                  bytes[i] = (byte)i;
>              }
>              setAttachment(new DataHandler(new ByteArrayDataSource(bytes)));
> 
> Has anyone else gotten Dispatch attachments to work?
> 
> Thanks,
> 
>    - Dennis
> 
> --
> 
> Dennis M. Sosnoski
> Java SOA and Web Services Consulting
> <http://www.sosnoski.com/consult.html>
> CXF and Web Services Security Training
> <http://www.sosnoski.com/training.html>
> Web Services Jump-Start <http://www.sosnoski.com/jumpstart.html>


Re: Attachments for Dispatch not supported?

Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Yes, I can't see anywhere that it's happening.

As I read the JAX-WS spec, though, it sounds like it's supposed to:

JAX-WS 2.2

10.1.1.2 SOAP Handlers
...
Mime attachments specified by the 
javax.xml.ws.binding.attachments.inbound and javax.xml-
.ws.binding.attachments.outbound properties defined in the 
MessageContext 9.2 can be modified
in logical handlers. A SOAP message with the attachments specified using 
the properties is generated
before invoking the first SOAPHandler. Any changes to the two properites 
in consideration above in the
MessageContext after invoking the first SOAPHandler are ignored. The 
SOAPHandler however may
change the properties in the MessageContext

Use of javax.xml.ws.binding.attachments.outbound property in Dispatch
• When using Dispatch in SOAP / HTTP binding in payload mode, 
attachments specified using the
javax.xml.ws.binding.attachments.outbound property will be included as 
mime attachments
in the message.
• When using Dispatch in SOAP / HTTP binding in message mode, the 
javax.xml.ws.binding-
.attachments.outbound property will be ignored as the message type 
already provides a way to
specify attachments.

Anyone else care to offer an opinion?

- Dennis

On 06/10/2013 10:03 PM, Aki Yoshida wrote:
> I know it's working for the SOAPMessage mode, as you can get the SOAP
> message and attach attachments directly before dispatching.
>
> But I am not sure how to get it working with the Source mode. You need
> something that pulls the attachments from the request context and put them
> in the SOAP message so that the serialization picks up the attachments. I
> don't know where this is happening.
>
>
> 2013/6/9 Dennis Sosnoski <dm...@sosnoski.com>
>
>> I've been trying to use attachments with the Dispatch api, and haven't
>> been able to make it work. After digging through the code I couldn't see
>> anywhere that it was even trying to make it work. Is this just not
>> supported?
>>
>> Attachments work without any problems on the Provider side.
>>
>> Here's a sample for Dispatch:
>>
>>          // create and configure the dispatch object with actual service
>> endpoint address
>>          Service service = Service.create(new QName("http://cxf.apache.org",
>> "attachmentService"));
>>          QName portQName = new QName("http://cxf.apache.org",
>> "attachmentPort");
>>          service.addPort(portQName, SOAPBinding.SOAP12HTTP_**BINDING,
>> args[0]);
>>          Dispatch<Source> dispatch = service.createDispatch(**portQName,
>> Source.class, Service.Mode.PAYLOAD,
>>              new AddressingFeature(true));
>>          SOAPBinding binding = (SOAPBinding)dispatch.**getBinding();
>>          binding.setMTOMEnabled(true);
>>
>>          // configure logging to view messages being exchanged
>>          ...
>>
>>          // set attachment to be sent
>>          Map<String, Object> requestContext = dispatch.getRequestContext();
>>          Map<String, DataHandler> attachments = (Map<String,
>> DataHandler>)requestContext.
>>              get(MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS);
>>          if (attachments == null) {
>>              attachments = new HashMap<String, DataHandler>();
>> requestContext.put(**MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS,
>> attachments);
>>          }
>>          byte[] bytes = new byte[1024];
>>          for (int i = 0; i < bytes.length; i++) {
>>              bytes[i] = (byte)i;
>>          }
>>          attachments.put("attachment-1"**, new DataHandler(new
>> ByteArrayDataSource(bytes)));
>>
>>          // configure the WS-Addressing Action to select operation
>>          ...
>>
>>          // execute the request
>>          Source response = dispatch.invoke(new StreamSource(new
>> ByteArrayInputStream("<test/>"**.getBytes("UTF-8"))));
>>          System.out.println("Success");
>>
>> The request gets sent using mime, but without the attachment. Here's the
>> Provider code that works:
>>
>> @MTOM(threshold = 0, enabled = true)
>> @WebServiceProvider(
>>    portName = AttachConstants.PORT_**LOCALNAME,
>>    serviceName = AttachConstants.SERVICE_**LOCALNAME,
>>    targetNamespace = AttachConstants.SERVICE_**NAMESPACE)
>> @ServiceMode(value = Service.Mode.PAYLOAD)
>> @BindingType(javax.xml.ws.**soap.SOAPBinding.SOAP12HTTP_**BINDING)
>> public class AttachProvider implements Provider<StreamSource>
>> {
>>      /** Injected context for invocations. */
>>      @Resource
>>      private WebServiceContext serviceContext;
>>
>>      private void setAttachment(DataHandler handler) {
>>          Map<String, DataHandler> attachments = new HashMap<String,
>> DataHandler>();
>>          attachments.put(**AttachConstants.OUT_ATTACH_ID, handler);
>> serviceContext.**getMessageContext().put(**MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS,
>> attachments);
>>      }
>>
>>      public StreamSource invoke(StreamSource request) {
>>          ...
>>             byte[] bytes = new byte[AttachConstants.**ATTACHMENT_SIZE];
>>              for (int i = 0; i < AttachConstants.ATTACHMENT_**SIZE; i++) {
>>                  bytes[i] = (byte)i;
>>              }
>>              setAttachment(new DataHandler(new ByteArrayDataSource(bytes)));
>>
>> Has anyone else gotten Dispatch attachments to work?
>>
>> Thanks,
>>
>>    - Dennis
>>
>> --
>>
>> Dennis M. Sosnoski
>> Java SOA and Web Services Consulting <http://www.sosnoski.com/**
>> consult.html <http://www.sosnoski.com/consult.html>>
>> CXF and Web Services Security Training <http://www.sosnoski.com/**
>> training.html <http://www.sosnoski.com/training.html>>
>> Web Services Jump-Start <http://www.sosnoski.com/**jumpstart.html<http://www.sosnoski.com/jumpstart.html>
>>


Re: Attachments for Dispatch not supported?

Posted by Aki Yoshida <el...@gmail.com>.
I know it's working for the SOAPMessage mode, as you can get the SOAP
message and attach attachments directly before dispatching.

But I am not sure how to get it working with the Source mode. You need
something that pulls the attachments from the request context and put them
in the SOAP message so that the serialization picks up the attachments. I
don't know where this is happening.


2013/6/9 Dennis Sosnoski <dm...@sosnoski.com>

> I've been trying to use attachments with the Dispatch api, and haven't
> been able to make it work. After digging through the code I couldn't see
> anywhere that it was even trying to make it work. Is this just not
> supported?
>
> Attachments work without any problems on the Provider side.
>
> Here's a sample for Dispatch:
>
>         // create and configure the dispatch object with actual service
> endpoint address
>         Service service = Service.create(new QName("http://cxf.apache.org",
> "attachmentService"));
>         QName portQName = new QName("http://cxf.apache.org",
> "attachmentPort");
>         service.addPort(portQName, SOAPBinding.SOAP12HTTP_**BINDING,
> args[0]);
>         Dispatch<Source> dispatch = service.createDispatch(**portQName,
> Source.class, Service.Mode.PAYLOAD,
>             new AddressingFeature(true));
>         SOAPBinding binding = (SOAPBinding)dispatch.**getBinding();
>         binding.setMTOMEnabled(true);
>
>         // configure logging to view messages being exchanged
>         ...
>
>         // set attachment to be sent
>         Map<String, Object> requestContext = dispatch.getRequestContext();
>         Map<String, DataHandler> attachments = (Map<String,
> DataHandler>)requestContext.
>             get(MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS);
>         if (attachments == null) {
>             attachments = new HashMap<String, DataHandler>();
> requestContext.put(**MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS,
> attachments);
>         }
>         byte[] bytes = new byte[1024];
>         for (int i = 0; i < bytes.length; i++) {
>             bytes[i] = (byte)i;
>         }
>         attachments.put("attachment-1"**, new DataHandler(new
> ByteArrayDataSource(bytes)));
>
>         // configure the WS-Addressing Action to select operation
>         ...
>
>         // execute the request
>         Source response = dispatch.invoke(new StreamSource(new
> ByteArrayInputStream("<test/>"**.getBytes("UTF-8"))));
>         System.out.println("Success");
>
> The request gets sent using mime, but without the attachment. Here's the
> Provider code that works:
>
> @MTOM(threshold = 0, enabled = true)
> @WebServiceProvider(
>   portName = AttachConstants.PORT_**LOCALNAME,
>   serviceName = AttachConstants.SERVICE_**LOCALNAME,
>   targetNamespace = AttachConstants.SERVICE_**NAMESPACE)
> @ServiceMode(value = Service.Mode.PAYLOAD)
> @BindingType(javax.xml.ws.**soap.SOAPBinding.SOAP12HTTP_**BINDING)
> public class AttachProvider implements Provider<StreamSource>
> {
>     /** Injected context for invocations. */
>     @Resource
>     private WebServiceContext serviceContext;
>
>     private void setAttachment(DataHandler handler) {
>         Map<String, DataHandler> attachments = new HashMap<String,
> DataHandler>();
>         attachments.put(**AttachConstants.OUT_ATTACH_ID, handler);
> serviceContext.**getMessageContext().put(**MessageContext.OUTBOUND_**MESSAGE_ATTACHMENTS,
> attachments);
>     }
>
>     public StreamSource invoke(StreamSource request) {
>         ...
>            byte[] bytes = new byte[AttachConstants.**ATTACHMENT_SIZE];
>             for (int i = 0; i < AttachConstants.ATTACHMENT_**SIZE; i++) {
>                 bytes[i] = (byte)i;
>             }
>             setAttachment(new DataHandler(new ByteArrayDataSource(bytes)));
>
> Has anyone else gotten Dispatch attachments to work?
>
> Thanks,
>
>   - Dennis
>
> --
>
> Dennis M. Sosnoski
> Java SOA and Web Services Consulting <http://www.sosnoski.com/**
> consult.html <http://www.sosnoski.com/consult.html>>
> CXF and Web Services Security Training <http://www.sosnoski.com/**
> training.html <http://www.sosnoski.com/training.html>>
> Web Services Jump-Start <http://www.sosnoski.com/**jumpstart.html<http://www.sosnoski.com/jumpstart.html>
> >
>
>