Thanks for the example. I cannot get your code working though. I get the following:
[qtp1422312468-17] HandleUpload INFO Upload received [ qtp1422312468-17] HandleUpload INFO Exchange body: org.apache.camel.converter.stream.InputStreamCache@1cf48789 [qtp1422312468-17] HandleUpload INFO Attachment size: 0 [qtp1422312468-17] HandleUpload INFO Attachment object size: 0 [qtp1422312468-17] HandleUpload WARN No attachments found! I am testing with the Postman app in the Chrome Browser and using Jetty. I'm using Camel 2.16.2, since we're deploying in ServiceMix. I tried testing with Camel 2.19.3 and observed the same problem so I don't think a newer version of Camel fixes things. What environment are you running your code inside? On Sat, Sep 30, 2017 at 9:13 PM, Roman Vottner <r...@gmx.at> wrote: > Our Camel REST DSL configuration looks like this: > > onException(Exception.class) > .handled(true) > .logExhausted(false) > .log(LoggingLevel.ERROR, ">> In default/message exception handler. > ${exception}, message: ${exception.message}, stacktrace: > ${exception.stacktrace}") > .onRedelivery((Exchange exchange) -> LOG.debug(">> Default > exception handler")) > .bean(PrepareErrorResponse.class).id("ErrorResponse") > .end(); > > restConfiguration() > .component("undertow") > .port("{{server.port}}") > .contextPath("/api") > .endpointProperty("matchOnUriPrefix", "true") > .endpointProperty("sendServerVersion", "false") > .endpointProperty("chunked", "true"); > > where the actual route handling the multipart-request does look something > along the line: > > rest("/someEndpoint") > .post("/{id}") > .consumes(MediaType.MULTIPART_FORM_DATA_VALUE) > .route().routeId("upload-multipart-route") > // Spring Security authentication check via Authorization header > .bean(SpringSecurityContextLoader.class) > .policy(authorizationPolicy) > .log("Uploading to resource id ${header.id}") > .log(LoggingLevel.INFO, LOG, CONFIDENTIAL,"Headers: ${headers}") > .bean(HandleUpload.class) > .process((Exchange exchange) -> { > exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 200); > exchange.getIn().setHeader(Exchange.CONTENT_TYPE, > MediaType.APPLICATION_JSON_UTF8_VALUE); > ... > }) > .endRest(); > > and the HandleUpload class looking something like this: > > public class HandleUpload { > > private static final Logger LOG = LoggerFactory.getLogger(Method > Handles.lookup().lookupClass()); > > @Autowired > private SomeRepository someRepository; > > @Handler > public void processUpload(@Attachments Map<String, DataHandler> > attachments, > @Header("Content-Type") String contentType, > @Header("id") String id, > Exchange exchange) > throws Exception { > LOG.info("Upload received"); > > LOG.info("Exchange body: " + exchange.getIn().getBody()); > LOG.info("Attachment size: " + (attachments == null ? 0 : > attachments.size())); > LOG.info("Attachment object size: " + > (exchange.getIn().getAttachmentObjects() > == null ? 0 > : exchange.getIn().getAttachmentObjects().size())); > if (exchange.getIn().getAttachmentNames() != null) { > for (String name : exchange.getIn().getAttachmentNames()) { > LOG.info("Attachment name: " + name); > } > } > > if (contentType == null || !contentType.startsWith(MediaT > ype.MULTIPART_FORM_DATA_VALUE)) { > LOG.warn("Unsupported media type!"); > throw new UnSupportedUploadMediaTypeException("Content-Type has to > be 'multipart/form-data'"); > } > > if (attachments.size() == 0) { > LOG.warn("No attachments found!"); > } else { > for (String key : attachments.keys()) { > LOG.info("Filename: " + key); > > String uploadKey = id + "_" + new Date().toInstant().toEpochMilli() > + "_" + > attachments.get(key).getDataSource().getName(); > > // stream data directly to a file to save memory footprint > File targetFile = new File(uploadKey); > try (OutputStream outStream = new FileOutputStream(targetFile, > false)) { > attachments.get(key).writeTo(outStream); > } > > ... > } > } > > ... > } > } > > Although we currently test Undertow, switching it with Jetty shouldn't be > an issue. > > HTH, > roman > > > > Am 01.10.2017 um 02:18 schrieb Mark: > >> I understand that, problem is that I can't figure out how to configure the >> Camel Route to properly receive/parse the data. If I was receiving >> JSON/KML, this would be easy using the functionality in Camel. Binary >> files seem to be totally different. >> >> >> On Sat, Sep 30, 2017 at 8:13 PM, Mark Nuttall <mknutt...@gmail.com> >> wrote: >> >> it is just a file. any example of processing a file should work. you will >>> be able to save it somewhere and then you will have to call some >>> processor >>> to read/process it. >>> >>> On Fri, Sep 29, 2017 at 7:47 PM, Mark <elihusma...@gmail.com> wrote: >>> >>> I'm trying to figure out how to process a binary file that is sent to my >>>> Camel REST service via POST. I have not found any good examples on how >>>> this can be done using Camel. Does anyone have any experiences they >>>> >>> could >>> >>>> share or links to more documentation? >>>> >>>> I'm currently using the jetty component for the restconfiguration. >>>> >>>> Thanks, >>>> Mark >>>> >>>> >