啟用 HTTP 導管用戶端內容和使用者自訂內容

您可以針對 Liberty 上的 JAX-WS 應用程式,利用 ibm-ws-bnd.xml 檔來定義 HTTP 用戶端內容和使用者自訂內容。

開始之前

ibm-ws-bnd.xml 檔必須在 Web 型 Web 服務應用程式(WAR 檔)的 /WEB-INF 目錄中,或在 EJB 型 Web 服務應用程式(JAR 檔)的 /META-INF 目錄中。 如果用戶端是在 clientContainer 中執行,ibm-ws-bnd.xml 檔必須位於用戶端 EAR 中之 JAR 檔的 /META-INF 目錄內。

關於這項作業

您可以針對 @WebServiceRef 註釋所注入的特定服務用戶端或埠,利用 ibm-ws-bnd.xml 檔中的 service-refport 元素來定義 HTTP 用戶端內容和使用者自訂內容。 port 元素中的內容會置換 service-ref 元素中的相同內容。
HTTP 用戶端內容
Liberty 支援下列 HTTP 用戶端內容;這些內容的字首必須有 http.conduit.client.。例如:http.conduit.client.ConnectionTimeout。 這些 HTTP 用戶端內容只在傳送或接收 SOAP 訊息時才有效,當連接到 WSDL URL 時不適用。
  • ConnectionTimeout
  • ReceiveTimeout
  • AsyncExecuteTimeout
  • AsyncExecuteTimeoutRejection
  • AutoRedirect
  • MaxRetransmits
  • AllowChunking
  • ChunkingThreshold
  • Connection
  • DecoupledEndpoint
  • ProxyServer
  • ProxyServerPort
  • ProxyServerType
  • NonProxyHosts
如需這些內容的相關資訊,請參閱 Apache CXF 中的 HTTP 配置綱目用戶端 HTTP 傳輸(包括 SSL 支援)
使用者自訂內容
除了 Liberty 中支援的 HTTP 用戶端內容之外,您也可以定義您的應用程式中所可能用到的使用者自訂內容,並從用戶端要求環境定義中擷取這些內容。properties 元素中所定義的所有屬性都會放在服務用戶端要求環境定義中。

關於 ibm-ws-bnd.xml 檔內所能配置的所有可用元素,請參閱Liberty:ibm-ws-bnd.xml 檔

程序

  1. 配置 HTTP 導管內容。 下列範例顯示如何在 ibm-ws-bnd.xml 檔中配置 HTTP 用戶端內容 ConnectionTimeoutReceiveTimeout。 下列範例顯示如何針對利用 @WebServiceRef(name="service/SimpleEchoService") 注入的服務用戶端的所有埠來套用 HTTP 用戶端內容 ConnectionTimeoutReceiveTimeout,對於 SimpleEchoPort 埠,也會套用使用者自訂內容 vendor 的值。
    <?xml version="1.0" encoding="UTF-8"?>
    <webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
    				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    				xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd "
    		version="1.0">
    	<service-ref name="service/SimpleEchoService">
    		<port name="SimpleEchoPort">
    			<properties vendor="IBM" />
    		</port>
    				<properties http.conduit.client.ConnectionTimeout="10000" 
    			http.conduit.client.ReceiveTimeout="15000" />
    	</service-ref>
    	...
    </webservices-bnd>
  2. 之後,依照下列方式,從 @WebServiceRef(name="service/SimpleEchoService") 註釋所注入的用戶端要求環境定義中,擷取 ibm-ws-bnd.xml 檔所定義的內容。
    @WebServiceRef(name="service/SimpleEchoService")
    		private EchoService echoService;
       ...
    Echo echo = echoService.getEchoPort();
    		BindingProvider bp = (BindingProvider)echo;
    String connTimeout = bp.getRequestContext().get("http.conduit.client.ConnectionTimeout").toString();
    String recTimeout = bp.getRequestContext().get("http.conduit.client.ReceiveTimeout").toString();
    String vendor = bp.getRequestContext().get("vendor").toString();
    		...

指示主題類型的圖示 作業主題

檔名:twlp_dep_jaxws_http_conduit.html