You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/06/09 08:47:11 UTC
[camel] 03/03: CAMEL-18044: Switch from deprecated JBossUserMarshaller to JavaSerializationMarshaller
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7fe73207fbbeb2f0674d648325523ad751196b8a
Author: James Netherton <ja...@gmail.com>
AuthorDate: Thu Jun 9 08:05:22 2022 +0100
CAMEL-18044: Switch from deprecated JBossUserMarshaller to JavaSerializationMarshaller
---
camel-dependencies/pom.xml | 2 +-
.../camel-infinispan/camel-infinispan/pom.xml | 7 +--
.../InfinispanRemoteAggregationRepository.java | 15 ++----
.../DefaultExchangeHolderInitializer.java | 27 +++++++++++
.../DefaultExchangeHolderProtoAdapter.java | 38 +++++++++++++++
.../protostream/DefaultExchangeHolderUtils.java | 54 ++++++++++++++++++++++
parent/pom.xml | 2 +-
7 files changed, 128 insertions(+), 17 deletions(-)
diff --git a/camel-dependencies/pom.xml b/camel-dependencies/pom.xml
index 9c9027c1e43..77d4bf0893b 100644
--- a/camel-dependencies/pom.xml
+++ b/camel-dependencies/pom.xml
@@ -451,7 +451,7 @@
<protobuf-maven-plugin-version>0.6.1</protobuf-maven-plugin-version>
<protobuf-version>3.19.4</protobuf-version>
<protonpack-version>1.8</protonpack-version>
- <protostream-version>4.4.1.Final</protostream-version>
+ <protostream-version>4.4.3.Final</protostream-version>
<pubnub-version>4.25.0</pubnub-version>
<pulsar-version>2.10.0</pulsar-version>
<qpid-broker-version>8.0.6</qpid-broker-version>
diff --git a/components/camel-infinispan/camel-infinispan/pom.xml b/components/camel-infinispan/camel-infinispan/pom.xml
index 3cf482b074c..01f9754d017 100644
--- a/components/camel-infinispan/camel-infinispan/pom.xml
+++ b/components/camel-infinispan/camel-infinispan/pom.xml
@@ -48,9 +48,10 @@
<version>${infinispan-version}</version>
</dependency>
<dependency>
- <groupId>org.infinispan</groupId>
- <artifactId>infinispan-jboss-marshalling</artifactId>
- <version>${infinispan-version}</version>
+ <groupId>org.infinispan.protostream</groupId>
+ <artifactId>protostream-processor</artifactId>
+ <version>${protostream-version}</version>
+ <scope>provided</scope>
</dependency>
<!-- testing - camel -->
diff --git a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteAggregationRepository.java b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteAggregationRepository.java
index 760703bb448..7642c2e31ea 100644
--- a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteAggregationRepository.java
+++ b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteAggregationRepository.java
@@ -19,13 +19,13 @@ package org.apache.camel.component.infinispan.remote;
import java.util.function.Supplier;
import org.apache.camel.component.infinispan.InfinispanAggregationRepository;
+import org.apache.camel.component.infinispan.remote.protostream.DefaultExchangeHolderContextInitializer;
import org.apache.camel.support.DefaultExchangeHolder;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.function.Suppliers;
import org.infinispan.client.hotrod.Flag;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.api.BasicCache;
-import org.infinispan.jboss.marshalling.core.JBossUserMarshaller;
public class InfinispanRemoteAggregationRepository extends InfinispanAggregationRepository {
private final Supplier<BasicCache<String, DefaultExchangeHolder>> cache;
@@ -54,25 +54,16 @@ public class InfinispanRemoteAggregationRepository extends InfinispanAggregation
InfinispanRemoteConfiguration conf = configuration != null ? configuration : new InfinispanRemoteConfiguration();
- //
- // the Aggregation repository uses org.apache.camel.support.DefaultExchangeHolder as
- // "wire format" which is based on java.io.Serializable. Starting from Infinispan 11
- // the Jboss Marshaller has been removed for internal operation and deprecated thus
- // to make DefaultExchangeHolder working, we need to explicit register JBoss Marshaller
- //
- // TODO: we should re-work DefaultExchangeHolder and make it possible to plug a custom
- // serialization strategy (i.e. json, protobuf, avro)
- //
if (conf.getCacheContainerConfiguration() == null) {
conf.setCacheContainerConfiguration(
new ConfigurationBuilder()
- .marshaller(JBossUserMarshaller.class)
+ .addContextInitializer(new DefaultExchangeHolderContextInitializer())
.build());
} else {
conf.setCacheContainerConfiguration(
new ConfigurationBuilder()
.read(conf.getCacheContainerConfiguration())
- .marshaller(JBossUserMarshaller.class)
+ .addContextInitializer(new DefaultExchangeHolderContextInitializer())
.build());
}
diff --git a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderInitializer.java b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderInitializer.java
new file mode 100644
index 00000000000..92beded0a30
--- /dev/null
+++ b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderInitializer.java
@@ -0,0 +1,27 @@
+/*
+ * 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.component.infinispan.remote.protostream;
+
+import org.infinispan.protostream.SerializationContextInitializer;
+import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
+
+@AutoProtoSchemaBuilder(
+ includeClasses = { DefaultExchangeHolderProtoAdapter.class },
+ className = "DefaultExchangeHolderContextInitializer",
+ schemaPackageName = "org.apache.camel.support")
+interface DefaultExchangeHolderInitializer extends SerializationContextInitializer {
+}
diff --git a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderProtoAdapter.java b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderProtoAdapter.java
new file mode 100644
index 00000000000..623af277553
--- /dev/null
+++ b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderProtoAdapter.java
@@ -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.component.infinispan.remote.protostream;
+
+import org.apache.camel.support.DefaultExchangeHolder;
+import org.infinispan.protostream.annotations.ProtoAdapter;
+import org.infinispan.protostream.annotations.ProtoFactory;
+import org.infinispan.protostream.annotations.ProtoField;
+
+/**
+ * Custom {@link ProtoAdapter} to serialize / deserialize {@link DefaultExchangeHolder} to / from byte[].
+ */
+@ProtoAdapter(DefaultExchangeHolder.class)
+final class DefaultExchangeHolderProtoAdapter {
+ @ProtoFactory
+ public DefaultExchangeHolder create(byte[] serializedExchangeHolderBytes) {
+ return DefaultExchangeHolderUtils.deserialize(serializedExchangeHolderBytes);
+ }
+
+ @ProtoField(number = 1, required = true)
+ public byte[] serializedExchangeHolderBytes(DefaultExchangeHolder defaultExchangeHolder) {
+ return DefaultExchangeHolderUtils.serialize(defaultExchangeHolder);
+ }
+}
diff --git a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderUtils.java b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderUtils.java
new file mode 100644
index 00000000000..b439ed62301
--- /dev/null
+++ b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/protostream/DefaultExchangeHolderUtils.java
@@ -0,0 +1,54 @@
+/*
+ * 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.component.infinispan.remote.protostream;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.camel.support.DefaultExchangeHolder;
+import org.apache.camel.util.ClassLoadingAwareObjectInputStream;
+
+/**
+ * Utilities for {@link DefaultExchangeHolder} and the Infinispan Protostream marshaller.
+ */
+final class DefaultExchangeHolderUtils {
+
+ private DefaultExchangeHolderUtils() {
+ // Utility class
+ }
+
+ static byte[] serialize(DefaultExchangeHolder holder) {
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) {
+ oos.writeObject(holder);
+ return baos.toByteArray();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static DefaultExchangeHolder deserialize(byte[] bytes) {
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ClassLoadingAwareObjectInputStream(bais)) {
+ return (DefaultExchangeHolder) ois.readObject();
+ } catch (IOException | ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/parent/pom.xml b/parent/pom.xml
index 3c79bbfd664..8263f5c0c3b 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -438,7 +438,7 @@
<protobuf-version>3.19.4</protobuf-version>
<protobuf-maven-plugin-version>0.6.1</protobuf-maven-plugin-version>
<protonpack-version>1.8</protonpack-version>
- <protostream-version>4.4.1.Final</protostream-version>
+ <protostream-version>4.4.3.Final</protostream-version>
<pubnub-version>4.25.0</pubnub-version>
<pulsar-version>2.10.0</pulsar-version>
<qpid-broker-version>8.0.6</qpid-broker-version>