httpclient在glassfish servlet中发布到https时出现“SSL证书错误”

时间:2015-05-29 07:48:33

标签: java maven servlets ssl glassfish

我用apache httpClient编写了一个静态post方法:

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;
    }
}

当我独立测试它时,这种方法工作正常,但是一旦我将它构建为maven依赖项并将其包含在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

应该是什么问题?

1 个答案:

答案 0 :(得分:0)

我通过在glassfish domain.xml添加一些配置来修复此问题:

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

发布此案以防万一可能对某些问题有所帮助。

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