Set the timeout duration of the cxf WebService client in spring.

Source: Internet
Author: User

It is mainly set during client calls:

  1. When using WebService, we may need a backup WebService server. once the master server is down, we can use the backup server. in this case, you need to modify the connection time of the client to the server.
  2. In the spring + cxf WebService environment, the client has two configurable Time Attributes: connectiontimeout and receivetimeout.
  3. Connectiontimeout -- WebService is based on a TCP connection. This attribute can be understood as the time setting for a TCP handshake. If the time exceeds the set length, the connection times out. in milliseconds. The default value is 30000 milliseconds, that is, 30 seconds.
  4. Receivetimeout -- this attribute is the waiting time for a response after a WebService request is sent. If the response time exceeds the configured length, it is regarded as a response timeout. in milliseconds, the default value is 60000 milliseconds, that is, 60 seconds.
  5. Example of setting beans. xml:
  6. <? XMLVersion = "1.0" encoding = "UTF-8"?>
  7. <BeansXmlns = "http://www.springframework.org/schema/beans"
  8. Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
  9. Xmlns: Jee = "http://www.springframework.org/schema/jee"
  10. Xmlns: jaxws = "http://cxf.apache.org/jaxws"
  11. Xmlns: http-conf = "http://cxf.apache.org/transports/http/configuration"
  12. Xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  13. Http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
  14. Http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
  15. Http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
  16. <Http-conf: conducting itName = "{http://impl.service.product.super.com/?projectservice.http-conduit">
  17. <Http-conf: ClientConnectiontimeout = "10000" receivetimeout = "20000"/>
  18. </HTTP-conf: conducting it> 
  19. </Beans>
  20. Note the following points:
  21. 1: You need to specify the http-conf namespace xmlns: http-conf = http://cxf.apache.org/transports/http/configuration
  22. 2: Specify mode location: http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
  23. 3: http-conf: Name attribute in the pipeline, which specifies the service for which the setting takes effect. In this example, only the service with the service name {http://impl.service.product.sw#com/#projectservicetakes effect.
  24. The following settings will take effect for all services.
  25. <Http-conf: conducting itName = "*. http-conduit">

  26. <Http-conf: client……>
  27. </HTTP-conf: conducting it>
  28. For more detailed configuration, see the official cxf documentation:
  29. Http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html

 

'2. code writing:

Private Static VoidRecievetimeoutwrapper (Object O)

{

Conductor it =
(Clientproxy.Getclient(O). getconduit ());

Httpconduit Hc =
(Httpconduit) conduit;

Httpclientpolicy
Client =NewHttpclientpolicy ();


Client. setreceivetimeout (1000*60*5); // 5-minute timeout. This time is the response timeout.

// Client. setconnectiontimeout (1000*45); // The connection times out in 45 seconds.


HC. setclient (client );

}

 

Recievetimeoutwrapper (o) wraps each service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.