cancel
Showing results for 
Search instead for 
Did you mean: 

ANet Java SDK - ExceptionInInitializerError coming from HttpUtility.postData()

I wrote a Java class that has methods implementing calls to the Anet Java API for processing basic credit card transactions. Works fine when calling it from a web app, and I get valid responses back from Anet. However, when trying to call it from Java running in Oracle DB then I get the following errors:

 

When trying an AUTH_ONLY_TRANSACTION or AUTH_CAPTURE_TRANSACTION:

 

The FIRST time it runs, it throws this error:

Dec 21, 2016 3:08:45 PM net.authorize.util.HttpUtility postData
SEVERE: Execution error for http post Message: 'java.lang.ExceptionInInitializerError'

 

The SECOND time and after it throws this error:

Dec 21, 2016 3:40:28 PM net.authorize.util.HttpUtility postData
SEVERE: Execution error for http post Message: 'java.lang.NoClassDefFoundError'

 

No further info is given on where the static initializer error is occurring, or on what class it can't find.

 

I'm using anet-java-sdk-1.9.2.jar, and loading it (plus all dependency jars) into Oracle, although perhaps I am missing some dependency???

 

Don't know where to go from here, as it works from my web environment, but not from Oracle.

mdmaurer
Member
3 REPLIES 3

Hi @mdmaurer,

 

I personally don't have much experience with Java in Oracle DB. I hope some other developers would see this and be able to offer some assistance.

 

I can offer general troubleshooting tips, like making sure that Oracle is seeing the classes and dependencies from the SDK in the correct location. Make sure the buildpath or classpath is correct and the sdk and all its dependencies are correctly added.

 

Make sure that the version of the SDK that you're compiling against is the same as what's installed in Oracle DB and that all of the same components are there.

 

Other general troubleshooting tips for "NoClassDefFoundError"} can be found here: http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html

Aaron
All Star

Thanks, Aaron.

 

I have made some progress on this, and am posting the info here for future reference for anyone attempting to call the Java API from Oracle.

 

First, all the required Java classes need to be loaded into the db using the "loadjava" command ($ORACLE_HOME/bin/loadjava -user -v -r <1>.jar, <2>.jar, <3>.jar, ...). They need to be loaded and "resolved", which is what the "-r" switch does. You need to get a clean load of all the jars and dependencies before proceeding. I did ignore these 3 resolution errors: (org/apache/log/format/AvalonFormatter, org/apache/commons/logging/impl/AvalonLogger, org/apache/commons/logging/impl/ServletContextCleaner). The list of jars I loaded include the AuthNet SDK (anet-java-sdk-1.9.2.jar in my case), my own custom jar containing my Java classes that call the AuthNet SDK, plus all the required dependency jars (in my case this included logkit-1.0.1.jar, commons-logging-1.1.1.jar, commons-codec-1.3.jar, log4j-1.2.16.jar, httpclient-4.0.1.jar, and httpcore-4.0.1.jar).

 

The crux of my issue was missing db permissions that needed to be granted to the Oracle db user. I discovered these by downloading a copy of the AuthNet Java SDK source code and modifying it slightly to add some extra debug statements, and so the exception handlers in question would print a full stack trace (which I was not seeing in the log file). I did this in several methods of the following classes of the net.authorize.util package: HttpUtility.java, HttpCallTask.java, HttpClient.java. Then I did a Maven build of the SDK with my changes. Each time I tried to process a transaction it would fail and produce one db permission error in the stack trace. I would grant the missing permission and try again. It was a slow process, but one by one I was eventually able to discover all the missing permissions. Once they were all granted then the transactions started processing successfully, and returning valid results!

 

Here is a list of the permissions I had to grant to the Oracle db user (user-name "SERV" in this case):

 

  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getenv.http.ConnectionTimeout', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getenv.http.ReadTimeout', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getenv.https.proxyUse', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getenv.https.proxyHost', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'getenv.https.proxyPort', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'accessDeclaredMembers', '' )'
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.RuntimePermission', 'accessClassInPackage.com.sun.xml.internal.bind.v2.model.annotation', '' )'
  • dbms_java.grant_permission( 'SERV', 'SYS:java.lang.reflect.ReflectPermission', 'suppressAccessChecks', '' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.net.SocketPermission', 'apitest.authorize.net', 'resolve' )
  • dbms_java.grant_permission( 'SERV', 'SYS:java.net.SocketPermission', '23.201.59.7:443', 'connect,resolve' )
  • dbms_java.grant_permission( 'SERV', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInputStream.SYS:com.sun.xml.internal.bind.v2.runtime.reflect.opt.FieldAccessor_Ref', 'read' )
  • dbms_java.grant_permission( 'SERV', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInputStream.SYS:com.sun.xml.internal.bind.v2.runtime.reflect.opt.FieldAccessor_Boolean', 'read' )
  • dbms_java.grant_permission( 'SERV', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInputStream.SYS:com.sun.xml.internal.bind.v2.runtime.reflect.opt.FieldAccessor_Integer', 'read' )
  • dbms_java.grant_permission( 'SERV', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInputStream.SYS:com.sun.xml.internal.bind.v2.runtime.reflect.opt.FieldAccessor_Short', 'read' )
  • dbms_java.grant_permission( 'SERV', 'SYS:oracle.aurora.rdbms.HandlePermission', 'HandleInputStream.SYS:com.sun.xml.internal.bind.v2.runtime.reflect.opt.FieldAccessor_Long', 'read' )

Mike

 

mdmaurer
Member

Thanks for updating us, Mike!

 

This is super helpful info for other developers and their future integrations, so I really appreciate you coming back and posting it here.