I always have connection timeout when making GET request from one Controller to another with Unirest library
Application runs at
http://localhost:9000
My code in Slash extends Controller
is:
String URL = "http://localhost:9000/api/link/HZbeTR";
Logger.info("Requesting API. URL: %s. ObjectRef: %s", URL, objectRef);
HttpResponse<String> apiResponse = Unirest.get(URL).asString();
At logs I have:
17:40:24,296 INFO ~ Requesting API. URL: http://192.168.2.36:9000/api/link/HZbeTR. ObjectRef: 5g2NqY
17:41:24,527 ERROR ~ Exception while searching for link by ident. Ident: HZbeTR, ObjectRef: 5g2NqY
17:41:24,528 ERROR ~ ObjectRef: 5g2NqY
com.mashape.unirest.http.exceptions.UnirestException: java.net.SocketTimeoutException: Read timed out
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:143)
at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:56)
at controllers.Slash.index(Slash.java:39)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:524)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:475)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:451)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:446)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:160)
at Invocation.HTTP Request(Play!)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:138)
... 8 more
17:41:24,932 DEBUG ~ Try to write on a closed channel[keepAlive:true]: Remote host may have closed the connection
Path /api/link/{str}
is routed to another class extending controller.
When requesting directly to http://localhost:9000/api/link/HZbeTR
, just few milliseconds and I have response.
I debugged networking and found that is no request like GET http://localhost:9000/api/link/HZbeTR
Also I put String URL = "http://yandex.ru"
and Unirest did request to Yandex successfully.
In dev mode, the execution pool size is 1 so you're essentially blocking yourself. If you increase the pool size, you should fix this problem. See the docs at https://www.playframework.com/documentation/1.4.x/configuration#play.pool for more info.
play.pool=2
NB You may need to explicitly define the mode this setting applies to.