This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27538-azure-files-cloudevent-source in repository https://gitbox.apache.org/repos/asf/camel.git
commit 67d2521825b2cd90461c929646b30a8e0a8b5a48 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Nov 25 08:35:00 2026 +0100 CAMEL-27538: camel-azure-files - the CloudEvent source is the share, not the storage account host The azure-files:application-cloudevents data type transformer built CamelCloudEventSource from CamelFileHost, the host of the storage account, so all the shares of an account had the same source. The consumer now sets a new CamelAzureFilesShareName header, and the transformer builds the source as azure.storage.files.<share name>, as the queue, blob and datalake transformers use the queue, container and file system since CAMEL-27101. Added to the CAMEL-27101 entry of the 4.24 upgrade guide. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/catalog/components/azure-files.json | 3 +- .../camel/component/file/azure/azure-files.json | 3 +- .../camel/component/file/azure/FilesConstants.java | 2 + .../camel/component/file/azure/FilesConsumer.java | 11 +++ .../AzureFilesCloudEventDataTypeTransformer.java | 4 +- .../file/azure/FilesConsumerShareNameTest.java | 87 ++++++++++++++++++++++ ...zureFilesCloudEventDataTypeTransformerTest.java | 25 +++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 16 ++-- .../endpoint/dsl/FilesEndpointBuilderFactory.java | 12 +++ 9 files changed, 154 insertions(+), 9 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-files.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-files.json index b9358eb7376d..d50f2c900b45 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-files.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/azure-files.json @@ -45,7 +45,8 @@ "CamelOverruleFileName": { "index": 11, "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Object", "deprecated": false, "autowired": false, "secret": false, "description": "Is used for overruling CamelFileName header and use the value instead (but only once, as the producer will remove this header after writing the file). The value can be only be a String. Notice that if the option fileName has been configured, then this is [...] "CamelRemoteFileInputStream": { "index": 12, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "java.io.InputStream", "deprecated": false, "autowired": false, "secret": false, "description": "The remote file input stream.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#REMOTE_FILE_INPUT_STREAM" }, "CamelFileLocalWorkPath": { "index": 13, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "Path to the local work file, if local work directory is used.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_LOCAL_WORK_PATH" }, - "CamelFileHost": { "index": 14, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The remote hostname.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_HOST" } + "CamelFileHost": { "index": 14, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The remote hostname.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_HOST" }, + "CamelAzureFilesShareName": { "index": 15, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the share the file was consumed from.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#SHARE_NAME" } }, "bodyTypes": { "consumerOut": { "carriers": [ "file" ], "dependsOn": [ "preMove" ], "byOption": [ { "option": "streamDownload", "value": "true", "carriers": [ "stream" ] }, { "option": "download", "value": "false", "carriers": [ "null" ] } ], "description": "The file as read: a RemoteFile with its content loaded as bytes, which converts to text, bytes or a stream; a stream with streamDownload; with preMove its content, a byte array" }, diff --git a/components/camel-azure/camel-azure-files/src/generated/resources/META-INF/org/apache/camel/component/file/azure/azure-files.json b/components/camel-azure/camel-azure-files/src/generated/resources/META-INF/org/apache/camel/component/file/azure/azure-files.json index b9358eb7376d..d50f2c900b45 100644 --- a/components/camel-azure/camel-azure-files/src/generated/resources/META-INF/org/apache/camel/component/file/azure/azure-files.json +++ b/components/camel-azure/camel-azure-files/src/generated/resources/META-INF/org/apache/camel/component/file/azure/azure-files.json @@ -45,7 +45,8 @@ "CamelOverruleFileName": { "index": 11, "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Object", "deprecated": false, "autowired": false, "secret": false, "description": "Is used for overruling CamelFileName header and use the value instead (but only once, as the producer will remove this header after writing the file). The value can be only be a String. Notice that if the option fileName has been configured, then this is [...] "CamelRemoteFileInputStream": { "index": 12, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "java.io.InputStream", "deprecated": false, "autowired": false, "secret": false, "description": "The remote file input stream.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#REMOTE_FILE_INPUT_STREAM" }, "CamelFileLocalWorkPath": { "index": 13, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "Path to the local work file, if local work directory is used.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_LOCAL_WORK_PATH" }, - "CamelFileHost": { "index": 14, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The remote hostname.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_HOST" } + "CamelFileHost": { "index": 14, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The remote hostname.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#FILE_HOST" }, + "CamelAzureFilesShareName": { "index": 15, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The name of the share the file was consumed from.", "constantName": "org.apache.camel.component.file.azure.FilesConstants#SHARE_NAME" } }, "bodyTypes": { "consumerOut": { "carriers": [ "file" ], "dependsOn": [ "preMove" ], "byOption": [ { "option": "streamDownload", "value": "true", "carriers": [ "stream" ] }, { "option": "download", "value": "false", "carriers": [ "null" ] } ], "description": "The file as read: a RemoteFile with its content loaded as bytes, which converts to text, bytes or a stream; a stream with streamDownload; with preMove its content, a byte array" }, diff --git a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConstants.java b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConstants.java index b74de0e451b4..c770d05ac4ae 100644 --- a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConstants.java +++ b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConstants.java @@ -78,6 +78,8 @@ public final class FilesConstants { @Metadata(description = "The remote hostname.", javaType = "String") public static final String FILE_HOST = "CamelFileHost"; + @Metadata(label = "consumer", description = "The name of the share the file was consumed from.", javaType = "String") + public static final String SHARE_NAME = "CamelAzureFilesShareName"; private FilesConstants() { } diff --git a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConsumer.java b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConsumer.java index f5490b157b5d..c72b26bb8cec 100644 --- a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConsumer.java +++ b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/FilesConsumer.java @@ -46,6 +46,8 @@ public class FilesConsumer extends RemoteFileConsumer<ShareFileItem> { protected String endpointPath; + private final String share; + private transient String toString; public FilesConsumer(FilesEndpoint endpoint, Processor processor, @@ -53,6 +55,15 @@ public class FilesConsumer extends RemoteFileConsumer<ShareFileItem> { GenericFileProcessStrategy<?> processStrategy) { super(endpoint, processor, fileOperations, processStrategy); this.endpointPath = endpoint.getConfiguration().getDirectory(); + this.share = endpoint.getConfiguration().getShare(); + } + + @Override + protected Exchange createExchange(GenericFile<ShareFileItem> file) { + Exchange answer = super.createExchange(file); + // the share the file comes from, which names the CloudEvent source + answer.getIn().setHeader(FilesConstants.SHARE_NAME, share); + return answer; } @Override diff --git a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformer.java b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformer.java index f24debb5261d..c89c684ca267 100644 --- a/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformer.java +++ b/components/camel-azure/camel-azure-files/src/main/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformer.java @@ -50,9 +50,9 @@ public class AzureFilesCloudEventDataTypeTransformer extends Transformer { headers.putIfAbsent(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, cloudEvent.version()); headers.put(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.azure.storage.files.poll"); - if (message.getHeaders().containsKey(FilesConstants.FILE_HOST)) { + if (message.getHeaders().containsKey(FilesConstants.SHARE_NAME)) { headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE, - "azure.storage.files." + message.getHeader(FilesConstants.FILE_HOST, String.class)); + "azure.storage.files." + message.getHeader(FilesConstants.SHARE_NAME, String.class)); } headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(FilesConstants.FILE_NAME, String.class)); diff --git a/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/FilesConsumerShareNameTest.java b/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/FilesConsumerShareNameTest.java new file mode 100644 index 000000000000..b86d036e804d --- /dev/null +++ b/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/FilesConsumerShareNameTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.file.azure; + +import com.azure.storage.file.share.models.ShareFileItem; +import org.apache.camel.Exchange; +import org.apache.camel.cloudevents.CloudEvent; +import org.apache.camel.component.file.azure.transform.AzureFilesCloudEventDataTypeTransformer; +import org.apache.camel.component.file.remote.RemoteFile; +import org.apache.camel.spi.DataType; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +/** + * The consumer sets the name of the share on each exchange, and the CloudEvent data type names the share as the source + * (CAMEL-27538). + */ +class FilesConsumerShareNameTest extends CamelTestSupport { + + @Test + void testConsumerSetsShareName() { + FilesEndpoint endpoint = context.getEndpoint("azure-files://account/myshare/inbox", FilesEndpoint.class); + TestConsumer consumer = new TestConsumer(endpoint, mock(FilesOperations.class)); + + Exchange exchange = consumer.exchangeOf(remoteFile(endpoint, "inbox", "hello.txt")); + + assertEquals("myshare", exchange.getIn().getHeader(FilesConstants.SHARE_NAME)); + assertEquals("account.file.core.windows.net", exchange.getIn().getHeader(FilesConstants.FILE_HOST)); + + new AzureFilesCloudEventDataTypeTransformer().transform(exchange.getIn(), DataType.ANY, DataType.ANY); + assertEquals("azure.storage.files.myshare", exchange.getIn().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE)); + assertEquals("hello.txt", exchange.getIn().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT)); + } + + @Test + void testConsumerSetsShareNameWithoutDirectory() { + FilesEndpoint endpoint = context.getEndpoint("azure-files://account/othershare", FilesEndpoint.class); + TestConsumer consumer = new TestConsumer(endpoint, mock(FilesOperations.class)); + + Exchange exchange = consumer.exchangeOf(remoteFile(endpoint, "", "hello.txt")); + + assertEquals("othershare", exchange.getIn().getHeader(FilesConstants.SHARE_NAME)); + } + + private static RemoteFile<ShareFileItem> remoteFile(FilesEndpoint endpoint, String directory, String name) { + RemoteFile<ShareFileItem> file = new RemoteFile<>(); + file.setEndpointPath(directory); + file.setFileNameOnly(name); + file.setFileName(name); + file.setRelativeFilePath(name); + file.setAbsoluteFilePath(directory.isEmpty() ? name : directory + "/" + name); + file.setHostname(endpoint.getConfiguration().getHost()); + return file; + } + + /** + * Gives the test access to the exchange that the consumer creates for a polled file. + */ + private static final class TestConsumer extends FilesConsumer { + + TestConsumer(FilesEndpoint endpoint, FilesOperations operations) { + super(endpoint, exchange -> { + }, operations, null); + } + + Exchange exchangeOf(RemoteFile<ShareFileItem> file) { + return createExchange(file); + } + } +} diff --git a/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformerTest.java b/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformerTest.java index f6e6ecec43b6..141c7556b7ac 100644 --- a/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformerTest.java +++ b/components/camel-azure/camel-azure-files/src/test/java/org/apache/camel/component/file/azure/transform/AzureFilesCloudEventDataTypeTransformerTest.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.camel.Exchange; import org.apache.camel.cloudevents.CloudEvent; +import org.apache.camel.component.file.azure.FilesConstants; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.BodyType.Carrier; import org.apache.camel.spi.BodyTypes; @@ -31,6 +32,7 @@ import org.apache.camel.support.DefaultExchange; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; class AzureFilesCloudEventDataTypeTransformerTest { @@ -55,4 +57,27 @@ class AzureFilesCloudEventDataTypeTransformerTest { exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_TYPE)); } } + + @Test + void theSourceIsTheShare() { + // CAMEL-27538: files of the same share have the same source, which names the share and not the account host + for (String fileName : Arrays.asList("a.txt", "b.txt")) { + Exchange exchange = new DefaultExchange(camelContext); + exchange.getMessage().setHeader(FilesConstants.SHARE_NAME, "myshare"); + exchange.getMessage().setHeader(FilesConstants.FILE_HOST, "myaccount.file.core.windows.net"); + exchange.getMessage().setHeader(FilesConstants.FILE_NAME, fileName); + transformer.transform(exchange.getMessage(), DataType.ANY, DataType.ANY); + assertEquals("azure.storage.files.myshare", exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE)); + assertEquals(fileName, exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT)); + } + } + + @Test + void noShareNoSource() { + // the host, which the source was built from before, no longer gives a source + Exchange exchange = new DefaultExchange(camelContext); + exchange.getMessage().setHeader(FilesConstants.FILE_HOST, "myaccount.file.core.windows.net"); + transformer.transform(exchange.getMessage(), DataType.ANY, DataType.ANY); + assertNull(exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE)); + } } diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index e9b4e310d599..2d4ce32933a8 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -8567,12 +8567,13 @@ header, such as one that does not come from the `aws2-sqs` consumer, gets no Clo also when it has a `CamelAwsSqsReceiptHandle` header. A route that relies on the old source can set the `CamelCloudEventSource` header itself after the transformer. -=== camel-azure, camel-google, camel-aws2-kinesis - the CloudEvent source is the queue, container, file system, topic, stream, subscription or calendar +=== camel-azure, camel-google, camel-aws2-kinesis - the CloudEvent source is the queue, container, file system, share, topic, stream, subscription or calendar -Seven `application-cloudevents` data type transformers now set the `CamelCloudEventSource` header (the `ce-source` -of the CloudEvent) to the queue, container, file system, topic, stream, subscription or calendar the message was -consumed from, as `aws2-sqs:application-cloudevents` and `aws2-s3:application-cloudevents` do. Before, they used a -value of each message, such as its id, so most events had a source of their own. The CloudEvent id is unchanged. +Eight `application-cloudevents` data type transformers now set the `CamelCloudEventSource` header (the `ce-source` +of the CloudEvent) to the queue, container, file system, share, topic, stream, subscription or calendar the message was +consumed from, as `aws2-sqs:application-cloudevents` and `aws2-s3:application-cloudevents` do. Before, most of them +used a value of each message, such as its id, so most events had a source of their own, and `azure-files` used the +host of the storage account, so all the shares of an account had the same source. The CloudEvent id is unchanged. [cols="2,3,3", options="header"] |=== @@ -8590,6 +8591,10 @@ value of each message, such as its id, so most events had a source of their own. | `azure.storage.datalake.` and the archive status of the file | `azure.storage.datalake.` and the file system name +| `azure-files:application-cloudevents` +| `azure.storage.files.` and the host of the storage account, such as `myaccount.file.core.windows.net` +| `azure.storage.files.` and the share name + | `azure-servicebus:application-cloudevents` | `azure.servicebus.partition.` and the partition key of the message | `azure.servicebus.` and the queue or topic name @@ -8612,6 +8617,7 @@ The name comes from a new header that the consumer now sets on each message: * `azure-storage-queue`: `CamelAzureStorageQueueConsumedQueueName` * `azure-storage-blob`: `CamelAzureStorageBlobConsumedContainerName` * `azure-storage-datalake`: `CamelAzureStorageDataLakeConsumedFileSystemName` +* `azure-files`: `CamelAzureFilesShareName` * `azure-servicebus`: `CamelAzureServiceBusTopicOrQueueName` * `aws2-kinesis`: `CamelAwsKinesisStreamName`, set by both the polling and the KCL consumer * `google-pubsub`: `CamelGooglePubsubSubscriptionName`, set by the synchronous and the asynchronous pull diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FilesEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FilesEndpointBuilderFactory.java index 5e6781393f6f..092002145aed 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FilesEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/FilesEndpointBuilderFactory.java @@ -4483,6 +4483,18 @@ public interface FilesEndpointBuilderFactory { public String fileHost() { return "CamelFileHost"; } + /** + * The name of the share the file was consumed from. + * + * The option is a: {@code String} type. + * + * Group: consumer + * + * @return the name of the header {@code AzureFilesShareName}. + */ + public String azureFilesShareName() { + return "CamelAzureFilesShareName"; + } } static FilesEndpointBuilder endpointBuilder(String componentName, String path) { class FilesEndpointBuilderImpl extends AbstractEndpointBuilder implements FilesEndpointBuilder, AdvancedFilesEndpointBuilder {
