Java Reference
In-Depth Information
class AlertFilter implements ContainerRequestFilter,
ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext)
throws IOException {
alert(requestContext);
}
...
Table 8-3 lists the different priorities that are available by default, along with their priority number.
Table 8-3. Priority Values
Priority
Number
Priorities.AUTHENTICATION
1000
Priorities.AUTHORIZATION
2000
Priorities.HEADER_DECORATOR
3000
Priorities.ENTITY_CODER
4000
Priorities.USER
5000
The default priority, if nothing is specified, is Priorities.USER .
Asynchronous Processing
Asynchronous processing with JAX-RS is available for both the Client API and Server API. On the server side, it is
possible for a resource method to suspend a client connection and then resume it at some point in the future when
the response becomes available. To make this occur, the method that is responsible for receiving requests within the
web resource must accept an @Suspended final AsyncResponse argument. It is assumed that this method will be
performing some long-running task, and hence it will be made asynchronous in order to achieve better performance.
The AsyncResponse argument will be called at some point in the future when the long-running task has completed,
and its resume method will be invoked.
Asynchronous tasks usually involve the spawning of a thread, which will be used to run a process in the
background. JAX-RS asynchronous processing is no different; the long-running operation should occur within
a Runnable instance, and the AsyncResponse resume method should be called at the end of the task within the
Runnable . The ManagedExecutorService , part of the new Java EE Concurrency API (covered in Chapter 11), can be
used to submit the Runnable for processing. The following example demonstrates this process:
@Path("/async/longRunningservice")
public class LongRunningService {
@Resource(name = "concurrent/BatchExecutor")
ManagedExecutorService mes;
 
 
Search WWH ::




Custom Search