1. 程式人生 > >“No subject alternative names present” 異常解決

“No subject alternative names present” 異常解決

前段時間嘗試在自己本機訪問https 資源,一直困於“No subject alternative names present”這個錯誤。

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://IP:8443/security/2.0?wsdl. It failed with:

java.security.cert.CertificateException: No subject alternative names present.

      at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151

)

      at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165

)

      at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)

      at javax.xml.ws.Service.<init>(Service.java:56)

因為之前專案吃緊,只好在公司已經配置好的平臺上開發,把這個問題擱置了下來。隨著第一個版本的成功釋出,得了些空閒時間再次來研究這個問題。

I read that the problem usually appears when the "cn" in the certificate does not match the address of the server. 
The "CN" in my certificate is "PRESS44" 
The server address that was given to me is an ip. 

https://xxx.xxx.xxx.xxx:123

難道不能用IP地址,必須要用主機名?先查查伺服器端的配置。找到伺服器端的keystore 檔案

/usr/java/jdk1.6.0_15/bin/keytool -list -v -keystore -list -v -keystore server.keystore

一查果然CN用的是主機名,複製過來替換原來URL的IP地址。先在測試的Java類裡跑跑看,“No subject” 問題是過了,又報如下的錯:

Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://hostname:8443/security/2.0?wsdl. It failed with:

      at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)

      at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)

      at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)

      at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)

      at javax.xml.ws.Service.<init>(Service.java:56)

訪問WSDL也需要安全認證,真是麻煩啊!突然想起前段時間做調研時,JBoss裡似乎可以設定一個叫 ignoreHttpsHost 的引數。反正最後也要部署到JBoss,不妨就試試看,設定好三個引數:

System.setProperty("javax.net.ssl.trustStore", "C:\\test\\jssecacerts"); 
System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); 
System.setProperty("org.jboss.security.ignoreHttpsHost", "true");

啟動JBoss,跑SoapUI測試用例,三秒之後,成功返回結果。