12.13.3. Configure Asynchronous Jobs for RESTEasy
This topic covers examples of the query parameters for asynchronous jobs with RESTEasy.
Role based security does not work with the Asynchronous Job Service, as it cannot be implemented portably. If the Asynchronous Job Serivce is used, application security must be done through XML declarations in the
While GET, DELETE, and PUT methods can be invoked asynchronously, this breaks the HTTP 1.1 contract of these methods. While these invocations may not change the state of the resource if invoked more than once, they do change the state of the server as new Job entries with each invocation.
Example 12.18. The Asynch Parameter
asynchquery parameter is used to run invocations in the background. A 202 Accepted response is returned, as well as a Location header with a URL pointing to where the response of the background method is located.
The example above will return a 202 Accepted response. It will also return a Location header with a URL pointing to where the response of the background method is located. An example of the location header is shown below:
HTTP/1.1 202 Accepted Location: http://example.com/asynch/jobs/3332334
The URI will take the form of:
GET, POST and DELETE operations can be performed on this URL.
- GET returns the JAX-RS resource method invoked as a response if the job was completed. If the job has not been completed, this GET will return a 202 Accepted response code. Invoking GET does not remove the job, so it can be called multiple times.
- POST does a read of the job response and removes the job if it has been completed.
- DELETE is called to manually clean up the job queue.
NoteWhen the Job queue is full, it will evict the earliest job from memory automatically, without needing to call DELETE.
Example 12.19. Wait / Nowait
The GET and POST operations allow for the maximum wait time to be defined, using the
nowaitquery parameters. If the
waitparameter is not specified, the operation will default to
nowait=true, and will not wait at all if the job is not complete. The
waitparameter is defined in milliseconds.
Example 12.20. The Oneway Parameter
RESTEasy supports fire and forget jobs, using the
The example above will return a 202 Accepted response, but no job will be created.