我们正在为我们的某个产品评估Azure SDK for Java使用情况。所以我想知道以下细节:
答案 0 :(得分:0)
对于您的第一个问题,0.7版SDK是产品场景的稳定版本。 有关更多信息,请参阅https://azure.microsoft.com/en-us/documentation/articles/java-download-mac/,如果您有任何进一步的询问,请随时告诉我们。
关于第二个问题 - 如何从Java中获取证书。请检查以下代码,看看是否有帮助:
KeyStore ks = null;
String certificateStr = "<cert string>";
String password = "<password>";
StringBufferInputStream sbis = null;
try {
ks = KeyStore.getInstance("JKS");
char[] passwordArray = password.toCharArray();
sbis = new StringBufferInputStream(certificateStr);
ks.load(sbis, passwordArray);
sbis.close();
} catch (Exception e) {
e.printStackTrace();
}
对于第三个问题,Azure支持.PFX格式证书文件。您可能需要参考文档https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure-ssl-certificate/和https://azure.microsoft.com/en-us/documentation/articles/cloud-services-configure-ssl-certificate/,以了解如何为Azure中的APP启用HTTPS以及如何为Azure中的APP配置SSL。
最诚挚的问候。
评论2的示例代码:
String keyStoreName = "<keyStoreName>";
String password = "<password>";
URL url = new URL("<url string>");
// Get KeyStore
KeyStore ks = null;
FileInputStream fis = null;
try {
ks = KeyStore.getInstance("JKS");
char[] passwordArray = password.toCharArray();
fis = new java.io.FileInputStream(keyStoreName);
ks.load(fis, passwordArray);
fis.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
fis.close();
}
}
// Get SSLSocketFactory
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(ks, password.toCharArray());
SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
// Process GET Request
SSLSocketFactory sslFactory = context.getSocketFactory();
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(sslFactory);
con.setRequestMethod("GET");
con.addRequestProperty("x-ms-version", "2013-08-01");
InputStream responseStream = (InputStream) con.getContent();
String response = getStringFromInputStream(responseStream);
responseStream.close();