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