Pages

Friday, November 6, 2015

jdbc connection from java callout in osb without provider url

Recently  I was developing a javacallout from osb where i was needed to call a jdbc that is configured on weblogic of osb. and did not want to configure provider url for creating database connection lookup  that goes as follows.

Properties p=new Properties() p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");  p.put(Context.PROVIDER_URL,"t3://hostname:port");

problem here was that for javacallout if to be put in jar provider url cannot be hardcoded neither good way to pass as parameter in method call or putting in properties file is also not possible as osb do not allow uploading as resources (though may be possible to put in jar but that too i did not want)

So after carefully reading oracle document i found that if you are creating server side objects / application that run in the same jvm of the weblogic server, as in my case javacallout in osb, you do not need to specify the Context.PROVIDER_URL property. Usernames and passwords are required only if you want to sign in as a specific User.
To create a Context from within a server-side object, you first must create a new InitialContext, as follows:

  Context ctx = new InitialContext();

You do not need to specify a factory or a provider URL. By default, the context is created as a Context and is connected to the local naming service.

and this solved my problem !