You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2021/12/13 15:57:50 UTC

[camel-quarkus] branch CAMEL-QUARKUS-3382 updated (b81bb76 -> 32c6810)

This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a change to branch CAMEL-QUARKUS-3382
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git.


 discard b81bb76  protobuf: Missing method "getName" when using contentTypeFormat=json in native mode #3382
     new 32c6810  protobuf: Missing method "getName" when using contentTypeFormat=json in native mode #3382

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b81bb76)
            \
             N -- N -- N   refs/heads/CAMEL-QUARKUS-3382 (32c6810)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 extensions/protobuf/runtime/src/main/doc/configuration.adoc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

[camel-quarkus] 01/01: protobuf: Missing method "getName" when using contentTypeFormat=json in native mode #3382

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch CAMEL-QUARKUS-3382
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 32c68100831178c3bedc00f6c4d740a5572a7703
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Dec 13 16:23:22 2021 +0100

    protobuf: Missing method "getName" when using contentTypeFormat=json in native mode #3382
---
 .../ROOT/pages/reference/extensions/protobuf.adoc  | 20 ++++++++++++++--
 .../runtime/src/main/doc/configuration.adoc        | 24 +++++++++++++++++--
 .../component/protobuf/it/ProtobufResource.java    | 22 +++++++++++++++++-
 .../component/protobuf/it/ProtobufRoute.java       | 14 +++++++++++
 .../component/protobuf/it/ProtobufTest.java        | 27 ++++++++++++++++++++++
 5 files changed, 102 insertions(+), 5 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc b/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
index eba2417..7bd6910 100644
--- a/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/protobuf.adoc
@@ -64,6 +64,22 @@ service and message definitions stored in the `src/main/proto` directory:
 </build>
 ----
 
-You may want to check the https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[integration test]
-in our source tree as an example.
+Moreover, please note that some additional configurations might be needed when using `contentTypeFormat=json`.
+Indeed, in such a case, the generated `Builder` class needs to be registered for reflection.
+
+For instance, let's examine the `ProtobufDataFormat` below:
+
+[source,java]
+----
+ProtobufDataFormat protobufJsonDataFormat = new ProtobufDataFormat(Person.getDefaultInstance(), ProtobufDataFormat.CONTENT_TYPE_FORMAT_JSON);
+----
+
+In such a case, the `Person.Builder` class should be xref:user-guide/native-mode.adoc#reflection[registered for reflection], for instance as below:
+
+[source,java]
+----
+@RegisterForReflection(targets = { org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person.Builder.class })
+----
+
+The https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[camel-quarkus-protobuf integration test] is a good way to learn more.
 
diff --git a/extensions/protobuf/runtime/src/main/doc/configuration.adoc b/extensions/protobuf/runtime/src/main/doc/configuration.adoc
index 068cfbe..b23eacc 100644
--- a/extensions/protobuf/runtime/src/main/doc/configuration.adoc
+++ b/extensions/protobuf/runtime/src/main/doc/configuration.adoc
@@ -1,3 +1,4 @@
+=== Generate classes from protobuf `.proto` files
 Use the `generate-code` goal of `quarkus-maven-plugin` to generate Java classes from your `*.proto`
 service and message definitions stored in the `src/main/proto` directory:
 
@@ -21,5 +22,24 @@ service and message definitions stored in the `src/main/proto` directory:
 </build>
 ----
 
-You may want to check the https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[integration test]
-in our source tree as an example.
+The https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[camel-quarkus-protobuf integration test] is a good way to learn more.
+
+=== Serialize/Deserialize Java beans using JSON fields representation
+Please note that some additional configurations might be needed when using `contentTypeFormat=json`.
+Indeed, in such a case, the generated `Builder` class needs to be registered for reflection.
+
+For instance, let's examine the `ProtobufDataFormat` below:
+
+[source,java]
+----
+ProtobufDataFormat protobufJsonDataFormat = new ProtobufDataFormat(Person.getDefaultInstance(), ProtobufDataFormat.CONTENT_TYPE_FORMAT_JSON);
+----
+
+In such a case, the `Person.Builder` class should be xref:user-guide/native-mode.adoc#reflection[registered for reflection], for instance as below:
+
+[source,java]
+----
+@RegisterForReflection(targets = { org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person.Builder.class })
+----
+
+A concrete implementation of such a scenario is present in the https://github.com/apache/camel-quarkus/tree/main/integration-tests/protobuf[camel-quarkus-protobuf integration test].
diff --git a/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
index 3cc02a5..1b7d92d 100644
--- a/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
+++ b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufResource.java
@@ -39,7 +39,7 @@ public class ProtobufResource {
     @Path("/marshal")
     @GET
     @Produces(MediaType.APPLICATION_OCTET_STREAM)
-    public byte[] xstreamXmlMarshal(@QueryParam("id") int id, @QueryParam("name") String name) {
+    public byte[] marshal(@QueryParam("id") int id, @QueryParam("name") String name) {
         final Person person = Person.newBuilder()
                 .setId(id)
                 .setName(name)
@@ -56,4 +56,24 @@ public class ProtobufResource {
         return "{\"name\": \"" + person.getName() + "\",\"id\": " + person.getId() + "}";
     }
 
+    @Path("/marshal-json")
+    @GET
+    @Produces(MediaType.APPLICATION_JSON)
+    public String marshalJson(@QueryParam("id") int id, @QueryParam("name") String name) {
+        final Person person = Person.newBuilder()
+                .setId(id)
+                .setName(name)
+                .build();
+        return producerTemplate.requestBody("direct:protobuf-marshal-json", person, String.class);
+    }
+
+    @Path("/unmarshal-json")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String unmarshalJson(String body) {
+        final Person person = producerTemplate.requestBody("direct:protobuf-unmarshal-json", body, Person.class);
+        return person.getName() + " - " + person.getId();
+    }
+
 }
diff --git a/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
index f74d60e..9722977 100644
--- a/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
+++ b/integration-tests/protobuf/src/main/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufRoute.java
@@ -16,9 +16,13 @@
  */
 package org.apache.camel.quarkus.component.protobuf.it;
 
+import io.quarkus.runtime.annotations.RegisterForReflection;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.protobuf.ProtobufDataFormat;
 import org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person;
 
+@RegisterForReflection(targets = {
+        org.apache.camel.quarkus.component.protobuf.it.model.AddressBookProtos.Person.Builder.class })
 public class ProtobufRoute extends RouteBuilder {
 
     @Override
@@ -31,5 +35,15 @@ public class ProtobufRoute extends RouteBuilder {
                 .unmarshal()
                 .protobuf(Person.class.getName());
 
+        ProtobufDataFormat protobufJsonDataFormat = new ProtobufDataFormat(Person.getDefaultInstance(),
+                ProtobufDataFormat.CONTENT_TYPE_FORMAT_JSON);
+
+        from("direct:protobuf-marshal-json")
+                .marshal(protobufJsonDataFormat)
+                .end();
+
+        from("direct:protobuf-unmarshal-json")
+                .unmarshal(protobufJsonDataFormat)
+                .end();
     }
 }
diff --git a/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java b/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
index 8a019b6..9a1f7d3 100644
--- a/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
+++ b/integration-tests/protobuf/src/test/java/org/apache/camel/quarkus/component/protobuf/it/ProtobufTest.java
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
 
 @QuarkusTest
 class ProtobufTest {
@@ -64,4 +65,30 @@ class ProtobufTest {
                 .body(equalTo(json));
 
     }
+
+    @Test
+    void marshalJson() {
+
+        RestAssured.given()
+                .queryParam("name", name)
+                .queryParam("id", id)
+                .get("/protobuf/marshal-json")
+                .then()
+                .statusCode(200)
+                .body("name", equalTo(name))
+                .body("id", equalTo(id));
+
+    }
+
+    @Test
+    void unmarshalJson() {
+
+        RestAssured.given()
+                .body(json)
+                .post("/protobuf/unmarshal-json")
+                .then()
+                .statusCode(200)
+                .body(is("Joe - 2345"));
+
+    }
 }