You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/12/02 08:08:42 UTC
[camel-kamelets] 10/28: Remove AWS S3 Json output type
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit 30c5571f822c4832514f87ca5211d449719d9d85
Author: Christoph Deppisch <cd...@redhat.com>
AuthorDate: Fri Nov 18 19:44:05 2022 +0100
Remove AWS S3 Json output type
Not a robust solution at the moment
---
.../converter/aws2/s3/AWS2S3JsonOutputType.java | 63 ----------------------
.../apache/camel/datatype/converter/aws2-s3-json | 18 -------
...peTest.java => AWS2S3BinaryOutputTypeTest.java} | 31 +++++------
3 files changed, 14 insertions(+), 98 deletions(-)
diff --git a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputType.java b/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputType.java
deleted file mode 100644
index 74736d67..00000000
--- a/library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputType.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.aws2.s3;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.camel.CamelExecutionException;
-import org.apache.camel.Exchange;
-import org.apache.camel.component.aws2.s3.AWS2S3Constants;
-import org.apache.camel.kamelets.utils.format.spi.DataTypeConverter;
-import org.apache.camel.kamelets.utils.format.spi.annotations.DataType;
-import software.amazon.awssdk.core.ResponseInputStream;
-import software.amazon.awssdk.utils.IoUtils;
-
-/**
- * Json output data type represents file name as key and file content as Json structure.
- * <p/>
- * Example Json structure: { "key": "myFile.txt", "content": "Hello", }
- */
-@DataType(scheme = "aws2-s3", name = "json")
-public class AWS2S3JsonOutputType implements DataTypeConverter {
-
- private static final String TEMPLATE = "{" +
- "\"key\": \"%s\", " +
- "\"content\": \"%s\"" +
- "}";
-
- @Override
- public void convert(Exchange exchange) {
- String key = exchange.getMessage().getHeader(AWS2S3Constants.KEY, String.class);
-
- ResponseInputStream<?> bodyInputStream = exchange.getMessage().getBody(ResponseInputStream.class);
- if (bodyInputStream != null) {
- try {
- exchange.getMessage().setBody(String.format(TEMPLATE, key, IoUtils.toUtf8String(bodyInputStream)));
- return;
- } catch (IOException e) {
- throw new CamelExecutionException("Failed to convert AWS S3 body to Json", exchange, e);
- }
- }
-
- byte[] bodyContent = exchange.getMessage().getBody(byte[].class);
- if (bodyContent != null) {
- exchange.getMessage().setBody(String.format(TEMPLATE, key, new String(bodyContent, StandardCharsets.UTF_8)));
- }
- }
-}
diff --git a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/converter/aws2-s3-json b/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/converter/aws2-s3-json
deleted file mode 100644
index 7a7c544f..00000000
--- a/library/camel-kamelets-utils/src/main/resources/META-INF/services/org/apache/camel/datatype/converter/aws2-s3-json
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# 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.aws2.s3.AWS2S3JsonOutputType
\ No newline at end of file
diff --git a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputTypeTest.java b/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3BinaryOutputTypeTest.java
similarity index 76%
rename from library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputTypeTest.java
rename to library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3BinaryOutputTypeTest.java
index 53357add..26b359f4 100644
--- a/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3JsonOutputTypeTest.java
+++ b/library/camel-kamelets-utils/src/test/java/org/apache/camel/kamelets/utils/format/converter/aws2/s3/AWS2S3BinaryOutputTypeTest.java
@@ -35,14 +35,14 @@ import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class AWS2S3JsonOutputTypeTest {
+public class AWS2S3BinaryOutputTypeTest {
private final DefaultCamelContext camelContext = new DefaultCamelContext();
- private final AWS2S3JsonOutputType outputType = new AWS2S3JsonOutputType();
+ private final AWS2S3BinaryOutputType outputType = new AWS2S3BinaryOutputType();
@Test
- void shouldMapFromStringToJsonModel() throws Exception {
+ void shouldMapFromStringToBytesModel() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);
exchange.getMessage().setHeader(AWS2S3Constants.KEY, "test1.txt");
@@ -50,13 +50,11 @@ public class AWS2S3JsonOutputTypeTest {
outputType.convert(exchange);
Assertions.assertTrue(exchange.getMessage().hasHeaders());
- assertEquals("test1.txt", exchange.getMessage().getHeader(AWS2S3Constants.KEY));
-
- assertJsonModelBody(exchange, "test1.txt", "Test1");
+ assertBinaryBody(exchange, "test1.txt", "Test1");
}
@Test
- void shouldMapFromBytesToJsonModel() throws Exception {
+ void shouldMapFromBytesToBytesModel() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);
exchange.getMessage().setHeader(AWS2S3Constants.KEY, "test2.txt");
@@ -64,13 +62,11 @@ public class AWS2S3JsonOutputTypeTest {
outputType.convert(exchange);
Assertions.assertTrue(exchange.getMessage().hasHeaders());
- assertEquals("test2.txt", exchange.getMessage().getHeader(AWS2S3Constants.KEY));
-
- assertJsonModelBody(exchange, "test2.txt", "Test2");
+ assertBinaryBody(exchange, "test2.txt", "Test2");
}
@Test
- void shouldMapFromInputStreamToJsonModel() throws Exception {
+ void shouldMapFromInputStreamToBytesModel() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);
exchange.getMessage().setHeader(AWS2S3Constants.KEY, "test3.txt");
@@ -79,20 +75,21 @@ public class AWS2S3JsonOutputTypeTest {
outputType.convert(exchange);
Assertions.assertTrue(exchange.getMessage().hasHeaders());
- assertEquals("test3.txt", exchange.getMessage().getHeader(AWS2S3Constants.KEY));
-
- assertJsonModelBody(exchange, "test3.txt", "Test3");
+ assertBinaryBody(exchange, "test3.txt", "Test3");
}
@Test
public void shouldLookupDataType() throws Exception {
DefaultDataTypeRegistry dataTypeRegistry = new DefaultDataTypeRegistry();
CamelContextAware.trySetCamelContext(dataTypeRegistry, camelContext);
- Optional<DataTypeConverter> converter = dataTypeRegistry.lookup("aws2-s3", "json");
+ Optional<DataTypeConverter> converter = dataTypeRegistry.lookup("aws2-s3", "binary");
Assertions.assertTrue(converter.isPresent());
}
- private static void assertJsonModelBody(Exchange exchange, String key, String content) {
- assertEquals(String.format("{\"key\": \"%s\", \"content\": \"%s\"}", key, content), exchange.getMessage().getBody());
+ private static void assertBinaryBody(Exchange exchange, String key, String content) {
+ assertEquals(key, exchange.getMessage().getHeader(AWS2S3Constants.KEY));
+
+ assertEquals(byte[].class, exchange.getMessage().getBody().getClass());
+ assertEquals(content, exchange.getMessage().getBody(String.class));
}
}