如何在 Jboss 5 中配置外部服务调用证书
Posted
技术标签:
【中文标题】如何在 Jboss 5 中配置外部服务调用证书【英文标题】:How do i configure external service call certificates in Jboss 5 【发布时间】:2016-04-03 08:31:33 【问题描述】:当尝试从纯 java 代码连接外部服务时,我得到了正确的响应。我正在使用 Java 1.8.51。为了在纯 java 代码中设置证书,我使用以下属性,
System.setProperty("javax.net.ssl.keyStore", path);
System.setProperty("javax.net.ssl.keyStorePassword", password);
System.setProperty("javax.net.ssl.trustStore", path);
System.setProperty("javax.net.ssl.trustStorePassword", password);
通过在从 JBoss 5 连接外部服务时使用相同的代码,我得到以下异常,
org.springframework.ws.client.WebServiceIOException: I/O error: Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:543)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:436)
at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:421)
at com.intuit.ds.dash.som.helper.customercentral.CustomerCentralService_old.getResponseFromCC(CustomerCentralService_old.java:185)
at com.intuit.ds.dash.som.helper.customercentral.CustomerCentralService_old.main(CustomerCentralService_old.java:284)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at java.io.FilterOutputStream.flush(FilterOutputStream.java:140)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:506)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.springframework.ws.transport.http.CommonsHttpConnection.onSendAfterWrite(CommonsHttpConnection.java:112)
at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:47)
at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:622)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:585)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
【问题讨论】:
【参考方案1】:我通过在 JAVAOPTS 中的 run.bat (for windows)、run.sh for (linux) 中添加以下属性解决了这个问题,
For Windows run.bat
set JAVA_OPTS=%JAVA_OPTS% -Djavax.net.ssl.keyStore="keystorepath" -Djavax.net.ssl.keyStorePassword="password"
For Linux run.sh
JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.keyStore=keystorepath -Djavax.net.ssl.keyStorePassword=password"
【讨论】:
以上是关于如何在 Jboss 5 中配置外部服务调用证书的主要内容,如果未能解决你的问题,请参考以下文章
在 JBoss EAP 6.2 中无法通过 SSL 连接到 SOAP 服务