Reading RESTful documentation, it does not seem like it is possible to implement an asynchronous instance, but someone may know better on SO.
What I mean here is I would like to execute service requests asynchronously:
@Path("/helloworld", asyncSupported=true)
public class MyHelloWorldService {
...
}
I know asyncSupported
is not defined in @Path
, but I am looking for something similar to @WebServlet
. Then, I would like to use AsyncContext
instances (or anything equivalent).
Is this possible?
The asynchronous web services receives the request, sends a confirmation message to the initiating client, and starts process the request. Once processing of the request is complete, the asynchronous web service acts as a client to send the response back to the callback service.
Although REST proved to be much easier to implement than other comms (notably the XML-based SOAP), it has an inherent disadvantage in that it is synchronous in nature, rather than asynchronous. “A client sends a request, the server sends a response,” Roper said, describing how REST works.
By asynchronous, I mean that the client will make the request and continue with its execution with out waiting for the response from the service.Is it possible to achieve this? I need to deploy the service in WebSphere Application Server. web-services rest asynchronous.
RestEasy has some support1 for it - using a custom annotation called @Suspend
.
See here: http://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/Asynchronous_HTTP_Request_Processing.html
There is also a framework/library on top of Jersey called Atmosphere however that might be overkill for your usecase as its focus appears to be on long-polling client/server web applications ( e.g. chats - https://github.com/Atmosphere/atmosphere )
[1] The CDI scope for your request will be lost in in the thread that actually executes the logic. See the RESTEasy-682 issue for more information. This is a problem that hasn't been solved by any REST frameworks that I know of at this moment[March 2014].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With