/** * Get the context path section of an address * * @param addr * @return */ public static String getContextPath(String addr) { return getContextPathInternal(getPathFromString(addr)); }
/** * Get the final path section of an address (for servlet * container, this is typically a url-pattern for an endpoint) * * @param addr * @return */ public static String getPath(String addr) { return getPathInternal(getPathFromString(addr)); }
@Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
@Override public void handle(HttpExchange ex) throws IOException { try { delegate.handle(new HttpExchangeDelegate(ex)); } catch (IOException e) { e.printStackTrace(); throw e; } catch (RuntimeException e) { e.printStackTrace(); throw e; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
public synchronized void removeHandler(String address) { server.removeContext(PathUtils.getContextPath(address) + PathUtils.getPath(address)); handlerCount--; }
@Override public HttpContext getHttpContext() { if (contextDelegate == null) { contextDelegate = new HttpContextDelegate(delegate.getHttpContext(), PathUtils.getPath(delegate.getRequestURI())); } return contextDelegate; }
@Override public String getContextPath() { return PathUtils.getContextPath(delegate.getRequestURI()); }
@Override public void write(byte[] b, int off, int len) throws IOException { if (!written) { onFirstWrite(); written = true; } if (wrappedStream != null) { wrappedStream.write(b, off, len); } }
private static String getContextPathInternal(String rawpath) { String path = removeTrailingSlash(rawpath); if (path == null || path.length() == 0) { return "/"; } int idx = path.lastIndexOf("/"); return idx > 0 ? path.substring(0, idx) : path; }
public static String getPath(URI addr) { return getPathInternal(addr.getPath()); }
public static String getContextPath(URI addr) { return getContextPathInternal(addr.getPath()); }
public static HttpContext createHttpContext(HttpServer server, String contextPath, String path) { return new HttpContextDelegate(server.createContext(contextPath + path), path); } }
@Override public void setHandler(HttpHandler handler) { if (handler instanceof com.sun.net.httpserver.HttpHandler) { delegate.setHandler((com.sun.net.httpserver.HttpHandler) handler); } else { delegate.setHandler(new HttpHandlerDelegate(handler)); } }
@Override public void handle(HttpExchange ex) throws IOException { ClassLoader origClassLoader = SecurityActions.getContextClassLoader(); try { SecurityActions.setContextClassLoader(this.classLoader); this.handle(new HttpExchangeDelegate(ex)); } catch (Exception e) { LOG.throwing(Handler.class.getName(), "handle(" + HttpExchange.class.getName() + " ex)", e); if (e instanceof IOException) { throw (IOException) e; } else { throw new RuntimeException(e); } } finally { SecurityActions.setContextClassLoader(origClassLoader); } } }
public synchronized void addHandler(String address, HttpHandler handler) { if (server == null) //start the server on first call { InetSocketAddress isa = host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port); try { server = HttpServer.create(isa, BACKLOG); server.setExecutor(Executors.newCachedThreadPool()); server.start(); } catch (IOException e) { throw new RuntimeException(e); } } server.createContext(PathUtils.getContextPath(address) + PathUtils.getPath(address), handler); handlerCount++; }
@Override public void write(int b) throws IOException { if (!written) { onFirstWrite(); written = true; } if (wrappedStream != null) { wrappedStream.write(b); } }
private static String getPathInternal(String rawpath) { String path = removeTrailingSlash(rawpath); if (path == null || path.length() == 0) { return path; } int idx = path.lastIndexOf("/"); return idx > 0 ? path.substring(path.lastIndexOf("/")) : ""; }
this.handle(new HttpExchangeDelegate(ex));
this.handle(new HttpExchangeDelegate(ex));