Search code examples
jax-rscxfmultipart

MultipartBody Content-Type attributes dropped on CXF Upgrade


After upgrading Apache CXF from 2.4.0 to 3.1.4, the Content-Type header on responses from JAX-RS methods have dropped several attributes.

Under CXF 2.4.0, the header is:

Content-Type: multipart/mixed; type="application/octet-stream"; boundary="uuid:61b631f1-0aa9-4cc8-ad85-3c09129ec442"; start="<DocumentName.ext>"; start-info="application/octet-stream"

Under CXF 3.1.4, it is:

Content-Type: multipart/mixed; boundary="uuid:804168d7-70ed-44e7-a471-9647372b9224"

Note: attributes type, start, start-info missing.

Here's the code we're using:

@GET
@Path( "{order_id}/document/{document_id}/file" )
@Produces("multipart/mixed")
public MultipartBody getDocument( @PathParam( "order_id") int _orderId,  @PathParam( "document_id") int _documentId) throws Exception {

   FileInfo fileInfo = findFileInfo( _orderId, _documentId );

   List<Attachment> atts = new ArrayList<Attachment>();

   File internalFile = fileInfo.getActualFile();

   String fileName = fileInfo.getOriginalDocumentName();

   String fileSize = String.valueOf( internalFile.length() );

   ContentDisposition cd = new ContentDisposition("attachment; filename=\"" + fileName + "\"; size=" + fileSize );

   InputStream inputStreamToUse = new FileInputStream( internalFile );

   Attachment att = new Attachment(fileName, inputStreamToUse, cd);

   atts.add( att );

   return new MultipartBody(atts, true);    
}

I can't find any references in the Migration Guides to changes in this area and the style of the above method seems to match the one from the getBooks2() method in the JAX-RS Multipart documentation.

Any guidance on what might be causing the different behaviour?


Solution

  • That was done because apparently only a multipart/related media type may have optional start and start-info attributes according to https://www.rfc-editor.org/rfc/rfc2387.

    A more complete discussion of the topic is on the CXF mailing list, particularly this message which indicates that Content-Type was broken as well.