cancel
Showing results for 
Search instead for 
Did you mean: 

Transaction class not found

I'm having trouble with the Transaction class.  I have a java console app that runs a test transaction just fine but when I try to integrate the same code into my web app running under Tomcat 8 I get a class not found error.

 

I have the same libs included in web app project that I do for the console app

 

java.lang.NoClassDefFoundError: net/authorize/Transaction

 

What is interesting is the Transaction class is imported from net.authorize.aim.Transaction not net.authorize.Transaction (no aim package).

 

I've been able to narrow it down to the inclusion (not even execution) of this line in the code

 

Result<Transaction> result = (Result<Transaction>) merchant_.postTransaction(authCaptureTransaction);

 

Possibly a conflict with JSP and the http libs Tomcat uses?

 

Any ideas?

 

 

 

import java.math.*;
import java.sql.Connection;

import net.authorize.Environment;
import net.authorize.Merchant;
import net.authorize.TransactionType;
import net.authorize.aim.Result;
import net.authorize.aim.Transaction;

 

 

        Merchant merchant_ = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey);


        // create credit card
        net.authorize.data.creditcard.CreditCard creditCard = net.authorize.data.creditcard.CreditCard.createCreditCard();
        creditCard.setCreditCardNumber(ccrTrans.accountNo());
        creditCard.setExpirationMonth(String.valueOf(TimeHelper.monthOfYear(ccrTrans.expDate())));
        creditCard.setExpirationYear(String.valueOf(TimeHelper.year(ccrTrans.expDate())));

        
        // create transaction
        Transaction authCaptureTransaction = merchant_.createAIMTransaction(TransactionType.AUTH_CAPTURE, new BigDecimal(ccrTrans.amount()));
        authCaptureTransaction.setCreditCard(creditCard);

        Result<Transaction> result = (Result<Transaction>) merchant_.postTransaction(authCaptureTransaction);

        ccrTrans.procRef(result.getTarget().getTransactionId());
        ccrTrans.respMsg(result.getResponseText());
        ccrTrans.procResult(result.getResponseCode().ordinal());

zappullae59
Contributor
6 REPLIES 6

https://github.com/AuthorizeNet/sdk-java/blob/master/src/main/java/net/authorize/aim/Transaction.jav...

 

public class Transaction extends net.authorize.Transaction implements Serializable {

sound like you missing the src/main/java/net/authorize level https://github.com/AuthorizeNet/sdk-java/tree/master/src/main/java/net/authorize

RaynorC1emen7
Expert

Thanks for the help.  I built the lib from the github source.  All the unit tests work fine.  I have the identical code running with the same anet jar with a console app.  My code compiles without errors.  It just doesn't work when under Tomcat. and it fails when the class is instantiated yet it compiled.  Something is missing.

Here's another strange thing.  I took the code directly  readme.md of the source; put it into a jsp file; it compiles fine with Eclipse.  At run time I get these errors when Tomcat compiles it.  Very strange.

 

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: [16] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.Environment resolves to a package

An error occurred at line: [17] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.Merchant resolves to a package

An error occurred at line: [18] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.TransactionType resolves to a package

An error occurred at line: [19] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.aim.Result resolves to a package

An error occurred at line: [20] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.aim.Transaction resolves to a package

An error occurred at line: 17 in the jsp file: /TestAIM1.jsp
Merchant cannot be resolved to a type
14:   
15:   <%
16:     String apiLoginID = "YOUR_API_LOGIN_ID";
17:     String transactionKey = "YOUR_TRANSACTION_KEY"; Merchant merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey);
18: 
19:     // create credit card
20:     CreditCard creditCard = CreditCard.createCreditCard();

 

 

Here's the code:

 

 

  <%@ page import="java.math.BigDecimal" %>
  <%@ page import="java.util.Map" %>
 
 
  <%@ page import="net.authorize.Environment" %>
  <%@ page import="net.authorize.Merchant" %>
  <%@ page import="net.authorize.TransactionType" %>
  <%@ page import="net.authorize.aim.Result" %>
  <%@ page import="net.authorize.aim.Transaction" %>
  <%@ page import="net.authorize.data.*" %>
  <%@ page import="net.authorize.data.creditcard.*" %>
 
  <%
    String apiLoginID = "YOUR_API_LOGIN_ID";
    String transactionKey = "YOUR_TRANSACTION_KEY"; Merchant merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey);

    // create credit card
    CreditCard creditCard = CreditCard.createCreditCard();
    creditCard.setCreditCardNumber("4111 1111 1111 1111");
    creditCard.setExpirationMonth("12");
    creditCard.setExpirationYear("2015");

    // create transaction
    Transaction authCaptureTransaction = merchant.createAIMTransaction(TransactionType.AUTH_CAPTURE, new BigDecimal(1.99));
    authCaptureTransaction.setCreditCard(creditCard);

    Result<Transaction> result = (Result<Transaction>)merchant.postTransaction(authCaptureTransaction);

I've also tried adding the anet source directly into Eclipse as a project instead of using the compiled jar ang get the same results on the JSP page at run time, not compile time.

 

 

INFO: Server startup in 766 ms
Sep 27, 2015 8:39:26 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/OwHINWeb] threw exception [Unable to compile class for JSP:

An error occurred at line: [16] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.Environment resolves to a package

An error occurred at line: [17] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.Merchant resolves to a package

An error occurred at line: [18] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.TransactionType resolves to a package

An error occurred at line: [19] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.aim.Result resolves to a package

An error occurred at line: [20] in the generated java file: [C:\Dev\bsg\Eclipse Workspaces\zap\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\OwHINWeb\org\apache\jsp\TestAIM1_jsp.java]
Only a type can be imported. net.authorize.aim.Transaction resolves to a package

An error occurred at line: 17 in the jsp file: /TestAIM1.jsp
Merchant cannot be resolved to a type
14:   
15:   <%
16:     String apiLoginID = "YOUR_API_LOGIN_ID";
17:     String transactionKey = "YOUR_TRANSACTION_KEY"; Merchant merchant = Merchant.createMerchant(Environment.SANDBOX, apiLoginID, transactionKey);
18:
19:     // create credit card
20:     CreditCard creditCard = CreditCard.createCreditCard();

 

Got it working.  I really don't know why this was nessasary but I had to add all the jar files required by the ANet API to my web-inf/lib folder or to the debug config classpath for Tomcat.  Both approaches solved the problem.  Previously to using anet if I added an external jar to the project in Eclipse it was picked up by the app.  Maybe its a web app thing, I don't know but it works now.