You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Soto <al...@envieta.com> on 2019/03/25 14:31:25 UTC
Rest DSL, Servlet, Jetty, Multi part file upload
Hello,
Using Camel version 2.21.1, I need to process file upload from a multi part form web UI. My setup is as follows:
<restConfiguration
component="servlet"
bindingMode="json"
contextPath=“api/rest"
port="{{port}}"
enableCORS="false">
<componentProperty key="matchOnUriPrefix" value="true"/>
<endpointProperty key="servletName" value="querierRestApiServlet"/>
<dataFormatProperty key="prettyPrint" value="true" />
</restConfiguration>
<rest path="/offline" bindingMode="off">
<put uri="/datasources" consumes="multipart/form-data">
<to uri="direct:/offline/datasources"/>
</put>
</rest>
<route id="datasource-import">
<from uri="direct:/offline/datasources"/>
<bean ref="uploadHandler"/>
<to uri="direct:success"/>
</route>
My uploadHandler bean
public void processUpload(Exchange exchange) throws Exception {
Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
if (attachments.size() == 0) {
log.warn("No attachments found!");
} else {
for (String key : attachments.keySet()) {
log.info("Filename: " + key);
}
}
}
My integration test:
Part[] parts = {new StringPart("comment", “File to upload"),
new FilePart(outPath.getFileName().toString(), outPath.toFile())};
MultipartRequestEntity entity = new MultipartRequestEntity(parts, new HttpMethodParams());
HttpClient httpclient = new HttpClient();
PutMethod httppost = new PutMethod("http://localhost:8182/api/rest/offline/datasources");
httppost.setRequestEntity(entity);
int status = httpclient.executeMethod(httppost);
The problem is that upload handler never receives any attachments. Any help would be appreciated.
Best regards,
Alex soto