camel-Netty4 Consume multipart/form-data, curl doesn't work, works with postman
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.
Re: Camel HTTP4 Component and Curl Post Request behaving differently
The issue got resolved when I started sending the query parameters under header Exchange.HTTP_QUERY and removed it from the main url. Earlier my url was like https4://example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0 <https://debraj:deb...@example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0>". Now in the working case my url is like https4://example.com/oms-api/ <https://debraj:deb...@example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0> and the query parameters are send as : headers.put(Exchange.HTTP_QUERY, " Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0 <https://debraj:deb...@example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0> ") Can someone please let me know is it always recommended to send query parameters under Exchange.HTTP_QUERY? I am asking this because sending the query parameters with the main url is not failing always. On Thu, Apr 14, 2016 at 2:08 PM, Debraj Manna wrote: > Hi, > > I am facing a weird problem with Camel Http 4 component. Let me try to > explain. > > I am making a post request (added the header Exchange.HTTP_METHOD: > HttpMethods.POST) via camel http 4 component. It is returning me > > { > "ErrorResponse": { > "Head": { > "RequestAction": "UpdateOrderInformation", > "ErrorType": "Sender", > "ErrorCode": "7", > "ErrorMessage": "E007: Login failed. Signature mismatch" > }, > "Body": "" > } > } > > Authentication was performed using authUserName & authPassword. > > But when I am sending the same url via curl as shown below:- > > curl -v -H "Accept: application/json" -H "Content-Type: application/json" > -X POST -d '{"Request": {"Orders":[{"id_sales_order": > 397,"address_billing": {"first_name":"John","last_name": "Doe","phone": > "1234567","phone2": "1234","address1": "Sesamestreet 123","city": > "Berlin","postcode": "12345","country": "Germany"}}]}}' " > https://debraj:deb...@example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0 > " > > { > "SuccessResponse": { > "Head": { > "RequestId": "", > "RequestAction": "UpdateOrderInformation", > "ResponseType": "", > "Timestamp": "2015-07-02T12:26:03+0200" > }, > "Body": [] > } > > I have enabled debug http log. Below is the output:- > > 2016-04-14T12:44:18.375+0530 | DEBUG | qtp1202042637-19 | > RequestAddCookies| - - | > {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} > | CookieSpec selected: default > 2016-04-14T12:44:18.385+0530 | DEBUG | qtp1202042637-19 | > RequestAuthCache | - - | > {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} > | Auth cache not set in the context > 2016-04-14T12:44:18.386+0530 | DEBUG | qtp1202042637-19 | > olingHttpClientConnectionManager | - - | > {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494
Camel HTTP4 Component and Curl Post Request behaving differently
Hi, I am facing a weird problem with Camel Http 4 component. Let me try to explain. I am making a post request (added the header Exchange.HTTP_METHOD: HttpMethods.POST) via camel http 4 component. It is returning me { "ErrorResponse": { "Head": { "RequestAction": "UpdateOrderInformation", "ErrorType": "Sender", "ErrorCode": "7", "ErrorMessage": "E007: Login failed. Signature mismatch" }, "Body": "" } } Authentication was performed using authUserName & authPassword. But when I am sending the same url via curl as shown below:- curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"Request": {"Orders":[{"id_sales_order": 397,"address_billing": {"first_name":"John","last_name": "Doe","phone": "1234567","phone2": "1234","address1": "Sesamestreet 123","city": "Berlin","postcode": "12345","country": "Germany"}}]}}' " https://debraj:deb...@example.com/oms-api/?Action=UpdateOrderInformation&ServiceName=OMS&Signature=25566099c0b6b6c5123bbfede4c91590512050668f957e2a43ef982a0dcf1c00&Timestamp=2016-04-14T12%3A44%3A17+0530&Version=1.0 " { "SuccessResponse": { "Head": { "RequestId": "", "RequestAction": "UpdateOrderInformation", "ResponseType": "", "Timestamp": "2015-07-02T12:26:03+0200" }, "Body": [] } I have enabled debug http log. Below is the output:- 2016-04-14T12:44:18.375+0530 | DEBUG | qtp1202042637-19 | RequestAddCookies| - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | CookieSpec selected: default 2016-04-14T12:44:18.385+0530 | DEBUG | qtp1202042637-19 | RequestAuthCache | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | Auth cache not set in the context 2016-04-14T12:44:18.386+0530 | DEBUG | qtp1202042637-19 | olingHttpClientConnectionManager | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | Connection request: [route: {s}->https://example.com:443][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 200] 2016-04-14T12:44:18.404+0530 | DEBUG | qtp1202042637-19 | olingHttpClientConnectionManager | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | Connection leased: [id: 0][route: {s}->https://example.com:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 200] 2016-04-14T12:44:18.406+0530 | DEBUG | qtp1202042637-19 | MainClientExec | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | Opening connection {s}->https://example.com:443 2016-04-14T12:44:18.470+0530 | DEBUG | qtp1202042637-19 | aultHttpClientConnectionOperator | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.exchangeId,ID-debraj1247-34494-1460618050527-0-6}{camel.messageId,ID-debraj1247-34494-1460618050527-0-5}{camel.routeId,route8}{reqId,fc652d13-8d81-4993-be88-89e93d93d7ef}{tId,5710da8e-abff--b609-852c9d1118df}} | Connecting to example.com/54.169.255.232:443 2016-04-14T12:44:18.471+0530 | DEBUG | qtp1202042637-19 | SSLConnectionSocketFactory | - - | {{camel.breadcrumbId,ID-debraj1247-34494-1460618050527-0-5}{camel.contextId,camel-1}{camel.e
Re: curl
I tried below, testingsimple> but getting the below error stating caught: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: .stdout on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: stdout on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: stdout not found on bean: testing of type: java.lang.String. Exchange[Message: testing]: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: .stdout on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: stdout on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: stdout not found on bean: testing of type: java.lang.String. Exchange[Message: testing] Please help me out. I tried many other stuffs as well but none seem to work. -- View this message in context: http://camel.465427.n5.nabble.com/curl-tp5771624p5772195.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: curl
Hi Asaf, Claus, thanks for your replies. " did not work and i tried few other escape stuffs as well but none seem to work. The only way that i was able to pass the json is by using a temporary file. --silent --sslv3 --verbose --cacert {{cacertFile}} --key {{keyFile}} --cert {{certFile}} -H Content-Type:application/json -u {{user}} -X POST {{host}}/tenants -d @/003/temp.json *In my case, the JSON needs to be framed dynamically. Its not a static json content. * *Any idea on how to frame the JSON content dynamically in camel ?* I have this as the json string -- /response/JSONString *I get this above JSON string from one of the external components. how to write this string to the file and rewrite it everytime?* -- View this message in context: http://camel.465427.n5.nabble.com/curl-tp5771624p5772180.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: curl
I think you didn't escape the quotation marks inside the -d value which is the JSON. Try or better - store this json as is in a file "/tmp/1.json", and use --data-binary @/tmp/1.json to send it in curl. On Mon, Sep 28, 2015 at 1:28 PM, Suganya wrote: > Hi, > > Thanks for your reply. > > The GET command is working using the exec component. > > But I am stuck with the POST or the PUT command. The input data is in JSON > format. But I am unable to pass it. > > Where am I going wrong? below is the command. > > "tenant description"}' -u {{user}} --sslv3"/> > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/curl-tp5771624p5772053.html > Sent from the Camel - Users mailing list archive at Nabble.com. >
Re: curl
Hi, Thanks for your reply. The GET command is working using the exec component. But I am stuck with the POST or the PUT command. The input data is in JSON format. But I am unable to pass it. Where am I going wrong? below is the command. -- View this message in context: http://camel.465427.n5.nabble.com/curl-tp5771624p5772053.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: curl
You can use the exec component http://camel.apache.org/exec On Fri, Sep 18, 2015 at 10:11 AM, Suganya wrote: > Hi, > ' > Is it possible to run curl command in camel routes? > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/curl-tp5771624.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - http://davsclaus.com @davsclaus Camel in Action 2nd edition: https://www.manning.com/books/camel-in-action-second-edition
curl
Hi, ' Is it possible to run curl command in camel routes? -- View this message in context: http://camel.465427.n5.nabble.com/curl-tp5771624.html Sent from the Camel - Users mailing list archive at Nabble.com.