Skip to content

Commit 5d8f871

Browse files
committed
Add more headers in platform-http multipart uploads
1 parent 56c4fa4 commit 5d8f871

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ private void populateMultiFormData(
332332
}
333333

334334
protected void populateAttachments(List<FileUpload> uploads, Message message) {
335+
message.setHeader(Exchange.ATTACHMENTS_SIZE, uploads.size());
335336
for (FileUpload upload : uploads) {
336337
final String name = upload.name();
337338
final String fileName = upload.fileName();
@@ -357,13 +358,15 @@ protected void populateAttachments(List<FileUpload> uploads, Message message) {
357358

358359
// populate body in case there is only one attachment
359360
if (uploads.size() == 1) {
361+
message.setHeader(Exchange.FILE_PATH, localFile.getAbsolutePath());
362+
message.setHeader(Exchange.FILE_LENGTH, upload.size());
360363
message.setHeader(Exchange.FILE_NAME, upload.fileName());
361364
String ct = MimeTypeHelper.probeMimeType(upload.fileName());
362365
if (ct == null) {
363366
ct = upload.contentType();
364367
}
365368
if (ct != null) {
366-
message.setHeader(Exchange.CONTENT_TYPE, ct);
369+
message.setHeader(Exchange.FILE_CONTENT_TYPE, ct);
367370
}
368371
message.setBody(localFile);
369372
}

components/camel-platform-http-vertx/src/test/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpEngineTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ public void configure() {
430430
}
431431

432432
exchange.getIn().setHeader("ConcatFileContent", result);
433-
});
433+
})
434+
.setHeader("UploadedAttachments", simple("${headers.CamelAttachmentsSize}"));
434435
}
435436
});
436437

@@ -444,6 +445,7 @@ public void configure() {
444445
.then()
445446
.statusCode(204)
446447
.body(emptyOrNullString())
448+
.header("UploadedAttachments", is(String.valueOf(attachmentIds.size())))
447449
.header("ConcatFileContent",
448450
is("Test multipart upload content myFirstTestFileTest multipart upload content mySecondTestFile"));
449451
} finally {
@@ -476,7 +478,9 @@ public void configure() {
476478
AttachmentMessage message = exchange.getMessage(AttachmentMessage.class);
477479
DataHandler attachment = message.getAttachment(attachmentId);
478480
exchange.getMessage().setHeader("myDataHandler", attachment);
479-
});
481+
})
482+
.setHeader("UploadedFileContentType", simple("${header.CamelFileContentType}"))
483+
.setHeader("UploadedFileSize", simple("${header.CamelFileLength}"));
480484
}
481485
});
482486

@@ -489,6 +493,8 @@ public void configure() {
489493
.then()
490494
.statusCode(200)
491495
.header("myDataHandler", containsString("jakarta.activation.DataHandler"))
496+
.header("UploadedFileContentType", is("text/plain"))
497+
.header("UploadedFileSize", is(String.valueOf(fileContent.getBytes().length)))
492498
.body(is(fileContent));
493499
} finally {
494500
context.stop();

components/camel-platform-http/src/main/docs/platform-http-component.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ Since Apache Camel 4.10, multipart file uploads are easier and harmonized across
9191
* The Apache Camel message contains:
9292
** The uploaded file in the message body
9393
** The file name in the "CamelFileName" message header
94-
** The file's content type in the "Content-Type" message header
94+
** The file's content type in the "CamelFileContentType" message header
95+
** The file's size in the "CamelFileLength" message header
96+
97+
In case of multiple uploads, the header "CamelAttachmentsSize" contains the number of files uploaded.
9598

9699
include::spring-boot:partial$starter.adoc[]

core/camel-api/src/generated/java/org/apache/camel/ExchangeConstantProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ExchangeConstantProvider {
1313

1414
private static final Map<String, String> MAP;
1515
static {
16-
Map<String, String> map = new HashMap<>(160);
16+
Map<String, String> map = new HashMap<>(161);
1717
map.put("ACCEPT_CONTENT_TYPE", "CamelAcceptContentType");
1818
map.put("AGGREGATED_COLLECTION_GUARD", "CamelAggregatedCollectionGuard");
1919
map.put("AGGREGATED_COMPLETED_BY", "CamelAggregatedCompletedBy");
@@ -25,6 +25,7 @@ public class ExchangeConstantProvider {
2525
map.put("AGGREGATION_COMPLETE_CURRENT_GROUP", "CamelAggregationCompleteCurrentGroup");
2626
map.put("AGGREGATION_STRATEGY", "CamelAggregationStrategy");
2727
map.put("ASYNC_WAIT", "CamelAsyncWait");
28+
map.put("ATTACHMENTS_SIZE", "CamelAttachmentsSize");
2829
map.put("AUTHENTICATION", "CamelAuthentication");
2930
map.put("AUTHENTICATION_FAILURE_POLICY_ID", "CamelAuthenticationFailurePolicyId");
3031
map.put("BATCH_COMPLETE", "CamelBatchComplete");

core/camel-api/src/main/java/org/apache/camel/Exchange.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public interface Exchange extends VariableAware {
117117
String CONTENT_TYPE = "Content-Type";
118118
String COOKIE_HANDLER = "CamelCookieHandler";
119119
String CORRELATION_ID = "CamelCorrelationId";
120+
String ATTACHMENTS_SIZE = "CamelAttachmentsSize";
120121

121122
// The schema of the message payload
122123
String CONTENT_SCHEMA = "CamelContentSchema";

0 commit comments

Comments
 (0)