dwarakesh tp
dwarakesh tp

Reputation: 137

How to increase timeout while making a REST call from a Java jersey client?

I am making a REST call which takes around 2 or 3 minutes to respond, but I am getting a connect timed out exception. How do I increase the timeout for the REST call that is being made.

Here is the code snippet,

    Client restClient = Client.create();
    WebResource webResource = restClient.resource(requestURL);
    ClientResponse response =  webResource.accept("application/json").header("Authorization", authStringEnc)
                .get(ClientResponse.class);
        if (response.getStatus() != 200)
        {
            throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
        }

Kindly help me solve this issue.

Upvotes: 2

Views: 5222

Answers (1)

Salahin Rocky
Salahin Rocky

Reputation: 435

Or you can change the request header like:

Connection: Keep-Alive Keep-Alive: timeout= set_your_desired_time limit

Upvotes: 2

Related Questions