I'm a C developer who needs to create a basic async REST server (synchronous version works fine) in Java using the Microprofile (Helidon MP) framework. Here is my strategy to do this:
The client should do the POST call and provide JSON objects that the POST endpoint will receive. Then, the POST Endpoint method will call a business logic that should do stuff with the received JSON objects. This logic must be run asynchronously. POST should immediately return 202 Accepted. The client should check for async task completion status using a GET request (simple pooling style).
Should POST return a URI that the GET call will use? How? This GET should also provide the percentage of the task completion if the task is in progress. Finally, if the business logic is done, the GET should return the result.
I have a little previous experience with async Java, but no experience with async in this Microprofile/Java EE/Jakarta or whatever it is. I tried several different approaches (AsyncResponse, CompletitionStatus, etc.) to write this code (async POST Method) but nothing seems to be working. The skeleton of the POST functions looks like this:
@Path("/logic")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response logic(JsonObject jsonObject){
BusinessLogic bl = new BusinessLogic();
// This should be done asynchronously.
//How to do it correctly in Microprofile?
bl.doSomethingWithInput(jsonObject);
return Response.status(Response.Status.ACCEPTED).build(); //Return ACCEPTED and the task URI???
}
The GET Handler:
@Path("/logicstatus")
@GET
@@Produces(MediaType.APPLICATION_JSON)
public Response logicStatus(URI as query param???) {
// Magic here?
retrun Response.status(Response.Status.OK).entity(resultJson).build();
}
Thanks a lot. Java reminds me how I love writing device drivers in C :D.