Skip to content

Commit

Permalink
camel-jackson-protobuf data format native support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Jun 7, 2021
1 parent 1f3cc5c commit 49dac80
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Protobuf Jackson
:cq-artifact-id: camel-quarkus-jackson-protobuf
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-description: Marshal POJOs to Protobuf and back using Jackson.
:cq-deprecated: false
:cq-jvm-since: 1.8.1
:cq-native-since: n/a
:cq-native-since: 1.8.1

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.8.1## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.8.1## [.badge-key]##Native since##[.badge-supported]##1.8.1##

Marshal POJOs to Protobuf and back using Jackson.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-jackson-protobuf
:cq-artifact-id-base: jackson-protobuf
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.8.1
:cq-native-since: n/a
:cq-native-since: 1.8.1
:cq-camel-part-name: protobuf-jackson
:cq-camel-part-title: Protobuf Jackson
:cq-camel-part-description: Marshal POJOs to Protobuf and back using Jackson.
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<module>iota</module>
<module>irc</module>
<module>jackson-avro</module>
<module>jackson-protobuf</module>
<module>jasypt</module>
<module>java-joor-dsl</module>
<module>jbpm</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson-protobuf</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,14 @@
package org.apache.camel.quarkus.component.jackson.protobuf.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.jboss.logging.Logger;

class JacksonProtobufProcessor {

private static final Logger LOG = Logger.getLogger(JacksonProtobufProcessor.class);
private static final String FEATURE = "camel-jackson-protobuf";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/**
* Remove this once this extension starts supporting the native mode.
*/
@BuildStep(onlyIf = NativeBuild.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
void warnJvmInNative(JvmOnlyRecorder recorder) {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<properties>
<camel.quarkus.jvmSince>1.8.1</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.8.1</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand All @@ -53,6 +54,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson-protobuf</artifactId>
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<module>influxdb</module>
<module>ipfs</module>
<module>jackson</module>
<module>jackson-protobuf</module>
<module>jacksonxml</module>
<module>jaxb</module>
<module>jdbc</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.8.1-SNAPSHOT</version>
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-jackson-protobuf-integration-test</artifactId>
<name>Camel Quarkus :: Protobuf Jackson :: Integration Test</name>
<artifactId>camel-quarkus-integration-test-jackson-protobuf</artifactId>
<name>Camel Quarkus :: Integration Tests :: Protobuf Jackson</name>
<description>Integration tests for Camel Quarkus Protobuf Jackson extension</description>

<dependencyManagement>
Expand All @@ -45,6 +44,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson-protobuf</artifactId>
Expand All @@ -67,6 +70,19 @@
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-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-jackson-protobuf-deployment</artifactId>
Expand All @@ -81,4 +97,34 @@
</exclusions>
</dependency>
</dependencies>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.jackson.protobuf.it;

import java.io.IOException;
import java.io.InputStream;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.jackson.SchemaResolver;
import org.apache.camel.component.jackson.protobuf.JacksonProtobufDataFormat;
import org.apache.camel.util.IOHelper;

@Path("/jackson-protobuf")
@ApplicationScoped
public class JacksonProtobufResource {

@Inject
ProducerTemplate producerTemplate;

@Path("/marshal")
@POST
public Response protobufJacksonMarshal(String message) throws Exception {
Pojo pojo = new Pojo(message);
byte[] result = producerTemplate.requestBody("direct:marshal-pojo", pojo, byte[].class);
return Response.ok(result).build();
}

@Path("/unmarshal/{type}")
@POST
@Consumes("application/octet-stream")
public Response protobufJacksonUnMarshal(@PathParam("type") String type, byte[] message) throws Exception {
Response.ResponseBuilder builder = Response.ok();
String directUri = "direct:unmarshal-" + type;

if (type.equals("pojo") || type.equals("defined-dataformat")) {
Pojo result = producerTemplate.requestBody(directUri, message, Pojo.class);
builder.entity(result.getText());
} else if (type.equals("json-node")) {
JsonNode result = producerTemplate.requestBody(directUri, message, JsonNode.class);
builder.entity(result.at("/text").asText());
} else {
throw new IllegalArgumentException("Unknown unmarshal type: " + type);
}

return builder.build();
}

@Named
public SchemaResolver protobufSchemaResolver() throws IOException {
InputStream resource = JacksonProtobufResource.class.getResourceAsStream("/pojo.proto");
ProtobufSchema schema = ProtobufSchemaLoader.std.parse(IOHelper.loadText(resource));
return ex -> schema;
}

@Named
public JacksonProtobufDataFormat jacksonProtobufDataFormat() {
JacksonProtobufDataFormat dataFormat = new JacksonProtobufDataFormat();
dataFormat.setAutoDiscoverObjectMapper(true);
dataFormat.setAutoDiscoverSchemaResolver(true);
dataFormat.setUnmarshalType(Pojo.class);
return dataFormat;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.jackson.protobuf.it;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.ProtobufLibrary;

public class JacksonProtobufRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:marshal-pojo")
.marshal().protobuf(ProtobufLibrary.Jackson, Pojo.class, "protobufSchemaResolver");

from("direct:unmarshal-pojo")
.unmarshal().protobuf(ProtobufLibrary.Jackson, Pojo.class, "protobufSchemaResolver");

from("direct:unmarshal-json-node")
.unmarshal().protobuf(ProtobufLibrary.Jackson, JsonNode.class, "protobufSchemaResolver");

from("direct:unmarshal-defined-dataformat")
.unmarshal("jacksonProtobufDataFormat");
}
}

0 comments on commit 49dac80

Please sign in to comment.