[jboss-svn-commits] JBL Code SVN: r24821 - in labs/jbossesb/trunk/product: rosetta/tests/src/org/jboss/soa/esb/listeners/gateway and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jan 20 07:02:44 EST 2009
Author: beve
Date: 2009-01-20 07:02:44 -0500 (Tue, 20 Jan 2009)
New Revision: 24821
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java
labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_router/readme.txt
labs/jbossesb/trunk/product/samples/quickstarts/jms_router/src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2287 "DefaultJMSPropertiesSetter should filter out provider specific properties when performing the mapping"
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -24,12 +24,14 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Enumeration;
+import java.util.regex.Pattern;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.message.Properties;
import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
@@ -55,6 +57,20 @@
public class DefaultESBPropertiesSetter implements ESBPropertiesSetter
{
private Logger log = Logger.getLogger( DefaultESBPropertiesSetter.class );
+ private Pattern propertiesPattern;
+
+ /**
+ * No args constructor.
+ */
+ public DefaultESBPropertiesSetter()
+ {
+ }
+
+ public DefaultESBPropertiesSetter(final String propertiesFilter)
+ {
+ AssertArgument.isNotNull(propertiesFilter, "propertiesFilter");
+ propertiesPattern = Pattern.compile(propertiesFilter);
+ }
public void setPropertiesFromJMSMessage( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
{
@@ -118,12 +134,22 @@
{
while (properties.hasMoreElements())
{
- String key = properties.nextElement();
- Object value = fromJMSMessage.getObjectProperty(key);
+ final String key = properties.nextElement();
+
+ if (filter() && propertiesPattern.matcher(key).matches())
+ continue;
+
+ final Object value = fromJMSMessage.getObjectProperty(key);
if (null != value)
esbProperties.setProperty(key, value);
}
}
}
+
+ private boolean filter()
+ {
+ return propertiesPattern != null;
+ }
+
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -321,7 +321,7 @@
} else {
_composerName = PackageJmsMessageContents.class.getName();
_composerClass = PackageJmsMessageContents.class;
- _composer = new PackageJmsMessageContents(PackageJmsMessageContents.createPayloadProxy(_config));
+ _composer = new PackageJmsMessageContents(_config);
sProcessMethod = "process";
_logger
.debug("No <" + ListenerTagNames.ACTION_ELEMENT_TAG
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -57,6 +57,11 @@
public PackageJmsMessageContents(ConfigTree config) {
this(createPayloadProxy(config)) ;
+ String excludeProperties = config.getAttribute("excludeProperties");
+ if (excludeProperties != null)
+ {
+ esbPropertiesStrategy = new DefaultESBPropertiesSetter(excludeProperties);
+ }
}
public PackageJmsMessageContents(MessagePayloadProxy payloadProxy) {
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -34,6 +34,7 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
import org.jboss.soa.esb.testutils.SerializableMockQueue;
@@ -129,6 +130,38 @@
assertEquals( redelivered, toESBMessage.getProperties().getProperty( JMSPropertiesSetter.JMS_REDELIVERED )) ;
}
+ @Test
+ public void setPropertiesFilterAllVendorSpecificProperties() throws JMSException
+ {
+ final String filter = "[JMS_].*";
+ DefaultESBPropertiesSetter setter = new DefaultESBPropertiesSetter(filter);
+
+ final String propertyKey = "JMS_SomeVendor_Property";
+ final String propertyValue = "myPropertyValue";
+ fromJMSTextMessage.setStringProperty( propertyKey, propertyValue );
+
+ setter.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ Properties properties = toESBMessage.getProperties();
+ assertNull(properties.getProperty(propertyKey));
+ }
+
+ @Test
+ public void setPropertiesFilterIBMQVendorSpecificProperties() throws JMSException
+ {
+ final String filter = "[JMS_IBMQ].*";
+ DefaultESBPropertiesSetter setter = new DefaultESBPropertiesSetter(filter);
+
+ final String propertyKey = "JMS_IBMQ_Property";
+ final String propertyValue = "myPropertyValue";
+ fromJMSTextMessage.setStringProperty( propertyKey, propertyValue );
+
+ setter.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ Properties properties = toESBMessage.getProperties();
+ assertNull(properties.getProperty(propertyKey));
+ }
+
@Before
public void setup()
{
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -21,6 +21,7 @@
*/
package org.jboss.soa.esb.listeners.gateway;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -80,6 +81,22 @@
packer = new PackageJmsMessageContents(proxy);
objectMsg = new ObjectMessageImpl();
}
+
+ @Test
+ public void usePropertiesFilter() throws JMSException, IOException, URISyntaxException, MessageDeliverException {
+ final String propertyKey = "JMS_IBMQ_Property";
+ final ConfigTree config = new ConfigTree("config");
+ config.setAttribute("excludeProperties", "[JMS_].*");
+
+ PackageJmsMessageContents packer = new PackageJmsMessageContents(config);
+
+ objectMsg.setObject( messageContent );
+ objectMsg.setStringProperty(propertyKey, "somevalue");
+
+ Message message = packer.process( objectMsg );
+
+ assertNull(message.getProperties().getProperty(propertyKey));
+ }
@Test
public void process_ObjectMessage() throws JMSException, IOException, URISyntaxException, MessageDeliverException {
Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/jboss-esb.xml 2009-01-20 12:02:44 UTC (rev 24821)
@@ -26,10 +26,10 @@
name="SimpleListener"
description="JMS Secured quickstart sample">
<listeners>
- <jms-listener name="JMS-Gateway"
- busidref="quickstartGwChannel"
- is-gateway="true"
- />
+ <jms-listener name="JMS-Gateway" busidref="quickstartGwChannel" is-gateway="true" >
+ <!-- Comment out to exclude properties that are vendor specific. -->
+ <!--property name="excludeProperties" value="[JMS_].*"/-->
+ </jms-listener>
<jms-listener name="jmssecured"
busidref="quickstartEsbChannel"/>
</listeners>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/readme.txt 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/readme.txt 2009-01-20 12:02:44 UTC (rev 24821)
@@ -1,40 +1,56 @@
-Overview:
-=========
- The purpose of the jms_router quickstart is to show how the JMSRouter
- action can be configured.
- This quickstart also shows how a JMSCorrelationID can be used with the ESB.
-
-Running this quickstart:
-========================
- Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
- and a more detailed descripton of the different ways to run the quickstarts.
-
-To Run standalone mode:
-=======================
- 1. In a command terminal window in the quickstart folder type
- 'ant deploy-jms-dests'.
- 2. In a command terminal window in this folder ("Window1"), type 'ant run'.
- 3. Open another command terminal window in this folder ("Window2"), type
- 'ant runtest'.
- 4. Switch back to "Window1" to see the output from the ESB
- 5. When finished, interrupt the ESB using Ctrl-C and, in this folder
- ("Window1"), type 'ant undeploy-jms-dests'.
-
-To Run '.esb' archive mode:
-===========================
- 1. In a command terminal window in this folder ("Window1"), type 'ant deploy'.
- 2. Open another command terminal window in this folder ("Window2"), type
- 'ant runtest'.
- 3. Switch back to Application Server console to see the output from the ESB
- 4. In this folder ("Window1"), type 'ant undeploy'.
-
-What to look at in this Quickstart:
-===================================
- 1. src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage
- Notice how the JMS Message is set with a correlationID.
- Notice how the receive from the response destination uses the
- correlation id.
- 2. jboss-esb.xml
- Take a look at how the JMSRouter can be configured.
-
-
+Overview:
+=========
+ The purpose of the jms_router quickstart is to show how the JMSRouter
+ action can be configured.
+ This quickstart also shows how a JMSCorrelationID can be used with the ESB, and
+ how JMS properties can be excluded at the JMS gateway by setting the 'excludeProperties'.
+
+Running this quickstart:
+========================
+ Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
+ and a more detailed descripton of the different ways to run the quickstarts.
+
+To Run standalone mode:
+=======================
+ 1. In a command terminal window in the quickstart folder type
+ 'ant deploy-jms-dests'.
+ 2. In a command terminal window in this folder ("Window1"), type 'ant run'.
+ 3. Open another command terminal window in this folder ("Window2"), type
+ 'ant runtest'.
+ 4. Switch back to "Window1" to see the output from the ESB
+ 5. When finished, interrupt the ESB using Ctrl-C and, in this folder
+ ("Window1"), type 'ant undeploy-jms-dests'.
+
+To Run '.esb' archive mode:
+===========================
+ 1. In a command terminal window in this folder ("Window1"), type 'ant deploy'.
+ 2. Open another command terminal window in this folder ("Window2"), type
+ 'ant runtest'.
+ 3. Switch back to Application Server console to see the output from the ESB
+ 4. In this folder ("Window1"), type 'ant undeploy'.
+
+What to look at in this Quickstart:
+===================================
+ 1. src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage
+ Notice how the JMS Message is set with a correlationID.
+ Notice how the receive from the response destination uses the
+ correlation id.
+
+ 2. jboss-esb.xml
+ Take a look at how the JMSRouter can be configured.
+
+ 3. 'excludeProperties' property.
+ This propery can be used to filter out unwanted properties that exist in
+ the JMS message arriving at the gateway.
+
+ Usually there is no problem simply letting properties flow through but some
+ JMS Provider do not excepts JMS vendor specific properties that are not there
+ own and will throw an exception. This property was added to avoid this.
+
+ As you can see in the configuration that we specifying a regular expression to filter
+ out all properties that start with 'JMS_' but this regular expression could be
+ used to filter out other properties too.
+
+ Try uncommenting the 'excludeProperties' property in jboss-esb.xml and you will see
+ that this property is no longer passed through and will be null in "Window2"
+
Modified: labs/jbossesb/trunk/product/samples/quickstarts/jms_router/src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_router/src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage.java 2009-01-20 12:01:23 UTC (rev 24820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_router/src/org/jboss/soa/esb/samples/quickstart/jmsrouter/test/SendJMSMessage.java 2009-01-20 12:02:44 UTC (rev 24821)
@@ -50,6 +50,8 @@
private Destination replyToDestination;
private String correlationId;
+ private String vendorSpecificPropertyName = "JMS_IBMQ_Property";
+
public void setupConnection(String destination) throws JMSException, NamingException
{
InitialContext iniCtx = new InitialContext();
@@ -79,6 +81,7 @@
ObjectMessage objectMsg = session.createObjectMessage(msg);
objectMsg.setJMSCorrelationID( correlationId );
objectMsg.setJMSReplyTo( replyToDestination );
+ objectMsg.setStringProperty(vendorSpecificPropertyName, "Vendor specific property value");
producer.send(objectMsg);
System.out.println("Sent message with CorrelationID : " + correlationId );
@@ -104,6 +107,7 @@
System.out.println("\t[MessageType : TextMessage]");
System.out.println( "\t[Text : " + ((TextMessage)jmsMsg).getText() + "]" );
}
+ System.out.println("\t[Property: "+ vendorSpecificPropertyName + " : " + jmsMsg.getStringProperty(vendorSpecificPropertyName) + "]" );
consumer.close();
}
More information about the jboss-svn-commits
mailing list