This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 6571331 Document that AtlasMap user classes may need to be registered
for reflection fixes #2319
6571331 is described below
commit 657133140410e5f9198926c156efd5268dc6b378
Author: Zineb Bendhiba <[email protected]>
AuthorDate: Thu Mar 11 11:41:39 2021 +0100
Document that AtlasMap user classes may need to be registered for
reflection fixes #2319
---
.../ROOT/pages/reference/extensions/atlasmap.adoc | 2 +
.../runtime/src/main/doc/configuration.adoc | 2 +
integration-tests/atlasmap/pom.xml | 34 ++++++++++++++
.../component/atlasmap/it/AtlasmapResource.java | 12 -----
.../camel/quarkus/component/atlasmap/it/Route.java | 35 ++++++++++++++
.../component/atlasmap/it/model/Account.java | 50 ++++++++++++++++++++
.../mapping/json/atlasmapping-csv-to-java.json | 46 +++++-------------
.../mapping/json/atlasmapping-java-to-csv.json | 54 +++++++---------------
.../component/atlasmap/it/AtlasmapTest.java | 20 ++++----
9 files changed, 161 insertions(+), 94 deletions(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/atlasmap.adoc
b/docs/modules/ROOT/pages/reference/extensions/atlasmap.adoc
index d017239..0770da6 100644
--- a/docs/modules/ROOT/pages/reference/extensions/atlasmap.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/atlasmap.adoc
@@ -53,5 +53,7 @@ In native mode, include this file for native build. Example:
quarkus.native.resources.includes = mapping/atlas-mapping.json
----
+When mapping Java documents, you may need to register the corresponding Java
classes for reflection.
+
You may want to check the
https://github.com/apache/camel-quarkus/tree/master/integration-tests/atlasmap[integration
test] in our source tree as an example.
diff --git a/extensions/atlasmap/runtime/src/main/doc/configuration.adoc
b/extensions/atlasmap/runtime/src/main/doc/configuration.adoc
index 2764e4c..e8a9ac5 100644
--- a/extensions/atlasmap/runtime/src/main/doc/configuration.adoc
+++ b/extensions/atlasmap/runtime/src/main/doc/configuration.adoc
@@ -12,4 +12,6 @@ In native mode, include this file for native build. Example:
quarkus.native.resources.includes = mapping/atlas-mapping.json
----
+When mapping Java documents, you may need to register the corresponding Java
classes for reflection.
+
You may want to check the
https://github.com/apache/camel-quarkus/tree/master/integration-tests/atlasmap[integration
test] in our source tree as an example.
\ No newline at end of file
diff --git a/integration-tests/atlasmap/pom.xml
b/integration-tests/atlasmap/pom.xml
index f9f37db..e67bdd0 100644
--- a/integration-tests/atlasmap/pom.xml
+++ b/integration-tests/atlasmap/pom.xml
@@ -51,6 +51,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-platform-http</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jackson</artifactId>
+ </dependency>
<!-- test dependencies -->
<dependency>
@@ -78,6 +86,32 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-jackson-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-platform-http-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
<profiles>
diff --git
a/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapResource.java
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapResource.java
index 990e4cf..18109cc 100644
---
a/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapResource.java
+++
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapResource.java
@@ -121,24 +121,12 @@ public class AtlasmapResource {
}
@GET
- @Path("json/csv2java")
- public Person convertCsv2JavaWithJson(String csv) {
- return
producerTemplate.requestBody("atlasmap:mapping/json/atlasmapping-csv-to-java.json",
csv, Person.class);
- }
-
- @GET
@Path("json/csv2xml")
public String convertCsv2XmlWithJson(String csv) {
return
producerTemplate.requestBody("atlasmap:mapping/json/atlasmapping-csv-to-xml.json",
csv, String.class);
}
@GET
- @Path("json/java2csv")
- public String convertJava2CsvWithJson(Person person) {
- return
producerTemplate.requestBody("atlasmap:mapping/json/atlasmapping-java-to-csv.json",
person, String.class);
- }
-
- @GET
@Path("json/xml2csv")
public String convertXml2CsvWithJson(String xml) {
return
producerTemplate.requestBody("atlasmap:mapping/json/atlasmapping-xml-to-csv.json",
xml, String.class);
diff --git
a/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/Route.java
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/Route.java
new file mode 100644
index 0000000..d6a5dbd
--- /dev/null
+++
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/Route.java
@@ -0,0 +1,35 @@
+/*
+ * 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.quarkus.component.atlasmap.it;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.quarkus.component.atlasmap.it.model.Account;
+
+public class Route extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+
+ // example of Routes that need the class Account to be registred for
reflection
+ from("platform-http:/atlasmap/json/java2csv?httpMethodRestrict=POST")
+ .unmarshal().json(Account.class)
+ .to("atlasmap:mapping/json/atlasmapping-java-to-csv.json");
+
+ from("platform-http:/atlasmap/json/csv2java?httpMethodRestrict=POST")
+ .to("atlasmap:mapping/json/atlasmapping-csv-to-java.json")
+ .marshal().json(Account.class);
+ }
+}
diff --git
a/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/model/Account.java
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/model/Account.java
new file mode 100644
index 0000000..19cdb95
--- /dev/null
+++
b/integration-tests/atlasmap/src/main/java/org/apache/camel/quarkus/component/atlasmap/it/model/Account.java
@@ -0,0 +1,50 @@
+/*
+ * 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.quarkus.component.atlasmap.it.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@RegisterForReflection
+public class Account {
+
+ String id;
+ String userName;
+
+ public Account() {
+ }
+
+ public Account(String id, String userName) {
+ this.id = id;
+ this.userName = userName;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+}
diff --git
a/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-csv-to-java.json
b/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-csv-to-java.json
index 3335b9f..815606a 100644
---
a/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-csv-to-java.json
+++
b/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-csv-to-java.json
@@ -10,8 +10,8 @@
},
{
"jsonType": "io.atlasmap.v2.DataSource",
- "id": "Person",
- "uri":
"atlas:java?className=org.apache.camel.quarkus.component.atlasmap.it.model.Person",
+ "id": "Account",
+ "uri":
"atlas:java?className=org.apache.camel.quarkus.component.atlasmap.it.model.Account",
"dataSourceType": "TARGET"
}
],
@@ -23,8 +23,8 @@
"inputField": [
{
"jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "firstName",
- "path": "/<>/firstName",
+ "name": "id",
+ "path": "/<>/id",
"fieldType": "STRING",
"docId": "target-csv"
}
@@ -32,10 +32,10 @@
"outputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "firstName",
- "path": "/firstName",
+ "name": "id",
+ "path": "/id",
"fieldType": "STRING",
- "docId": "Person"
+ "docId": "Account"
}
]
},
@@ -45,8 +45,8 @@
"inputField": [
{
"jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "lastName",
- "path": "/<>/lastName",
+ "name": "userName",
+ "path": "/<>/userName",
"fieldType": "STRING",
"docId": "target-csv"
}
@@ -54,32 +54,10 @@
"outputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "lastName",
- "path": "/lastName",
+ "name": "userName",
+ "path": "/userName",
"fieldType": "STRING",
- "docId": "Person"
- }
- ]
- },
- {
- "jsonType": "io.atlasmap.v2.Mapping",
- "mappingType": "MAP",
- "inputField": [
- {
- "jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "age",
- "path": "/<>/age",
- "fieldType": "STRING",
- "docId": "target-csv"
- }
- ],
- "outputField": [
- {
- "jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "age",
- "path": "/age",
- "fieldType": "INTEGER",
- "docId": "Person"
+ "docId": "Account"
}
]
}
diff --git
a/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-java-to-csv.json
b/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-java-to-csv.json
index dd29ded..ba6b797 100644
---
a/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-java-to-csv.json
+++
b/integration-tests/atlasmap/src/main/resources/mapping/json/atlasmapping-java-to-csv.json
@@ -4,14 +4,14 @@
"dataSource": [
{
"jsonType": "io.atlasmap.v2.DataSource",
- "id": "org.apache.camel.quarkus.component.atlasmap.it.model.Person",
- "uri":
"atlas:java?className=org.apache.camel.quarkus.component.atlasmap.it.model.Person",
+ "id": "org.apache.camel.quarkus.component.atlasmap.it.model.Account",
+ "uri":
"atlas:java?className=org.apache.camel.quarkus.component.atlasmap.it.model.Account",
"dataSourceType": "SOURCE"
},
{
"jsonType": "io.atlasmap.csv.v2.CsvDataSource",
- "id": "Person",
- "uri": "atlas:csv:Person",
+ "id": "Account",
+ "uri": "atlas:csv:Account",
"dataSourceType": "TARGET"
}
],
@@ -23,19 +23,19 @@
"inputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "firstName",
- "path": "/firstName",
+ "name": "id",
+ "path": "/id",
"fieldType": "STRING",
- "docId":
"org.apache.camel.quarkus.component.atlasmap.it.model.Person"
+ "docId":
"org.apache.camel.quarkus.component.atlasmap.it.model.Account"
}
],
"outputField": [
{
"jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "firstName",
- "path": "/firstName",
+ "name": "id",
+ "path": "/id",
"fieldType": "STRING",
- "docId": "Person"
+ "docId": "Account"
}
]
},
@@ -45,41 +45,19 @@
"inputField": [
{
"jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "lastName",
- "path": "/lastName",
+ "name": "userName",
+ "path": "/userName",
"fieldType": "STRING",
- "docId":
"org.apache.camel.quarkus.component.atlasmap.it.model.Person"
+ "docId":
"org.apache.camel.quarkus.component.atlasmap.it.model.Account"
}
],
"outputField": [
{
"jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "lastName",
- "path": "/lastName",
+ "name": "userName",
+ "path": "/userName",
"fieldType": "STRING",
- "docId": "Person"
- }
- ]
- },
- {
- "jsonType": "io.atlasmap.v2.Mapping",
- "mappingType": "MAP",
- "inputField": [
- {
- "jsonType": "io.atlasmap.java.v2.JavaField",
- "name": "age",
- "path": "/age",
- "fieldType": "INTEGER",
- "docId":
"org.apache.camel.quarkus.component.atlasmap.it.model.Person"
- }
- ],
- "outputField": [
- {
- "jsonType": "io.atlasmap.csv.v2.CsvField",
- "name": "age",
- "path": "/age",
- "fieldType": "STRING",
- "docId": "Person"
+ "docId": "Account"
}
]
}
diff --git
a/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
b/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
index 21ddac5..1a1e115 100644
---
a/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
+++
b/integration-tests/atlasmap/src/test/java/org/apache/camel/quarkus/component/atlasmap/it/AtlasmapTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.quarkus.component.atlasmap.it;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
+import org.apache.camel.quarkus.component.atlasmap.it.model.Account;
import org.apache.camel.quarkus.component.atlasmap.it.model.Person;
import org.junit.jupiter.api.Test;
@@ -220,17 +221,16 @@ class AtlasmapTest {
@Test
void testCsv2JavaWithJson() {
- String request = "firstName,lastName,age\r\n" +
- "foo,bar,35\r\n";
+ String request = "id,userName\r\n" +
+ "1,user\r\n";
given()
.contentType(ContentType.JSON)
.body(request)
.when()
- .get("/json/csv2java")
+ .post("/json/csv2java")
.then()
- .body("firstName", equalTo("foo"))
- .body("lastName", equalTo("bar"))
- .body("age", equalTo(35));
+ .body("id", equalTo("1"))
+ .body("userName", equalTo("user"));
}
@Test
@@ -263,14 +263,14 @@ class AtlasmapTest {
@Test
void testJava2CsvWithJson() {
- String expectedResult = "firstName,lastName,age\r\n" +
- "foo,bar,35\r\n";
- Person person = new Person("foo", "bar", 35);
+ String expectedResult = "id,userName\r\n" +
+ "1,user\r\n";
+ Account person = new Account("1", "user");
given()
.contentType(ContentType.JSON)
.body(person)
.when()
- .get("/json/java2csv")
+ .post("/json/java2csv")
.then()
.body(equalTo(expectedResult));
}