2015-05-29 61 views
0

我有写一个静态的POST方法与Apache的HttpClient:HttpClient的患上了“SSL证书错误”时,后为https在GlassFish中的servlet

public class HttpPost { 
    public static HttpPostResult post(String url, String xml) throws IOException { 
     Logger.getAnonymousLogger().log(Level.INFO, url + "|" + xml); 
     HttpClient httpClient = new HttpClient(); 
     HttpPostResult httpPostResult = new HttpPostResult(); 
     PostMethod postMethod = new PostMethod(url); 
     StringRequestEntity stringRequestEntity = new StringRequestEntity(xml,"xml","utf-8"); 
     postMethod.setRequestEntity(stringRequestEntity); 
     httpClient.executeMethod(postMethod); 
     httpPostResult.setStatus(postMethod.getStatusCode()); 
     httpPostResult.setResponseStr(postMethod.getResponseBodyAsString()); 
     return httpPostResult; 
    } 
} 

这种方法工作时,我测试了单机就好了,但一旦我把它建到行家的依赖,并在HTTP Servlet中涉及它,它只是不工作,并且响应字符串变成:

<html> 
<head><title>400 The SSL certificate error</title></head> 
<body bgcolor="white"> 
<center><h1>400 Bad Request</h1></center> 
<center>The SSL certificate error</center> 
<hr><center>nginx</center> 
</body> 
</html> 

似乎远程主机使用nginx的,我想也许有一些SSL信任问题发生,但远程主机是可信任的(由可信任机构签署的CA),它是https://api.mch.weixin.qq.com/pay/orderquery

应该是什么问题?

回答

0

我解决了这个问题通过添加一些配置GlassFish中domain.xml有:

<jvm-options>-Djavax.net.ssl.keyStorePassword=changeit</jvm-options> 
<jvm-options>-Djavax.net.ssl.trustStorePassword=changeit</jvm-options> 

后这情况可能会有所帮助一些人能有同样的问题。

请注意,changeit是glassfish密钥库的默认密码。