用於 Web 服務主機名稱驗證的行為差異

在 Liberty 中執行 Web 服務時,依預設會使用憑證來驗證 HTTPS URL 中給定的主機名稱,而在 WebSphere Application Server Traditional 中則不然。 如果主機名稱無效,Liberty 伺服器會擲出下列異常狀況:

java.io.IOException: The https URL hostname does not match the Common Name (CN) on the server certificate in the client's truststore. Make sure the server certificate is correct, or to disable this check (NOT recommended for production) set the CXF client TLS configuration property disableCNCheck to true.

此行為差異影響使用 Java API for XML Web Services (JAX-WS) 的用戶端應用程式,JAX-WS 是由 javax.xml.ws 套件提供。 如果參照 JAX-WS API,會標示該專案一次。

建議的解決方案是以正確主機名稱建立伺服器憑證。或者,您可以在需要停用主機名稱驗證的 JAX-WS 用戶端,設定 http.conduit.tlsClientParameters.disableCNCheck 內容,以自訂驗證行為。 作法是在 server.xml 檔中新增 <webservices-bnd> 應用程式連結,並針對每個用戶端,以 <service-ref> 元素設定此內容,如下列範例所示:

<enterpriseApplication id="SimpleEcho" name="SimpleEcho"  location="SimpleEcho.ear">
  <webservices-bnd moduleName="SimpleEcho">
    <service-ref name="service/SimpleEchoService">
      <port name="SimpleEchoPort">
        <properties vendor="IBM"/>
      </port>
      <properties http.conduit.tlsClientParameters.disableCNCheck="true"/>
    </service-ref>
  </webservices-bnd>
</enterpriseApplication>

您也可以在 ibm-ws-bnd.xml 檔的 <service-ref> 元素中新增此內容,以停用主機名稱驗證,如下列範例所示:

<service-ref name="service/SimpleEchoService">
  <port name="SimpleEchoPort">
    <properties vendor="IBM"/>
  </port>
  <properties http.conduit.tlsClientParameters.disableCNCheck="true"/>
</service-ref>

如需在 Liberty 中為 Web 服務用戶端配置 Web 服務參照配置的相關詳細資訊,請參閱下列資源: