Hi A good idea is to check the unit tests of the components. Maybe you can find some sample code there.
For http try look in https://github.com/apache/camel/tree/master/components/camel-http/src/test/java/org/apache/camel/component/http and https://github.com/apache/camel/tree/master/components/camel-jetty/src/test/java/org/apache/camel/component/jetty On Thu, Jun 12, 2014 at 9:07 PM, Shing Hing Man <[email protected]> wrote: > Hi, > > I tried to use producerTemplate to send a http post with an attached file. > > > > ProducerTemplate template = context.createProducerTemplate(); > > Exchange exchange = template.send("http://localhost:8080/file", > new Processor() { > public void process(Exchange exchange) throws Exception { > > Message msgIn = exchange.getIn(); > String userHome=System.getProperty("user.home"); > File file = new File(userHome + "/test.txt"); > DataHandler dh = new DataHandler(new > FileDataSource(file)); > > msgIn.addAttachment("myFile",dh); > msgIn.setHeader(Exchange.CONTENT_TYPE, > "multipart/form-data"); > > msgIn.setHeader(Exchange.HTTP_METHOD, "POST"); > } > > }); > > At the server side, I received something like : > > > RequestContext(HttpRequest(POST,http://localhost:8080/file,List(Content-Length: > 0, Host: localhost:8080, User-Agent: Jakarta Commons-HttpClient/3.1, > breadcrumbId: > ID-gauss-site-41171-1402599541172-0-1),Empty,HTTP/1.1),Actor[akka://default/temp/$a],) > > The Context type and the attached file seem not to have reached the server. > > > Is the above a correct way to send http post with attachment ? > > Thanks in advance for any assistance ! > > Shing -- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/
