>     void bindAttachmentsToSoapRequest(Object proxyObject, byte[]
> attachments) {
>         //...
> 
>         final Client client = ClientProxy.getClient(proxyObject);
> 
> client.getEndpoint().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
>                                  new DataHandler(new
> ByteArrayDataSource(attachments, "content/type")));
>     }

That definitely won't work.     I think the best way to get this to work is:
import org.apache.cxf.attachment.AttachmentImpl;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;

Collection<Attachment> atts = new ArrayList<Attachment>();
atts.add(new AttachmentImpl("myId", new DataHandler(new
        ByteArrayDataSource(attachments, "content/type"));

 ((BindingProvider)proxyObject).getRequestContext().put(
            Message.ATTACHMENTS,
            atts);


Dan



On Fri December 18 2009 12:29:38 am erskine.dedios wrote:
> Hi.
> 
> I'm very new to cxf, could you help me sort this out?  I am able to send a
> soap message successfully, but attachments don't seem to get sent.
> 
> Below is a snippet of my code. ..
> 
>             JaxWsProxyFactoryBean proxyFactory = new
> JaxWsProxyFactoryBean();
>             proxyFactory.setServiceClass(SendMessage.class);
> 
> proxyFactory.setAddress("http://nelson:8089/mockSendMessageBinding";);
>             remoteSendMessageService = (SendMessage) proxyFactory.create();
> 
>             bindAttachmentsToSoapRequest(remoteSendMessageService,
> attachments);
> 
>             remoteSendMessageService.sendMessage(destinationList,
>                                                  origin,
>                                                  subject);
> 
> 
> //...
> 
>     void bindAttachmentsToSoapRequest(Object proxyObject, byte[]
> attachments) {
>         //...
> 
>         final Client client = ClientProxy.getClient(proxyObject);
> 
> client.getEndpoint().put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS,
>                                  new DataHandler(new
> ByteArrayDataSource(attachments, "content/type")));
>     }
> 
> I use soapui to receive my soap messages.
> 
> 
> 
> Thanks.
> Kin
> 

-- 
Daniel Kulp
[email protected]
http://www.dankulp.com/blog

Reply via email to