启用 HTTP 同步管道客户机属性和用户定制属性

可通过对 Liberty 上的 JAX-WS 应用程序使用 ibm-ws-bnd.xml 文件来定义 HTTP 客户机属性和用户定制属性。

开始之前

ibm-ws-bnd.xml 文件必须位于基于 Web 的 Web Service 应用程序(WAR 文件)的 /WEB-INF 目录中,或基于 EJB 的 Web Service 应用程序(JAR 文件)的 /META-INF 目录中。如果客户机正在运行 clientContainer,那么 ibm-ws-bnd.xml 文件必须在客户机 EAR 的 JAR 文件的 /META-INF 目录中。

关于此任务

可以使用 ibm-ws-bnd.xml 文件中的 service-refport 元素来定义由 @WebServiceRef 注释注入的特定服务客户机或端口的 HTTP 客户机属性和用户定制属性。port 元素中的属性将覆盖 service-ref 元素中的相同属性。
HTTP 客户机属性
Liberty 支持下列 HTTP 客户机属性;这些属性必须具有前缀 http.conduit.client.。例如:http.conduit.client.ConnectionTimeout。仅当发送或接收 SOAP 消息时,这些 HTTP 客户机属性才有效,并且它们不适用于连接至 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