如何在Java Webservice客户端请求中使用SSL/TLS握手
Im使用JavaHTTPWebService客户端,以文本/xml请求格式向服务器发出POST请求。实际上,它在我的系统中运行良好。但是,在服务器端,他们无法从我这边得到任何请求。服务器不在我们的控制范围内,它是与政府相关的服务器,他们使用SSL/TLS握手来确保安全。服务器团队提供了握手的密钥 实际上,我不知道如何使用SSL/TLS以及如何在代码中添加它。服务器团队被告知,他们将在握手成功后收到请求 我现在卡住了。是否需要在我的Tomcat服务器上添加证书?如何在我的请求中添加SSL握手??如果有人知道SSL/TLS握手,请帮助我提示 提前谢谢 我的代码如下:如何在Java Webservice客户端请求中使用SSL/TLS握手,java,web-services,ssl,Java,Web Services,Ssl,Im使用JavaHTTPWebService客户端,以文本/xml请求格式向服务器发出POST请求。实际上,它在我的系统中运行良好。但是,在服务器端,他们无法从我这边得到任何请求。服务器不在我们的控制范围内,它是与政府相关的服务器,他们使用SSL/TLS握手来确保安全。服务器团队提供了握手的密钥 实际上,我不知道如何使用SSL/TLS以及如何在代码中添加它。服务器团队被告知,他们将在握手成功后收到请求 我现在卡住了。是否需要在我的Tomcat服务器上添加证书?如何在我的请求中添加SSL握手??如
public File sendRequest(File req_xml, String responseFileName) {
File xmlFile = new File(responseFileName);
try {
OutputStream outputStream = new FileOutputStream(xmlFile);
HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
httpClient.getParams().setParameter("http.useragent",
"Web Service Test Client");
BufferedReader br = null;
PostMethod methodPost = new PostMethod("http://192.168.1.53:8080/MyApplication/service");
try {
methodPost.setRequestBody(new FileInputStream(req_xml));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
methodPost.setRequestHeader("Content-Type", "text/xml");
try {
int returnCode = httpClient.executeMethod(methodPost);
if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.out
.println("The Post method is not implemented by this URI");
methodPost.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(
methodPost.getResponseBodyAsStream()));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = methodPost.getResponseBodyAsStream().read(
bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
methodPost.releaseConnection();
if (br != null)
try {
br.close();
} catch (Exception fe) {
fe.printStackTrace();
}
}
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
return xmlFile;
}
把它改成
PostMethod methodPost = new PostMethod("https://192.168.1.53:8080/MyApplication/service");
我得到了SSL问题的解决方案。Tomcat将为SSL握手做所有事情。我们需要在系统中安装证书。并在我们的应用程序中添加以下属性:
System.setProperty("javax.net.ssl.keyStore", "Our Installed Key Path");
System.setProperty("javax.net.ssl.keyStorePassword", "keystore password");
System.setProperty("javax.net.ssl.trustStore", "our trust store");
System.setProperty("javax.net.ssl.trustStorePassword", "trust store pwd");
System.setProperty("javax.net.ssl.trustStoreType", "trust store type");
嗨,EJP,谢谢你的快速回复。。不幸的是,这不起作用。我认为握手是必要的。。。你知道握手吗。。?
System.setProperty("javax.net.ssl.keyStore", "Our Installed Key Path");
System.setProperty("javax.net.ssl.keyStorePassword", "keystore password");
System.setProperty("javax.net.ssl.trustStore", "our trust store");
System.setProperty("javax.net.ssl.trustStorePassword", "trust store pwd");
System.setProperty("javax.net.ssl.trustStoreType", "trust store type");