/** * Shutdown the server. * * @throws Exception * the server refuses to halt, or wasn't running. */ public void tearDown() throws Exception { RecordingLogger.clear(); log.clear(); server.stop(); }
/** @return all requests since the server was started. */ public List<AccessEvent> getRequests() { return new ArrayList<AccessEvent>(log.getEvents()); }
public AppServer() { connector = new SelectChannelConnector(); connector.setPort(0); try { final InetAddress me = InetAddress.getByName("localhost"); connector.setHost(me.getHostAddress()); } catch (UnknownHostException e) { throw new RuntimeException("Cannot find localhost", e); } contexts = new ContextHandlerCollection(); log = new TestRequestLog(); log.setHandler(contexts); server = new Server(); server.setConnectors(new Connector[] { connector }); server.setHandler(log); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { for (;;) { try { active.acquire(); break; } catch (InterruptedException e) { continue; } } super.handle(target, baseRequest, request, response); if (DispatcherType.REQUEST.equals(baseRequest.getDispatcherType())) log((Request) request, (Response) response); } finally { active.release(); } }
log = new TestRequestLog(); log.setHandler(contexts);
/** {@inheritDoc} */ @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { for (;;) { try { active.acquire(); break; } catch (InterruptedException e) { continue; } } super.handle(target, baseRequest, request, response); if (DispatcherType.REQUEST.equals(baseRequest.getDispatcherType())) log((Request) request, (Response) response); } finally { active.release(); } }
/** * Get requests. * * @return all requests since the server was started. */ public List<AccessEvent> getRequests() { return new ArrayList<>(log.getEvents()); }
/** * Start the server on a random local port. * * @throws Exception * the server cannot be started, testing is not possible. */ public void setUp() throws Exception { RecordingLogger.clear(); log.clear(); server.start(); }
/** * @param path * the path to locate requests for. * @return all requests which match the given path. */ public List<AccessEvent> getRequests(String path) { ArrayList<AccessEvent> r = new ArrayList<AccessEvent>(); for (AccessEvent event : log.getEvents()) { if (event.getPath().equals(path)) { r.add(event); } } return r; }
/** * Shutdown the server. * * @throws Exception * the server refuses to halt, or wasn't running. */ public void tearDown() throws Exception { RecordingLogger.clear(); log.clear(); server.stop(); for (File f : filesToDelete) { f.delete(); } filesToDelete.clear(); }
/** * Get requests. * * @param path * the path to locate requests for. * @return all requests which match the given path. */ public List<AccessEvent> getRequests(String path) { ArrayList<AccessEvent> r = new ArrayList<>(); for (AccessEvent event : log.getEvents()) { if (event.getPath().equals(path)) { r.add(event); } } return r; }
/** * Start the server on a random local port. * * @throws Exception * the server cannot be started, testing is not possible. */ public void setUp() throws Exception { RecordingLogger.clear(); log.clear(); server.start(); config.setSecurePort(getSecurePort()); if (secureConfig != null) { secureConfig.setSecurePort(getSecurePort()); } }