Thursday, 8 November 2007

Accessing a JMS queue from stand alone client in OAS 10.1.2

I am normally accessing JMS queues from OAS 10.1.3 but today I had to do it in 10.1.2 and found that unless I created a new user I was unable to get access to the queue once authenticated, his exactly what I did.

1. Log into ias console and click on your oc4j container, I used home
2. Click on administration link
3. Click on security link
4. Click add user button and created a user as follows

user: test
password: test123

Note: Check all check boxes to add all group names to ensure no permission issues will exist using this user

5. Edit $ORACLE_HOME/j2ee/home/config/jms.xml and ensure the following two entries exist

<queue name="Demo Queue" location="jms/demoQueue">
A dummy queue
</queue>

<queue-connection-factory
name="jms/QueueConnectionFactory"
location="jms/QueueConnectionFactory"/>

6. Now the code will be as follows, I am using an ormi:// connection where I obtained the container RMI port using "opmnctl status -l"


package mypackage1;
import java.util.Hashtable;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.InitialContext;

public class TestJMSConnection
{

/**
*
*
@param args
*/
public static void main(String[] args) throws Exception
{
TestJMSConnection testJMSConnection = new TestJMSConnection();
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.PROVIDER_URL,"ormi://10.187.80.135:12401");
env.put(Context.SECURITY_PRINCIPAL,"test");
env.put(Context.SECURITY_CREDENTIALS,"test123");
InitialContext ctx = new InitialContext(env);

System.out.println("Initial Context Set");

QueueConnectionFactory qcf = (QueueConnectionFactory)
ctx.lookup("jms/QueueConnectionFactory");

System.out.println("Found factory jms/QueueConnectionFactory");

Queue q = (Queue) ctx.lookup("jms/demoQueue");

System.out.println("Found queue jms/demoQueue");

System.out.println("all done..");
}
}


7. In JDeveloper 10.1.2 you need to add these two libraries so the code compiles
  • Oracle 9ias
  • J2EE
8. When run the output is as follows:

Initial Context Set
Found factory jms/QueueConnectionFactory
Found queue jms/demoQueue
all done..