are you the owner of the rest endpoint? If yes, could you show how is it? Configs and what it expects.
2016-07-14 8:56 GMT-03:00 manishpillai1540 <[email protected]>: > Hi All, > > I am facing a similar issue following is the code snippet to send form data > to a legacy web service : > > 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&move=processed&moveFailed=error&antExclude=**/processed/**,**/error/**") > > .setHeader(Exchange.HTTP_METHOD,constant("POST")) > .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("http4://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 <T> T convertTo(Class<T> 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 <T> T convertTo(Class<T> aClass, Exchange exchange, Object > o) > throws TypeConversionException { > return convertTo(aClass,o); > } > > public <T> T mandatoryConvertTo(Class<T> type, Object value) throws > TypeConversionException, NoTypeConversionAvailableException { > return convertTo(type,value); > } > > public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, > Object value) throws TypeConversionException, > NoTypeConversionAvailableException { > return convertTo(type,value); > } > > public <T> T tryConvertTo(Class<T> type, Object value) { > return convertTo(type,value); > } > > public <T> T tryConvertTo(Class<T> type, Exchange exchange, Object > value) { > return convertTo(type,value); > } > } > > > I am getting the following error : > > > Message History > > --------------------------------------------------------------------------------------------------------------------------------------- > RouteId ProcessorId Processor > Elapsed (ms) > [route1 ] [route1 ] > > [file://C:%5Ctemp?antExclude=**%2Fprocessed%2F**%2C**%2Ferror%2F**&delay=5000&m] > [ 238] > [route1 ] [setHeader1 ] [setHeader[CamelHttpMethod] > ] [ 7] > [route1 ] [process1 ] [Processor@0x4e57449e > ] [ 15] > [route1 ] [to1 ] > [http4://localhost:8080/JAX_RS_Application/resource/restwb/upload > ] [ 205] > > Stacktrace > > --------------------------------------------------------------------------------------------------------------------------------------- > org.apache.camel.http.common.HttpOperationFailedException: HTTP operation > failed invoking > http://localhost:8080/JAX_RS_Application/resource/restwb/upload with > statusCode: 415 > at > > org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:279) > at > > org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:187) > at > > org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) > at > org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) > at > > org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) > at > > org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) > at > > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) > at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) > at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) > at > > org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) > at > > org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454) > at > > org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226) > at > > org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190) > at > > org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) > at > > org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) > 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) > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Reading-Binary-Files-and-Passing-to-HTTP-Component-tp510207p5785109.html > Sent from the Camel - Users mailing list archive at Nabble.com. >
