/** * Add a servlet in the server. * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class */ public void addServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { addInternalServlet(name, pathSpec, clazz, false); addFilterPathMapping(pathSpec, webAppContext); }
@Override public void write(int b) throws IOException { data[0] = (byte) b; quoteHtmlChars(out, data, 0, 1); }
/** * @param infoServer that we're trying to send all requests to * @param hostname may be null. if given, will be used for redirects instead of host from client. */ public RedirectServlet(InfoServer infoServer, String hostname) { regionServerInfoPort = infoServer.getPort(); regionServerHostname = hostname; }
/** * Create an HttpServer instance for the given webapp * @param webapp the webapp to work with * @param conf the configuration to use for the server * @param pathSpecs the paths specifications the server will service * @return the server * @throws IOException if it could not be created */ public static HttpServer createServer(String webapp, Configuration conf, String[] pathSpecs) throws IOException { return localServerBuilder(webapp).setFindPort(true).setConf(conf).setPathSpec(pathSpecs).build(); }
public static HttpServer createTestServerWithSecurity(Configuration conf) throws IOException { prepareTestWebapp(); return localServerBuilder(TEST).setFindPort(true).setConf(conf).setSecurityEnabled(true) // InfoServer normally sets these for us .setUsernameConfKey(HttpServer.HTTP_SPNEGO_AUTHENTICATION_PRINCIPAL_KEY) .setKeytabConfKey(HttpServer.HTTP_SPNEGO_AUTHENTICATION_KEYTAB_KEY) .build(); }
/** * Create an HttpServer instance for the given webapp * @param webapp the webapp to work with * @return the server * @throws IOException if it could not be created */ public static HttpServer createServer(String webapp) throws IOException { return localServerBuilder(webapp).setFindPort(true).build(); } /**
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Do the authorization if (HttpServer.hasAdministratorAccess(getServletContext(), request, response)) { // Authorization is done. Just call super. super.doGet(request, response); } } }
/** * Check that a server is alive by probing the {@link HttpServer#isAlive()} method * and the text of its toString() description * @param server server */ private void assertAlive(HttpServer server) { assertTrue("Server is not alive", server.isAlive()); assertToStringContains(server, HttpServer.STATE_DESCRIPTION_ALIVE); }
/** * Create and start a server with the test webapp * * @return the newly started server * * @throws IOException on any failure * @throws AssertionError if a condition was not met */ public static HttpServer createAndStartTestServer() throws IOException { HttpServer server = createTestServer(); server.start(); return server; }
public void addServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { this.httpServer.addServlet(name, pathSpec, clazz); }
/** * If the server is non null, stop it * @param server to stop * @throws Exception on any failure */ public static void stop(HttpServer server) throws Exception { if (server != null) { server.stop(); } }
/** * Add an internal servlet in the server. * Note: This method is to be used for adding servlets that facilitate * internal communication and not for user facing functionality. For * servlets added using this method, filters are not enabled. * * @param name The name of the servlet (can be passed as null) * @param pathSpec The path spec for the servlet * @param clazz The servlet class */ public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz) { addInternalServlet(name, pathSpec, clazz, false); }
public String getWebAppsPath(String appName) throws FileNotFoundException { return getWebAppsPath(this.appDir, appName); }
public static HttpServer createTestServer(Configuration conf, AccessControlList adminsAcl) throws IOException { prepareTestWebapp(); return createServer(TEST, conf, adminsAcl); }
/** * Assert that the result of {@link HttpServer#toString()} contains the specific text * @param server server to examine * @param text text to search for */ private void assertToStringContains(HttpServer server, String text) { String description = server.toString(); assertTrue("Did not find \"" + text + "\" in \"" + description + "\"", description.contains(text)); }
/** * Create an HttpServer instance for the given webapp * @param webapp the webapp to work with * @param conf the configuration to use for the server * @return the server * @throws IOException if it could not be created */ public static HttpServer createServer(String webapp, Configuration conf) throws IOException { return localServerBuilder(webapp).setFindPort(true).setConf(conf).build(); }
private void assertNotLive(HttpServer server) { assertTrue("Server should not be live", !server.isAlive()); assertToStringContains(server, HttpServer.STATE_DESCRIPTION_NOT_LIVE); }
@Override public void write(byte[] data, int off, int len) throws IOException { quoteHtmlChars(out, data, off, len); }
/** * Create but do not start the test webapp server. The test webapp dir is * prepared/checked in advance. * * @return the server instance * * @throws IOException if a problem occurs * @throws AssertionError if a condition was not met */ public static HttpServer createTestServer() throws IOException { prepareTestWebapp(); return createServer(TEST); }
public static HttpServer createServer(String webapp, Configuration conf, AccessControlList adminsAcl) throws IOException { return localServerBuilder(webapp).setFindPort(true).setConf(conf).setACL(adminsAcl).build(); }