使用Httpunit的时候处理HTTPS问题(二)

使用Httpunit的时候处理HTTPS问题(二)

晕,好好的过了一个新年,能跑的单元测试都不能用了,全都报错如下:
javax.net.ssl.SSLKeyException: RSA premaster secret error
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at com.meterware.httpunit.HttpWebResponse.readResponseHeader(HttpWebResponse.java:162)
at com.meterware.httpunit.HttpWebResponse.readHeaders(HttpWebResponse.java:200)
at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:56)
at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:67)
at com.meterware.httpunit.WebConversation.newResponse(WebConversation.java:76)
at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:184)
at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:252)
at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:485)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:146)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:144)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:110)
at com.meterware.httpunit.WebClient.sendRequest(WebClient.java:95)
at net.tss.vendors._1800flowers.statemachine.F1800OrderUtility.addItemToCart(F1800OrderUtility.java:329)
at net.tss.vendors._1800flowers.statemachine.F1800OrderUtility.paypalCreateCart(F1800OrderUtility.java:104)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessor.doPayPalCreateCart(F1800PayPalOrderProcessor.java:59)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext$F1800PayPalOrderStateMachine_Default$F1800PayPalOrderStateMachine_PayPayCartCreate.Entry(F1800PayPalOrderProcessorContext.java:242)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext$F1800PayPalOrderStateMachine_Default$F1800PayPalOrderStateMachine_Create.next(F1800PayPalOrderProcessorContext.java:191)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext.next(F1800PayPalOrderProcessorContext.java:26)
at net.tss.app.statemachine.OrderProcessor.next(OrderProcessor.java:96)
at net.tss.app.statemachine.PayPalResumeableOrderProcessor.createCart(PayPalResumeableOrderProcessor.java:51)
at net.tss.app.ejb.mdb.manager.OrderUnitManager.executeOrderUnit(OrderUnitManager.java:65)
at net.tss.app.ejb.mdb.manager.OrderUnitManagerTest.testPayPalToken(OrderUnitManagerTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
at com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.<init>(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderFieldKey(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFieldKey(Unknown Source)
at com.meterware.httpunit.HttpWebResponse.loadHeaders(HttpWebResponse.java:216)
at com.meterware.httpunit.HttpWebResponse.readHeaders(HttpWebResponse.java:198)
... 45 more
Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
at com.sun.net.ssl.internal.ssl.JsseJce.getKeyGenerator(Unknown Source)
... 61 more
15:02:33,520 ERROR [F1800OrderUtility] addItemToCart() [Order ID: 9992, Customer ID: null] Ex : addItemToCart()
javax.net.ssl.SSLKeyException: RSA premaster secret error
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at com.meterware.httpunit.HttpWebResponse.readResponseHeader(HttpWebResponse.java:162)
at com.meterware.httpunit.HttpWebResponse.readHeaders(HttpWebResponse.java:200)
at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:56)
at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:67)
at com.meterware.httpunit.WebConversation.newResponse(WebConversation.java:76)
at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:184)
at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:252)
at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:485)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:146)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:144)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:110)
at com.meterware.httpunit.WebClient.sendRequest(WebClient.java:95)
at net.tss.vendors._1800flowers.statemachine.F1800OrderUtility.addItemToCart(F1800OrderUtility.java:329)
at net.tss.vendors._1800flowers.statemachine.F1800OrderUtility.paypalCreateCart(F1800OrderUtility.java:104)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessor.doPayPalCreateCart(F1800PayPalOrderProcessor.java:59)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext$F1800PayPalOrderStateMachine_Default$F1800PayPalOrderStateMachine_PayPayCartCreate.Entry(F1800PayPalOrderProcessorContext.java:242)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext$F1800PayPalOrderStateMachine_Default$F1800PayPalOrderStateMachine_Create.next(F1800PayPalOrderProcessorContext.java:191)
at net.tss.vendors._1800flowers.statemachine.F1800PayPalOrderProcessorContext.next(F1800PayPalOrderProcessorContext.java:26)
at net.tss.app.statemachine.OrderProcessor.next(OrderProcessor.java:96)
at net.tss.app.statemachine.PayPalResumeableOrderProcessor.createCart(PayPalResumeableOrderProcessor.java:51)
at net.tss.app.ejb.mdb.manager.OrderUnitManager.executeOrderUnit(OrderUnitManager.java:65)
at net.tss.app.ejb.mdb.manager.OrderUnitManagerTest.testPayPalToken(OrderUnitManagerTest.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
at com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.<init>(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderFieldKey(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFieldKey(Unknown Source)
at com.meterware.httpunit.HttpWebResponse.loadHeaders(HttpWebResponse.java:216)
at com.meterware.httpunit.HttpWebResponse.readHeaders(HttpWebResponse.java:198)
... 45 more
Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
at com.sun.net.ssl.internal.ssl.JsseJce.getKeyGenerator(Unknown Source)
... 61 more

不知道啥子原因,检查一下是否导入证书,执行命令
java InstallCert www.xxxx.com
发现也要报错。

这时发现我的JRE升级到了1.6.23。我貌似就是过年的时候升级的。于是决定重新安装JDK。安装到了C盘。
导入证书执行
javac InstallCert.java 又报错了,报错如下:
C:\Program Files\Java\jre6\lib\security>javac InstallCert.java
InstallCert.java:137: 写入 InstallCert.SavingTrustManager 时出错: InstallCert$S
avingTrustManager.class (拒绝访问。)
    private static class SavingTrustManager implements X509TrustManager {
                   ^
1 错误

看这个错误,想想,是不是我是WIN7的操作系统,C盘是受保护的,所以JAVA没有权限写入文件。于是我又重新安装了一次JDK,安装到了D盘。导入证书,终于一切OK了。折腾啊。

你可能感兴趣的:(java,eclipse,.net,JUnit,sun)