API Request and Testing the Connection

DamDev
New Contributor

API Request and Testing the Connection

Salut la communauté, en fait je suis nouveau dans l'utilisation de la plateforme api, j'ai créé un projet avec l'api visa direct et l'authentification se fait avec SSL bidirectionnel. J'ai réussi le Test de la connectivité SSL bidirectionnelle à l'aide de Postman, mais le problème vient de mon code Java.

Ci-dessous mon code et l'exception levée après l'exécution

Toute aide me sera bénéfique

chaîne statique privée USER_ID = "Mon identifiant utilisateur" ; // Définir l'ID utilisateur pour l'application à partir du portail VDP
private static String PASSWORD = "my password" ; // Définir le mot de passe pour l'application depuis le portail VDP

// Paramètres du magasin de clés chaîne
statique privée KEY_STORE_PATH = "C:\\Users\\Admin\\Desktop\\VISA guise\\PROJET GEBTEST\\PRIVATE KEY\\KEYSTORE_PATH\\keystore.jks" ;
Chaîne statique privée KEY_STORE_PASSWORD = "1234_v" ;
Chaîne statique privée PRIVATE_KEY_PASSWORD = "123456789_Visa" ; // Le mot de passe pour déchiffrer la clé privée du client

//////////////////////*********************************************************

public static void main(String args[]) throws Exception {
String baseUri = "visadirect/";
Chaîne resourcePath = "fundstransfer/v1/pushfundstransactions/" ;
URL de chaîne = " https://sandbox.api.visa.com/ " + baseUri + resourcePath ;

// Charger le certificat client dans le magasin de clés
SSLContext sslcontext = SSLContexts.custom()
.loadKeyMaterial(new File(KEY_STORE_PATH), KEY_STORE_PASSWORD.toCharArray(),
PRIVATE_KEY_PASSWORD.toCharArray())
.build();

// Autoriser uniquement le protocole TLSv1
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());

// Créer l'objet de requête POST
try (CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslSocketFactory)
.build()) {
// Créer l'objet de requête POST
HttpPost httpPost = new HttpPost(url);

httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
httpPost.setHeader(HttpHeaders.ACCEPT, "application/json");
httpPost.setHeader(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eIZq6hvqx8GoOqsFCeW3ZgBoDdD9NsK6DV2YkpFXKhPtZ18EdC+6cC2XGTgfMq0Ls4ftC1CEYhW6Z9l3cUdWDRfwYLXsDzsmD9Am8piIU9xxLuq7DdV+dpgF9d4sQa3tMyryVMnOttopz0dLRz5OJXbbOdCPidV6DNbQh0kSuqKMYBGGiMF8sH9crXHh60/2Ten682bp7hUG+4u2MMRnBBbNOa1WBknukzs81e4XylIL8U7jl4JVQV4OqAVSzRMGt1L0e/QF9bw4bjcbm8aNy5Ghlv0/QVhxuzkh/pC2y/vmRh8blVA=");

// Charger le corps de la requête de publication
String body = "{\"systemsTraceAuditNumber\":350420,"
+ "\"retrievalReferenceNumber\":\"401010350420\","
+ "\"localTransactionDateTime\":\"2022- 08-11T14:52:00\","
+ "\"acquiringBin\":409999,"
+ "\"acquirerCountryCode\":\"101\","
+ "\"senderAccountNumber\":\"1234567890123456\" ,"
+ "\"senderCountryCode\":\"USA\","
+ "\"transactionCurrencyCode\":\"USD\","
+ "\"senderName\":\"John Smith\","
+ " \"senderAddress\":\"44 Market St.\","
+ "\"senderCity\":\"San Francisco\","
+ "\"senderStateCode\":\"CA\","
+ "\"recipientName\":\"Adam Smith\","
+ "\ "recipientPrimaryAccountNumber\":\"4957030420210454\","
feeProgramIndicator\":\"123\"}" ; StringEntity postBodyEntity = new StringEntity(body); httpPost.setEntity(postBodyEntity); // Effectue l'appel System.out.println("Executing request " + httpPost.getRequestLine()); // Récupère les en-têtes de réponse

try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
// Récupère les en-têtes de réponse
Header[] h = response.getAllHeaders();

// Récupère l'objet json de réponse
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
résultat StringBuffer = new StringBuffer();
Ligne de cordes ;
while ((line = rd.readLine()) != null) {
result.append(line);
}

// Affiche les détails de la réponse
System.out.println("----------------------------------------- ----");
Entité HttpEntity = réponse.getEntity();
System.out.println(response.getStatusLine());

System.out.println("En-têtes de réponse :");
System.out.println("----------------------------------------");
for (int i = 0; i < h.length; i++)
System.out.println(h[i].getName() + ":" + h[i].getValue());
System.out.println("----------------------------------------");
System.out.println("Corps de la réponse :");
System.out.println(result);

// Nettoyer
EntityUtils.consume(entity);
}
}
}

chaîne statique privée getBasicAuthHeader(String userId, String password) {
return "Basic " + base64Encode(userId + ":" + password);
}

public static String base64Encode(String token) {
byte[] encodedBytes = Base64.encodeBase64(token.getBytes());
renvoie une nouvelle chaîne (encodedBytes, Charset.forName("UTF-8"));
}

l'exception levée après l'exécution

Exception dans le thread "principal" java.security.UnrecoverableKeyException : Impossible de récupérer la clé
sur java.base/sun.security.provider.KeyProtector.recover(KeyProtector.java:304)
sur java.base/sun.security.provider.JavaKeyStore.engineGetKey (JavaKeyStore.java:162)
sur java.base/sun.security.util.KeyStoreDelegator.engineGetKey(KeyStoreDelegator.java:91)
sur java.base/java.security.KeyStore.getKey(KeyStore.java:1078)
sur java. base/sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:141)
sur java.base/sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:64)
sur java.base/javax. net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:275)
sur org.apache.http.ssl.SSLContextBuilder.loadKeyMaterial(SSLContextBuilder.java:301)
sur org.apache.http.ssl.SSLContextBuilder.loadKeyMaterial(SSLContextBuilder.java:336)
sur org.apache.http.ssl.SSLContextBuilder.loadKeyMaterial (SSLContextBuilder.java:343)
sur com.visa.vdp.api.client.VisaDirectClient.main(VisaDirectClient.java:73) Échec
de l'exécution de la commande.
org.apache.commons.exec.ExecuteException : processus terminé avec une erreur : 1 (valeur de sortie : 1)
sur org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
sur org.apache.commons.exec .DefaultExecutor.execute (DefaultExecutor.java:166)
sur org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:982)
sur org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:929)
sur org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:457)
sur org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
sur org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
sur org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
sur org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
sur org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
sur org.apache.maven.lifecycle. internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
sur org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
sur org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
sur org.apache .maven.DefaultMaven.doExecute (DefaultMaven.java:305)
sur org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
sur org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
sur org. apache.maven.cli.MavenCli.execute (MavenCli.java:957)
à org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
à org.apache.maven.cli.MavenCli.main (MavenCli. java:193)
sur jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
sur java.lang.reflect.Method.invoke (Method.java:577)
sur org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
sur org.codehaus.plexus.classworlds.launcher.Launcher .launch (Launcher.java:225)
sur org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
sur org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347 )
------------------------------------------------- -----------------------
ÉCHEC DE CONSTRUCTION
------------------------- -----------------------------------------------
Temps total : 16.451 s
Terminé le : 2022-08-11T15:00:11+01:00
-------------------------------- ----------------------------------------
Échec de l'exécution de l'objectif org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (default-cli) sur le projet vdp_maven : Échec de l'exécution de la commande. : Le processus s'est terminé avec une erreur : 1 (Valeur de sortie : 1) -> [Aide 1]

Pour voir la trace complète de la pile des erreurs, relancez Maven avec le commutateur -e.
Réexécutez Maven à l'aide du commutateur -X pour activer la journalisation complète du débogage.

Pour plus d'informations sur les erreurs et les solutions possibles, veuillez lire les articles suivants :
[Aide 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

2 REPLIES 2
jenn_kh
Community Moderator

Re: API Request and Testing the Connection

Thank you for reaching out, @DamDev! An agent is looking into this and will get back to you as soon as possible. If any community members know a solution, please feel free to respond here.

-Jenn

I_Doroteo3
Visa Developer Support Specialist

Re: API Request and Testing the Connection

Hi @DamDev

 

Do you have a sponsor bank? 

  

Please review the Visa Direct documentation using this link.  https://developer.visa.com/capabilities/visa_direct/docs-getting-started  

  

In particular, see the top few paragraphs, that are enclosed in the box with an exclamation mark, that discuss the requirements to use Visa Direct.  

  

After having read the documentation, if you meet those requirements and if you have questions about Visa Direct, then please email the Visa Direct Regional Mailbox that pertains to the region you are from.  

  

To reach the various regional product office, please use these email addresses. 

USVisaDirect@visa.com 

CanadaVisaDirect@visa.com 

EUVisaDirect@visa.com 

VE_FF@visa.com– Note: This mailbox is specific for the Fast Funds migration in the region and will retire in the future. 

LACVisaDirect@visa.com 

CEMEAVisaDirect@visa.com 

APVisaDirect@visa.com 

  

For all other regions, please reach out to local Visa representatives. 

 

Thanks, 

Illana