This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch azure-storage-blob-cloud-events in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit fc3b65624641fb0e0006a64f5e7462261eeaf777 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Sep 18 13:29:47 2023 +0200 Azure Storage Blob Source: Add CloudEvents Data Type Transformer Signed-off-by: Andrea Cosentino <[email protected]> --- library/camel-kamelets-utils/pom.xml | 5 +++ .../blob/AzureStorageBlobCloudEventOutputType.java | 47 ++++++++++++++++++++++ .../azure-storage-blob-application-cloudevents | 18 +++++++++ 3 files changed, 70 insertions(+) diff --git a/library/camel-kamelets-utils/pom.xml b/library/camel-kamelets-utils/pom.xml index cd5e4883..e5d799b9 100644 --- a/library/camel-kamelets-utils/pom.xml +++ b/library/camel-kamelets-utils/pom.xml @@ -87,6 +87,11 @@ <artifactId>camel-aws2-sqs</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-azure-storage-blob</artifactId> + <scope>provided</scope> + </dependency> <!-- Dependencies for mongodb connection configuration --> <dependency> diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java new file mode 100644 index 00000000..ec4f5166 --- /dev/null +++ b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/azure/storage/blob/AzureStorageBlobCloudEventOutputType.java @@ -0,0 +1,47 @@ +/* + * 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.kamelets.utils.format.converter.azure.storage.blob; + +import org.apache.camel.Message; +import org.apache.camel.component.aws2.s3.AWS2S3Constants; +import org.apache.camel.component.azure.storage.blob.BlobConstants; +import org.apache.camel.kamelets.utils.format.converter.utils.CloudEvents; +import org.apache.camel.spi.DataType; +import org.apache.camel.spi.DataTypeTransformer; +import org.apache.camel.spi.Transformer; + +import java.util.Map; + +/** + * Output data type represents Azure Storage Blob get blob response as CloudEvent V1. The data type sets Camel specific + * CloudEvent headers on the exchange. + */ +@DataTypeTransformer(name = "azure-storage-blob:application-cloudevents") +public class AzureStorageBlobCloudEventOutputType extends Transformer { + + @Override + public void transform(Message message, DataType fromType, DataType toType) { + final Map<String, Object> headers = message.getHeaders(); + + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_ID, message.getExchange().getExchangeId()); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event.azure.storage.blob.getBlob"); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SOURCE, "azure.storage.blob." + message.getHeader(BlobConstants.BLOB_NAME, String.class)); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_SUBJECT, message.getHeader(BlobConstants.BLOB_NAME, String.class)); + headers.put(CloudEvents.CAMEL_CLOUD_EVENT_TIME, CloudEvents.getEventTime(message.getExchange())); + } +} diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents new file mode 100644 index 00000000..b3efe4e9 --- /dev/null +++ b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/transformer/azure-storage-blob-application-cloudevents @@ -0,0 +1,18 @@ +# +# 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. +# + +class=org.apache.camel.kamelets.utils.format.converter.azure.storage.blob.AzureStorageBlobCloudEventOutputType \ No newline at end of file
