Unable to send file to rest webservice via apache camel http
<p>I am new to Camel and I am facing an issue while sending files to webservice via camel http.<br>
I have a rest web service which consumes Multipart form data type content and accepts input as part of form data.
When I send file and form parameter via camel it gives me the following error at camel console:</p>

<pre><code>Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/JAX_RS_Application/resource/restwb/upload with statusCode: 415
    at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:230)
    at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:156)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:435)
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
</code></pre>

<p>The error i get on the server side console is as follows:</p>

<pre><code>SEVERE: MessageBodyReader not found for media type=application/octet-stream, typ
e=class org.glassfish.jersey.media.multipart.FormDataMultiPart, genericType=clas
s org.glassfish.jersey.media.multipart.FormDataMultiPart.
</code></pre>

<p>The code snippet of the Rest web-service created via jersey is as follows:</p>

<pre><code>import java.io.IOException;
import java.io.InputStream;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

@Path("/restwb") 
public class FileResource {
    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public String uploadFile(@FormDataParam("username") String username,@FormDataParam("password") String password,@FormDataParam("upload") InputStream is) {
            String output ="Hi "+username+" your password is "+password;
            output=output+IOUtils.LINE_SEPARATOR +IOUtils.LINE_SEPARATOR;
            output=output+"Output :"+IOUtils.LINE_SEPARATOR+"------------------------------------------------------------------------------"+IOUtils.LINE_SEPARATOR;
            try {
                output=output+IOUtils.toString(is)+IOUtils.LINE_SEPARATOR+IOUtils.LINE_SEPARATOR;
                output=output+"==================================================================================================="+IOUtils.LINE_SEPARATOR+IOUtils.LINE_SEPARATOR;
                System.out.println("Output :"+output);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return output;
    }
}
</code></pre>

<p>And my Camel config is as follows:</p>

<pre><code>import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.Synchronization;
import org.apache.camel.spi.UnitOfWork;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.james.mime4j.message.Multipart;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * Created by Manish.Pillai on 7/16/2015.
 */
public class LoggingMain {

    private static final Logger logger =Logger.getLogger(LoggingMain.class);

    public static void main(String[] args) throws  Exception{
        CamelContext camelContext =new DefaultCamelContext();
        try {
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() throws Exception {
                    from("file:C:\\temp?delay=5000&amp;move=processed&amp;moveFailed=error&amp;antExclude=**/processed/**,**/error/**")
                            .process(new Processor() {
                                public void process(Exchange exchange) throws Exception {
                                    exchange.getContext().getTypeConverterRegistry().addTypeConverter(HttpEntity.class,InputStream.class,new InputStreamToHttpEntityConvertor());
                                    exchange.getOut().setBody(exchange.getIn().getBody(),HttpEntity.class);
                                }
                            })
                            .to("http://localhost:8080/JAX_RS_Application/resource/restwb/upload");
                }
            });

            camelContext.getRestConfiguration();
            camelContext.start();
            Thread.sleep(5000);
            camelContext.stop();

        } catch (Exception e) {
            logger.error(e.getMessage());
        }
    }

    static class InputStreamToHttpEntityConvertor implements TypeConverter {

        public boolean allowNull() {
            return false;
        }

        public &lt;T&gt; T convertTo(Class&lt;T&gt; type, Object value) throws TypeConversionException {
            Exchange exchange=(Exchange)value;

            StringBody username = new StringBody("username", ContentType.MULTIPART_FORM_DATA);
            StringBody password = new StringBody("password", ContentType.MULTIPART_FORM_DATA);
            MultipartEntityBuilder multipartEntityBuilder=MultipartEntityBuilder.create();
            multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
            multipartEntityBuilder.addPart("upload", new FileBody(exchange.getIn().getBody(File.class), ContentType.MULTIPART_FORM_DATA, (String) exchange.getIn().getHeader(Exchange.FILE_NAME)));
            multipartEntityBuilder.addPart("username",username);
            multipartEntityBuilder.addPart("password",password);
            return (T)multipartEntityBuilder.build();
        }

        public &lt;T&gt; T convertTo(Class&lt;T&gt; aClass, Exchange exchange, Object o) throws TypeConversionException {
            return convertTo(aClass,o);
        }

        public &lt;T&gt; T mandatoryConvertTo(Class&lt;T&gt; type, Object value) throws TypeConversionException, NoTypeConversionAvailableException {
            return convertTo(type,value);
        }

        public &lt;T&gt; T mandatoryConvertTo(Class&lt;T&gt; type, Exchange exchange, Object value) throws TypeConversionException, NoTypeConversionAvailableException {
            return convertTo(type,value);
        }

        public &lt;T&gt; T tryConvertTo(Class&lt;T&gt; type, Object value) {
            return convertTo(type,value);
        }

        public &lt;T&gt; T tryConvertTo(Class&lt;T&gt; type, Exchange exchange, Object value) {
            return convertTo(type,value);
        }
    }

}
</code></pre>

<p>Any leads would be helpful.</p>