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 );