[jboss-svn-commits] JBL Code SVN: r20096 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta: tests/src/org/jboss/soa/esb/actions/routing and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 21 05:20:45 EDT 2008
Author: beve
Date: 2008-05-21 05:20:45 -0400 (Wed, 21 May 2008)
New Revision: 20096
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
Log:
Work for JBESB-1627 "Support authentication on outgoing JMS (i.e. JMSRouter)"
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2008-05-21 08:53:01 UTC (rev 20095)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2008-05-21 09:20:45 UTC (rev 20096)
@@ -62,25 +62,31 @@
* Sample Action Configuration:
* <pre>
* <action class="org.jboss.soa.esb.actions.routing.JMSRouter">
- * jndiName="queue/A"
- * message-prop-<i>>prop-name<</i>="<i>>prop-value<</i>" >!-- (Optional)--<
- * unwrap="true/false" >!-- (Optional - default false)--<
- * persistent="true/false" >!-- (Optional - default true)--<
- * priority="integer" >!-- (Optional - default Message.DEFAULT_PRIORITY)--<
- * time-to-live="long" >!-- (Optional - default Message.DEFAULT_TIME_TO_LIVE)--<
- * />
+ * <property name="jndiName" value="queue/A"/>
+ * </action>
+ *
+ * Optional attributes:
+ * <property name="unwrap" value="false"/>
+ * <property name="message-prop-<i>>prop-name<</i>="<i>> value="prop-value<</i>" />
+ * <property name="persistent" value="true"/>
+ * <property name="priority" value="javax.jms.Message.DEFAULT_PRIORITY"/>
+ * <property name="time-to-live" value="javax.jms.Message.DEFAULT_TIME_TO_LIVE"/>
+ * <property name="security-principal" value="username"/>
+ * <property name="security-credential" value="pasword"/>
* </pre>
- * Note how properties to be set on the message are prefixed with "message-prop-".
- * <p/>
+ * Description of configuration attribues:
* <ul>
- * <li>'unwrap' true will extract the message payload from the Message object before sending</li>
- * <li>'unwrap' false false will send the serialized Message object</li>
+ * <li><i>message-prop</i>: properties to be set on the message are prefixed with "message-prop-".
+ * <li><i>unwrap</i>:true will extract the message payload from the Message object before sending. false false will send the serialized Message object.
+ * <li><i>persistent</i>: the JMS DeliveryMode. 'true'(default) or 'false'.
+ * <li><i>priority</i>: the JMS Priority to be used.
+ * <li><i>time-to-live</i>: the JMS Time-To-Live to be used.
+ * <li><i>security-principal</i>: security principal use when creating the JMS connection.
+ * <li><i>security-credential</i>: the security credentials to use when creating the JMS connection.
* </ul>
*
- * TODO: Add support for JMS Topic destinations.
- *
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
- * @author <a href="mailto:daniel.bevenius at redpill.se">daniel.bevenius at redpill.se</a>
+ * @author <a href="mailto:daniel.bevenius at redhat.com">daniel.bevenius at redhat.com</a>
* @since Version 4.0
*/
public class JMSRouter extends AbstractRouter {
@@ -101,6 +107,14 @@
*/
public static final String TIME_TO_LIVE_ATTR = "time-to-live";
/**
+ * Security principal used when creating the JMS connection
+ */
+ public static final String SECURITY_PRINCIPAL = "security-principal";
+ /**
+ * Security credential used when creating the JMS connection
+ */
+ public static final String SECURITY_CREDITIAL = "security-credential";
+ /**
* Routing properties.
*/
private ConfigTree properties;
@@ -160,7 +174,14 @@
if ( ttlStr != null )
timeToLive = Long.parseLong( ttlStr );
- createQueueSetup( queueName );
+ final String securityPrincipal = properties.getAttribute(SECURITY_PRINCIPAL);
+ final String securityCredential = properties.getAttribute(SECURITY_CREDITIAL);
+ if ( securityPrincipal != null && securityCredential == null )
+ throw new ConfigurationException("'" + SECURITY_PRINCIPAL + "' must be accompanied by a '" + SECURITY_CREDITIAL + "'");
+ else if ( securityCredential != null && securityPrincipal == null )
+ throw new ConfigurationException("'" + SECURITY_CREDITIAL + "' must be accompanied by a '" + SECURITY_PRINCIPAL + "'");
+
+ createQueueSetup(queueName, securityPrincipal, securityCredential);
}
/**
@@ -302,10 +323,11 @@
super.finalize();
}
- protected void createQueueSetup( String queueName ) throws ConfigurationException
- {
- try {
- queueSetup = new JMSSendQueueSetup(queueName);
+ void createQueueSetup( final String queueName, final String principal, final String credential ) throws ConfigurationException
+ {
+ try
+ {
+ queueSetup = new JMSSendQueueSetup(queueName,principal,credential);
queueSetup.setDeliveryMode( deliveryMode );
queueSetup.setPriority( priority );
queueSetup.setTimeToLive( timeToLive );
@@ -315,9 +337,16 @@
logger.debug( "JMSRouter Priority : " + priority);
logger.debug( "JMSRouter TimeToLive : " + timeToLive);
}
- } catch (Throwable t) {
+ }
+ catch (Throwable t)
+ {
throw new ConfigurationException("Failed to configure JMS Queue for routing.", t);
}
+ }
+
+ protected void createQueueSetup( String queueName ) throws ConfigurationException
+ {
+ createQueueSetup(queueName, null, null );
}
private static class JMSSendQueueSetup {
@@ -330,14 +359,16 @@
// TODO: Modify to support topic destinations too
- private JMSSendQueueSetup(String queueName) throws NamingException, JMSException, ConnectionException, NamingContextException {
+ private JMSSendQueueSetup(final String queueName, final String principal, final String credential) throws NamingException, JMSException, ConnectionException, NamingContextException {
environment = new Properties();
environment.setProperty(Context.PROVIDER_URL, Configuration.getJndiServerURL());
environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, Configuration.getJndiServerContextFactory());
environment.setProperty(Context.URL_PKG_PREFIXES, Configuration.getJndiServerPkgPrefix());
Context oCtx = NamingContextPool.getNamingContext(environment);
try {
- pool = JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory");
+ pool = ( principal != null ) ?
+ JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory", principal, credential) :
+ JmsConnectionPoolContainer.getPool(environment, "ConnectionFactory" );
this.queueName = queueName;
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2008-05-21 08:53:01 UTC (rev 20095)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2008-05-21 09:20:45 UTC (rev 20096)
@@ -26,12 +26,10 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.List;
import javax.jms.Destination;
import javax.jms.JMSException;
@@ -46,12 +44,9 @@
import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.junit.Before;
import org.junit.Ignore;
@@ -60,9 +55,10 @@
import org.mockejb.jms.TextMessageImpl;
/**
- *
+ * Integration test for {@link JMSRouter}
+ * <p/>
* @author John Doe
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="daniel.bevenius at redhat.com">Daniel Bevenius</a>
*
*/
public class JmsRouterIntegrationTest
@@ -75,15 +71,8 @@
private Message msg;
private ConfigTree tree;
- @Before
- public void setup() throws URISyntaxException
- {
- msg = createESBMessageObject( messageID, bodyContent );
- tree = createConfigTree();
- }
-
@Test
- public void process_unwrap_false() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ public void processWithUnwrapFalse() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
{
MockJMSRouter router = new MockJMSRouter(tree);
router.route( msg );
@@ -92,7 +81,7 @@
}
@Test
- public void process_unwrap_true() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ public void processWithUnwrapTrue() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
{
tree.setAttribute( "unwrap", "true" );
MockJMSRouter router = new MockJMSRouter( tree );
@@ -108,9 +97,37 @@
assertEquals ( textMessage.getJMSCorrelationID(), messageID );
assertEquals ( textMessage.getText(), bodyContent );
}
+
+ @Test
+ public void constructorWithSecurity() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ final String principal = "guest";
+ final String credential = "guest";
+ tree.setAttribute( "unwrap", "true" );
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, principal );
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, credential );
+ MockJMSRouter router = new MockJMSRouter( tree );
+
+ assertEquals ( principal, router.getSecurityPrincipal() );
+ assertEquals ( credential, router.getSecurityCredential() );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfPrincipalIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_CREDITIAL, "testpassword" );
+ new MockJMSRouter( tree );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfCredentialIsNull() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( JMSRouter.SECURITY_PRINCIPAL, "testuser" );
+ new MockJMSRouter( tree );
+ }
@Test ( expected = ActionProcessingException.class )
- public void route_negative() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
+ public void shouldThrowIfObjectIsNotAMessageObject() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
{
ConfigTree tree = createConfigTree();
JMSRouter router = new MockJMSRouter(tree);
@@ -118,7 +135,7 @@
}
@Test
- public void setJMSReplyTo_queue() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
+ public void setJMSReplyToQueue() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
{
final String queueName = "testQueue";
@@ -133,12 +150,11 @@
assertTrue( replyTo instanceof Queue );
Queue replyToQueue = (Queue) replyTo;
assertEquals( queueName , replyToQueue.getQueueName() );
-
}
@Test
@Ignore
- public void setJMSReplyTo_topic() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
+ public void setJMSReplyToTopic() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
{
final String queueName = "testTopic";
@@ -155,61 +171,16 @@
assertEquals( queueName , replyToTopic.getTopicName() );
}
- /*
- * Not quite sure that this is supposed to be testing.
- * Can we remove this test? /Daniel
- */
@Test
- @Ignore
- public void testRouter () throws Exception
+ public void constructWithDefaultPersitentAttribute() throws ConfigurationException, NamingException, JMSException
{
- boolean exception = false;
-
- Message msg = MessageFactory.getInstance().getMessage();
-
- msg.getBody().add("hello world".getBytes());
- JMSRouter router = new JMSRouter( createConfigTree() );
- try
- {
- router.route(msg);
- }
- catch (ActionProcessingException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- router.unwrap = true;
-
- try
- {
- msg.getBody().add("hello world");
- router.process(msg);
- }
- catch (ActionProcessingException ex)
- {
- exception = true;
- }
-
- if (!exception)
- fail();
-
- router.getErrorNotification(null);
- router.getOkNotification(null);
- }
-
- @Test
- public void construct_with_default_persitent_attribute() throws ConfigurationException, NamingException, JMSException
- {
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
assertTrue( router.isDeliveryModePersistent() );
}
@Test
- public void construct_with_persitent_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithPersitentAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
config.setAttribute( JMSRouter.PERSISTENT_ATTR, "false" );
@@ -219,7 +190,7 @@
}
@Test
- public void construct_with_default_priority_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithDefaultPriorityAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
@@ -227,7 +198,7 @@
}
@Test
- public void construct_with_priority_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithPriorityAttribute() throws ConfigurationException, NamingException, JMSException
{
final int expectedPriority = 9;
ConfigTree config = createConfigTree();
@@ -238,7 +209,7 @@
}
@Test
- public void construct_with_default_time_to_live_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithDefaultTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
{
ConfigTree config = createConfigTree();
JMSRouter router = new JMSRouter( config );
@@ -246,7 +217,7 @@
}
@Test
- public void construct_with_time_to_live_attribute() throws ConfigurationException, NamingException, JMSException
+ public void constructWithTimeToLiveAttribute() throws ConfigurationException, NamingException, JMSException
{
final long ttl = 6000l;
ConfigTree config = createConfigTree();
@@ -256,6 +227,15 @@
assertEquals ( ttl, router.getTimeToLive() );
}
+ @Before
+ public void setup() throws URISyntaxException
+ {
+ msg = createESBMessageObject( messageID, bodyContent );
+ tree = createConfigTree();
+ }
+
+ // private
+
private void assertProcessContract( final String messageID, final Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
{
final Message message = router.process ( msg );
@@ -264,12 +244,30 @@
assertEquals ( jmsMessage.getJMSCorrelationID(), messageID );
}
+ private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
+ msg.getBody().add(body.getBytes());
+ return msg;
+ }
+
+ private static ConfigTree createConfigTree()
+ {
+ ConfigTree tree = new ConfigTree("test");
+ tree.setAttribute("jndiName", "/queue/A");
+ return tree;
+ }
+
private static class MockJMSRouter extends JMSRouter
{
@SuppressWarnings ( "unused" )
private Logger log = Logger.getLogger( MockJMSRouter.class );
private javax.jms.Message jmsMessage;
+
+ private String securityPrincipal;
+ private String securityCredential;
public MockJMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException
{
@@ -278,6 +276,12 @@
@Override
protected void createQueueSetup( String queueName ) throws ConfigurationException { }
+
+ void createQueueSetup( final String queueName, final String principal, final String credential )
+ {
+ this.securityPrincipal = principal;
+ this.securityCredential = credential;
+ }
@Override
protected void send( javax.jms.Message jmsMessage ) throws JMSException
@@ -305,23 +309,16 @@
impl.setObject( (Serializable) message );
return impl;
}
+
+ public String getSecurityPrincipal() {
+ return securityPrincipal;
+ }
+
+ public String getSecurityCredential() {
+ return securityCredential;
+ }
}
- private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
- {
- Message msg = MessageFactory.getInstance().getMessage();
- msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
- msg.getBody().add(body.getBytes());
- return msg;
- }
-
- private static ConfigTree createConfigTree()
- {
- ConfigTree tree = new ConfigTree("test");
- tree.setAttribute("jndiName", "/queue/A");
- return tree;
- }
-
/*
* Just here to help Ant to find annotated test.
*/
More information about the jboss-svn-commits
mailing list