You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
In Seam, a message can be easily sent to a JMS queue by using the QueueSender and QueueSession components (see Seam Reference, chapter 19). However, I was not able to figure out how to configure them to access a security-enabled JMS queue (i. e.: a queue that requires a user and password).
The workaround below will override Seam's built-in QueueConnection so a user and password can be provided. All you need to do is create this class somewhere in your Seam app. No additional configuration is necessary (other than the ones outlined by the Seam Reference, of course)
import javax.jms.JMSException; import javax.jms.QueueConnectionFactory; import javax.naming.NamingException; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Create; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Install; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.Unwrap; import org.jboss.seam.annotations.intercept.BypassInterceptors; import org.jboss.seam.jms.ManagedQueueSender; import org.jboss.seam.util.Naming; @Scope(ScopeType.APPLICATION) @BypassInterceptors @Name("org.jboss.seam.jms.queueConnection") @Install(precedence=Install.FRAMEWORK, genericDependencies=ManagedQueueSender.class) public class AuthenticatedQueueConnection { private final String CONNECTION_FACTORY_JNDI_NAME = "UIL2ConnectionFactory"; private final String USER = "queue_user"; private final String PASSWORD = "queue_password"; private javax.jms.QueueConnection queueConnection; @Create public void init() throws NamingException, JMSException { QueueConnectionFactory connectionFactory = (QueueConnectionFactory)Naming.getInitialContext().lookup(CONNECTION_FACTORY_JNDI_NAME); queueConnection = connectionFactory.createQueueConnection(USER, PASSWORD); queueConnection.start(); } @Destroy public void destroy() throws JMSException { queueConnection.stop(); queueConnection.close(); } @Unwrap public javax.jms.QueueConnection getQueueConnection() { return queueConnection; } }
To receive messages from a secured JMS queue, add the following annotations to your MDB:
@ActivationConfigProperty(propertyName="user", propertyValue="queue_user") @ActivationConfigProperty(propertyName="password", propertyValue="queue_password")