when I'm unable to set the timeout when I use the HTTP client from the playframework. This is my code:
val request: Future[WSResponse] = WS
.url(url)
.withAuth(user, password, WSAuthScheme.BASIC)
//5 minute timeout in milliseconds
.withRequestTimeout(300000)
.put("")
This won't give me an error but the request will time out directly after 2 minutes. Is there something else which has to be set so that the timeout is used?
Update: I use the 2.4.8 version of playframework. It looks like this version has the following bug: https://github.com/playframework/playframework/issues/4846
However, the suggested hotfix isn't working for me eigher.
val request: Future[WSResponse] = WS
.url(url)
.asInstanceOf[NingWSRequest]
.copy(requestTimeout = Some(-1))
.withAuth(user, password, WSAuthScheme.BASIC)
.withRequestTimeout(-1)
.put("")
Both will give me a timeout after 2 minutes.
I can't guarantee this will work for you, but it seems to work for me and you could potentially adapt it:
val httpClient = Try(WS.underlying.asInstanceOf[AsyncHttpClient])
.getOrElse(throw new NotImplementedError("Unsupported HTTP client"))
val putBuilder = httpClient.preparePut(url)
putBuilder.setRequestTimeout(-1).addHeader(user, "Basic " + password)
val promise = Promise[Response]()
httpClient.executeRequest(putBuilder.build(),
new AsyncCompletionHandler[Response] {
def onCompleted(response: Response): Response = {
promise.success(response)
response
}
def onThrowable(t: Throwable): Unit = {
promise.failure(t)
super.onThrowable(t)
}
}
)
Good luck.
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.