public static boolean isConnectionOpen(HttpServletRequest request, byte[] heartbeat) { Request jettyRequest = (Request) request; AbstractHttpConnection connection = jettyRequest.getConnection(); Socket socket = (Socket) connection.getEndPoint().getTransport(); if (log.isLoggable(Level.FINE)) log.fine("Checking if client connection is still open: " + socket.getRemoteSocketAddress()); try { socket.getOutputStream().write(heartbeat); socket.getOutputStream().flush(); return true; } catch (IOException ex) { if (log.isLoggable(Level.FINE)) log.fine("Client connection has been closed: " + socket.getRemoteSocketAddress()); return false; } }
public static boolean isConnectionOpen(HttpServletRequest request, byte[] heartbeat) { Request jettyRequest = (Request)request; AbstractHttpConnection connection = jettyRequest.getConnection(); Socket socket = (Socket)connection.getEndPoint().getTransport(); if (log.isLoggable(Level.FINE)) log.fine("Checking if client connection is still open: " + socket.getRemoteSocketAddress()); try { socket.getOutputStream().write(heartbeat); socket.getOutputStream().flush(); return true; } catch (IOException ex) { if (log.isLoggable(Level.FINE)) log.fine("Client connection has been closed: " + socket.getRemoteSocketAddress()); return false; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection(); connection.getRequest().setHandled(true); response.setContentType(MimeTypes.TEXT_PLAIN_8859_1); ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096); writer.write(request.getAttribute(Dispatcher.ERROR_STATUS_CODE) + " " + request.getAttribute(Dispatcher.ERROR_MESSAGE) + " " + request.getAttribute(Dispatcher.ERROR_REQUEST_URI)); writer.flush(); response.setContentLength(writer.size()); writer.writeTo(response.getOutputStream()); writer.destroy(); }
@Override protected Request getRequest(final Object[] args) { if (args == null || args.length < 1) { return null; } if (args[0] instanceof AbstractHttpConnection) { try { AbstractHttpConnection connection = (AbstractHttpConnection) args[0]; return connection.getRequest(); } catch (Throwable ignored) { } } return null; }