JAVA - 使用密钥库对 AWS Elastic Beanstalk 中的 Web 服务进行 SSL 调用
JAVA - Make SSL call with keystore into webservice inside AWS Elastic Beanstalk
我在 AWS Elastic Beanstalk 中加载了一个网络服务 Java。
此 Web 服务使用 jks 密钥库进行 SSL rest 调用。
当我在我的机器上执行网络服务时,我用
加载密钥库
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");
使用 System.setProperty 我需要 file.jks 的绝对路径。
如何在 AWS Elastic Beanstalk 上制作相同的内容?
(我尝试使用 getAbsolutePath() 和 getCanonicalPath() 但是,在我的机器上,这些指令 return myEclipse root)
首先,您必须将 file.jks
与 java 应用程序(WAR 或 JAR)捆绑在一起,然后您可以从 [=10= 的相对路径中获取绝对路径] 如这个接受的答案中所述:Converting Relative Paths to Absolute Paths
感谢您的回答。
我是这样解决的:首先我把我的jks文件放在一个项目包"package"中,客户端"Test"。
在我的代码中,我写道:
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");
它也适用于 AWS Elastic Beanstalk!
我在 AWS Elastic Beanstalk 中加载了一个网络服务 Java。 此 Web 服务使用 jks 密钥库进行 SSL rest 调用。 当我在我的机器上执行网络服务时,我用
加载密钥库 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");
使用 System.setProperty 我需要 file.jks 的绝对路径。 如何在 AWS Elastic Beanstalk 上制作相同的内容?
(我尝试使用 getAbsolutePath() 和 getCanonicalPath() 但是,在我的机器上,这些指令 return myEclipse root)
首先,您必须将 file.jks
与 java 应用程序(WAR 或 JAR)捆绑在一起,然后您可以从 [=10= 的相对路径中获取绝对路径] 如这个接受的答案中所述:Converting Relative Paths to Absolute Paths
感谢您的回答。 我是这样解决的:首先我把我的jks文件放在一个项目包"package"中,客户端"Test"。 在我的代码中,我写道:
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");
它也适用于 AWS Elastic Beanstalk!