Tuesday, June 2, 2015

Weblogic rmi connection.prepareCall throwing NullPointerException

Introduction:

In a standalone java application which creates DB connection through datasource lookup using initial context. The connection is not null but when it calls prepareCall() It throws NullPointerException.

Here is the source code which is responsible for the error.

public static boolean callProc(Connection connection)
  {
    logger.info("Calling the procedure");
    CallableStatement localCallableStatement = null;
    try
    {
      logger.warn("Calling Procedure");
      localCallableStatement = connection.prepareCall("CALL db_proc_name()");
      localCallableStatement.execute();
      logger.warn("Procedure Execution Complete");
    }


Error: 

java.lang.NullPointerException at weblogic.utils.wrapper.WrapperFactory.getCachedWrapperClass(WrapperFactory.java:49)

Below is the complete error stacktrace.

java.lang.NullPointerException
        at weblogic.utils.wrapper.WrapperFactory.getCachedWrapperClass(WrapperFactory.java:49)
        at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:212)
        at weblogic.utils.wrapper.WrapperFactory.getWrapperClass(WrapperFactory.java:200)
        at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:189)
        at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:182)
        at weblogic.jdbc.rmi.internal.CallableStatementStub.readResolve(CallableStatementStub.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1056)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1784)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
        at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120)
        at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:121)
        at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56)
        at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:164)
        at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:165)
        at weblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_oracle_jdbc_driver_T4CConnection_1030_WLStub.prepareCall(Unknown Source)
        at weblogic.jdbc.rmi.SerialConnection.prepareCall(SerialConnection.java:238)

Screenshot is as below.



Cause: 


Client JVM has different version of weblogic classes in the classpath than the weblogic server it is communicating. It may be possible that the client is trying to connect to weblogic 10.3 but the weblogic jar used in the client code is of version 8.1.

Analysis:


I followed the below steps in order to fix the problem.

1. Adding the right version of weblogic.jar further gave me below error. In my case I moved from weblogic 8.1 version to weblogic 10.3 version so I added weblogic.jar from 10.3 version.

Error: 

Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/subject/AbstractSubject

Below is the complete error stacktrace.


Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/subject/AbstractSubject
        at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at com.frp.dataAccess.M6DataSource.getConnection(Unknown Source)
        at com.frp.core.SAFileWriteController.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: weblogic.security.subject.AbstractSubject
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 7 more

Screenshot is as below.




2.  After encountering the above exception I added wlclient.jar to the classpath but that also resulted in a different error

Error:

 Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/acl/UserInfo

Below is the complete error stacktrace.

Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/acl/UserInfo
        at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at com.frp.dataAccess.M6DataSource.getConnection(Unknown Source)
        at com.frp.core.SAFileWriteController.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: weblogic.security.acl.UserInfo
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 7 more

Screenshot is as below:


after performing above two steps it did not help in fixing the issue rather resulted in different errors. So I reverted both the steps and used below as a solution for all 3 of above errors.

Solution:


I was able to resolve this issue by creating and adding wlfullclient.jar in the standalone client classpath. Also weblogic.jar and wlclient.jar is no more required in classpath as mentioned in analysis section.

It seems it is not recommended since release 10 to use weblogic.jar in the client so instead of that wlfullclient.jar is used. Using jdk1.6 it can be created with following three steps

1. Change directories to the server/lib directory.
cd WL_HOME/server/lib

2. Use the following command to create wlfullclient.jar in the server/lib directory:
java -jar wljarbuilder.jar

3. You can now copy and bundle the wlfullclient.jar with client applications and modify the classpath.


Hope above helps in fixing the above exception for your application, please leave your feedback or query.

No comments:

Post a Comment