-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from christophd/issue/fix-aws2-ddb-streams-so…
…urce-kamelet CMLK-1907: Fix AWS DDB Streams Source Kamelet
- Loading branch information
Showing
7 changed files
with
204 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...n/java/org/apache/camel/kamelets/utils/serialization/gson/JavaTimeInstantTypeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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.serialization.gson; | ||
|
||
import java.lang.reflect.Type; | ||
import java.time.Instant; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
|
||
public class JavaTimeInstantTypeAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { | ||
|
||
@Override | ||
public JsonElement serialize(final Instant time, final Type typeOfSrc, | ||
final JsonSerializationContext context) { | ||
return new JsonPrimitive(time.getEpochSecond() * 1000); | ||
} | ||
|
||
@Override | ||
public Instant deserialize(final JsonElement json, final Type typeOfT, | ||
final JsonDeserializationContext context) throws JsonParseException { | ||
return Instant.ofEpochMilli(json.getAsLong()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...org/apache/camel/kamelets/utils/transform/aws2/ddb/Ddb2JsonStructDataTypeTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.transform.aws2.ddb; | ||
|
||
import java.time.Instant; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import org.apache.camel.Message; | ||
import org.apache.camel.kamelets.utils.serialization.gson.JavaTimeInstantTypeAdapter; | ||
import org.apache.camel.spi.DataType; | ||
import org.apache.camel.spi.DataTypeTransformer; | ||
import org.apache.camel.spi.Transformer; | ||
|
||
@DataTypeTransformer(name = "aws2-ddb:application-x-struct") | ||
public class Ddb2JsonStructDataTypeTransformer extends Transformer { | ||
|
||
private final Gson gson = new GsonBuilder() | ||
.registerTypeAdapter(Instant.class, new JavaTimeInstantTypeAdapter()) | ||
.create(); | ||
|
||
@Override | ||
public void transform(Message message, DataType fromType, DataType toType) { | ||
if (message.getBody() instanceof String) { | ||
return; | ||
} | ||
|
||
message.setBody(gson.toJson(message.getBody())); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...in/resources/META-INF/services/org/apache/camel/transformer/aws2-ddb-application-x-struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class=org.apache.camel.kamelets.utils.transform.aws2.ddb.Ddb2JsonStructDataTypeTransformer |
13 changes: 13 additions & 0 deletions
13
...sources/META-INF/services/org/apache/camel/transformer/aws2-ddb-application-x-struct.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"transformer": { | ||
"kind": "transformer", | ||
"name": "aws2-ddb:application-x-struct", | ||
"title": "Aws2 Ddb (Application Json Struct)", | ||
"description": "Transforms DynamoDB record into a Json node", | ||
"deprecated": false, | ||
"javaType": "org.apache.camel.kamelets.utils.transform.aws2.ddb.Ddb2JsonStructDataTypeTransformer", | ||
"groupId": "org.apache.camel", | ||
"artifactId": "camel-aws2-ddb", | ||
"version": "4.6.0-SNAPSHOT" | ||
} | ||
} |