If your are still abused to use Java API for RESTful Web Services but building non blocking api with help of:
@Suspended asyncResponse: AsyncResponse
@Suspended asyncResponse: AsyncResponse
Keep in mind that javax.ws.rs.container.ContainerRequestFilter doesn't support non blocking nature and in case it's a part of invocation chain - it will block the calling thread and make usage of @Suspended
The best workaround is to migrate into functional style code - and use loan pattern if possible.
Code can look like:
@GET
@Produces("text/html")
def handleRequest(@Suspended res: AsyncResponse): Unit = {
authenticateBasicAsync(realm = "secure site") {
userName =>
res.resume(s"The user is '$userName'")
}
}
@Produces("text/html")
def handleRequest(@Suspended res: AsyncResponse): Unit = {
authenticateBasicAsync(realm = "secure site") {
userName =>
res.resume(s"The user is '$userName'")
}
}
This code will be easier migrate in future to akka-http or other async http libraries.
No comments:
Post a Comment