JDK 版本信息:
java version "1.6.0_113"
Java(TM) SE Runtime Environment (build 1.6.0_113-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.111-b01, mixed mode)
Linux 版本信息:
Linux testUser 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
Linux version 2.6.32-431.el6.x86_64 (mockbuild@x86-023.build.eng.bos.redhat.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Sun Nov 10 22:19:54 EST 2013
Weblogic 版本
WebLogic Server 10.3.6.0
weblogic11g,也就是 10.3.6 版本
JAVA 代码中通过 org.apache.http.client.methods.HttpPost(来自 JAR 包 httpclient-4.5.9.jar)调用一个 https 的接口(第三方平台提供的接口,接口地址公司保密,不能提供出来,类似 https://testfile.comyan.org.cn/system/sc/qeuestUpload),报错。报错详细信息如下: 方法入口是 sendHttpsAndSkipCertificate 这个方法
javax.net.ssl.SSLException: Server key
at com.sun.net.ssl.internal.ssl.Handshaker.throwSSLException(Handshaker.java:1139)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:248)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:817)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:753)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:989)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1295)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1322)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1306)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.company.kb.common.utils.HttpUrlTool.sendHttpsAndSkipCertificate(HttpUrlTool.java:1528)
at com.company.kb.policy.app.newest.platform.car.service.shenzhen.platservice.uploadPolicyInfo(VhlPlatformHandlerShenzhenNewestImpl.java:19083)
at com.company.kb.policy.prod.vhl.bm.PolicyAppVhlBM.sendUrServiceBm(PolicyAppVhlBM.java:1002)
at com.company.kb.policy.prod.vhl.bm.PolicyAppVhlBM.sendUrService(PolicyAppVhlBM.java:907)
at com.company.kb.policy.app.quickapp.action.QuickAppBaseBizAction.sendUr(QuickAppBaseBizAction.java:2634)
at sun.reflect.GeneratedMethodAccessor7523.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:404)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:354)
at com.isoftstone.fwk.facade.BizControllerImpl.handleRequest(BizControllerImpl.java:126)
at com.isoftstone.fwk.facade.BizControllerPojoAdapter.handleRequest(BizControllerPojoAdapter.java:37)
at com.isoftstone.fwk.action.BaseWebAction.perform(BaseWebAction.java:67)
at sun.reflect.GeneratedMethodAccessor239.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:404)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:354)
at com.isoftstone.fwk.action.ActionControl.excute(ActionControl.java:19)
at com.isoftstone.fwk.web.WebControl.doAction(WebControl.java:225)
at com.isoftstone.fwk.web.WebControl.doPost(WebControl.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.isoftstone.fwk.web.filter.DWCallbackFilter.doFilter(DWCallbackFilter.java:110)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:116)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:59)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:238)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:99)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.isoftstone.iaeap.web.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:97)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3748)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1499)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:263)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.security.spec.InvalidKeySpecException: key spec not recognised
at cfca.sadk.org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(BaseKeyFactorySpi.java:36)
at cfca.sadk.org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(KeyFactorySpi.java:89)
at java.security.KeyFactory.generatePublic(KeyFactory.java:304)
at com.sun.net.ssl.internal.ssl.HandshakeMessage$ECDH_ServerKeyExchange.<init>(HandshakeMessage.java:920)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:244)
... 87 more
javax.net.ssl.SSLException: Server key
at com.sun.net.ssl.internal.ssl.Handshaker.throwSSLException(Handshaker.java:1139)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:248)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:817)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:753)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:989)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1295)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1322)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1306)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.company.kb.common.utils.HttpUrlTool.sendHttpsAndSkipCertificate(HttpUrlTool.java:1528)
at com.company.kb.policy.app.newest.platform.car.service.shenzhen.VhlPlatformHandlerShenzhenNewestImpl.uploadPolicyInfo(VhlPlatformHandlerShenzhenNewestImpl.java:19083)
at com.company.kb.policy.prod.vhl.bm.PolicyAppVhlBM.undrDicision(PolicyAppVhlBM.java:1002)
at com.company.kb.policy.prod.vhl.bm.PolicyAppVhlBM.quickSubmitToUnderwriting(PolicyAppVhlBM.java:907)
at com.company.kb.policy.app.quickapp.action.QuickAppBaseBizAction.quickSubmitToUnderwriting(QuickAppBaseBizAction.java:2634)
at sun.reflect.GeneratedMethodAccessor7523.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:404)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:354)
at com.isoftstone.fwk.facade.BizControllerImpl.handleRequest(BizControllerImpl.java:126)
at com.isoftstone.fwk.facade.BizControllerPojoAdapter.handleRequest(BizControllerPojoAdapter.java:37)
at com.isoftstone.fwk.action.BaseWebAction.perform(BaseWebAction.java:67)
at sun.reflect.GeneratedMethodAccessor239.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:404)
at org.apache.commons.beanutils.MethodUtils.invokeExactMethod(MethodUtils.java:354)
at com.isoftstone.fwk.action.ActionControl.excute(ActionControl.java:19)
at com.isoftstone.fwk.web.WebControl.doAction(WebControl.java:225)
at com.isoftstone.fwk.web.WebControl.doPost(WebControl.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at com.isoftstone.fwk.web.filter.DWCallbackFilter.doFilter(DWCallbackFilter.java:110)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
项目中调用 http 接口的方法代码如下:
private static CloseableHttpClient buildSSLCloseableHttpClient() throws Exception {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// 信任所有
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
// ALLOW_ALL_HOSTNAME_VERIFIER:这个主机名验证器基本上是关闭主机名验证的,实现的是一个空操作,并且不会抛出 javax.net.ssl.SSLException 异常。
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
}
public static String sendHttpsAndSkipCertificate(Map<String,String> httpMap, String jsonStr) throws BusinessServiceException {
long startTime = 0L;
long endTime = 0L;
String result = null;// 返回的结果
CloseableHttpResponse response = null;
CloseableHttpClient client = null;
HttpPost httpPost = new HttpPost( httpMap.get("url")); //创建 HttpPost 对象
// 参数不为空
if(StringUtils.isNotBlank(jsonStr)) {
try {
//包装成一个 Entity 对象
StringEntity entity = new StringEntity(jsonStr, CommCodeConstants.ENCODING_UTF_8);
//设置请求的内容
httpPost.setEntity(entity);
//设置请求的报文头部的编码
httpPost.setHeader(new BasicHeader("Content-Type", "application/json;charset=utf-8"));
//设置期望服务端返回的编码
httpPost.setHeader(new BasicHeader("Accept", "application/json, text/plain, */*"));
//设置连接超时时间 30 秒
httpPost.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 30000);
//调用方法,创建 CloseableHttpClient 对象
client = buildSSLCloseableHttpClient();
startTime = System.currentTimeMillis();
response = client.execute( httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if(HttpURLConnection.HTTP_OK == statusCode) {
HttpEntity httpEntity = response.getEntity();
//取出应答字符串
result = EntityUtils.toString( httpEntity);
} else {
throw ExceptionUtil.createBusException("没有正确连接[" + httpMap.get("name") + "],HTTP 服务返回有误,服务返回编码:" + statusCode);
}
} catch (Exception e) {
endTime = System.currentTimeMillis() - startTime;
logger.error("sendHttpsAndSkipCertificateError,endTime" + endTime, e);
e.printStackTrace();
result = e.getMessage().toString();
throw ExceptionUtil.createBusException( httpMap.get("name") +"接口交互出错:"+e.getMessage().toString());
} finally {
if (response != null) {
try {//关闭 response 和 client
response.close();
} catch(Exception e) {
endTime = System.currentTimeMillis() - startTime;
logger.error("sendHttpsAndSkipCertificateError,endTime" + endTime, e);
e.printStackTrace();
}
}
if (client != null) {
try {//关闭 response 和 client
client.close();
} catch(Exception e) {
endTime = System.currentTimeMillis() - startTime;
logger.error("sendHttpsAndSkipCertificateError,endTime" + endTime, e);
e.printStackTrace();
}
}
}
}
return result;
}
这个问题对我来说太难了。我个人猜测是我们公司服务器上面的证书有问题,但是我不知道怎么看服务器上面的证书。即使我看到了服务器上面的证书我也不知道怎么判断我们服务器上的证书有没有问题。我们生产环境上面调这个接口不会报错,测试环境上周测试的时候不会报错,昨天跟今天测试的时候每次调用都报错。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.