You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by opicina <da...@insiel.it> on 2011/09/06 11:48:10 UTC
add attachment to a cxf client
Hi i have some problem to add an attachment with cxf:
*I have generate the cxf client:*
/org.apache.cxf.jaxws.JaxWsProxyFactoryBean proxyFactory = new
JaxWsProxyFactoryBean();
proxyFactory.setServiceClass(ProtPT.class);
proxyFactory.setAddress("http://xxxxxxx/services/xxxxxxxxxxxxx");
Map<String,Object> props = new HashMap<String, Object>();
props.put("mtom-enabled", Boolean.TRUE);
props.put("schema-validation-enabled", Boolean.FALSE);
proxyFactory.setProperties(props);
client = (ProtPT) proxyFactory.create();/
*now i would like to add an attachment; something like this:*
File file = new File(DOC);
FileDataSource ds = new FileDataSource(file);
List<Attachment> attachments = new ArrayList<Attachment>();
InternetHeaders headers = new InternetHeaders();
headers.addHeader("Content-Type", "application/pdf");
headers.addHeader("Content-ID", "doc.pdf");
headers.addHeader("Content-Transfer-Encoding", "base64");
headers.addHeader("Content-Disposition", "123456789034567834567");
*now how can add this attachment to the request?*
(the wsdl I use has no xsd:base64Binary element).
With axis I now that I can use the attachmentPart but how does it work with
cxf??
thanks
--
View this message in context: http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-tp4773822p4773822.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: add attachment to a cxf client
Posted by John <ja...@hotmail.com>.
Sergey Beryozkin <sb...@...> writes:
>
> Sorry, may be it was just too early for me yesterday . just got
> confused when I saw 'AttachmentUtil' which reminded me of
> AttachmentUtils shipped in the jaxrs frontend
>
> Sergey
>
> On 07/09/11 10:42, Sergey Beryozkin wrote:
> > Wow, that seems like to show a combination of CXF JAXRS & JAXWS code in
> > action, nice
> > Sergey
> >
> > On 07/09/11 10:02, opicina wrote:
> >> With this code it works:
> >>
> >> File file = new File(DOC);
> >> FileDataSource ds = new FileDataSource(file);
> >>
> >> List<Attachment> attachments = new ArrayList<Attachment>();
> >> InternetHeaders headers = new InternetHeaders();
> >> headers.addHeader("Content-Type", "application/pdf");
> >> headers.addHeader("Content-ID", "doc.pdf");
> >> headers.addHeader("Content-Transfer-Encoding", "base64");
> >> headers.addHeader("Content-Disposition",
> >> "filename="+"123456789034567834567");
> >>
> >> Attachment attach = AttachmentUtil.createAttachment(ds.getInputStream(),
> >> headers);
> >> attachments.add(attach);
> >>
> >> BindingProvider bp = (BindingProvider) client;
> >> java.util.Map<String, Object> reqContext = bp.getRequestContext();
> >> reqContext.put( Message.ATTACHMENTS, attachments );
> >>
> >> thanks!
> >>
> >>
> >> --
> >> View this message in context:
> >> http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-
tp4773822p4777834.html
> >>
> >> Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
Hello all,
I tried this way but it seems like the context is not reset and so the
attachment gets added to every subsequent message. That means that every
webservice call afterwards will have this attachment. The workaround I am
considering is storing the attachment in a local thread and insert back in an
outerceptor. Any better ideas ?
I am having some problems on a larger scale with CXF interceptors but also JAX-
WS handlers because they seem extremely complicated in the way they operate
(especially with the interceptor chain and the cachedOutputStream business with
CXF). And I seem to learn everything from threads in forums which feels wrong on
so many levels. Is this normal ??
Thanks and regards,
John.
Re: add attachment to a cxf client
Posted by Sergey Beryozkin <sb...@gmail.com>.
Sorry, may be it was just too early for me yesterday :-). just got
confused when I saw 'AttachmentUtil' which reminded me of
AttachmentUtils shipped in the jaxrs frontend :-)
Sergey
On 07/09/11 10:42, Sergey Beryozkin wrote:
> Wow, that seems like to show a combination of CXF JAXRS & JAXWS code in
> action, nice :-)
> Sergey
>
> On 07/09/11 10:02, opicina wrote:
>> With this code it works:
>>
>> File file = new File(DOC);
>> FileDataSource ds = new FileDataSource(file);
>>
>> List<Attachment> attachments = new ArrayList<Attachment>();
>> InternetHeaders headers = new InternetHeaders();
>> headers.addHeader("Content-Type", "application/pdf");
>> headers.addHeader("Content-ID", "doc.pdf");
>> headers.addHeader("Content-Transfer-Encoding", "base64");
>> headers.addHeader("Content-Disposition",
>> "filename="+"123456789034567834567");
>>
>> Attachment attach = AttachmentUtil.createAttachment(ds.getInputStream(),
>> headers);
>> attachments.add(attach);
>>
>> BindingProvider bp = (BindingProvider) client;
>> java.util.Map<String, Object> reqContext = bp.getRequestContext();
>> reqContext.put( Message.ATTACHMENTS, attachments );
>>
>> thanks!
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-tp4773822p4777834.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
Re: add attachment to a cxf client
Posted by Sergey Beryozkin <sb...@gmail.com>.
Wow, that seems like to show a combination of CXF JAXRS & JAXWS code in
action, nice :-)
Sergey
On 07/09/11 10:02, opicina wrote:
> With this code it works:
>
> File file = new File(DOC);
> FileDataSource ds = new FileDataSource(file);
>
> List<Attachment> attachments = new ArrayList<Attachment>();
> InternetHeaders headers = new InternetHeaders();
> headers.addHeader("Content-Type", "application/pdf");
> headers.addHeader("Content-ID", "doc.pdf");
> headers.addHeader("Content-Transfer-Encoding", "base64");
> headers.addHeader("Content-Disposition",
> "filename="+"123456789034567834567");
>
> Attachment attach = AttachmentUtil.createAttachment(ds.getInputStream(),
> headers);
> attachments.add(attach);
>
> BindingProvider bp = (BindingProvider) client;
> java.util.Map<String, Object> reqContext = bp.getRequestContext();
> reqContext.put( Message.ATTACHMENTS, attachments );
>
> thanks!
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-tp4773822p4777834.html
> Sent from the cxf-user mailing list archive at Nabble.com.
Re: add attachment to a cxf client
Posted by opicina <da...@insiel.it>.
With this code it works:
File file = new File(DOC);
FileDataSource ds = new FileDataSource(file);
List<Attachment> attachments = new ArrayList<Attachment>();
InternetHeaders headers = new InternetHeaders();
headers.addHeader("Content-Type", "application/pdf");
headers.addHeader("Content-ID", "doc.pdf");
headers.addHeader("Content-Transfer-Encoding", "base64");
headers.addHeader("Content-Disposition",
"filename="+"123456789034567834567");
Attachment attach = AttachmentUtil.createAttachment(ds.getInputStream(),
headers);
attachments.add(attach);
BindingProvider bp = (BindingProvider) client;
java.util.Map<String, Object> reqContext = bp.getRequestContext();
reqContext.put( Message.ATTACHMENTS, attachments );
thanks!
--
View this message in context: http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-tp4773822p4777834.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: add attachment to a cxf client
Posted by Daniel Kulp <dk...@apache.org>.
I think you can do something like:
((BindingProvider)client).getRequestContext()
.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
That should return a:
Map<String, DataHandler>
that you can use to add datahandlers.
Alternatively, you can create a Collection<Attachment> where the Attachments
implement org.ache.cxf.message.Attachment (you can use our AttachmentImpl
subclass) and add that to the RequestContext as above but with the key
Message.ATTACHMENTS. Thats the internal representation.
Dan
On Tuesday, September 06, 2011 2:48:10 AM opicina wrote:
> Hi i have some problem to add an attachment with cxf:
>
> *I have generate the cxf client:*
>
> /org.apache.cxf.jaxws.JaxWsProxyFactoryBean proxyFactory = new
> JaxWsProxyFactoryBean();
> proxyFactory.setServiceClass(ProtPT.class);
> proxyFactory.setAddress("http://xxxxxxx/services/xxxxxxxxxxxxx");
>
> Map<String,Object> props = new HashMap<String, Object>();
> props.put("mtom-enabled", Boolean.TRUE);
> props.put("schema-validation-enabled", Boolean.FALSE);
> proxyFactory.setProperties(props);
>
> client = (ProtPT) proxyFactory.create();/
>
> *now i would like to add an attachment; something like this:*
>
> File file = new File(DOC);
> FileDataSource ds = new FileDataSource(file);
>
> List<Attachment> attachments = new ArrayList<Attachment>();
> InternetHeaders headers = new InternetHeaders();
> headers.addHeader("Content-Type", "application/pdf");
> headers.addHeader("Content-ID", "doc.pdf");
> headers.addHeader("Content-Transfer-Encoding", "base64");
> headers.addHeader("Content-Disposition", "123456789034567834567");
>
> *now how can add this attachment to the request?*
> (the wsdl I use has no xsd:base64Binary element).
>
> With axis I now that I can use the attachmentPart but how does it work with
> cxf??
>
> thanks
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/add-attachment-to-a-cxf-client-tp4773822p47
> 73822.html Sent from the cxf-user mailing list archive at Nabble.com.
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com