From 9a0298f3e95d5b489b2589e37f0945084bcbab5a Mon Sep 17 00:00:00 2001 From: Dejan Bosanac Date: Tue, 15 Dec 2015 13:33:49 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6077 - define default values (based on system property) for connection factory and object message (cherry picked from commit eeec0c07b06e6121ed33e20f7c663214538d0da1) --- .../activemq/camel/ObjectMessageTest.java | 8 +++++-- .../activemq/camel/jms-object-message.xml | 23 +++++++++++++++++++ .../activemq/ActiveMQConnectionFactory.java | 7 ++---- .../command/ActiveMQObjectMessage.java | 3 ++- .../ClassLoadingAwareObjectInputStream.java | 2 +- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/activemq-camel/src/test/java/org/apache/activemq/camel/ObjectMessageTest.java b/activemq-camel/src/test/java/org/apache/activemq/camel/ObjectMessageTest.java index 226cfd36df..8cb5e0f3dd 100644 --- a/activemq-camel/src/test/java/org/apache/activemq/camel/ObjectMessageTest.java +++ b/activemq-camel/src/test/java/org/apache/activemq/camel/ObjectMessageTest.java @@ -58,8 +58,12 @@ public class ObjectMessageTest extends CamelSpringTestSupport { assertCorrectObjectReceived(resultTrusted); MockEndpoint resultCamel = resolveMandatoryEndpoint("mock:result-camel", MockEndpoint.class); - resultCamel.expectedMessageCount(0); - resultCamel.assertIsSatisfied(1, TimeUnit.SECONDS); + resultCamel.expectedMessageCount(1); + resultCamel.assertIsNotSatisfied(); + + MockEndpoint resultEmpty = resolveMandatoryEndpoint("mock:result-empty", MockEndpoint.class); + resultEmpty.expectedMessageCount(1); + resultEmpty.assertIsNotSatisfied(); } diff --git a/activemq-camel/src/test/resources/org/apache/activemq/camel/jms-object-message.xml b/activemq-camel/src/test/resources/org/apache/activemq/camel/jms-object-message.xml index a4534c09ea..7d7eca8510 100644 --- a/activemq-camel/src/test/resources/org/apache/activemq/camel/jms-object-message.xml +++ b/activemq-camel/src/test/resources/org/apache/activemq/camel/jms-object-message.xml @@ -31,6 +31,10 @@ + + + + @@ -75,6 +79,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index 97a4fd7dc9..cb8e80a62c 100755 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -43,10 +43,7 @@ import org.apache.activemq.thread.TaskRunnerFactory; import org.apache.activemq.transport.Transport; import org.apache.activemq.transport.TransportFactory; import org.apache.activemq.transport.TransportListener; -import org.apache.activemq.util.IdGenerator; -import org.apache.activemq.util.IntrospectionSupport; -import org.apache.activemq.util.JMSExceptionSupport; -import org.apache.activemq.util.URISupport; +import org.apache.activemq.util.*; import org.apache.activemq.util.URISupport.CompositeData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -180,7 +177,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne protected int xaAckMode = -1; // ensure default init before setting via brokerUrl introspection in sub class private boolean rmIdFromConnectionId = false; private boolean consumerExpiryCheckEnabled = true; - private List trustedPackages = new ArrayList(); + private List trustedPackages = Arrays.asList(ClassLoadingAwareObjectInputStream.serializablePackages); private boolean trustAllPackages = false; // ///////////////////////////////////////////// diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQObjectMessage.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQObjectMessage.java index 0d762de56b..5995a80913 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQObjectMessage.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQObjectMessage.java @@ -25,6 +25,7 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; @@ -69,7 +70,7 @@ public class ActiveMQObjectMessage extends ActiveMQMessage implements ObjectMess public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_OBJECT_MESSAGE; - private List trustedPackages = new ArrayList(); + private List trustedPackages = Arrays.asList(ClassLoadingAwareObjectInputStream.serializablePackages); private boolean trustAllPackages = false; protected transient Serializable object; diff --git a/activemq-client/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java b/activemq-client/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java index d8fe33ee2c..bebec875e5 100644 --- a/activemq-client/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java +++ b/activemq-client/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java @@ -109,7 +109,7 @@ public class ClassLoadingAwareObjectInputStream extends ObjectInputStream { } } if (!found) { - throw new ClassNotFoundException("Forbidden " + clazz + "! This class is not allowed to be serialized. Add package with 'org.apache.activemq.SERIALIZABLE_PACKAGES' system property."); + throw new ClassNotFoundException("Forbidden " + clazz + "! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes."); } } }