Java

Java 安全網路服務

  • March 1, 2010

(我正在從stackoverflow重新發布這個問題。如果有某種方法可以加入問題或只是移動問題,請告訴我。謝謝。)

我正在嘗試將 http 網路服務轉換為 https。我將標籤添加到網路服務。

@SecurityDomain(value = "jbossws-ssl")

@WebContext(contextRoot="/common/ws",  // already here
urlPattern="/A2",   // already here
   authMethod = "CLIENT-CERT",  // added
   transportGuarantee = "CONFIDENTIAL") // added

但是當我的客戶嘗試連接時,https://host:80/path/to/ws我得到一個異常:

Caused by: java.io.IOException: HTTPS hostname wrong: should be <host>.

(整個事情如下所示)。我懷疑這與正在使用的證書有關。我認為我需要使用 java keytool 來解決這個問題。如果有人可以為我驗證,將不勝感激。

javax.xml.soap.SOAPException: java.io.IOException: Could not transmit message
       at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:115)
       at org.jboss.ws.core.soap.SOAPConnectionImpl.call(SOAPConnectionImpl.java:66)
       at com.alcatel.tpapps.common.utils.SOAPClient.execute(SOAPClient.java:146)
       at com.alcatel.tpapps.common.utils.SOAPClient.main(SOAPClient.java:233)
Caused by: java.io.IOException: Could not transmit message
       at org.jboss.ws.core.client.RemotingConnectionImpl.invoke(RemotingConnectionImpl.java:192)
       at org.jboss.ws.core.client.SOAPRemotingConnection.invoke(SOAPRemotingConnection.java:77)
       at org.jboss.ws.core.soap.SOAPConnectionImpl.callInternal(SOAPConnectionImpl.java:106)
       ... 3 more
Caused by: org.jboss.remoting.CannotConnectException: Can not connect http client invoker. HTTPS hostname wrong:  should be <host>.
       at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:368)
       at org.jboss.remoting.transport.http.HTTPClientInvoker.transport(HTTPClientInvoker.java:148)
       at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:141)
       at org.jboss.remoting.Client.invoke(Client.java:1858)
       at org.jboss.remoting.Client.invoke(Client.java:718)
       at org.jboss.ws.core.client.RemotingConnectionImpl.invoke(RemotingConnectionImpl.java:171)
       ... 5 more
Caused by: java.io.IOException: HTTPS hostname wrong:  should be <host>
       at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.java:490)
       at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:415)
       at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
       at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:857)
       at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
       at org.jboss.remoting.transport.http.HTTPClientInvoker.useHttpURLConnection(HTTPClientInvoker.java:288)
       ... 10 more

更新 1

我嘗試了以下方法,但對異常沒有影響:

host[user:/path][525]% keytool -genkey -keystore server.keystore -alias host
...
...

更新 2

實際上不確定我在更新 1 中所做的是否正確,因為我不必在那裡指定主機名……

錯誤消息抱怨您的埠。http 通常在埠 80 上執行,https 在埠 443 上執行。您正在嘗試在埠 80 上使用 https。將您的呼叫從

https://sco-up:80/path/to/ws

https://sco-up/path/to/ws

這將自動使用埠 443 進行 https 連接。

引用自:https://serverfault.com/questions/109226