This discussion is archived
3 Replies Latest reply: Mar 6, 2013 8:06 AM by Joe Weinstein RSS

Weblogic & JNDI Data Source with proxy user.

993803 Newbie
Currently Being Moderated
We're trying to use Oracle proxy user authentication on a data source configured in WebLogic 10.3.6, however, we want to approach it in a programatic way. So we want to obtain the DataSource, and set the proxy related properties inside the application.

We came up with the following snippet:

Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://10.1.1.10:7003");
env.put(Context.SECURITY_PRINCIPAL, "weblogic");
env.put(Context.SECURITY_CREDENTIALS, "weblogic");

Context context = new InitialContext(env);
javax.sql.DataSource ds = (javax.sql.DataSource) context.lookup("ds_puser");
OracleConnection oconn = (OracleConnection) ds.getConnection();

The problem comes up when we try to cast the connection to OracleConnection, the thing is that the returned type is actually a 1036_WLStub.

How can we avoid that type or cast to it to something useful? I found this reference on Oracle forums and he's being able to cast it directly:

Re: My problem in using weblogic Datasource and proxy user

Can someone help us out?

Thanks a lot in advance!

Edited by: 990800 on 27-feb-2013 13:26
  • 1. Re: Weblogic & JNDI Data Source with proxy user.
    Joe Weinstein Expert
    Currently Being Moderated
    Hi. An external client to WebLogic will never get a concrete driver class. It can
    only get a proxy for the real connection that is back in the WLS engine. You
    should be able to cast the proxy to any public Interface the original connection
    implements, or any documented WebLogic.jdbc extension, but again, it can
    never be the actual object.
  • 2. Re: Weblogic & JNDI Data Source with proxy user.
    993803 Newbie
    Currently Being Moderated
    Thanks for your answer, but then, I still don't understand how on the example I provided he was able to cast the DS without any problem to OracleConnection.

    Thanks a lot in advance!
  • 3. Re: Weblogic & JNDI Data Source with proxy user.
    Joe Weinstein Expert
    Currently Being Moderated
    A DataSource is an Interface. What the code gets from the jndi tree is some concrete object that
    the code doesn't need to know the name of, or anything specific about it, as long as it implements
    the DataSource Interface, which it successfully casts to, to allow calling the methods defined in the
    DataSource Interface. If you call for a plumber, you don't need to know his name as long as you
    can get a plumber, and can call the "Fix this leak" method, defined in the Plumber Interface.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points