Search in sources :

Example 21 with AsyncResponse

use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.

the class CallbackResourceBase method isSuspended.

@GET
@Path("issuspended")
public String isSuspended(@QueryParam("stage") String stage) {
    AsyncResponse response = takeAsyncResponse(stage);
    boolean is = response.isSuspended();
    addResponse(response, stage);
    return is ? TRUE : FALSE;
}
Also used : AsyncResponse(jakarta.ws.rs.container.AsyncResponse) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 22 with AsyncResponse

use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.

the class CallbackResourceBase method takeAsyncResponse.

protected static AsyncResponse takeAsyncResponse(int stageId) {
    final ResponseBuilder error = createErrorResponseBuilder();
    AsyncResponse asyncResponse = null;
    try {
        asyncResponse = stage[stageId].take();
    } catch (InterruptedException e) {
        throw new WebApplicationException(error.entity("ArrayBlockingQueue#take").build());
    }
    return asyncResponse;
}
Also used : WebApplicationException(jakarta.ws.rs.WebApplicationException) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) AsyncResponse(jakarta.ws.rs.container.AsyncResponse)

Example 23 with AsyncResponse

use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.

the class CallbackResourceBase method resumeWithCheckedException.

@GET
@Path("resumechecked")
public String resumeWithCheckedException(@QueryParam("stage") String stage) {
    AsyncResponse async = takeAsyncResponse(stage);
    boolean b = async.resume(new IOException(RESUMED));
    addResponse(async, stage);
    return b ? TRUE : FALSE;
}
Also used : IOException(java.io.IOException) AsyncResponse(jakarta.ws.rs.container.AsyncResponse) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 24 with AsyncResponse

use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.

the class CallbackResourceBase method isCanceled.

@GET
@Path("iscanceled")
public String isCanceled(@QueryParam("stage") String stage) {
    AsyncResponse response = takeAsyncResponse(stage);
    boolean is = response.isCancelled();
    addResponse(response, stage);
    return is ? TRUE : FALSE;
}
Also used : AsyncResponse(jakarta.ws.rs.container.AsyncResponse) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 25 with AsyncResponse

use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.

the class AsyncServletResource method timeout.

@GET
@Path("timeout")
@Produces("text/plain")
public void timeout(@Suspended final AsyncResponse response) {
    response.setTimeout(10, TimeUnit.MILLISECONDS);
    Thread t = new Thread() {

        private Logger log = Logger.getLogger(AsyncServletResource.class);

        @Override
        public void run() {
            try {
                Thread.sleep(100000);
                Response jaxrs = Response.ok("goodbye").type(MediaType.TEXT_PLAIN).build();
                response.resume(jaxrs);
            } catch (Exception e) {
                StringWriter errors = new StringWriter();
                e.printStackTrace(new PrintWriter(errors));
                log.error(errors.toString());
            }
        }
    };
    t.start();
}
Also used : Response(jakarta.ws.rs.core.Response) AsyncResponse(jakarta.ws.rs.container.AsyncResponse) StringWriter(java.io.StringWriter) Logger(org.jboss.logging.Logger) PrintWriter(java.io.PrintWriter) Path(jakarta.ws.rs.Path) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

AsyncResponse (jakarta.ws.rs.container.AsyncResponse)59 Path (jakarta.ws.rs.Path)47 GET (jakarta.ws.rs.GET)43 Response (jakarta.ws.rs.core.Response)23 Produces (jakarta.ws.rs.Produces)16 PrintWriter (java.io.PrintWriter)13 StringWriter (java.io.StringWriter)13 Logger (org.jboss.logging.Logger)13 POST (jakarta.ws.rs.POST)10 ForbiddenException (jakarta.ws.rs.ForbiddenException)6 IOException (java.io.IOException)4 WebApplicationException (jakarta.ws.rs.WebApplicationException)3 CompletionCallback (jakarta.ws.rs.container.CompletionCallback)2 ContainerRequestContext (jakarta.ws.rs.container.ContainerRequestContext)2 ContainerRequestFilter (jakarta.ws.rs.container.ContainerRequestFilter)2 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)2 Date (java.util.Date)2 Objects (java.util.Objects)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2