0

クライアント層でオブジェクト (SERIALIZABLE オブジェクト) へのプロキシを作成し、このオブジェクトを EJB に送信します (Weblogic 10.3.4 サーバーで EJB 3.0 を使用)。EJB では、パラメータが null です。送信しているオブジェクトがクライアントで null でないこと、およびそれがシリアライズ可能であることを確認しました (System.out.println(c instanceof Serializable) は true を出力しました)。何が問題なのですか?

// 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(); 
}

クライアントでのオブジェクトの作成:

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!
4

1 に答える 1

0

Cglib は、別のクラスを拡張するときに新しいクラスを動的に作成します。このクラスはインターフェイスによってシリアル化できる場合がありますが、クライアントで作成されたときにサーバーで使用することはできません。実際のところ、cglib クラスは実行中の JVM インスタンスに固有であるため、事実上シリアライズ可能ではありません。サーバーで同じ強化を行ったとしても、クラスは異なります。したがって、サーバーはClassNotFoundExceptionを設定する代わりに をスローする必要がありますnull。コンテナーでバグを発見した可能性があります。

于 2013-12-29T01:05:47.467 に答える