protected void resetRequest() { synchronized (this.responseLock) { ServerHttpAsyncRequestControl control = this.asyncRequestControl; this.asyncRequestControl = null; this.readyToSend = false; this.response = null; updateLastActiveTime(); if (control != null && !control.isCompleted()) { if (control.isStarted()) { try { control.complete(); } catch (Throwable ex) { // Could be part of normal workflow (e.g. browser tab closed) logger.debug("Failed to complete request: " + ex.getMessage()); } } } } }
/** * Start asynchronous support or if unavailable return {@code null} to cause * {@link #waitForResponse()} to block. * @return the async request control */ protected ServerHttpAsyncRequestControl startAsync() { try { // Try to use async to save blocking ServerHttpAsyncRequestControl async = this.request .getAsyncRequestControl(this.response); async.start(); return async; } catch (Exception ex) { return null; } }
@Test public void httpConnectionAsync() throws Exception { ServerHttpAsyncRequestControl async = mock(ServerHttpAsyncRequestControl.class); ServerHttpRequest request = mock(ServerHttpRequest.class); given(request.getAsyncRequestControl(this.response)).willReturn(async); HttpConnection connection = new HttpConnection(request, this.response); connection.waitForResponse(); verify(async).start(); connection.respond(HttpStatus.NO_CONTENT); verify(async).complete(); }
/** * Start asynchronous support or if unavailble return {@code null} to cause * {@link #waitForResponse()} to block. * @return the async request control */ protected ServerHttpAsyncRequestControl startAsync() { try { // Try to use async to save blocking ServerHttpAsyncRequestControl async = this.request .getAsyncRequestControl(this.response); async.start(); return async; } catch (Exception ex) { return null; } }
@Override public boolean isActive() { ServerHttpAsyncRequestControl control = this.asyncRequestControl; return (control != null && !control.isCompleted()); }
@Override protected ServerHttpAsyncRequestControl startAsync() { getServletRequest().setAsyncSupported(true); return super.startAsync(); }