Search in sources :

Example 11 with AsyncResponse

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

the class JaxrsAsyncServletResource 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 12 with AsyncResponse

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

the class JaxrsAsyncServletResource method setTimeoutHandler.

@POST
@Path("timeouthandler")
public void setTimeoutHandler(@QueryParam("stage") String stage, int handlerValue) {
    JaxrsAsyncServletTimeoutHandler handler = new JaxrsAsyncServletTimeoutHandler(handlerValue);
    AsyncResponse async = takeAsyncResponse(stage);
    async.setTimeoutHandler(handler);
    async.setTimeout(200L, TimeUnit.MILLISECONDS);
    addResponse(async, stage);
}
Also used : AsyncResponse(jakarta.ws.rs.container.AsyncResponse) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 13 with AsyncResponse

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

the class JaxrsAsyncServletResource 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 14 with AsyncResponse

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

the class JaxrsAsyncServletResource method resume.

@POST
@Path("resume")
public String resume(@QueryParam("stage") String stage, String response) {
    AsyncResponse async = takeAsyncResponse(stage);
    boolean b = resume(async, response);
    addResponse(async, stage);
    return b ? TRUE : FALSE;
}
Also used : AsyncResponse(jakarta.ws.rs.container.AsyncResponse) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 15 with AsyncResponse

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

the class LegacySuspendResource method timeout.

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

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                Response jaxrs = Response.ok("hello").type(MediaType.TEXT_PLAIN).build();
                response.resume(jaxrs);
            } catch (Exception e) {
                StringWriter errors = new StringWriter();
                e.printStackTrace(new PrintWriter(errors));
                logger.error(errors.toString());
            }
        }
    };
    t.start();
}
Also used : Response(jakarta.ws.rs.core.Response) AsyncResponse(jakarta.ws.rs.container.AsyncResponse) StringWriter(java.io.StringWriter) 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