How to periodically send an HTTP status code 102 Processing a response through Grizzly

I have a Java application that runs on top of the Grizzly web server. I am already calling Response.suspend()and running the request in the background thread. It works a lot. Here is a sample code.

import org.glassfish.grizzly.http.server.Request;
import org.glassfish.grizzly.http.server.Response;

class Handler extends org.glassfish.grizzly.http.server.HttpHandler
{
   @Override
   public void service(Request request, Response response)
   {
       response.suspend();
       // Execute the request in a background thread
   }

   private static void execute(Request request, Response response)
   {
      // Process the request

      response.setStatus(200);
      // Populate the response headers and body
      response.resume();
   }
}

For one type of request, processing may take some time. I would like to periodically send the HTTP status code 102 Processingback to the client so that the client does not time out. How should I do it? I understand that I may have to complete a periodic scheduled task to send 102 Processing. It's not a problem. How do I interact with an object Response?

. HTTP 102. , , IllegalStateException, Response.isCommitted() .

response.setStatus(102, "Processing");

response.
   getOutputBuffer().
   acknowledge();
+4

Source: https://habr.com/ru/post/1652518/


All Articles