简体   繁体   中英

Rest Assured - Getting Operation Timed Out Error while testing using RestAssured. But The same endpoint working fine in browser

I have an endpoint to be tested using RestAssured . The same endpoint is working fine while opening it in browser/Postman. But, while trying to test the same using RestAssured ,

I am getting Operation Timed Out Error .

I had to connect to proxy to make that end point working in browser. used the same proxy in the rest assured also.

Sample Code below:

given().proxy("My_Proxy_URL_HERE",8080).when().get("My_API_URL_Here").then().log().all();

I am getting the response as

"Operation Timed Out" with Status Code 503.

I need your suggestion, what could be the possible issue, how to debug etc. Any suggestion is appreciated. Thanks in advance.

There can be many reasons for this behavior:

  • The address is just wrong and given there is some load balancer/proxy it can be configured to wait for a certain period of time and then respond with 503 status code. Note, 503 is not a "request timed out", but "Service Unavailable".

  • The request url is good, but the request lacks some headers so that the load balancer/proxy won't be able to route the request to the required server.

How to check this? there exist tools that can come handy in this situation:

  1. Check the access logs of the load balancer/proxy and even of your server if its possible - and see the request.

  2. If it doesn't help, try to compare requests coming from rest-assured vs regular request. You can use tools like Burp for example, there are others, or you can even roll your own.

The idea is simple: Start the "interceptor" on some port of your local computer (say, 9999 for example)

Configure the interceptor to forward all the requests to proxy of your choice (identified by URL - My_Proxy_URL_HERE and port 8080). Now rest-assured must call localhost:9999 and the request will be intercepted by this tool. You'll be able to inspect its contents - headers, body, http method - everything. Do the same for browser request and compare.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM