Frank Nielsen
2005-01-28 07:59:26 UTC
Hi,
I have problems with Weblogic v8.1 SPn, when i try to make an
anonymous call to a remote ejb interface using reflection. I have
attached an example you can test with, just change the look method
parameter to any remote interface on your server. When i run the test
it works from commandline using weblogic.jar in classpath, but when i
use the same code within my deployed application (*.ear) i get
Exceptions. On v8.1 SP2 i get ClassCastException (shown in code) and
on SP3 i get a ClassNotFoundException exception (shown in code)..
When i use the code inside my application in weblogic i want to access
another Application (ear) remote interface without knowning its interfaces
through jar/class files in my application...
Do any of you have experience with this way of accessing ejb inside an
application in weblogic??
Cheers Frank
-----------------------------------------------------
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.EJBObject;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBHome;
import java.util.Properties;
import java.lang.reflect.Method;
public class Test {
public static Object invoke( Class c, Object obj, String mname,
Object[] parameter ) throws Exception {
Method[] methods = c.getMethods();
String name = null;
Object r = null;
for( int i = 0; i < methods.length; i++ ) {
name = methods.getName();
if( name.equals( mname ) ) {
r = methods.invoke( obj, parameter );
}
} return r;
}
public static void main( String[] args ) {
try {
Properties jndiConf = new Properties();
jndiConf.put( Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory" );
jndiConf.put( Context.PROVIDER_URL, "t3://localhost:7001" );
Context ctx = new InitialContext( jndiConf );
Object home = ctx.lookup("test.RemoteFacadeHome");
EJBHome npfHome =(EJBHome) PortableRemoteObject.narrow(home,
EJBHome.class );
EJBMetaData metaData = npfHome.getEJBMetaData(); // <-- 8.1 sp2 throws
ClassCastException
Class homeClass = metaData.getHomeInterfaceClass(); // <-- 8.1 sp3
throws ClassNotFoundException
EJBObject theRemote =
(EJBObject)Test.invoke(homeClass,npfHome,"create",null);
// use the remote
System.out.println( "Success :D" );
Class remoteClass = metaData.getRemoteInterfaceClass();
System.out.println( "Success: " + remoteClass ); // <---- On
commandline we end here :)
} catch( Exception e ) { e.printStackTrace();
}
}
}
I have problems with Weblogic v8.1 SPn, when i try to make an
anonymous call to a remote ejb interface using reflection. I have
attached an example you can test with, just change the look method
parameter to any remote interface on your server. When i run the test
it works from commandline using weblogic.jar in classpath, but when i
use the same code within my deployed application (*.ear) i get
Exceptions. On v8.1 SP2 i get ClassCastException (shown in code) and
on SP3 i get a ClassNotFoundException exception (shown in code)..
When i use the code inside my application in weblogic i want to access
another Application (ear) remote interface without knowning its interfaces
through jar/class files in my application...
Do any of you have experience with this way of accessing ejb inside an
application in weblogic??
Cheers Frank
-----------------------------------------------------
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.EJBObject;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBHome;
import java.util.Properties;
import java.lang.reflect.Method;
public class Test {
public static Object invoke( Class c, Object obj, String mname,
Object[] parameter ) throws Exception {
Method[] methods = c.getMethods();
String name = null;
Object r = null;
for( int i = 0; i < methods.length; i++ ) {
name = methods.getName();
if( name.equals( mname ) ) {
r = methods.invoke( obj, parameter );
}
} return r;
}
public static void main( String[] args ) {
try {
Properties jndiConf = new Properties();
jndiConf.put( Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory" );
jndiConf.put( Context.PROVIDER_URL, "t3://localhost:7001" );
Context ctx = new InitialContext( jndiConf );
Object home = ctx.lookup("test.RemoteFacadeHome");
EJBHome npfHome =(EJBHome) PortableRemoteObject.narrow(home,
EJBHome.class );
EJBMetaData metaData = npfHome.getEJBMetaData(); // <-- 8.1 sp2 throws
ClassCastException
Class homeClass = metaData.getHomeInterfaceClass(); // <-- 8.1 sp3
throws ClassNotFoundException
EJBObject theRemote =
(EJBObject)Test.invoke(homeClass,npfHome,"create",null);
// use the remote
System.out.println( "Success :D" );
Class remoteClass = metaData.getRemoteInterfaceClass();
System.out.println( "Success: " + remoteClass ); // <---- On
commandline we end here :)
} catch( Exception e ) { e.printStackTrace();
}
}
}