Hi,
I am trying to use a CXF handling of attachments and I have a simple web
application and in the servlet I create a Message object as listed below
(method loadMessage) in which I use AttachmentDeserializer. And I don't
want the attachments to be loaded into memory or stored to file system. I
want the attachments to be "delegated" as mentioned in the article
http://ext2xhb.wordpress.com/2011/06/08/using-cxf-attachment-safely/
and i am interested in just reading the payload.
So, when i do ad.initializeAttachments() the payload input stream is added
to the message object (message.getContent(InputStream.class);). Its exactly
what i want but at the same time the attachments are loaded to memory. I
don't want that. How do i prevent that???. And I will drain the attachments
to an output stream as listed in the second method. At this point, the data
should be streamed from the input stream to the output stream.
Please advice....
public Message loadMessage(HttpServletRequest request) {
Message message = new MessageImpl();
try {
message.setContent(InputStream.class, request.getInputStream());
message.put(Message.CONTENT_TYPE, request.getContentType());
AttachmentDeserializer ad = new AttachmentDeserializer(message);
ad.initializeAttachments();
} catch (IOException e) {
throw new Exception("error loading attachments"); }
return message;
//I will worry about the clean up of streams.
public void drainAttachment(OutputStream os, Message mimeMessage){
Collection<Attachment> attachments = mimeMessage.getAttachments();
for(Attachment att : attachments){
att.getDataHandler().writeTo(os);
Thanks,
Sam
I am trying to use a CXF handling of attachments and I have a simple web
application and in the servlet I create a Message object as listed below
(method loadMessage) in which I use AttachmentDeserializer. And I don't
want the attachments to be loaded into memory or stored to file system. I
want the attachments to be "delegated" as mentioned in the article
http://ext2xhb.wordpress.com/2011/06/08/using-cxf-attachment-safely/
and i am interested in just reading the payload.
So, when i do ad.initializeAttachments() the payload input stream is added
to the message object (message.getContent(InputStream.class);). Its exactly
what i want but at the same time the attachments are loaded to memory. I
don't want that. How do i prevent that???. And I will drain the attachments
to an output stream as listed in the second method. At this point, the data
should be streamed from the input stream to the output stream.
Please advice....
public Message loadMessage(HttpServletRequest request) {
Message message = new MessageImpl();
try {
message.setContent(InputStream.class, request.getInputStream());
message.put(Message.CONTENT_TYPE, request.getContentType());
AttachmentDeserializer ad = new AttachmentDeserializer(message);
ad.initializeAttachments();
} catch (IOException e) {
throw new Exception("error loading attachments"); }
return message;
//I will worry about the clean up of streams.
public void drainAttachment(OutputStream os, Message mimeMessage){
Collection<Attachment> attachments = mimeMessage.getAttachments();
for(Attachment att : attachments){
att.getDataHandler().writeTo(os);
Thanks,
Sam