public static HttpServer createTestServer(Configuration conf, AccessControlList adminsAcl) throws IOException { prepareTestWebapp(); return createServer(TEST, conf, adminsAcl); }
/** * Recursively deletes a {@link File}. */ protected static void deleteRecursively(File d) { if (d.isDirectory()) { for (String name : d.list()) { File child = new File(d, name); if (child.isFile()) { child.delete(); } else { deleteRecursively(child); } } } d.delete(); }
/** * Prepare the test webapp by creating the directory from the test properties * fail if the directory cannot be created. * @throws AssertionError if a condition was not met */ protected static void prepareTestWebapp() { String webapps = System.getProperty(TEST_BUILD_WEBAPPS, BUILD_WEBAPPS_DIR); File testWebappDir = new File(webapps + File.separatorChar + TEST); try { if (!testWebappDir.exists()) { fail("Test webapp dir " + testWebappDir.getCanonicalPath() + " missing"); } } catch (IOException e) { } }
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(); } /**
/** * 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; }
/** * Pass in a server, return a URL bound to localhost and its port * @param server server * @return a URL bonded to the base of the server * @throws MalformedURLException if the URL cannot be created. */ public static URL getServerURL(HttpServer server) throws MalformedURLException { assertNotNull("No server", server); return new URL("http://" + NetUtils.getHostPortString(server.getConnectorAddress(0))); }
@Override public void run() { ready.countDown(); try { start.await(); assertEquals("a:b\nc:d\n", readOutput(new URL(baseUrl, "/echo?a=b&c=d"))); int serverThreads = server.webServer.getThreadPool().getThreads(); assertTrue("More threads are started than expected, Server Threads count: " + serverThreads, serverThreads <= MAX_THREADS); System.out.println("Number of threads = " + serverThreads + " which is less or equal than the max = " + MAX_THREADS); } catch (Exception e) { // do nothing } } });
@Override public HttpResponse run() throws Exception { // Logs in with Kerberos via GSS GSSManager gssManager = GSSManager.getInstance(); // jGSS Kerberos login constant Oid oid = new Oid("1.2.840.113554.1.2.2"); GSSName gssClient = gssManager.createName(principalName, GSSName.NT_USER_NAME); GSSCredential credential = gssManager.createCredential(gssClient, GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); HttpClientContext context = HttpClientContext.create(); Lookup<AuthSchemeProvider> authRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)) .build(); HttpClient client = HttpClients.custom().setDefaultAuthSchemeRegistry(authRegistry).build(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); URL url = new URL(getServerURL(server), "/echo?a=b"); context.setTargetHost(new HttpHost(url.getHost(), url.getPort())); context.setCredentialsProvider(credentialsProvider); context.setAuthSchemeRegistry(authRegistry); HttpGet get = new HttpGet(url.toURI()); return client.execute(get, context); } });
/** * Create an HttpServer instance on the given address for the given webapp * @param host to bind * @param port to bind * @return the server * @throws IOException if it could not be created */ public static HttpServer createServer(String host, int port) throws IOException { prepareTestWebapp(); return new HttpServer.Builder().setName(TEST) .addEndpoint(URI.create("http://" + host + ":" + port)) .setFindPort(true).build(); }
/** * 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(); }
/** * Create but do not start the test webapp server. The test webapp dir is * prepared/checked in advance. * @param conf the server configuration to use * @return the server instance * * @throws IOException if a problem occurs * @throws AssertionError if a condition was not met */ public static HttpServer createTestServer(Configuration conf) throws IOException { prepareTestWebapp(); return createServer(TEST, conf); }
/** * 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(); }
/** * 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(); }
/** * Create but do not start the test webapp server. The test webapp dir is * prepared/checked in advance. * @param conf the server configuration to use * @return the server instance * * @throws IOException if a problem occurs * @throws AssertionError if a condition was not met */ public static HttpServer createTestServer(Configuration conf, String[] pathSpecs) throws IOException { prepareTestWebapp(); return createServer(TEST, conf, pathSpecs); }