1

I have a webservice Java loaded in AWS Elastic Beanstalk. This webservice make SSL rest call using jks keystore. When I execute the webservice on my machine, I load keystore with

    System.setProperty("javax.net.ssl.trustStore", "c:\...\file.jks"); 
    System.setProperty("javax.net.ssl.trustStorePassword", "password");
    System.setProperty("javax.net.ssl.keyStore", "c:\...\file.jks"); 
    System.setProperty("javax.net.ssl.keyStorePassword", "sviluppo");   

With System.setProperty I need absolute path of file.jks. How Can I make the same on AWS Elastic Beanstalk?

(I tried with getAbsolutePath() and getCanonicalPath() but, on my machine, these istructions return myEclipse root)

wikimt
  • 71
  • 2
  • 11

2 Answers2

2

First, you have to bundle your file.jks with your java application (WAR or JAR) then you can get the absolute path from the relative path of file.jks as describe in this accepted answer: Converting Relative Paths to Absolute Paths

mkhayata
  • 327
  • 1
  • 3
  • 11
1

Thanks for your answer. I solve it in this way: first I put my jks file in a project package "package" with client "Test". Inside my code I wrote:

String pathKeyStore = package.Test.class.getResource("file.jks").getPath();
pathKeyStore = pathResourceKeyStore.replaceAll("%20", " ");

System.setProperty("javax.net.ssl.trustStore", pathKeyStore);
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("javax.net.ssl.keyStore", pathKeyStore); 
System.setProperty("javax.net.ssl.keyStorePassword", "password");

And it works also in AWS Elastic Beanstalk!

wikimt
  • 71
  • 2
  • 11