/** * Constructor for <code>SimpleHttpServer</code>. * * @param repository * @param withSsl */ public SimpleHttpServer(Repository repository, boolean withSsl) { this.db = repository; server = new AppServer(0, withSsl ? 0 : -1); }
public ServletContextHandler authBasic(ServletContextHandler ctx) { assertNotYetSetUp(); auth(ctx, new BasicAuthenticator()); return ctx; }
/** * Get requests. * * @return list of events */ protected List<AccessEvent> getRequests() { return server.getRequests(); }
/** * Start the server * * @throws Exception */ public void start() throws Exception { ServletContextHandler sBasic = server.authBasic(smart("/sbasic")); server.setUp(); final String srcName = db.getDirectory().getName(); uri = toURIish(sBasic, srcName); int sslPort = server.getSecurePort(); if (sslPort > 0) { secureUri = uri.setPort(sslPort).setScheme("https"); } }
/** * Get the URI to reference this server. * <p> * The returned URI includes the proper host name and port number, but does * not contain a path. * * @return URI to reference this server's root context. */ public URI getURI() { assertAlreadySetUp(); String host = connector.getHost(); if (host.contains(":") && !host.startsWith("[")) host = "[" + host + "]"; final String uri = "http://" + host + ":" + getPort(); try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException("Unexpected URI error on " + uri, e); } }
private URIish toURIish(String path) throws URISyntaxException { URI u = server.getURI().resolve(path); return new URIish(u.toString()); }
/** * Get port. * * @return the local port number the server is listening on. */ public int getPort() { assertAlreadySetUp(); return connector.getLocalPort(); }
private ServletContextHandler smart(final String path) { GitServlet gs = new GitServlet(); gs.setRepositoryResolver(new RepositoryResolver<HttpServletRequest>() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { if (!name.equals(nameOf(db))) throw new RepositoryNotFoundException(name); db.incrementOpen(); return db; } }); ServletContextHandler ctx = server.addContext(path); ctx.addServlet(new ServletHolder(gs), "/*"); return ctx; }
/** * Create a new servlet context within the server. * <p> * This method should be invoked before the server is started, once for each * context the caller wants to register. * * @param path * path of the context; use "/" for the root context if binding * to the root is desired. * @return the context to add servlets into. */ public ServletContextHandler addContext(String path) { assertNotYetSetUp(); if ("".equals(path)) path = "/"; ServletContextHandler ctx = new ServletContextHandler(); ctx.setContextPath(path); contexts.addHandler(ctx); return ctx; }
/** * Get the URI to reference this server. * <p> * The returned URI includes the proper host name and port number, but does * not contain a path. * * @return URI to reference this server's root context. */ public URI getURI() { assertAlreadySetUp(); String host = connector.getHost(); if (host.contains(":") && !host.startsWith("[")) host = "[" + host + "]"; final String uri = "http://" + host + ":" + getPort(); try { return new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException("Unexpected URI error on " + uri, e); } }
protected URIish toURIish(String path) throws URISyntaxException { URI u = server.getURI().resolve(path); return new URIish(u.toString()); }
/** @return the local port number the server is listening on. */ public int getPort() { assertAlreadySetUp(); return ((SelectChannelConnector) connector).getLocalPort(); }
private ServletContextHandler smart(String path) { GitServlet gs = new GitServlet(); gs.setRepositoryResolver(new RepositoryResolver<HttpServletRequest>() { @Override public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { if (!name.equals(nameOf(db))) throw new RepositoryNotFoundException(name); db.incrementOpen(); return db; } }); ServletContextHandler ctx = server.addContext(path); ctx.addServlet(new ServletHolder(gs), "/*"); return ctx; }
/** * Create a new servlet context within the server. * <p> * This method should be invoked before the server is started, once for each * context the caller wants to register. * * @param path * path of the context; use "/" for the root context if binding * to the root is desired. * @return the context to add servlets into. */ public ServletContextHandler addContext(String path) { assertNotYetSetUp(); if ("".equals(path)) path = "/"; ServletContextHandler ctx = new ServletContextHandler(); ctx.setContextPath(path); contexts.addHandler(ctx); return ctx; }
/** * Get requests. * * @param base * @param path * * @return list of events */ protected List<AccessEvent> getRequests(URIish base, String path) { return server.getRequests(base, path); }
/** * Configure basic authentication. * * @param ctx * @param methods * @return servlet context handler */ public ServletContextHandler authBasic(ServletContextHandler ctx, String... methods) { assertNotYetSetUp(); auth(ctx, new BasicAuthenticator(), methods); return ctx; }
public SimpleHttpServer(Repository repository) { this.db = repository; server = new AppServer(); }
/** * Convert path to URIish * * @param path * @return the URIish * @throws URISyntaxException */ protected URIish toURIish(String path) throws URISyntaxException { URI u = server.getURI().resolve(path); return new URIish(u.toString()); }
/** * Get secure port. * * @return the HTTPS port or -1 if not configured. */ public int getSecurePort() { assertAlreadySetUp(); return secureConnector != null ? secureConnector.getLocalPort() : -1; }