Java – WebService call timed out from the client

I am using resteasy client to call WebService One requirement is to abort / timeout the call if the running time exceeds 5 seconds How do I use resteasy client to achieve this? I only see the server timeout, that is, if it is not satisfied within a period of time, rest easy WebService will timeout the request@ H_ 419_ 2@

resolvent

Solution

The resteasy client usually uses Apache httpclient to handle network sessions

You can override the httpclient property with your own custom timeout parameters:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
httpconnectionParams.setConnectionTimeout(params,connectionTimeoutMillis);
httpconnectionParams.setSoTimeout(params,socketTimeoutMillis);

The first parameter allows you to specify the timeout value for establishing the initial connection, and the second allows you to specify the maximum time for the socket to wait without data sending

You can use the modified httpclient to build your clientexecution:

ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);

You can use it in turn to build a clientrequest object Or you can inject it into restclientproxyfactorybean if you use resteasy's spring configuration

This is not exactly the same as the absolute 5 second timeout, but adjusting these two properties usually fills in the bill according to the task you want to complete

The above is all the contents of Java - calling from the client timed out WebService collected by the programming home for you. I hope this article can help you solve the program development problems encountered by Java - calling from the client timed out WebService.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>