Integration and Testing

Authorize.Net API questions and help with your payment integration.

Posts: 4
Registered: ‎09-06-2018

Java API - Null response when errors are thrown



I am not getting any response programmically from Authorize.NET when my XML request is invalid. It is returning a null response object. I am using JDK 1.7.0_80 and anet-java-sdk-1.9.7.jar


I copy the request I logged into a SoapUI Rest request and I find out I have XML parsing errors.


<?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="" xmlns:xsd="" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00003</code><text>The 'AnetApi/xml/v1/schema/AnetApiSchema.xsd:invoiceNumber' element is invalid - The value &amp;#39;927-WR-896228-1364474&amp;#39; is invalid according to its datatype 'String' - The actual length is greater than the MaxLength value.</text></message></messages></ErrorResponse>


Here is how I am generating the transaction:


CreateTransactionRequest request = new CreateTransactionRequest();

// the request I built

CreateTransactionController controller = new CreateTransactionController(request);

response = controller.getApiResponse();

if(response != null)
// do something
// log no response


Why am I not getting any response from Java? I should be getting at least an error response.

Posts: 4
Registered: ‎09-06-2018

Re: Java API - Null response when errors are thrown

This is also happening when even a simple invalid credentials are supplied so there is no way to capture any errors from Authorize.Net while using the API. I'm assuming it is working for others in this approach?

Authorize.Net Expert
Posts: 75
Registered: ‎07-27-2016

Re: Java API - Null response when errors are thrown

Hi @kschaller1979


The SDK returns a ErrorResponse object instead of Response object in case of error while xsd validation, thus you will need to get the ErrorResponse if Response is null.



if(controller.getApiResponse() == null) -> controller.getErrorResponse()


The code should be something like this sample.




Happy Coding !