ConnectionUtil in Coldfusion

176 views
Skip to first unread message

Matthew Abbott

unread,
Sep 14, 2009, 4:10:41 PM9/14/09
to javaloader-dev
Everyone,

Im using the Javaloader along with Oracle's LDAP Jar file
ldapjclnt10.jar.

I first started working with straight java and trying to setup a
connection using the connectionUtil.
That went fine. When i try to do the same thing calling the java in
CF i get errors..

Here is the CF code...using the javaloader

<cfset Util = loader.create("oracle.ldap.util.Util")>
<cfset ctx = loader.create
("oracle.ldap.util.jndi.ConnectionUtil").getDefaultDirCtx
(host,port,bindDN,bindPass)>
<cfset roc = loader.create("oracle.ldap.util.RootOracleContext").init
(ctx)>
<cfset sub = roc.getSubscriber(ctx,Util.IDTYPE_DEFAULT, JavaCast
("null",""), JavaCast("null",""))>


Running this code i get the following error..
oracle.ldap.util.UtilException: Error in resolving Oracle Context:
cn=OracleContext Not an instance of DirContext

It cannot create a subscriber because the ctx is throwing the above
error.

Looking at the JavaDocs. the ConnectionUtil returns a
javax.naming.ldap.InitialLdapContext

http://java.sun.com/j2se/1.5.0/docs/api/index.html?javax/naming/ldap/InitialLdapContext.html

Maybe this is where i dont have a good grasp at java, but doesnt the
IntialLdapContext implement a DirContext?

Can I cast the <cfset ctx... > line to be a DirContext with CF?

I shouldnt have to, but i cant get the ConnectionUtil() method to work
in CF.

If you look at this url..

http://download.oracle.com/docs/cd/B28196_01/idmanage.1014/b15997/java_ext.htm#CIHEEHAH

scroll down to 5.10 Example: Search for OracleAS Single Sign-On Login
Name

As you can see, the code connection code is what im trying to
implement with CF.

Any idea on this?

Mark Mandel

unread,
Sep 14, 2009, 5:29:39 PM9/14/09
to javaloa...@googlegroups.com
What happens when you cfdump 'ctx'. Is it *actually* a javax.naming.ldap.InitialLdapContext?

What version of CF is this?

What line is the error being thrown on?

Mark
--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

Matthew Abbott

unread,
Sep 15, 2009, 9:50:57 AM9/15/09
to javaloader-dev
cfdump of ctx returns javax.naming.ldap.InitialLdapContext.
Im running this code on cf8, and cf9 beta.

the line that is bombing is the sub line.
<cfset sub = roc.getSubscriber(ctx,Util.IDTYPE_DEFAULT, JavaCast
("null",""), JavaCast("null",""))>

with the error.
Error in resolving Oracle Context: cn=OracleContext Not an instance of
DirContext

matthew
> >http://java.sun.com/j2se/1.5.0/docs/api/index.html?javax/naming/ldap/...
>
> > Maybe this is where i dont have a good grasp at java, but doesnt the
> > IntialLdapContext implement a DirContext?
>
> > Can I  cast the <cfset ctx... > line to be a DirContext with CF?
>
> > I shouldnt have to, but i cant get the ConnectionUtil() method to work
> > in CF.
>
> > If you look at this url..
>
> >http://download.oracle.com/docs/cd/B28196_01/idmanage.1014/b15997/jav...
>
> > scroll down to 5.10 Example: Search for OracleAS Single Sign-On Login
> > Name
>
> > As you can see, the code connection code is what im trying to
> > implement with CF.
>
> > Any idea on this?
>
> --
> E: mark.man...@gmail.com
> T:http://www.twitter.com/neurotic
> W:www.compoundtheory.com- Hide quoted text -
>
> - Show quoted text -

Mark Mandel

unread,
Sep 15, 2009, 5:09:23 PM9/15/09
to javaloa...@googlegroups.com
Stupid question but, have you gotten this to work in a plain ol' Java project? (no CF).

I'm wondering if there are missing dependencies or the like.

Mark

Matthew Abbott

unread,
Sep 15, 2009, 8:52:36 PM9/15/09
to javaloader-dev
Yeah if i write it in plain java it works fine.

I wrote it all in java, made sure it worked, then I compiled it into a
jar. tried loading that new jar into cf, and i still get the error.

-Matthew


On Sep 15, 5:09 pm, Mark Mandel <mark.man...@gmail.com> wrote:
> Stupid question but, have you gotten this to work in a plain ol' Java
> project? (no CF).
>
> I'm wondering if there are missing dependencies or the like.
>
> Mark
>
> > > W:www.compoundtheory.com-Hide quoted text -

Mark Mandel

unread,
Sep 15, 2009, 9:22:30 PM9/15/09
to javaloa...@googlegroups.com
Is the Oracle LDAP stuff open source?

It seems like a weird classloader issue, but it would be useful to see the line in the code that is throwing the error, and why.

Mark

Matthew Abbott

unread,
Sep 16, 2009, 9:24:23 AM9/16/09
to javaloader-dev
No Open Source. I just have the jar they provide.

On Sep 15, 9:22 pm, Mark Mandel <mark.man...@gmail.com> wrote:
> Is the Oracle LDAP stuff open source?
>
> It seems like a weird classloader issue, but it would be useful to see the
> line in the code that is throwing the error, and why.
>
> Mark
>
> > > > > W:www.compoundtheory.com-Hidequoted text -

Mark Mandel

unread,
Sep 16, 2009, 5:02:06 PM9/16/09
to javaloa...@googlegroups.com
No idea.

Time to hit the Oracle forums and ask about using the ldap library with URLClassLoaders/Custom classloaders.

Mark

Matthew Abbott

unread,
Sep 16, 2009, 5:25:13 PM9/16/09
to javaloader-dev
I took out using your JavaLoader, and put the jar files in the web-inf/
lib. Still get the errors in CF.
Now, again in Java it works fine.

I even took the java i wrote, put it in a jsp file, and ran that jsp
file on the cf server and it worked.

Yeah ill get back to the oracle forums again....

-Matthew

On Sep 16, 5:02 pm, Mark Mandel <mark.man...@gmail.com> wrote:
> No idea.
>
> Time to hit the Oracle forums and ask about using the ldap library with
> URLClassLoaders/Custom classloaders.
>
> Mark
>
> > > > > > > W:www.compoundtheory.com-Hidequotedtext -

Mark Mandel

unread,
Sep 16, 2009, 5:30:26 PM9/16/09
to javaloa...@googlegroups.com
With your plain ol' Java example, where there any dependencies that were required, other than the ldapjclnt10.jar?

Mark

Matthew Abbott

unread,
Sep 16, 2009, 5:46:10 PM9/16/09
to javaloader-dev
Nope. As far as I know and have read, everything i need is in that
ldap jar file.
I am getting tired of working with the ConnectionUtil class in CF....

Mark Mandel

unread,
Sep 17, 2009, 2:28:44 AM9/17/09
to javaloa...@googlegroups.com
Running into similar issues myself with something... you may wish to try something similar.

createObject("java", "java.lang.Thread").currentThread().setContextClassLoader(javaloader.getURLClassLoader());

(Written in email, beware typos)

This will set the current thread's context classloader to being the JavaLoader's ClassLoader.

It looks like ConnectionUtil is accessing a classLoader directly in an attempt to load up some classes.

That is, unless ConnectionUtil has a static method (or such) that allows you to overwrite which classloader is being used, which is possible.

Mark

Mark Mandel

unread,
Sep 17, 2009, 3:45:07 AM9/17/09
to javaloa...@googlegroups.com
If you are going to do this, make sure you reset it after... as leaving it in a thread pool'ed environment is no fun.

There are too many java libraries out there not built properly for a multi-layered classloader architecture.

Mark
Message has been deleted

Matthew Abbott

unread,
Apr 1, 2013, 1:01:09 PM4/1/13
to javaloa...@googlegroups.com
Hey all,

I was coming back to this post after a while and was trying the 1.1 JavaLoader.
What is happening when i switch the classLoaders it now displays a blank screen when i run the code.


javaloader = new javaloader.JavaLoader([ExpandPath('./jars/ldapjclnt11.jar')],false);

System = createObject("java", "java.lang.System");
Thread = createObject("java", "java.lang.Thread");
currentClassloader = Thread.currentThread().getContextClassLoader();

Thread.currentThread().setContextClassLoader(javaloader.getURLClassLoader());

Util = javaloader.create("oracle.ldap.util.Util");
ctx =javaloader.create("oracle.ldap.util.jndi.ConnectionUtil").getDefaultDirCtx(host,port,bindDN,pass);
roc = javaloader.create("oracle.ldap.util.RootOracleContext").init(ctx);
sub = roc.getSubscriber(ctx,Util.IDTYPE_DEFAULT, JavaCast("null",""), JavaCast("null",""));

//set it back to original classLoader
Thread.currentThread().setContextClassLoader(currentClassloader);


Now when i run this i get a blank screen, but if change false to true, i get the original error...

Error in resolving Oracle Context: cn=OracleContext Not an instance of DirContext



I saw the switchThreadContextClassLoader 
but im not sure how to use this really.  I created a function and passed it into the switchTheadContextClassLoader function but i get an error of function is of wrong type...

Just thought id share.  I did go on and not use this connectionUtil or RootOracleContext class and just using regular vanilla JNDI classes instead and everything works, but I wanted to see if i could get this to work again.
I tested this on CF10 today.
Reply all
Reply to author
Forward
0 new messages