on 04-08-2009 12:21 PM
Hi!
When I try to lookup the LogicalLockingFactory interface, I receive a ClassCastException.
For the lookup I use the following code:
LogicalLockingFactory lockingFactory = (LogicalLockingFactory) new InitialContext().lookup(
LogicalLockingFactory.JNDI_NAME);
I run on SAP Netweaver 7.1
Thanks in advance!
Gernot
Hi Gernot,
You receive this ClassCastException probably because the class loader which tries to load the class is not application classloader. I suggest change the class where you change the classloader.
So you should change the source like this
ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoa
der());
try {
//Perform the lookup here
} finally { // this step is very important!
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
It is very important to return back the original contextClassLoader when the lookup finishes.
Best regards,
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also have the same problem. But mine is a bit different as my application in EJB and i have a Java Program using the EJB .jar as lib file. Previously the EJB is compile in Netweaver 2004 and now i'm compiling the same one in Netweaver 2004s (7.0) and i'm hitting this ClassCastException in my JNDI. This is how i use the JNDI.
Gateway gateway = null;
try{
Properties env = new Properties();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl") ;
env.setProperty( javax.naming.Context.PROVIDER_URL, url);
Context ic = new InitialContext(env);
GatewayHome home = (GatewayHome)ic.lookup("GATEWAY");
gateway = home.create();
}
......
I get the ClassCastException in the lookup. It can't find. But when i changed back to the old EJB, it able to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In what kind of application are you performing the lookup? An EJB?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gernot,
I've had the same problem and opened a sap support call. I was told that there's class loader issues in the Appserver and got the suggestion to use
>
>ClassLoader oldClassLoader =
>Thread.currentThread().getContextClassLoader();
>Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
>try {
>//[lookup]
>} finally { // this step is very important!
>Thread.currentThread().setContextClassLoader(oldClassLoader);
>}
which did the trick.
NOTE: the above code is to work around an issue in 7.10 classloading in adapter applications. Do not use it in other scenarios
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.