首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

cxf 联接超时

2012-11-01 
cxf连接超时1?客户端(在spring中配置超时): ????如例: ????view?plaincopy?to?clipboardprint? ??beans??

cxf 连接超时

    1?客户端(在spring中配置超时): ????如例: ????view?plaincopy?to?clipboardprint? ??<beans???xmlns="http://www.springframework.org/schema/beans"??????????????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??????????????xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"??????????????xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration?? ??????????????????http://cxf.apache.org/schemas/configuration/http-conf.xsd?? ??????????????????http://www.springframework.org/schema/beans?? ??????????????????http://www.springframework.org/schema/beans/spring-beans.xsd"> ??????????????<http-conf:conduit?name="{http://apache.org/hello_world_soap_http}SoapPort.http-conduit"> ??????????????????<http-conf:client?ConnectionTimeout="30000"?ReceiveTimeout="60000"?/> ??????????????</http-conf:conduit> ??????????</beans> ??首先要注意的事情是<http:conduit>的name属性。 ????这个name包含服务的命名空间,WSDL的端口(port)名--就是wsdl的<wsdl:port>name属性,以及".http-conduit". ????就是下面这个模板:"{WSDL?Namespace}portName.http-conduit".?注意:它是端口名称(port?name),不是服务名称(service?name)。 ????name值的另一个选择是"*.http-conduit",是URL的正则表达式。例: ????<http:conduit?name=".*"> ????</http:conduit> ????在localhost:8080上为所有交互配置一个conduit.?在同一个服务端,如果你有多个客户端与不同的服务进行交互,这可能是最 ????简单的方法。 ????Namespace ????这个元素用于配置一个HTTP客户端,它定义在命名空间:http://cxf.apache.org/transports/http?/configuration. ????它通常被称为使用前缀http-conf.?为了使用HTTP配置元素,你需要添加下面显示的一行到你的端点配置文件的 ????beans元素。此外,你还需要添加配置元素的命名空间到xsi?:?schemaLocaion属性。 ????例:HTTP?客户端配置命名空间 ????<beans?.... ????xmlns:http-conf="http://cxf.apache.org/transports/http/configuration ????xsi:schemaLocation="... ????http://cxf.apache.org/transports/http/configuration ????http://cxf.apache.org/schemas/configuration/http-conf.xsd ????...> ????conduit元素 ????你使用http-conf:conduit元素和它的子元素配置一个HTTP客户端。?http-conf:conduit元素只有一个属性,name, ????它指定对应到端点接口的WSDL?port元素.?这个name属性的值是:prtQName.http-conduit. ????例如,下面的代码显示http-conf?:?conduit元素将被用于为一个端点接口添加配置,它指定为wsdl片断 ????<port?binding="widgetSOAPBinding"?name="widgetSOAPPort">,如果端点接口的目标命名空间是: ????例:http-conf:conduit?Element ????<http-conf:conduit?name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-conduit"> ????.... ????</http-conf:conduit> ????也你能使用通配符来指定http:conduit,你要配置: ????<http-conf:conduit?name="*.http-conduit"> ????.... ????</http:conf:conduit> ????http-conf:conduit元素有一些子元素,其中http-conf?:?client-----?指定http连接属性,如:超时,保持活动的请求,内容类型等。 ????这个是我们需要的。 ????这个http-conf:client元素有一些属性,定义超时的有两个: ????ConnectionTimeout(连接超时)------?指定的一个时间量,以毫秒为单位,客户端将在超时之前尝试建立连接。默认是 ????30000(30秒).?0?指定客户端将继续无限期地尝试打开一个连接。 ????ReceiveTimeout(接收超时)-----?指定的一个时间量,以毫秒为单位,客户端将在超时之前等待响应。默认是 ????60000(一分钟).?0?指定客户端将无限期等待。 ????2?客户端(在java代码直接控制超时配置) ????首先你需要从代理对象或客户端得到HTTPConduit,?然后你能设置HTTPClientPolicy,AuthorizationPolicy, ????ProxyAuthorizationPolicy,TLSClientParameters,和/或?HttpBasicAuthSupplier. ????view?plaincopy?to?clipboardprint??URL?wsdl?=?getClass().getResource("wsdl/greeting.wsdl");?? ??SOAPservice?service?=?new?SOAPservice(wsdl,serviceName);?? ??Greeter?greeter?=?service.getPort(portName,Greeter.class);???Client?client?=?ClientProxy.getClient(greeter);?? ??HTTPConduit?http?=?(HTTPConduit)client.getConduit();?? ??HTTPClientPolicy?httpClientPolicy?=?new?HTTPClientPolicy();?? ??httpClientPolicy.setConnectionTimeout(36000);?? ??httpClientPolicy.setReceiveTimeout(32000);?? ??http.setClient(httpClientPolicy);???greeter.sayHi("Hello"); ??3?服务端(在spring中配置) ????Namespace ????如例(与client差不多,意思也一样): ????<beans?... ????xmlns:http-conf="http://cxf.apache.org/transports/http/configuration ????xsi:schemaLocation="... ????http://cxf.apache.org/transports/http/configuration ????http://cxf.apache.org/schemas/configuration/http-conf.xsd ????...> ????destination元素 ????如例(与client差不多,意思也差不多) ????.... ????<http-conf:destination?name="{http://widgets/widgetvendor.net}widgetSOAPPort.http-destination> ????...... ????</http-conf:destination> ????http-conf:destination元素有个子元素:http-conf:server?------指定HTTP连接属性 ??<http-conf:server>有属性:ReceiveTimeout-----设置以毫秒为单位的时间长度,服务端在连接超时之前 ??尝试接收请求。默认是30000(30秒)。?指定服务器将不超时使用0?view?plaincopy?to?clipboardprint? ??<beans???xmlns="http://www.springframework.org/schema/beans"??????????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??????????xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"??????????xsi:schemaLocation="http://cxf.apache.org/transports/http/configuration?? ??????????????http://cxf.apache.org/schemas/configuration/http-conf.xsd?? ??????????????http://www.springframework.org/schema/beans?? ??????????????http://www.springframework.org/schema/beans/spring-beans.xsd">?????????<http-conf:destination?name="{http://apache.org/hello_world_soap_http}SoapPort.http-destination"> ??????????????<http-conf:server?????ReceiveTimeout="30000"/> ??????????</http-conf:destination> ??????</beans>??

热点排行