RESTEasy asynchronous processing with @Suspended -- actually synchronous?
by Steven Schlansker
Hello resteasy users,
I am trying to use the new JAX-RS 2.0 @Suspended AsyncResponse mechanism to write
a service that expects many idling connections (awaiting an event via long-poll),
and therefore seems like a good candidate for asynchronous responses, so as not
to use a large number of waiting threads.
The resource code is very simple:
@GET
@Produces(MediaType.APPLICATION_JSON)
public void watchForChanges(
@Suspended AsyncResponse asyncResponse,
@QueryParam("since") long since)
{
controller.watchForChanges(since, asyncResponse::resume);
}
The intent is that watchForChanges places the (inferred) Consumer<ResponseObject> on a queue,
and returns immediately. Later on a background thread comes by and completes the request.
However, when testing with say 20 clients, it sure looks like the end result is still a
thread per request model:
"qtp1718322084-43" - Thread t@43
java.lang.Thread.State: WAITING
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <3537ebd5> (a java.util.concurrent.CountDownLatch$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
at org.jboss.resteasy.core.SynchronousExecutionContext$SynchronousAsynchronousResponse.initialRequestThreadFinished(SynchronousExecutionContext.java:127)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:411)
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:247)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:225)
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:62)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1676)
<snip Jetty handler / filter chain>
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
The concept of a "SynchronousAsynchronousResponse" and implementation of in particular SynchronousDispatcher#invoke seem to be totally not what I want:
/**
* Callback by the initial calling thread. This callback will probably do nothing in an asynchronous environment
* but will be used to simulate AsynchronousResponse in vanilla Servlet containers that do not support
* asychronous HTTP.
*
*/
request.getAsyncContext().getAsyncResponse().initialRequestThreadFinished();
What am I doing wrong? How do I get truly asynchronous processing?
This is with RESTEasy 3.0.18 running on Jetty 9.3.11
Thanks for any advice,
Steven
8 years, 2 months
Doubt about request, exception
by Fabio Ebner
1 - How can I get the Exception message from my server? in my server(spring
boot restController) I return one message when Exception with this code:
@ResponseStatus(HttpStatus.NOT_FOUND)
public class UsuarioNotFoundException extends RuntimeException{
public UsuarioNotFoundException(String email) {
super("Usuário não encontrado: " + email + ", Favor verificar
o email ou a senha informados");
}
}
So how can I get this custom error message with RestEasy client?
8 years, 2 months
Imprecise http status code when a requested media type is not available
by Yonghee Shin
Hi,
When the requested media type in the "Accept" http header is not available
on the server side, currently http status 500 is returned instead of 406
(Not Acceptable).
I traced the code and a simple change below
in org.jboss.resteasy.springmvc.ResteasyHandlerMapping.getHandler(HttpServletRequest
request) made it return the proper code:
catch (NotFoundException e)
{
if (throwNotFound)
{
throw e;
}
logger.error("Resource Not Found: " + e.getMessage(), e);
}
catch (NotAcceptableException na) { // Added this exception handler
logger.error("Not acceptable: " + na.getMessage(), na);
requestWrapper.setError(406, "The requested media type is not
acceptable.");
return new HandlerExecutionChain(requestWrapper, interceptors);
}
catch (Failure e)
I'm using resteasy-spring-2.3.7.jar.
Is there any newer version that already addresses this issue or would it be
possible to enhance the code in the future release?
I appreciate your help.
Yonghee
8 years, 3 months
Client escapes slashes causing failure
by Gareth Healy
I have a client which uses the following method:
@GET
@Path("/{path}/treeHash")
Response getEntityHash(@PathParam("path") RelativePath path);
The RelativePath object gets converted into a value of:
t;unit-testing/e;ua2shhq9
Example full URL: /entity/t;unit-testing/e;ua2shhq9/treeHash
When its executed, the forward slash is converted to %2F (encoded /). This
causes the call to fail. What do i need to do, to make sure its not URL
encoded?
I've tried adding @Encoded, but that has no effect.
Cheers.
8 years, 3 months
Doubt about request exception
by Fabio Ebner
1 - How can I get the Exception message from my server? in my server(spring
boot restController) I return one message when Exception with this code:
@ResponseStatus(HttpStatus.NOT_FOUND)
public class UsuarioNotFoundException extends RuntimeException{
public UsuarioNotFoundException(String email) {
super("Usuário não encontrado: " + email + ", Favor verificar
o email ou a senha informados");
}
}
So how can I get this custom error message with RestEasy client?
8 years, 3 months
Re: [resteasy] Cannot use @Inject from Application class any suggest ?
by Jim Ma
Hi seb,
Sorry for the so late reply. We've moved the mailing list to jboss
mailing list: http://resteasy.jboss.org/mailinglists from May 2016.
If you have further question , please post there.
To answer your question, can you please provide more information ? for
example the steps , code and environment
which can help us understand this injection problem or quickly reproduce
this error.
Cheers,
Jim
On 09/08/2016 05:50 PM, Alessio Soldano wrote:
>
>
>
>
> -------- Messaggio Inoltrato --------
> Oggetto: [resteasy] Cannot use @Inject from Application class any
> suggest ?
> Data: Mon, 23 May 2016 10:19:21 +0200
> Mittente: sbeex <sbeex1(a)gmail.com>
> A: resteasy(a)lists.jboss.org
>
>
>
> Hello devs,
> I would like to instanciate a class in my main RestEasyApplication
> (Application class).
>
> But this TestDataLoader require some @Inject and they are all null at
> this point. How could I solve that "injection problem" ?
>
> When I use : @Startup annotation the script loads fine.
>
> Thx in advance for your attention
> seb
8 years, 3 months