Esempio n. 1
0
 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());
/*     */   }
Esempio n. 3
0
 @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;
 }
Esempio n. 4
0
 /*
  * 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());
     }
   }
 }
Esempio n. 5
0
 @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());
 }