camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ngthphat <ngth_p...@ymail.com>
Subject camel-Netty4 Consume multipart/form-data, curl doesn't work, works with postman
Date Mon, 14 Nov 2016 16:22:52 GMT
Hi all,I'm implementing a rest endpoint receive a multipart form data (upload
file). I did test my implementation with postman (chrome extension) and with
httpclient, both of them work well, except curl.*My
route:*rest(CommonConstants.BASE_CONTEXT_PATH)               
.description("Upload bank report")               
.consumes("multipart/form-data").produces("application/json")               
.post(CommonConstants.REPORT_UPLOAD_CONTEXT_PATH + "/{countryCode}")               
.to(Settings.camelURIUploadReportRoute());from(Settings.camelURIUploadReportRoute()).routeId(CommonConstants.REPORT_UPLOAD_ROUTE_ID)
              
.process(processor);*My Processor:*HttpRequest request =
exchange.getIn(NettyHttpMessage.class).getHttpRequest();HttpPostRequestDecoder
postRequestDecoder = new HttpPostRequestDecoder(request);with
HttpPostRequestDecoder, I can get MixedAttributes and MixedFileUpload as
expectation.*Test client side with httpclient:*        CloseableHttpClient
client = HttpClientBuilder.create().build();        File file = new
File("path_to_file");        String url = "url_to_rest_api";        HttpPost
post = new HttpPost(url);        FileBody fileBody = new FileBody(file,
ContentType.DEFAULT_BINARY);        StringBody stringBody1 = new
StringBody("value", ContentType.MULTIPART_FORM_DATA);       
MultipartEntityBuilder builder = MultipartEntityBuilder.create();       
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);       
builder.addPart("file", fileBody);        builder.addPart("key",
stringBody1);        HttpEntity entity = builder.build();       
post.setEntity(entity);        CloseableHttpResponse response =
client.execute(post);*However, when test with curl:*curl -s -i -X POST -H
"Content-Type: multipart/form-data" -F "data=@/path_to_file.xlsx" -F
"key=value" http://localhost:8595/url...curl return:HTTP/1.1 404 Not
FoundContent-Type: text/plainContent-Length: 0and log4j return:2016-11-14
22:34:47 WARN  NettyHttpConsumer:137 - HttpServerChannelHandler is not found
as attachment to handle exception, send 404 back to the
client.java.lang.UnsupportedOperationException: unsupported message type:
DefaultFullHttpResponse (expected: ByteBuf, FileRegion)I'm using:camel
v2.17.3camel-netty4-http v2.17.3 java version "1.8.0_101MacOSQuestion1: Does
my approach to consuming multipart/form-data with HttpPostRequestDecoder is
correct?Question2: Does the root cause relate to curl or is there missing 
some configuration on my app?



--
View this message in context: http://camel.465427.n5.nabble.com/camel-Netty4-Consume-multipart-form-data-curl-doesn-t-work-works-with-postman-tp5790110.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message