How to control the timeout of WebService calls on the client

Source: Internet
Author: User

1. on the client of the stub generated by cxf, the method is as follows (cxf2.1.1 ):

Simpleserviceservice SRV = new simpleserviceservice ();
Simpleservice serviceport = srv. getsimpleserviceport ();

// Timeout setting
Client Cl = clientproxy. getclient (serviceport );

Httpconduit HTTP = (httpconduit) Cl. getconduit ();

Httpclientpolicy = new httpclientpolicy ();
Httpclientpolicy. setconnectiontimeout (10000 );
Httpclientpolicy. setreceivetimeout (1000 );
HTTP. setclient (httpclientpolicy );

Serviceport. concatenate ("111", "2222 ");

Simpleserviceservice is the automatically generated stub class.

 

2. On the stub client generated by xfire, the method is as follows (xfire1.26 ):

Simpleserviceserviceclient serviceclient = new simpleserviceserviceclient ();
Simpleservice serviceport = serviceclient. getsimpleserviceport ();

Httpclientparams Params = new httpclientparams ();
Params. setparameter (httpclientparams. use_expect_continue, Boolean. False );
// Set connection timeout
Params. setparameter (httpclientparams. connection_manager_timeout, 2L );
// Set response timeout
Params. setintparameter (httpclientparams. so_timeout, 2 );

Client client = client. getinstance (serviceport );
Client. setproperty (commonshttpmessagesender. http_client_params, Params );

System. Out. println (serviceport. concatenate ("xfire1", "xfire2 "));

Simpleserviceserviceclient is the automatically generated stub class.

 

The above two methods achieve timeout control by controlling the underlying HTTP connection. If the timeout occurs, java.net. sockettimeoutexception: Read timed out will be thrown.

 

3. The client of Jax-ws also uses the client proxy of cxf to control the HTTP connection:

URL wsdlurl = new URL ("file: // D:/javaworkspace/Repository/prjcxfws/src/WSDL/prjcxfws. WSDL ");

QNAME serviceqname = new QNAME ("http://test.cxfws.com/", "simpleserviceservice ");

QNAME portqname = new QNAME ("http://test.cxfws.com/", "simpleserviceport ");

Service = service. Create (wsdlurl, serviceqname );


// Set Handler
Service. sethandlerresolver (New requestorderhandlerresolver ());

Simpleservice Port = (simpleservice) service. getport (portqname, simpleservice. Class );

// Timeout setting
Client Cl = clientproxy. getclient (port );

Httpconduit HTTP = (httpconduit) Cl. getconduit ();

Httpclientpolicy = new httpclientpolicy ();
Httpclientpolicy. setconnectiontimeout (10000 );
Httpclientpolicy. setreceivetimeout (1000 );
HTTP. setclient (httpclientpolicy );

System. Out. println (port. concatenate ("srt1", "srt2 "));

 

4. Jax-Dispatch: Someone found on the Internet that the following method is used: Try it and try it.

Dispatch. getrequestcontext (). Put ("com. Sun. xml. ws. Request. Timeout", 1000 );

 

 

 

 

 

 

 

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.