Search in sources :

Example 6 with MultiPartInputStreamParser

use of org.eclipse.jetty.util.MultiPartInputStreamParser in project camel by apache.

the class AttachmentHttpBinding method populateAttachments.

@Override
protected void populateAttachments(HttpServletRequest request, HttpMessage message) {
    Object object = request.getAttribute("org.eclipse.jetty.servlet.MultiPartFile.multiPartInputStream");
    if (object instanceof MultiPartInputStreamParser) {
        MultiPartInputStreamParser parser = (MultiPartInputStreamParser) object;
        Collection<Part> parts;
        try {
            parts = parser.getParts();
            for (Part part : parts) {
                DataSource ds = new PartDataSource(part);
                Attachment attachment = new DefaultAttachment(ds);
                for (String headerName : part.getHeaderNames()) {
                    for (String headerValue : part.getHeaders(headerName)) {
                        attachment.addHeader(headerName, headerValue);
                    }
                }
                message.addAttachmentObject(part.getName(), attachment);
            }
        } catch (Exception e) {
            throw new RuntimeCamelException("Cannot populate attachments", e);
        }
    }
}
Also used : Part(javax.servlet.http.Part) MultiPartInputStreamParser(org.eclipse.jetty.util.MultiPartInputStreamParser) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) Attachment(org.apache.camel.Attachment) RuntimeCamelException(org.apache.camel.RuntimeCamelException) DefaultAttachment(org.apache.camel.impl.DefaultAttachment) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) DataSource(javax.activation.DataSource)

Aggregations

MultiPartInputStreamParser (org.eclipse.jetty.util.MultiPartInputStreamParser)6 File (java.io.File)3 Part (javax.servlet.http.Part)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 MultipartConfigElement (javax.servlet.MultipartConfigElement)2 ServletRequestEvent (javax.servlet.ServletRequestEvent)2 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataSource (javax.activation.DataSource)1 ServletException (javax.servlet.ServletException)1 ServletInputStream (javax.servlet.ServletInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)1 Attachment (org.apache.camel.Attachment)1