camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shing Hing Man <>
Subject Camel 2.12.1 : How to send Http post with an attachment using ProducerTemplate
Date Thu, 12 Jun 2014 19:07:29 GMT

 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.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 !

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message