Advertisement
Guest User

Untitled

a guest
May 24th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // Example 3: Asynchronous Request Step1 triggering Asynchronous POST
  2. @POST
  3. @Path("/getstats")
  4. @Produces(MediaType.APPLICATION_JSON)
  5. @Consumes(MediaType.APPLICATION_JSON)
  6. public Response generateStats(TaskManager tm) {
  7. System.out.println("Inside");
  8.  
  9. GregorianCalendar gcal = new GregorianCalendar();
  10. SimpleDateFormat fmt = new SimpleDateFormat("MMddyyyy_hhmmss");
  11. String curdate = fmt.format(gcal.getTime());
  12.  
  13. System.out.println("Current Date: " + curdate);
  14.  
  15. // Generate a new Task Resource URI.
  16. URI taskuri = uriInfo.getAbsolutePathBuilder()
  17. .path("/taskmgr/" + curdate).build();
  18.  
  19. // Initiate Asychronous Report generation process with the return
  20. // estimated completion date
  21. GregorianCalendar escal = createReport(gcal);
  22. String esdate = fmt.format(escal.getTime());
  23.  
  24. // Update Task Manager with the estimated Asynchronous task status
  25. // result
  26. tm.setId(curdate);
  27. tm.setStatus("Pending");
  28. tm.setMessage("Resouce is getting processed asynchronously");
  29. tm.setResource(taskuri.toString());
  30. tm.setResultavailable(esdate);
  31.  
  32. // Add status Code =202, Header Content-Location with the URI of the new
  33. // resource, and body with Results details.
  34. Response res = Response.status(202).entity(tm)
  35. .header("Content-Location", taskuri.toString()).build();
  36.  
  37. return res;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement