cancel
Showing results for 
Search instead for 
Did you mean: 

Java API - Null response when errors are thrown

Hi,

 

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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 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
request.setTransactionRequest(transactionRequestType);

CreateTransactionController controller = new CreateTransactionController(request);
controller.execute();

response = controller.getApiResponse();

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

 

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

kschaller1979
Member
2 REPLIES 2

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?

kschaller1979
Member

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.

 

i.e 

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

 

The code should be something like this sample.

 

 

 

Happy Coding !

Kaushik

kikmak42
Authorize.Net Expert Authorize.Net Expert
Authorize.Net Expert