CAMEL: Akka-Camel Message is not wrapping Camel Jetty Message's .getAttachment method (for multi-part form support)
(taken from akka-modules)
This is the suggested way of doing multi-part requests on Camel's Jetty Component:
From Camel 2.3.0, camel-jetty support to multipart form post out of box. The submitted form-data are mapped into the message header. Camel-jetty creates an attachment for each uploaded file. The file name is mapped to the name of the attachment. The content type is set as the content type of the attachment file name. You can find the example here.
Note: getName() functions as shown below in versions 2.5 and higher. In earlier versions you receive the temporary file name for the attachment instead
However we're missing the getAttachment and Attachment method family in general in Akka-Camel's Message hence it's impossible to achieve the desired functionality through mentioned component.
This is the suggested way of doing multi-part requests on Camel's Jetty Component:
*Multi-part Form support*
From Camel 2.3.0, camel-jetty support to multipart form post out of box. The submitted form-data are mapped into the message header. Camel-jetty creates an attachment for each uploaded file. The file name is mapped to the name of the attachment. The content type is set as the content type of the attachment file name. You can find the example here.
Note: getName() functions as shown below in versions 2.5 and higher. In earlier versions you receive the temporary file name for the attachment instead
// Set the jetty temp directory which store the file for multi part form
// camel-jetty will clean up the file after it handled the request.
// The option works rightly from Camel 2.4.0
getContext().getProperties().put("CamelJettyTempDir", "target");
from("jetty://http://localhost:{{port}}/test").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
// The file name is attachment id
DataHandler data = in.getAttachment("NOTICE.txt");
assertNotNull("Should get the DataHandle NOTICE.txt", data);
// This assert is wrong, but the correct content-type (application/octet-stream)
// will not be returned until Jetty makes it available - currently the content-type
// returned is just the default for FileDataHandler (for the implentation being used)
//assertEquals("Get a wrong content type", "text/plain", data.getContentType());
assertEquals("Got the wrong name", "NOTICE.txt", data.getName());
assertTrue("We should get the data from the DataHandle", data.getDataSource()
.getInputStream().available() > 0);
// The other form date can be get from the message header
exchange.getOut().setBody(in.getHeader("comment"));
}
});
However we're missing the getAttachment and Attachment method family in general in Akka-Camel's Message hence it's impossible to achieve the desired functionality through mentioned component.
Leave a comment
on 2011-10-07 14:06 *
By viktorklang
Summary changed from Akka-Camel Message is not wrapping Camel Jetty Message's .getAttachment method (for multi-part form support) to CAMEL: Akka-Camel Message is not wrapping Camel Jetty Message's .getAttachment method (for multi-part form support)
on 2012-08-12 17:20 *
By Raymond Roestenburg
Assigned to set to Raymond Roestenburg
Status changed from New to Accepted
on 2012-08-28 20:52 *
By viktorklang
What's the status here?