【发布时间】:2016-04-08 03:14:21
【问题描述】:
我必须使用 2 路身份验证访问网络服务。以下是我的方法。
创建了 MyCustomSSLSocketFactory 类。
- 加载的 TrustManagers
- 已加载的密钥库管理器
- 如下创建 SSL 上下文和 SSL 套接字工厂。
我在调用 webservice 方法之前调用了这个类方法。
然后我做了如下:-
AxisProperties.setProperty("axis.socketSecureFactory",
"com.elipva.zephyr.twofa.util.MyCustomSSLSocketFactory");
Security.setProperty("ssl.SocketFactory.provider",
"com.elipva.zephyr.twofa.util.MyCustomSSLSocketFactory");
SSLContext context = SSLContext.getInstance(protocolVersion);
context.init(keyManagers, trustManagers, null);
SSLSocketFactory socketFactory = context.getSocketFactory();
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection)
.setSSLSocketFactory(sslSocketFactory);
connection.connect();
}
当我访问网络服务时,它给了我以下错误。
org.apache.axis2.AxisFault: Unconnected sockets not implemented
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:203)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
如果我遗漏了什么,请告诉我。
【问题讨论】:
-
我也尝试了以下方法,但它不起作用。 System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); Security.addProvider(新的 com.sun.net.ssl.internal.ssl.Provider()); System.setProperty("https.protocols", "SSLv3,TLSv1"); System.setProperty("javax.net.ssl.trustStore", ""); System.setProperty("javax.net.ssl.trustStorePassword", ""); System.setProperty("javax.net.ssl.trustStoreType", "");ecurity.ssl.allowUnsafeRenegotiation", "true");
-
System.setProperty("javax.net.ssl.keyStore", ""); System.setProperty("javax.net.ssl.keyStorePassword", ""); System.setProperty("javax.net.ssl.keyStoreType", ""); System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");但是上面的方法给了我握手失败的错误。我已正确导入证书,并且我在密钥库设置中使用的 pfx 文件中有私钥。
标签: java web-services ssl axis