Discussion:
EJB, Remote interface and reflection problems
(too old to reply)
Frank Nielsen
2005-01-28 07:59:26 UTC
Permalink
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();
}
}
}
Rob Woollen
2005-01-31 20:11:58 UTC
Permalink
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.

When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.

Within the server, each application is isolated so servers can host many
independent applications.

I'm curious to know about the npfHome object you get back from JNDI. If
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?

-- Rob
Post by Frank Nielsen
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();
}
}
}
Frank Nielsen
2005-02-04 10:37:49 UTC
Permalink
This post might be inappropriate. Click to display it.
Rob Woollen
2005-02-11 23:52:30 UTC
Permalink
That's what I was guessing. Essentially the referencing application has
a stub that includes methods from all the classes that it understands.

You have 3 options:

1) Put all your interfaces in the server's classpath
2) Package the npfHome classes in the application using reflection
3) Create a custom classloader which can load from the other applications

-- Rob
Post by Frank Nielsen
I have made a case at bea support and they are working on it right now...
The exception type differs depending on which SP i'm are running, on wls
java.lang.ClassCastException
at xx.xxx.getEJBMetaData(Unknown Source)
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to load
home class: java.lang.ClassNotFoundException
at
weblogic.ejb20.internal.EJBMetaDataImpl.getHomeInterfaceClass(EJBMetaDataImp
l.java:83)
java.lang.String toString( );
void remove( );
void remove( );
void undeploy( );
weblogic.rmi.internal.StubInfo getStubInfo( );
java.lang.String getIsIdenticalKey( );
boolean usesBeanManagedTx( );
javax.ejb.HomeHandle getHomeHandle( );
javax.ejb.EJBMetaData getEJBMetaData( );
javax.ejb.EJBObject allocateEJBObject( );
javax.ejb.EJBObject allocateEJBObject( );
int hashCode( );
boolean equals( );
boolean isWorkshopClient( );
java.lang.Class getClass( );
void wait( ,int );
void wait( );
void wait( );
void notify( );
void notifyAll( );
So no create method...
Cheers Frank
Post by Rob Woollen
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.
When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.
Within the server, each application is isolated so servers can host many
independent applications.
I'm curious to know about the npfHome object you get back from JNDI. If
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?
-- Rob
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
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();
}
}
}
Frank Nielsen
2005-02-14 07:53:37 UTC
Permalink
Hi Rob

Bea answer that the ClassCastException is by design, since there is no
networking class loading inside a bea application. Thereby they suggest
solution 3) of ours... Well, i don't wont to make any custom classloading
because we will properly get into other problems...

Could you detail your 2) solution?! As i understand the 2) solution is what
i am trying to do or??

Cheers Frank
Post by Rob Woollen
That's what I was guessing. Essentially the referencing application has
a stub that includes methods from all the classes that it understands.
1) Put all your interfaces in the server's classpath
2) Package the npfHome classes in the application using reflection
3) Create a custom classloader which can load from the other applications
-- Rob
Post by Frank Nielsen
I have made a case at bea support and they are working on it right now...
The exception type differs depending on which SP i'm are running, on wls
java.lang.ClassCastException
at xx.xxx.getEJBMetaData(Unknown Source)
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to load
home class: java.lang.ClassNotFoundException
at
weblogic.ejb20.internal.EJBMetaDataImpl.getHomeInterfaceClass(EJBMetaDataImp
Post by Rob Woollen
Post by Frank Nielsen
l.java:83)
java.lang.String toString( );
void remove( );
void remove( );
void undeploy( );
weblogic.rmi.internal.StubInfo getStubInfo( );
java.lang.String getIsIdenticalKey( );
boolean usesBeanManagedTx( );
javax.ejb.HomeHandle getHomeHandle( );
javax.ejb.EJBMetaData getEJBMetaData( );
javax.ejb.EJBObject allocateEJBObject( );
javax.ejb.EJBObject allocateEJBObject( );
int hashCode( );
boolean equals( );
boolean isWorkshopClient( );
java.lang.Class getClass( );
void wait( ,int );
void wait( );
void wait( );
void notify( );
void notifyAll( );
So no create method...
Cheers Frank
Post by Rob Woollen
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.
When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.
Within the server, each application is isolated so servers can host many
independent applications.
I'm curious to know about the npfHome object you get back from JNDI. If
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?
-- Rob
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
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();
}
}
}
Rob Woollen
2005-02-15 02:20:47 UTC
Permalink
I should disclose that I work at BEA, but I'm in development not
support. I think I sent a similar list to the support engineer handling
your case (or someone else with a very similar question.)

I think you already rejected my solution #2. I just meant you'd package
the required interfaces with the application using reflection.

That would be the most standard J2EE way of doing this and would
probably cause you the least problems in the long run.

Solution #1 is a pain because it means you have to restart the server to
change any of the interfaces. It seems like you want a completely
generic way to call your EJBs. If you had a base interface that they
all implemented with a set of common methods you needed to call via
reflection, then it might be reasonable to throw these interfaces in the
classpath.

Solution #3 is the most dynamic, but it's the hardest to implement and
maintain.

I'm sorry I don't know any simple solution to your problem.

-- Rob
Post by Frank Nielsen
Hi Rob
Bea answer that the ClassCastException is by design, since there is no
networking class loading inside a bea application. Thereby they suggest
solution 3) of ours... Well, i don't wont to make any custom classloading
because we will properly get into other problems...
Could you detail your 2) solution?! As i understand the 2) solution is what
i am trying to do or??
Cheers Frank
Post by Rob Woollen
That's what I was guessing. Essentially the referencing application has
a stub that includes methods from all the classes that it understands.
1) Put all your interfaces in the server's classpath
2) Package the npfHome classes in the application using reflection
3) Create a custom classloader which can load from the other applications
-- Rob
Post by Frank Nielsen
I have made a case at bea support and they are working on it right
now...
Post by Rob Woollen
Post by Frank Nielsen
The exception type differs depending on which SP i'm are running, on wls
java.lang.ClassCastException
at xx.xxx.getEJBMetaData(Unknown Source)
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to
load
Post by Rob Woollen
Post by Frank Nielsen
home class: java.lang.ClassNotFoundException
at
weblogic.ejb20.internal.EJBMetaDataImpl.getHomeInterfaceClass(EJBMetaDataImp
Post by Rob Woollen
Post by Frank Nielsen
l.java:83)
java.lang.String toString( );
void remove( );
void remove( );
void undeploy( );
weblogic.rmi.internal.StubInfo getStubInfo( );
java.lang.String getIsIdenticalKey( );
boolean usesBeanManagedTx( );
javax.ejb.HomeHandle getHomeHandle( );
javax.ejb.EJBMetaData getEJBMetaData( );
javax.ejb.EJBObject allocateEJBObject( );
javax.ejb.EJBObject allocateEJBObject( );
int hashCode( );
boolean equals( );
boolean isWorkshopClient( );
java.lang.Class getClass( );
void wait( ,int );
void wait( );
void wait( );
void notify( );
void notifyAll( );
So no create method...
Cheers Frank
Post by Rob Woollen
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.
When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.
Within the server, each application is isolated so servers can host many
independent applications.
I'm curious to know about the npfHome object you get back from JNDI. If
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?
-- Rob
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
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();
}
}
}
Frank Nielsen
2005-02-17 11:50:36 UTC
Permalink
Hi Rob

I'm with you on solution 2) that this is the normal way for j2ee. My
scenario is that application A will get in contact with external application
(b,c,d,...) as they come. So i want to configure my way to new Applications
rather than redeploy Application A with new client.jars alle the time...

I have tried to define a standard bean interface in Application A that all
other applications could implement, but again - i run into the same problem
with the exceptions. I don't have my code any more, so i can't list it
here...

So if you have an example of a Application A providing an interface to
application B, and Application A can access Application B by only using that
interface and not knowing of Application B's client.jar - i will be glad to
see it :)

Someone have talked about going through a proxy, do you have any experience
in that?

Cheers and thanks for the support, Frank
Post by Rob Woollen
I should disclose that I work at BEA, but I'm in development not
support. I think I sent a similar list to the support engineer handling
your case (or someone else with a very similar question.)
I think you already rejected my solution #2. I just meant you'd package
the required interfaces with the application using reflection.
That would be the most standard J2EE way of doing this and would
probably cause you the least problems in the long run.
Solution #1 is a pain because it means you have to restart the server to
change any of the interfaces. It seems like you want a completely
generic way to call your EJBs. If you had a base interface that they
all implemented with a set of common methods you needed to call via
reflection, then it might be reasonable to throw these interfaces in the
classpath.
Solution #3 is the most dynamic, but it's the hardest to implement and
maintain.
I'm sorry I don't know any simple solution to your problem.
-- Rob
Post by Frank Nielsen
Hi Rob
Bea answer that the ClassCastException is by design, since there is no
networking class loading inside a bea application. Thereby they suggest
solution 3) of ours... Well, i don't wont to make any custom
classloading
Post by Rob Woollen
Post by Frank Nielsen
because we will properly get into other problems...
Could you detail your 2) solution?! As i understand the 2) solution is what
i am trying to do or??
Cheers Frank
Post by Rob Woollen
That's what I was guessing. Essentially the referencing application has
a stub that includes methods from all the classes that it understands.
1) Put all your interfaces in the server's classpath
2) Package the npfHome classes in the application using reflection
3) Create a custom classloader which can load from the other
applications
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
-- Rob
Post by Frank Nielsen
I have made a case at bea support and they are working on it right
now...
Post by Rob Woollen
Post by Frank Nielsen
The exception type differs depending on which SP i'm are running, on wls
java.lang.ClassCastException
at xx.xxx.getEJBMetaData(Unknown Source)
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to
load
Post by Rob Woollen
Post by Frank Nielsen
home class: java.lang.ClassNotFoundException
at
weblogic.ejb20.internal.EJBMetaDataImpl.getHomeInterfaceClass(EJBMetaDataImp
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
l.java:83)
java.lang.String toString( );
void remove( );
void remove( );
void undeploy( );
weblogic.rmi.internal.StubInfo getStubInfo( );
java.lang.String getIsIdenticalKey( );
boolean usesBeanManagedTx( );
javax.ejb.HomeHandle getHomeHandle( );
javax.ejb.EJBMetaData getEJBMetaData( );
javax.ejb.EJBObject allocateEJBObject( );
javax.ejb.EJBObject allocateEJBObject( );
int hashCode( );
boolean equals( );
boolean isWorkshopClient( );
java.lang.Class getClass( );
void wait( ,int );
void wait( );
void wait( );
void notify( );
void notifyAll( );
So no create method...
Cheers Frank
Post by Rob Woollen
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.
When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.
Within the server, each application is isolated so servers can host many
independent applications.
I'm curious to know about the npfHome object you get back from JNDI.
If
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?
-- Rob
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
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();
}
}
}
Rob Woollen
2005-02-18 01:38:53 UTC
Permalink
I'll try to write you something quickly tomorrow. If i forget, ping me
on email. (Replace the please.noemail with bea)

-- Rob
Post by Frank Nielsen
Hi Rob
I'm with you on solution 2) that this is the normal way for j2ee. My
scenario is that application A will get in contact with external application
(b,c,d,...) as they come. So i want to configure my way to new Applications
rather than redeploy Application A with new client.jars alle the time...
I have tried to define a standard bean interface in Application A that all
other applications could implement, but again - i run into the same problem
with the exceptions. I don't have my code any more, so i can't list it
here...
So if you have an example of a Application A providing an interface to
application B, and Application A can access Application B by only using that
interface and not knowing of Application B's client.jar - i will be glad to
see it :)
Someone have talked about going through a proxy, do you have any experience
in that?
Cheers and thanks for the support, Frank
Post by Rob Woollen
I should disclose that I work at BEA, but I'm in development not
support. I think I sent a similar list to the support engineer handling
your case (or someone else with a very similar question.)
I think you already rejected my solution #2. I just meant you'd package
the required interfaces with the application using reflection.
That would be the most standard J2EE way of doing this and would
probably cause you the least problems in the long run.
Solution #1 is a pain because it means you have to restart the server to
change any of the interfaces. It seems like you want a completely
generic way to call your EJBs. If you had a base interface that they
all implemented with a set of common methods you needed to call via
reflection, then it might be reasonable to throw these interfaces in the
classpath.
Solution #3 is the most dynamic, but it's the hardest to implement and
maintain.
I'm sorry I don't know any simple solution to your problem.
-- Rob
Post by Frank Nielsen
Hi Rob
Bea answer that the ClassCastException is by design, since there is no
networking class loading inside a bea application. Thereby they suggest
solution 3) of ours... Well, i don't wont to make any custom
classloading
Post by Rob Woollen
Post by Frank Nielsen
because we will properly get into other problems...
Could you detail your 2) solution?! As i understand the 2) solution is
what
Post by Rob Woollen
Post by Frank Nielsen
i am trying to do or??
Cheers Frank
Post by Rob Woollen
That's what I was guessing. Essentially the referencing application has
a stub that includes methods from all the classes that it understands.
1) Put all your interfaces in the server's classpath
2) Package the npfHome classes in the application using reflection
3) Create a custom classloader which can load from the other
applications
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
-- Rob
Post by Frank Nielsen
I have made a case at bea support and they are working on it right
now...
Post by Rob Woollen
Post by Frank Nielsen
The exception type differs depending on which SP i'm are running, on
wls
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
java.lang.ClassCastException
at xx.xxx.getEJBMetaData(Unknown Source)
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Unable to
load
Post by Rob Woollen
Post by Frank Nielsen
home class: java.lang.ClassNotFoundException
at
weblogic.ejb20.internal.EJBMetaDataImpl.getHomeInterfaceClass(EJBMetaDataImp
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
l.java:83)
java.lang.String toString( );
void remove( );
void remove( );
void undeploy( );
weblogic.rmi.internal.StubInfo getStubInfo( );
java.lang.String getIsIdenticalKey( );
boolean usesBeanManagedTx( );
javax.ejb.HomeHandle getHomeHandle( );
javax.ejb.EJBMetaData getEJBMetaData( );
javax.ejb.EJBObject allocateEJBObject( );
javax.ejb.EJBObject allocateEJBObject( );
int hashCode( );
boolean equals( );
boolean isWorkshopClient( );
java.lang.Class getClass( );
void wait( ,int );
void wait( );
void wait( );
void notify( );
void notifyAll( );
So no create method...
Cheers Frank
Post by Rob Woollen
You shouldn't get a ClassCastException when you try to get the
EJBMetaData. It sounds like that was a bug which must have been fixed
in SP3.
When you run a standalone client, it has a network classloader that's
able to download the required classes from the server.
Within the server, each application is isolated so servers can host
many
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
independent applications.
I'm curious to know about the npfHome object you get back from JNDI.
If
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
you inspect that via reflection and look for a create method, is it
there? Do you get a ClassNotFoundException at that point as well?
-- Rob
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
another Application (ear) remote interface without knowning its
interfaces
Post by Rob Woollen
Post by Frank Nielsen
through jar/class files in my application...
Do any of you have experience with this way of accessing ejb inside
an
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
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
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
Post by Rob Woollen
Post by Frank Nielsen
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();
}
}
}
Loading...