Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CE01E200D11 for ; Mon, 2 Oct 2017 11:41:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC6CF1609EF; Mon, 2 Oct 2017 09:41:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C37821609DE for ; Mon, 2 Oct 2017 11:41:17 +0200 (CEST) Received: (qmail 2556 invoked by uid 500); 2 Oct 2017 09:41:16 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 2545 invoked by uid 99); 2 Oct 2017 09:41:16 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Oct 2017 09:41:16 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id D9522D8E23 for ; Mon, 2 Oct 2017 09:41:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.372 X-Spam-Level: *** X-Spam-Status: No, score=3.372 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, KAM_INFOUSMEBIZ=0.75, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, T_MIME_MALF=0.01, URI_HEX=1.313] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id IvUFbfE_Vhf9 for ; Mon, 2 Oct 2017 09:41:11 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id C10AF61023 for ; Mon, 2 Oct 2017 09:41:10 +0000 (UTC) Received: from [192.168.1.104] ([81.223.125.75]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0Lta9E-1dIIkc0UMO-010xWd for ; Mon, 02 Oct 2017 11:41:10 +0200 From: Roman Vottner Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_4A7D40A1-399A-4849-8A48-B851709DA696" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: REST DSL process multipart/form-data binary file? Date: Mon, 2 Oct 2017 11:41:20 +0200 X-Erpel_Message_Id: 1234 References: To: users@camel.apache.org In-Reply-To: X-Mailer: Apple Mail (2.3273) X-Provags-ID: V03:K0:SrgyVMkJcOhcI/H8bHBnkiu4Orsd+RfY8la8YFhZPCW9ze+EFgG ACqcVDDUuHeEM77pGegAPQvMWGyPlFXz9zjrlAwL6ObWY2mGPvTtphXUO6jeCYqz2ANFnpg tO8KcBSfonQn0wwHgU77sG4YLZ1N/l6bXG8ZkoUmb+4mwwZA3Gld1cXNHgcW+MqWZ3c0e1T Btiv9fIFG6n5f+onnF6EA== X-UI-Out-Filterresults: notjunk:1;V01:K0:9cyVzZdzaFw=:iMYmxxm97ibUXq8PW7LDqK ytO+QwMO8W5hOoO0KCxRRhreqKEwNzmQe8zrVBNIoMd6wkfJc+7wMpg+Qe0I72ZGxi2oNiBY8 fsTrnaT4+PfKKu9sYdNuv/4LN94aAsuiBL4R0n38ZRAQs6yxnU7NzRyTfJ2uXeP3f8YZK5UmN hSaDo/kj8oqraMV1CKQzBY4Q/Z1mBSY+MdQppe7r8lwMK7cBrXuJ0FvVB2BgEwjHmMISSthQw vtvczaXEviEAbhYbaHgJ3vN1HvzZw6G3rRjHFspjr/DwgVA61xSOmhsvd9Si9cSeD1W1i5L6e ge+odamBq6n27itHtd0KQeV9YvnQprQQcxITP00MSETaQjUQ3Hyp6Qp29ONNefmof437JoLcN BlHxi5cPLU3oX7noza5mO+qeNpSVPIy7MqcQrW80b8n3uGjec4AxvWGbspRWy5xtCyBxcn7kS jJ0aFmTFpphmvNkHJ4wLgnT0to7Au6UNZ9FNQ6FgR3NEfWPmb9OGB2cTA9n6ZjqT02QP3hbOK 4n1sfcHsBW3vENDMOcX8/VXdF2WcBOvwtvwPzoQiYEQBnJhEjQm7s4sZEER1loKZkaIbK/9fR +kCqzK4o99kG70+P3uBGGGEBlXlbY5U8meIYmMA6aLNHDGct2EV1IbCkgwipeBvUhTUOk3ecs fioCwGqAWT52Wc0DN1JZVVcRwU9xcR1prrd+WfB/uxTKdaW4RqbJrmPREaFYbz+cKjSWT4btM FaXb7pZw9zY+N6UfSkyg/JkI3NOuVgH0vBUpikyvjoXH2ddIsfwYiLoRxx1goqLP0k6TStxYf pod7btaS6Hb6Cg+qVFon7VBVvBMnBECGHMcK/uotaWYzd6DrzQ= archived-at: Mon, 02 Oct 2017 09:41:19 -0000 --Apple-Mail=_4A7D40A1-399A-4849-8A48-B851709DA696 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 How do you send data to your application? Have you specified a = Content-Disposition header for the respective parts? We analysed a raw request via wireshark and it does look something like = this: GET /api/someResource HTTP/1.1 Host: www.somewhere.com =E2=80=A6 Content-Type: multipart/form-data; = boundary=3D------------------------d9c950f09cd11bba --------------------------d9c950f09cd11bba Content-Disposition: form-data; name=3D"dat1"; filename=3D=E2=80=9ESomeFil= e.zip" Content-Type: application/octet-stream =E2=80=A6 --------------------------d9c950f09cd11bba Content-Disposition: form-data; name=3D"dat2"; = filename=3D=E2=80=9ESomeOtherFile.zip" Content-Type: application/octet-stream =E2=80=A6 We use Camel 2.19.0 and the Undertow version Camel = (camel-undertow-starter) and/or Spring-Boot = (spring-boot-starter-undertow) includes their dependencies (undertow = 1.4.13.FINAL).=20 > Am 02.10.2017 um 04:25 schrieb Mark Webb [via Camel] = : >=20 > Thanks for the example. I cannot get your code working though. I get = the=20 > following:=20 >=20 > [qtp1422312468-17] HandleUpload INFO Upload = received=20 > [ qtp1422312468-17] HandleUpload INFO Exchange = body:=20 > org.apache.camel.converter.stream.InputStreamCache@1cf48789=20 > [qtp1422312468-17] HandleUpload INFO Attachment = size: 0=20 > [qtp1422312468-17] HandleUpload INFO Attachment = object=20 > size: 0=20 > [qtp1422312468-17] HandleUpload WARN No attachments=20= > found!=20 >=20 > I am testing with the Postman app in the Chrome Browser and using = Jetty.=20 > I'm using Camel 2.16.2, since we're deploying in ServiceMix. I tried=20= > testing with Camel 2.19.3 and observed the same problem so I don't = think a=20 > newer version of Camel fixes things. What environment are you running = your=20 > code inside?=20 >=20 >=20 >=20 >=20 >=20 > On Sat, Sep 30, 2017 at 9:13 PM, Roman Vottner <[hidden email] = > wrote:=20= >=20 > > Our Camel REST DSL configuration looks like this:=20 > >=20 > > onException(Exception.class)=20 > > .handled(true)=20 > > .logExhausted(false)=20 > > .log(LoggingLevel.ERROR, ">> In default/message exception = handler.=20 > > ${exception}, message: ${exception.message}, stacktrace:=20 > > ${exception.stacktrace}")=20 > > .onRedelivery((Exchange exchange) -> LOG.debug(">> Default=20= > > exception handler"))=20 > > .bean(PrepareErrorResponse.class).id("ErrorResponse")=20 > > .end();=20 > >=20 > > restConfiguration()=20 > > .component("undertow")=20 > > .port("{{server.port}}")=20 > > .contextPath("/api")=20 > > .endpointProperty("matchOnUriPrefix", "true")=20 > > .endpointProperty("sendServerVersion", "false")=20 > > .endpointProperty("chunked", "true");=20 > >=20 > > where the actual route handling the multipart-request does look = something=20 > > along the line:=20 > >=20 > > rest("/someEndpoint")=20 > > .post("/{id}")=20 > > .consumes(MediaType.MULTIPART_FORM_DATA_VALUE)=20 > > .route().routeId("upload-multipart-route")=20 > > // Spring Security authentication check via Authorization = header=20 > > .bean(SpringSecurityContextLoader.class)=20 > > .policy(authorizationPolicy)=20 > > .log("Uploading to resource id ${header.id}")=20 > > .log(LoggingLevel.INFO, LOG, CONFIDENTIAL,"Headers: = ${headers}")=20 > > .bean(HandleUpload.class)=20 > > .process((Exchange exchange) -> {=20 > > exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, = 200);=20 > > exchange.getIn().setHeader(Exchange.CONTENT_TYPE,=20 > > MediaType.APPLICATION_JSON_UTF8_VALUE);=20 > > ...=20 > > })=20 > > .endRest();=20 > >=20 > > and the HandleUpload class looking something like this:=20 > >=20 > > public class HandleUpload {=20 > >=20 > > private static final Logger LOG =3D LoggerFactory.getLogger(Method=20= > > Handles.lookup().lookupClass());=20 > >=20 > > @Autowired=20 > > private SomeRepository someRepository;=20 > >=20 > > @Handler=20 > > public void processUpload(@Attachments Map=20 > > attachments,=20 > > @Header("Content-Type") String = contentType,=20 > > @Header("id") String id,=20 > > Exchange exchange)=20 > > throws Exception {=20 > > LOG.info("Upload received");=20 > >=20 > > LOG.info("Exchange body: " + exchange.getIn().getBody());=20 > > LOG.info("Attachment size: " + (attachments =3D=3D null ? 0 :=20 > > attachments.size()));=20 > > LOG.info("Attachment object size: " + = (exchange.getIn().getAttachmentObjects()=20 > > =3D=3D null ? 0=20 > > : exchange.getIn().getAttachmentObjects().size()));=20 > > if (exchange.getIn().getAttachmentNames() !=3D null) {=20 > > for (String name : exchange.getIn().getAttachmentNames()) {=20 > > LOG.info("Attachment name: " + name);=20 > > }=20 > > }=20 > >=20 > > if (contentType =3D=3D null || !contentType.startsWith(MediaT=20 > > ype.MULTIPART_FORM_DATA_VALUE)) {=20 > > LOG.warn("Unsupported media type!");=20 > > throw new UnSupportedUploadMediaTypeException("Content-Type = has to=20 > > be 'multipart/form-data'");=20 > > }=20 > >=20 > > if (attachments.size() =3D=3D 0) {=20 > > LOG.warn("No attachments found!");=20 > > } else {=20 > > for (String key : attachments.keys()) {=20 > > LOG.info("Filename: " + key);=20 > >=20 > > String uploadKey =3D id + "_" + new = Date().toInstant().toEpochMilli()=20 > > + "_" +=20 > > attachments.get(key).getDataSource().getName();=20 > >=20 > > // stream data directly to a file to save memory footprint=20= > > File targetFile =3D new File(uploadKey);=20 > > try (OutputStream outStream =3D new = FileOutputStream(targetFile,=20 > > false)) {=20 > > attachments.get(key).writeTo(outStream);=20 > > }=20 > >=20 > > ...=20 > > }=20 > > }=20 > >=20 > > ...=20 > > }=20 > > }=20 > >=20 > > Although we currently test Undertow, switching it with Jetty = shouldn't be=20 > > an issue.=20 > >=20 > > HTH,=20 > > roman=20 > >=20 > >=20 > >=20 > > Am 01.10.2017 um 02:18 schrieb Mark:=20 > >=20 > >> I understand that, problem is that I can't figure out how to = configure the=20 > >> Camel Route to properly receive/parse the data. If I was receiving=20= > >> JSON/KML, this would be easy using the functionality in Camel. = Binary=20 > >> files seem to be totally different.=20 > >>=20 > >>=20 > >> On Sat, Sep 30, 2017 at 8:13 PM, Mark Nuttall <[hidden email] = >=20 > >> wrote:=20 > >>=20 > >> it is just a file. any example of processing a file should work. = you will=20 > >>> be able to save it somewhere and then you will have to call some=20= > >>> processor=20 > >>> to read/process it.=20 > >>>=20 > >>> On Fri, Sep 29, 2017 at 7:47 PM, Mark <[hidden email] = > wrote:=20= > >>>=20 > >>> I'm trying to figure out how to process a binary file that is sent = to my=20 > >>>> Camel REST service via POST. I have not found any good examples = on how=20 > >>>> this can be done using Camel. Does anyone have any experiences = they=20 > >>>>=20 > >>> could=20 > >>>=20 > >>>> share or links to more documentation?=20 > >>>>=20 > >>>> I'm currently using the jetty component for the = restconfiguration.=20 > >>>>=20 > >>>> Thanks,=20 > >>>> Mark=20 > >>>>=20 > >>>>=20 > >=20 >=20 >=20 > If you reply to this email, your message will be added to the = discussion below: > = http://camel.465427.n5.nabble.com/REST-DSL-process-multipart-form-data-bin= ary-file-tp5814059p5814065.html = > To unsubscribe from Camel - Users, click here = . > NAML = --Apple-Mail=_4A7D40A1-399A-4849-8A48-B851709DA696--