@GET public void getList(@Suspended final AsyncResponse ar) throws NamingException { ar.setTimeoutHandler(new TimeoutHandler() { @Override public void handleTimeout(AsyncResponse ar) { ar.resume("Operation timed out"); } }); ar.setTimeout(4000, TimeUnit.MILLISECONDS); ar.register(new MyCompletionCallback()); ar.register(new MyConnectionCallback()); ManagedThreadFactory threadFactory = (ManagedThreadFactory) new InitialContext() .lookup("java:comp/DefaultManagedThreadFactory"); Executors.newSingleThreadExecutor(threadFactory).submit(new Runnable() { @Override public void run() { try { Thread.sleep(3000); ar.resume(response[0]); } catch (InterruptedException ex) { } } }); }
public static void setTimeout(long timeout, AsyncResponse asyncResponse) { asyncResponse.setTimeout(timeout, TimeUnit.MILLISECONDS); asyncResponse.setTimeoutHandler(resp -> resp.resume( Response.status(Response.Status.GATEWAY_TIMEOUT) .entity("HTTP GET timed out after " + timeout + " ms\n") .build())); }
public static void setTimeout(long timeout, AsyncResponse asyncResponse) { asyncResponse.setTimeout(timeout, TimeUnit.MILLISECONDS); asyncResponse.setTimeoutHandler(resp -> resp.resume( Response.status(Response.Status.GATEWAY_TIMEOUT) .entity("HTTP GET timed out after " + timeout + " ms\n") .build())); }
public static IInputStreamConsumer to(AsyncResponse asyncResponse, DocumentType targetType, long requestTimeout) { AsynchronousConversionResponse response = new AsynchronousConversionResponse(asyncResponse, targetType); asyncResponse.setTimeoutHandler(response); asyncResponse.setTimeout(requestTimeout, TimeUnit.MILLISECONDS); return response; }
private void configResponse(final AsyncResponse asyncResponse) { asyncResponse.register((CompletionCallback)throwable -> { if (throwable == null) { log.info("CompletionCallback-onComplete: OK"); } else { log.info("CompletionCallback-onComplete: ERROR: " + throwable.getMessage()); } }); asyncResponse.register((ConnectionCallback)disconnected -> { //Status.GONE=410 log.info("ConnectionCallback-onDisconnect"); disconnected.resume(Response.status(Response.Status.GONE).entity("disconnect!").build()); }); asyncResponse.setTimeoutHandler(r -> { //Status.SERVICE_UNAVAILABLE=503 log.info("TIMEOUT"); r.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("Operation time out.").build()); }); asyncResponse.setTimeout(TIMEOUT, TimeUnit.SECONDS); }
@POST @Path("bid/{exchangeId}/{key}") public void handleBid(@PathParam("exchangeId") final String exchangeId, @PathParam("key") final String key, final OrtbBidRequest request, @Suspended final AsyncResponse asyncResponse) throws FilterException, IOException { // Timeout for clarity. asyncResponse.setTimeout(timeoutMs, TimeUnit.MILLISECONDS); asyncResponse.setTimeoutHandler(timeoutHandler); // Sending no data as an example asyncResponse.resume(Response.noContent().build()); }
public StreamingAsyncSubscriber(AsyncResponse ar, String openTag, String closeTag, String sep, long pollTimeout, long asyncTimeout) { super(ar); this.openTag = openTag; this.closeTag = closeTag; this.separator = sep; this.pollTimeout = pollTimeout; this.asyncTimeout = 0; if (asyncTimeout > 0) { ar.setTimeout(asyncTimeout, TimeUnit.MILLISECONDS); ar.setTimeoutHandler(new TimeoutHandlerImpl()); } } @Override
public StreamingAsyncSubscriber(AsyncResponse ar, String openTag, String closeTag, String sep, long pollTimeout, long asyncTimeout) { super(ar); this.openTag = openTag; this.closeTag = closeTag; this.separator = sep; this.pollTimeout = pollTimeout; this.asyncTimeout = 0; if (asyncTimeout > 0) { ar.setTimeout(asyncTimeout, TimeUnit.MILLISECONDS); ar.setTimeoutHandler(new TimeoutHandlerImpl()); } } @Override
public AsyncResponseHandler withTimeout(Duration timeout, Supplier<Response> timeoutResponse) { asyncResponse.setTimeoutHandler(asyncResponse -> { asyncResponse.resume(timeoutResponse.get()); cancelFuture(); }); asyncResponse.setTimeout(timeout.toMillis(), MILLISECONDS); return this; }
public AsyncResponseHandler withTimeout(Duration timeout, Supplier<Response> timeoutResponse) { asyncResponse.setTimeoutHandler(asyncResponse -> { asyncResponse.resume(timeoutResponse.get()); cancelFuture(); }); asyncResponse.setTimeout(timeout.toMillis(), MILLISECONDS); return this; }
public AsyncResponseHandler withTimeout(Duration timeout, Supplier<Response> timeoutResponse) { asyncResponse.setTimeoutHandler(asyncResponse -> { asyncResponse.resume(timeoutResponse.get()); cancelFuture(); }); asyncResponse.setTimeout(timeout.toMillis(), MILLISECONDS); return this; }
JsonPolicyDef.Policy.NOTIFICATION_TO_CLIENT); asyncResponse.setTimeoutHandler(asyncRes -> asyncRes.resume(response));
@GET @Produces( "text/plain" ) public void poll( @Suspended final AsyncResponse response, @NotNull @HeaderParam( SharedConstants.CONNECTION_ID_HEADER ) final String sessionId, @NotNull @QueryParam( SharedConstants.RECEIVE_SEQUENCE_PARAM ) final int rxSequence ) { response.setTimeout( getPollTime(), TimeUnit.SECONDS ); response.register( (ConnectionCallback) this::doDisconnect ); response.setTimeoutHandler( this::doTimeout ); try { final String data = poll( sessionId, rxSequence ); if ( null != data ) { resume( response, data ); } else { _requests.put( response, new SuspendedRequest( sessionId, rxSequence, response ) ); } } catch ( final Exception e ) { handleException( sessionId, response, e ); } }
@GET @Path("/books/timeouthandlerresume/{id}") public void getBookDescriptionWithHandlerResumeOnly(@PathParam("id") String id, @Suspended AsyncResponse async) { async.setTimeout(1000, TimeUnit.MILLISECONDS); async.setTimeoutHandler(new TimeoutHandlerImpl(id, true)); }
@GET @Path("/books/timeouthandler/{id}") public void getBookDescriptionWithHandler(@PathParam("id") String id, @Suspended AsyncResponse async) { async.setTimeout(1000, TimeUnit.MILLISECONDS); async.setTimeoutHandler(new TimeoutHandlerImpl(id, false)); }
@GET @Path("/books/cancel") public void getBookDescriptionWithCancel(@PathParam("id") String id, @Suspended AsyncResponse async) { PhaseInterceptorChain.getCurrentMessage().getClass(); async.setTimeout(2000, TimeUnit.MILLISECONDS); async.setTimeoutHandler(new CancelTimeoutHandlerImpl()); }
@GET @Path("books/suspend/unmapped") @Produces("text/plain") public void handleNotMappedAfterSuspend(@Suspended AsyncResponse response) throws BookNotFoundFault { response.setTimeout(2000, TimeUnit.MILLISECONDS); response.setTimeoutHandler(new CancelTimeoutHandlerImpl()); throw new BookNotFoundFault(""); }
asyncResponse.setTimeoutHandler(asyncRes -> asyncRes.resume(ResponseFactory.response(Response.Status.NO_CONTENT)));
Policy.COMMAND_LISTED); asyncResponse.setTimeoutHandler(asyncRes -> asyncRes.resume(response));
response.setTimeoutHandler((asyncResp) -> asyncResp.resume(Response.status(Response.Status.REQUEST_TIMEOUT).build())); try {