Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example 3: Asynchronous Request Step1 triggering Asynchronous POST
- @POST
- @Path("/getstats")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Response generateStats(TaskManager tm) {
- System.out.println("Inside");
- GregorianCalendar gcal = new GregorianCalendar();
- SimpleDateFormat fmt = new SimpleDateFormat("MMddyyyy_hhmmss");
- String curdate = fmt.format(gcal.getTime());
- System.out.println("Current Date: " + curdate);
- // Generate a new Task Resource URI.
- URI taskuri = uriInfo.getAbsolutePathBuilder()
- .path("/taskmgr/" + curdate).build();
- // Initiate Asychronous Report generation process with the return
- // estimated completion date
- GregorianCalendar escal = createReport(gcal);
- String esdate = fmt.format(escal.getTime());
- // Update Task Manager with the estimated Asynchronous task status
- // result
- tm.setId(curdate);
- tm.setStatus("Pending");
- tm.setMessage("Resouce is getting processed asynchronously");
- tm.setResource(taskuri.toString());
- tm.setResultavailable(esdate);
- // Add status Code =202, Header Content-Location with the URI of the new
- // resource, and body with Results details.
- Response res = Response.status(202).entity(tm)
- .header("Content-Location", taskuri.toString()).build();
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement