Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6EEF8200B44 for ; Thu, 14 Jul 2016 19:58:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6DD33160A63; Thu, 14 Jul 2016 17:58:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9322D160A60 for ; Thu, 14 Jul 2016 19:58:37 +0200 (CEST) Received: (qmail 80326 invoked by uid 500); 14 Jul 2016 17:58:36 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 80314 invoked by uid 99); 14 Jul 2016 17:58:36 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Jul 2016 17:58:36 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D4E31C05EF for ; Thu, 14 Jul 2016 17:58:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.492 X-Spam-Level: ** X-Spam-Status: No, score=2.492 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 1ppq3g9tYVjz for ; Thu, 14 Jul 2016 17:58:33 +0000 (UTC) Received: from mail-vk0-f49.google.com (mail-vk0-f49.google.com [209.85.213.49]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id E7F555F239 for ; Thu, 14 Jul 2016 17:58:32 +0000 (UTC) Received: by mail-vk0-f49.google.com with SMTP id w127so63733178vkh.2 for ; Thu, 14 Jul 2016 10:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=BpZgmq/GhCKIjXNsJAAkWows5+hXrK3YYA6GDBYtwyA=; b=aSwUM72KNnr8hsnPLe5gET7uTWFoH8n+bTjPcUuyGs3G+v7s7A4Bqu4D/FJROFcT5K cbpMSGaz5kxJgBYKiNMRblOkteVTfgg+F6hDxt64ZnD4Ra45w1rbw61PDcQggkLIc/so 15tpSHQV3PEOcjYn6OO9Jdn1RQIXlgn5xy+MVg1lr7/6EpPrgLIkg+HEIXU2JSX4ueyq /flJG6MhC5q0XOvXXUNE5fPTr0rhwMfT267YN9Vz8u94vC/MGPLiKB2qheBM59K/YhaT ILHycurzOwRA80EpxwOUZXqCX5KgQr9Uxkn/AgUO7qT+dWAvUg3myiYwwqL+1QIbLI8E z5rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=BpZgmq/GhCKIjXNsJAAkWows5+hXrK3YYA6GDBYtwyA=; b=VmTLJODwAkgtIgUgaFKvX1vONcYJUSq5uaUC8UD2EvcVSTLLlrxISiy+/GqNM5vepG ccbRrReVCjjUiIynhJX7qIwHBJIN/0/Ko8PH7rXTVeqVFpZ7+gYyUOZRhJm2RT7BLQzx 9VSxmdnmBpEBvnTlmFJQ2Rv7c0BXX1Wby1usjK5aCq15LcRvkp+FR45/vuFrP2b2C1qv t2qa29gK7KIeG0F5qB/yoR3Ut7navdLHWh+GKXu6L+5vQt1YiCeKvp3v0DcKegPd3rgu MBVPud2bkwfxU2OrFRs0ergvzfypteQbAEdLD+6Hw6WQegHexCPoaSJ895LjZNOzfk7+ gUvw== X-Gm-Message-State: ALyK8tLkh1ANa8lPF/VApQ6cI/o+atGe6YCBJms1J789gidc6eYy/A+ptPfflCGn9jePndJbPFencWiUGUPxVQ== X-Received: by 10.31.115.79 with SMTP id o76mr7606131vkc.140.1468519105675; Thu, 14 Jul 2016 10:58:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.159.37.149 with HTTP; Thu, 14 Jul 2016 10:58:25 -0700 (PDT) In-Reply-To: <1468497401828-5785109.post@n5.nabble.com> References: <4C1C78A1.4030103@gmail.com> <1468497401828-5785109.post@n5.nabble.com> From: Eduardo Raupp Date: Thu, 14 Jul 2016 14:58:25 -0300 Message-ID: Subject: Re: Reading Binary Files and Passing to HTTP Component To: users@camel.apache.org Content-Type: multipart/alternative; boundary=94eb2c149702a3c78d05379c3fd6 archived-at: Thu, 14 Jul 2016 17:58:38 -0000 --94eb2c149702a3c78d05379c3fd6 Content-Type: text/plain; charset=UTF-8 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 : > 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 convertTo(Class 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 convertTo(Class aClass, Exchange exchange, Object > o) > throws TypeConversionException { > return convertTo(aClass,o); > } > > public T mandatoryConvertTo(Class type, Object value) throws > TypeConversionException, NoTypeConversionAvailableException { > return convertTo(type,value); > } > > public T mandatoryConvertTo(Class type, Exchange exchange, > Object value) throws TypeConversionException, > NoTypeConversionAvailableException { > return convertTo(type,value); > } > > public T tryConvertTo(Class type, Object value) { > return convertTo(type,value); > } > > public T tryConvertTo(Class 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. > --94eb2c149702a3c78d05379c3fd6--