zeta
Regular Visitor

Connection Failing using Java ApiClient

Hello there, I've figured it out how to test my Visa DCAS sandbox api via SOAP UI. I set up my keystore .p12 file along with its corresponding keystore password.

 

Now I'm trying to test the visa API sandbox via the provided java sample code. But I'm getting some troubles understanding some steps.

 

First here is how I set up the ApiClient variables:

 

apiClient.setUsername("************************pCbv4j-du1F20rotKa1YbKs");
apiClient.setPassword("**********ui0qCA3nOWn896");
apiClient.setKeystorePath("myProject_keyAndCertBundle.jks");
apiClient.setKeystorePassword("**********");

 

With that configuration I got this error when doing a request to the API:

 

org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://sandbox.api.visa.com/dcas/cardservices/v1/cards/4105837613490022/cardstatus": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target;

 

 

For the jks file I followed this steps from the VDC:

 

Step 1> keytool -importkeystore -srckeystore myProject_keyAndCertBundle.p12 -srcstoretype PKCS12 -destkeystore myProject_keyAndCertBundle.jks

Step 2>  keytool -list -v -keystore myProject_keyAndCertBundle.jks

Step 3> keytool -import -alias ejbca -keystore myProject_keyAndCertBundle.jks -file VDPCA-SBX.pem -storepass <password>

Step 4> keytool -import -alias digicert -keystore myProject_keyAndCertBundle.jks -file DigiCertGlobalRootCA.crt -storepass <password>

 

 

 

 

Hope I've been clear,

Thanks in advantage

8 REPLIES 8
DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @zeta,

 

I'd be happy to help you resolve the issue your experiencing. For me to do so, please provide the following information:

1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body

Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

zeta
Regular Visitor

Re: Connection Failing using Java ApiClient

Hey Diana, 

As I mentioned I don't have any problem using SoapUI.

The problem is building the ApiClient.java object in 

CardServicesApiTest

give in the Sample Code 

DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @zeta,

 

I have opened up ticket INC8784134 for the engineering team to take a look at your issue. I'll reach out to you when I have an update.




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @zeta,

 

For INC8784134, the sample code is provided and attached. However, we observed that you have experienced connectivity issues related to improper use of certs.


So, this is the format for the key generation that we personally use:

 

These commands to generate a keystore and create a csr from it to submit a csr for an app/project

 

  • keytool -genkeypair -alias client -keyalg RSA -keysize 2048 -keystore test.jks -storepass passwordHere -keypass passwordHere -dname "CN=cnHere, OU=occupationHere, O=orgHere, L=locationHere, ST=stateHere, C=countryHere"
  • keytool -certreq -alias client -keystore test.jks -storepass passwordHere -keypass passwordHere -file test.csr


These commands to bind the 3 certs from the credentials page to your keystore

 

  • keytool -import -alias DigiCertGlobalCA -keystore test.jks -file DigiCertGlobalRootCA.crt -storepass passwordHere -keypass passwordHere
  • keytool -import -alias ejbca -keystore test.jks -file VDPCA-SBX.pem -storepass passwordHere -keypass passwordHere
  • keytool -import -alias client -keystore test.jks -file cert.pem -storepass passwordHere -keypass passwordHere

 

If you have more information about credentials, keep us in the loop.

But, as far as information about the sample code, you'll need to find the CardServicesApiTest file to update your credentials and run:

 

.dps_card_and_account_services/card_services_api/src/test/java/com/visa/developer/sample/card_services_api/api/CardServicesApiTest.java

  

Updating credentials on line 87:
       // Configure HTTP basic authorization: basicAuth

        apiClient.setUsername("YOUR USERNAME");

        apiClient.setPassword("YOUR PASSWORD");

        apiClient.setKeystorePath("YOUR KEYSTORE PATH");

        apiClient.setKeystorePassword("YOUR KEYSTORE PASSWORD");

        apiClient.setPrivateKeyPassword("YOUR PRIVATEKEY PASSWORD");

 

// To set proxy uncomment the below lines

       // apiClient.setProxyHostName("proxy.address@example.com");

       // apiClient.setProxyPortNumber(0000);

 

The proxy information may not be required and should only be edited only if connection issues result from the apiClient tests.

   

Aside from that, the test is ad-libbed to work for an example card that would not effect any backend operations using “cardId_example”.
As such, the schema to all end points are not properly mapped to live data, but updating or creating new java objects in the /models folder would allow for mapping new objects.

 

If this sort of edit is required, you could force the apiClient call to return string format to see the json structure and reverse engineer the schema from there, or file an incident to example the sample code to fit a wider breadth of query results.

 

If there are any other questions, keep us in the loop! Please let us know if this resolved your issue so we can close your ticket, thanks!

 

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @zeta,

 

Can you please provide an update and let us know if you're issue is resolved? Once you confirm that it's resolved, I'll close out your case. Thanks!

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

baru18
Newbie

Re: Connection Failing using Java ApiClient

thanks a lot , this thread has solved my issue ❤️

 

baru

delta extranet

DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @baru18,

 

Great to hear that this forum post has helped to resolve your issue! We are happy to help!

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

DianaTran-Yee
Visa Developer Support Specialist

Re: Connection Failing using Java ApiClient

Hey @zeta,

 

This is our third attempt to reach out to you. Can you please confirm that your issue is resolved and that we can close your ticket? If we don't hear back from you in a couple of days, we will close your ticket. Thanks!

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.