Sending an object to a EJB becomes null when being created with CGLIB
I am creating a proxy to an object (A SERIALIZABLE object) in the client layer, and send this object to a EJB (Using EJB 3.0 on Weblogic 10.3.4 server). In the EJB, the parameter is null! I made sure that the object I am sending is not null in the client, and also that it is serializable (System.out.println(c instanceof Serializable) printed true). What could be the problem?
// Creating the proxy
public Object createProxy(Class targetClass)
{
Enhancer enchancer = new Enhancer();
enchancer.setSuperclass(targetClass);
enchancer.setInterfaces(new Class[] { Serializable.class })
enhancer.setCallback(new LazyInterceptor()); // LazyInterceptor implements Serializable
return enhancer.create();
}
Creating the object in the client:
SomeClass c = new SomeClass(); // SomeClass implements Serializable
getTestService.test(c); // In this call, the parameter in the EJB is **not** null
c = (SomeClass)createProxy开发者_运维技巧(c.getClass());
System.out.println(c instanceof Serializable); // This prints out true
getTestService.test(c); // In this call, the parameter in the EJB is null!
Cglib dynamically creates a new class when enhancing another class. This class might be serializable by interface but it will still not be available at the server when it was created at the client. As a matter of fact, no cglib class is ever factually serializable since they are unique to a running JVM instance. Even if you performed an identical enhancement at the server, the class will still be different. The server should therefore throw a ClassNotFoundException
instead of setting null
. You might have discovered a bug in your container.
精彩评论