public synchronized MockHttpExchange createExchange(String method, String path) { HttpContext best = null; int bestLength = -1; for (HttpContext context : contexts) { if (path.startsWith(context.getPath()) && context.getPath().length() > bestLength) { best = context; bestLength = context.getPath().length(); } } if (best == null) { return null; } return new MockHttpExchange(method, path, best); }
/* */ public synchronized void removeContext(HttpContext paramHttpContext) throws IllegalArgumentException { /* 239 */ if (!(paramHttpContext instanceof HttpContextImpl)) { /* 240 */ throw new IllegalArgumentException("wrong HttpContext type"); /* */ } /* 242 */ this.contexts.remove((HttpContextImpl)paramHttpContext); /* 243 */ this.logger.config("context removed: " + paramHttpContext.getPath()); /* */ }
@Override public synchronized HttpContext createContext(String path) { HttpContext context = instantiateContext(path); for (HttpContext trailContext : contexts) { if (path.equals(trailContext.getPath())) { throw new IllegalArgumentException("Handler already exists for path"); } } contexts.add(context); return context; }
/* * Removes a context. If the server doesn't have anymore contexts, it * would stop the server and server is removed from servers Map. */ /*package*/ void removeContext(HttpContext context) { InetSocketAddress inetAddress = context.getServer().getAddress(); synchronized (servers) { ServerState state = servers.get(inetAddress); int instances = state.noOfContexts(); if (instances < 2) { ((ExecutorService) state.getServer().getExecutor()).shutdown(); state.getServer().stop(0); servers.remove(inetAddress); } else { state.getServer().removeContext(context); state.oneLessContext(context.getPath()); } } }
@Override public synchronized void removeContext(String path) { if (path == null) { throw new NullPointerException(); } Iterator<HttpContext> iter = contexts.iterator(); while (iter.hasNext()) { HttpContext context = iter.next(); if (context.getPath().equals(path)) { iter.remove(); // Completed. return; } } // Not found. throw new IllegalArgumentException(); }
@Override public void removeContext(HttpContext context) { removeContext(context.getPath()); }