0

I'm sending an attachment using Apache CXF implementation. Even if I set the name of the dataHandler I don't know why is not reveiced on the server side.

Map<String, DataHandler> attachmentsMap = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
ByteArrayDataSource bads = new ByteArrayDataSource(file, PDF_MIME_TYPE);
bads.setName(fileId);

DataHandler dh = new DataHandler(bads);

AttachmentPart attachmentPart = message.createAttachmentPart();

attachmentPart.setContent(new ByteArrayInputStream(file), PDF_MIME_TYPE);
attachmentPart.setContentId(fileId);
attachmentPart.setMimeHeader("fileName", "test");
message.addAttachmentPart(attachmentPart);
message.saveChanges();

attachmentsMap.put(fileId, dh);

As you can see when I do "bads.setName(fileId);" also the name of the dataHandler is set. Locally if I do dh.getName I have the name set. After sending it is not present anymore

Aditzu
  • 696
  • 1
  • 14
  • 25

1 Answers1

0

Sad but unfortunately I will answer myself..again :)

A contentDisposition has to be set and put on the mimeHeader of the attachment like in the following way:

 String contentDisposition = "Content-Disposition: attachment; name=\"" + fileName + "\"";                                                
 attachmentPart.addMimeHeader("Content-Disposition", contentDisposition);

Hope this will be helpfull for someone.

Aditzu
  • 696
  • 1
  • 14
  • 25