I use the ldap server of Oracle Identity Management 10g (10.1.4.0.1) to register the connection, which you can download at otn. First we have to rename the object OracleDBConnection and its cn attribute to lowercase. Now we can register the connection with java. We have to set server_dn so java can find the oracledbconnection object. In all the Oracle examples they use searchbase but this is not going to work then you get the following error message cn=oracledbconnections,null.
Hashtable env = new Hashtable(5, 0.75f);
// env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://win2003_2:389");
env.put("server_dn", "cn=IDENT, cn=OracleContext");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=orcladmin");
env.put(Context.SECURITY_CREDENTIALS, "Welcome01");
String url = "jdbc:oracle:thin:@XPCND7010XMP:1521:orcl";
Properties properties = new Properties();
properties.setProperty("user","scott");
properties.setProperty("password","tiger");
try {
AQjmsFactory.registerConnectionFactory(env, "scott", url ,properties, "queue");
} catch ( JMSException e) {
e.printStackTrace();
}
This is how it looks in ldap.
Now we can try to lookup the scott connection and create a queueconnection so we can dequeue the scott.JMS_IN queue
Hashtable env = new Hashtable(5, 0.75f);
DirContext ctx;
QueueConnectionFactory queueConnectionFact;
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://win2003_2:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=orcladmin");
env.put(Context.SECURITY_CREDENTIALS, "Welcome01");
try {
ctx = new InitialDirContext(env);
ctx = (DirContext)ctx.lookup("cn=oracledbconnections,cn=IDENT,cn=OracleContext");
queueConnectionFact = (QueueConnectionFactory)ctx.lookup("cn=scott");
// Start QueueConnection
try {
connection = queueConnectionFact.createQueueConnection();
session = connection.createQueueSession(true, QueueSession.CLIENT_ACKNOWLEDGE);
connection.start();
queue = ((AQjmsSession)session).getQueue("scott", "JMS_IN");
sender = ((AQjmsSession)session).createSender(queue);
String xmlData = "1111";
TextMessage message = session.createTextMessage(xmlData);
sender.send(message);
session.commit();
} catch (JMSException e) {
// TODO
e.printStackTrace();
}
} catch (NamingException ee) {
// TODO
ee.printStackTrace();
}
We can also lookup the jdbc/scott datasource with JNDI and rmi. First we have to create a datasource in the oc4j container. You can do this with the em webapp or go the datasources.xml in the config folder. You need a lot of oc4j container libraries to get this working. ( oc4jclient.jar , oc4j-internal.jar, connector.jar, bcel.jar, pcl.jar, jazn.jar and adminclient.jar )
Context ctx;
try {
Properties parm = new Properties();
parm.setProperty("java.naming.factory.initial","com.evermind.server.rmi.RMIInitialContextFactory");
parm.setProperty("java.naming.provider.url","ormi://localhost:23791/");
parm.setProperty("java.naming.security.principal","oc4jadmin");
parm.setProperty("java.naming.security.credentials","welcome");
ctx = new InitialContext(parm);
DataSource ds = (DataSource)ctx.lookup("jdbc/scott");
//Bepaal dbUser:
Connection conn = ds.getConnection();
dbUser = conn.getMetaData().getUserName();
conn.close();
factory = AQjmsFactory.getQueueConnectionFactory(ds);
// Maak QueueConnection
connection = factory.createQueueConnection();
// Maak QueueSession
session = connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
// Start QueueConnection
connection.start();
// Haal Queue op
queue = ((AQjmsSession)session).getQueue(dbUser, queueTable);
// Maak QueueSender
sender = ((AQjmsSession)session).createSender(queue);
} catch (NamingException e) {
throw new RuntimeException("Fout opgetreden bij het starten ",
e);
} catch (JMSException je) {
throw new RuntimeException("Fout opgetreden bij het starten ",
je);
} catch (Throwable t) {
throw new RuntimeException("Fout opgetreden bij het starten ",
t);
}
Now you can store your connection in the ldap or Application Server.
Here is the example project. My jdeveloper home is D:\oracle\jdevstudio10133. This is voor j2ee rmi libs