使用SSL访问Web服务时出错

我有一个应该将文件发送到Web服务的程序,这需要SSL连接。 我按如下方式运行程序:

SET JAVA_HOME=C:\Program Files\Java\jre1.6.0_07 SET com.ibm.SSL.ConfigURL=ssl.client.props "%JAVA_HOME%\bin\java" -cp ".;Test.jar" ca.mypackage.Main 

这很好,但是当我改变第一行时

 SET JAVA_HOME=C:\Program Files\IBM\SDP\runtimes\base_v7\java\jre 

我收到以下错误:

 com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:119) at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:140) at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:86) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:593) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:552) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:537) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:434) at com.sun.xml.internal.ws.client.Stub.process(Stub.java:247) at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:132) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:242) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:222) at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:115) at $Proxy26.fileSubmit(Unknown Source) at com.testing.TestingSoapProxy.fileSubmit(TestingSoapProxy.java:81) at ca.mypackage.Main.main(Main.java:63) Caused by: java.net.SocketException: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory at javax.net.ssl.DefaultSSLSocketFactory.a(SSLSocketFactory.java:7) at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:1) at com.ibm.net.ssl.www2.protocol.https.c.afterConnect(c.java:110) at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:14) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:902) at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:86) at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:107) ... 14 more Caused by: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory at javax.net.ssl.SSLJsseUtil.b(SSLJsseUtil.java:20) at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:36) at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(HttpsURLConnection.java:16) at javax.net.ssl.HttpsURLConnection.(HttpsURLConnection.java:36) at com.ibm.net.ssl.www2.protocol.https.b.(b.java:1) at com.ibm.net.ssl.www2.protocol.https.Handler.openConnection(Handler.java:11) at java.net.URL.openConnection(URL.java:995) at com.sun.xml.internal.ws.api.EndpointAddress.openConnection(EndpointAddress.java:206) at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.createHttpConnection(HttpClientTransport.java:277) at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:103) ... 14 more 

所以看起来这个问题与我正在使用的JRE有关,但似乎没有意义的是非IBM JRE工作正常,但IBM JRE没有。 有什么想法或建议吗?

如果你的非IBM jre是sun,那么它已经附带了与它一起打包的SSL类实现。

似乎IBM jre根本不包含SSL实现类。

尝试在设置代码中的某处添加这两行:

 Security.setProperty("ssl.SocketFactory.provider", "com.ibm.jsse2.SSLSocketFactoryImpl"); Security.setProperty("ssl.ServerSocketFactory.provider", "com.ibm.jsse2.SSLServerSocketFactoryImpl"); 

Java仅允许JVM的一个SSL连接工厂类。 如果您正在使用WebSphere Application Server v6x / 7x / 8x附带的JDK或Rational Application Developer中的任何其他WebSphere服务器工具,那么那些需要来自WebSphere Application的IBM(com.ibm.websphere.ssl.protocol.SSLSocketFactory)特定类服务器运行时 因为java安全文件的JSSE套接字工厂设置如下

 # Default JSSE socket factories #ssl.SocketFactory.provider=com.ibm.jsse2.SSLSocketFactoryImpl #ssl.ServerSocketFactory.provider=com.ibm.jsse2.SSLServerSocketFactoryImpl # WebSphere socket factories (in cryptosf.jar) ssl.SocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLSocketFactory ssl.ServerSocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLServerSocketFactory 

因此,如果取消注释Default JSSE Socket工厂并注释掉WebSphere,那么WAS就会呕吐。

更好的解决方法是在类路径中包含com.ibm.ws.security.crypto.jar文件。 此jar文件依赖于com.ibm.ffdc.jar文件,因此您需要在类路径中很好地使用它。 这两个jar文件都可以在/plugins/

可以通过取消以下JSSE道具来在WAS_HOME / * / java / jre / lib / security / java.security文件中设置这些属性。

默认的JSSE套接字工厂

ssl.SocketFactory.provider = com.ibm.jsse2.SSLSocketFactoryImpl ssl.ServerSocketFactory.provider = com.ibm.jsse2.SSLServerSocketFactoryImpl

一个似乎对我有用的“解决方案”。 使用以下内容创建您自己的安全属性文件my.java.security

 ssl.SocketFactory.provider= ssl.ServerSocketFactory.provider= 

在调用Java(或我的maven)时,添加命令行选项:

 -Djava.security.properties=C:\myfiles\my.java.security 

来自IBM Liberty文档的内容: http ://www-01.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/rwlp_trouble.html?lang = en

在搜索相同的错误消息时找到此主题但找到了不同的解决方案。 要使用Apache Wink客户端测试https REST服务:

 ClientConfig config = new ClientConfig(); config.setBypassHostnameVerification(true); RestClient client = new RestClient(config); 

并设置工厂为空:

 Security.setProperty("ssl.SocketFactory.provider", ""); Security.setProperty("ssl.ServerSocketFactory.provider", ""); 

我的运行时是使用IBM WebSphere v8.5.5中的IBM JRE 1.7进行的独立Camel测试。

当我的批处理应用程序尝试使用Apache wink从Restful Web服务获取数据时,我遇到了类似的问题。 我使用MyEclipse作为我的开发环境。 并且正在使用IBM webSphere 8.5提供的jre。 当我改为Sun 1.6 jre时,问题得到了解决。

    Interesting Posts