private HttpServletResponse getResponse() { return (HttpServletResponse) continuation.getServletResponse(); }
private void handleContinuationExpired() { try { LOG.info("Continuation expired for {} after {} - returning 500", artifactDownloadRequest, JavaUtils.duration(start)); ((HttpServletResponse) continuation.getServletResponse()).sendError(500, "Hit client timeout"); } catch (Throwable t) { LOG.warn("{} while sending error after continuation for {}", t.getClass().getSimpleName(), artifactDownloadRequest.getTargetDirectory()); } finally { continuation.complete(); } }
@Override public void run() { try { if (!addDownloadRequest()) { if (continuation.isExpired()) { handleContinuationExpired(); return; } reEnqueue(); } } catch (Throwable t) { LOG.error("While trying to enqueue {}", artifactDownloadRequest.getTargetDirectory(), t); exceptionNotifier.notify(String.format("Error enqueuing download (%s)", t.getMessage()), t, ImmutableMap.of("targetDirectory", artifactDownloadRequest.getTargetDirectory())); try { ((HttpServletResponse) continuation.getServletResponse()).sendError(500); } catch (IOException e) { LOG.error("Couldn't send error for {}", artifactDownloadRequest.getTargetDirectory(), e); } finally { continuation.complete(); } } }
public EventSourceEmitter(EventSource eventSource, Continuation continuation) throws IOException { this.eventSource = eventSource; this.continuation = continuation; this.output = continuation.getServletResponse().getOutputStream(); }
public EventSourceEmitter(EventSource eventSource, Continuation continuation) throws IOException { this.eventSource = eventSource; this.continuation = continuation; this.output = continuation.getServletResponse().getOutputStream(); }
public EventSourceEmitter(EventSource eventSource, Continuation continuation) throws IOException { this.eventSource = eventSource; this.continuation = continuation; this.output = continuation.getServletResponse().getOutputStream(); }
public void onComplete(Continuation continuation) { ((HttpServletResponse)continuation.getServletResponse()).addHeader("history","onComplete"); }
@Override public void run() { ((HttpServletResponse)continuation.getServletResponse()).addHeader("history","resume"); continuation.resume(); } };
public void onTimeout(Continuation continuation) { ((HttpServletResponse)continuation.getServletResponse()).addHeader("history","onTimeout"); continuation.resume(); }
protected void flush() throws IOException { continuation.getServletResponse().flushBuffer(); }
protected void flush() throws IOException { continuation.getServletResponse().flushBuffer(); }
protected void flush() throws IOException { continuation.getServletResponse().flushBuffer(); }
/** * Method call to close the stream if you have no more data to send. */ @Override public void close() { try { continuation.getServletResponse().getWriter().close(); } catch (IOException ignore) { LOGGER.warn("Error during close of response", ignore); } continuation.complete(); } }
/** * Method to call to send next object to the stream. * @param object object to send. * @throws EndOfStreamException exception used to inform of end of stream. */ @Override public void next(Object object) throws EndOfStreamException { try { continuation.getServletResponse().getWriter().print("data: "); continuation.getServletResponse().getWriter().print(contentType.convertObject(object)); continuation.getServletResponse().getWriter().print("\n\n"); continuation.getServletResponse().getWriter().flush(); continuation.getServletResponse().flushBuffer(); } catch (IOException e) { continuation.complete(); throw new EndOfStreamException(e); } }
/** * Write datas for event-source. */ @Override public void run() { synchronized (handlerResponse) { try { Object data = handlerResponse.getAnswer().next(); if (data == null) { return; } continuation.getServletResponse().getWriter().print("data: "); continuation.getServletResponse().getWriter().print(contentType.convertObject(data)); continuation.getServletResponse().getWriter().print("\n\n"); continuation.getServletResponse().getWriter().flush(); continuation.getServletResponse().flushBuffer(); } catch (Exception ioException) { continuation.complete(); throw new RuntimeException("Clone event-source", ioException); } } }
public void warnAndSendHttpResponse(final Continuation httpContinuation, final Logger logger) { final HttpServletResponse httpResponse = (HttpServletResponse) httpContinuation.getServletResponse(); logger.log(Level.WARNING, this.getMessage(), this); try { httpResponse.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500, this.getMessage()); httpContinuation.complete(); } catch (final IOException io) { logger.log(Level.WARNING, "Can not send the HTTP error response", io); } } }
@Override public void onTimeout(final Continuation continuation) { final HttpServletResponse httpResponse = (HttpServletResponse) continuation.getServletResponse(); HTTPHelper.sendHTTPErrorResponse(logger, httpResponse, HttpStatus.GATEWAY_TIMEOUT_504, "Timeout"); continuation.complete(); }
public void warnAndSendHttpResponse(final Continuation httpContinuation, final Logger logger) { final HttpServletResponse httpResponse = (HttpServletResponse) httpContinuation.getServletResponse(); this.warnAndSendHttpResponse(httpResponse, logger); httpContinuation.complete(); }
public void cancel() { if (_continuation != null && _continuation.isSuspended() && !_continuation.isExpired()) { try { decBrowserId(); ((HttpServletResponse) _continuation.getServletResponse()).sendError(HttpServletResponse.SC_REQUEST_TIMEOUT); } catch (IOException x) { logger.trace("", x); } try { _continuation.complete(); } catch (Exception x) { logger.trace("", x); } } }
@Override public void onTimeout(Continuation cont) { if (continuation != null && cont == continuation) { continuation = null; if (isConnectionPersistant) { is_open = false; session.onDisconnect(DisconnectReason.TIMEOUT); abort(); } else { if (!is_open && buffer.isEmpty()) { session.onDisconnect(DisconnectReason.DISCONNECT); abort(); } else { try { finishSend(cont.getServletResponse()); } catch (IOException e) { session.onDisconnect(DisconnectReason.DISCONNECT); abort(); } } session.startTimeoutTimer(); } } }