@Test public void testBindObservable_exceptions() throws IOException { Observable<Integer> obs = Observable.range(1, 100); doThrow(ClientAbortException.class).when(emitter).send(anyInt()); SseEmitterUtil.bindObservable(emitter, obs); verify(emitter, times(100)).send(anyInt()); reset(emitter); obs = Observable.range(1, 100); doThrow(new IllegalStateException("ResponseBodyEmitter is already set complete")).when(emitter).send(anyInt()); SseEmitterUtil.bindObservable(emitter, obs); verify(emitter, times(100)).send(anyInt()); reset(emitter); obs = Observable.range(1, 100); doThrow(new IllegalStateException("Unit Test")).when(emitter).send(anyInt()); SseEmitterUtil.bindObservable(emitter, obs); verify(emitter, times(1)).send(anyInt()); verify(emitter).completeWithError(any()); reset(emitter); obs = Observable.range(1, 100); doThrow(new RuntimeException("Unit Test")).when(emitter).send(anyInt()); SseEmitterUtil.bindObservable(emitter, obs); verify(emitter, times(1)).send(anyInt()); verify(emitter).completeWithError(any()); }
@ExceptionHandler(ClientAbortException.class) @ResponseBody public ErrorResponse connectionAbort(final ClientAbortException e) { // Tomcat-specific exception when existing request is aborted by client log.debug("Client aborted connection", e); return null; }
@ExceptionHandler({ClientAbortException.class}) public ResponseEntity<GenericMessage<String>> connection_reset_by_peer(Exception e) { log.error("connection_reset_by_peer {}", e.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(messageOf(new RuntimeException(e.getMessage()))); }
@ExceptionHandler(ClientAbortException.class) public void clientAbortException(ClientAbortException e) { // Nothing to respond here as client has terminated connection }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (log.isDebugEnabled()) log.debug("service("); if (log.isDebugEnabled()) { log.debug("method=" + request.getMethod()); log.debug("params= " + request.getParameterMap()); } int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; Throwable ex = null; try { if (httpHeaderkeepAliveTimeout != null) { response.addHeader("Connection", "Keep-Alive"); response.addHeader("Keep-Alive", "timeout=" + httpHeaderkeepAliveTimeout); } super.service(request, response); status = response.getStatus(); } catch (Throwable e) { ex = e; if (!(e instanceof ClientAbortException)) { if (e instanceof FileNotFoundException) { status = HttpServletResponse.SC_NOT_FOUND; } if (!response.isCommitted()) { try { response.sendError(status, e.getMessage()); } catch (Throwable e2) { log.debug("ex2=" + e2 + " caused by:", e); } } } } finally { switch (status) { case HttpServletResponse.SC_OK: case BExceptionC.RESEND_LONG_POLL: case BExceptionC.UNAUTHORIZED: case BExceptionC.SESSION_CLOSED: if (log.isDebugEnabled()) log.debug(makeLogRequest(request, status)); break; case BExceptionC.FORBIDDEN: case BExceptionC.TIMEOUT: if (log.isInfoEnabled()) log.info(makeLogRequest(request, status)); break; default: if (log.isInfoEnabled()) log.info(makeLogRequest(request, status), ex); break; } } if (log.isDebugEnabled()) log.debug(")service"); }