Search in sources :

Example 46 with HttpServer

use of com.sun.net.httpserver.HttpServer in project cloudstack by apache.

the class ConsoleProxy method startupHttpCmdPort.

private static void startupHttpCmdPort() {
    try {
        s_logger.info("Listening for HTTP CMDs on port " + httpCmdListenPort);
        HttpServer cmdServer = HttpServer.create(new InetSocketAddress(httpCmdListenPort), 2);
        cmdServer.createContext("/cmd", new ConsoleProxyCmdHandler());
        // creates a default executor
        cmdServer.setExecutor(new ThreadExecutor());
        cmdServer.start();
    } catch (Exception e) {
        s_logger.error(e.getMessage(), e);
        System.exit(1);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 47 with HttpServer

use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.

the class CMRHTTPTests method testMdlHTTPRepos.

@Test
public void testMdlHTTPRepos() throws IOException {
    RequestCounter rq = new RequestCounter();
    String moduleA = "com.redhat.ceylon.compiler.java.test.cmr.modules.depend.a";
    // Clean up any cached version
    File carFileInCache = getModuleArchive(moduleA, "6.6.6", cacheDir);
    if (carFileInCache.exists())
        carFileInCache.delete();
    // Compile the first module in its own repo 
    File repo = makeRepo();
    Boolean result = getCompilerTask(Arrays.asList("-out", repo.getPath()), "modules/depend/a/module.ceylon", "modules/depend/a/package.ceylon", "modules/depend/a/A.ceylon").call();
    Assert.assertEquals(Boolean.TRUE, result);
    File carFile = getModuleArchive(moduleA, "6.6.6", repo.getPath());
    assertTrue(carFile.exists());
    final int port = allocPortForTest();
    final String repoAURL = getRepoUrl(port);
    // now serve the first repo over HTTP
    HttpServer server = startServer(port, repo, false, rq);
    try {
        // then try to compile only one module (the other being loaded from its car) 
        result = getCompilerTask(Arrays.asList("-out", destDir, "-rep", repoAURL, "-verbose:cmr", "-cp", getClassPathAsPath()), "modules/depend/b/module.ceylon", "modules/depend/b/package.ceylon", "modules/depend/b/a.ceylon", "modules/depend/b/B.ceylon").call();
        Assert.assertEquals(Boolean.TRUE, result);
    } finally {
        server.stop(1);
    }
    carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.depend.b", "6.6.6");
    assertTrue(carFile.exists());
    // make sure it cached the module in the cache repo
    assertTrue(carFileInCache.exists());
    // make sure it didn't cache it in the output repo
    carFile = getModuleArchive(moduleA, "6.6.6");
    assertFalse(carFile.exists());
    rq.check(37);
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 48 with HttpServer

use of com.sun.net.httpserver.HttpServer in project ceylon-compiler by ceylon.

the class CeylonDocToolTests method externalLinksToRemoteRepoWithoutModuleNamePattern.

@Test
public void externalLinksToRemoteRepoWithoutModuleNamePattern() throws Exception {
    HttpServer stubServer = HttpServer.create(new InetSocketAddress(0), 1);
    stubServer.createContext("/repo", new HttpHandler() {

        @Override
        public void handle(HttpExchange httpExchange) throws IOException {
            if (httpExchange.getRequestMethod().equals("HEAD")) {
                httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, -1);
            } else {
                httpExchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_IMPLEMENTED, -1);
            }
            httpExchange.close();
        }
    });
    stubServer.start();
    try {
        String repoUrl = "http://localhost:" + stubServer.getAddress().getPort() + "/repo";
        externalLinks(repoUrl, "file://not-existing-dir", "https://not-existing-url", repoUrl);
    } finally {
        stubServer.stop(0);
    }
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) HttpExchange(com.sun.net.httpserver.HttpExchange) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

HttpServer (com.sun.net.httpserver.HttpServer)48 InetSocketAddress (java.net.InetSocketAddress)28 HttpHandler (com.sun.net.httpserver.HttpHandler)12 IOException (java.io.IOException)10 File (java.io.File)7 Test (org.junit.Test)7 HttpContext (com.sun.net.httpserver.HttpContext)6 HttpExchange (com.sun.net.httpserver.HttpExchange)6 JarFile (java.util.jar.JarFile)6 MockHttpServer (org.elasticsearch.mocksocket.MockHttpServer)6 URL (java.net.URL)5 BasicAuthenticator (com.sun.net.httpserver.BasicAuthenticator)3 HttpsServer (com.sun.net.httpserver.HttpsServer)3 InputStream (java.io.InputStream)3 ExecutorService (java.util.concurrent.ExecutorService)3 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)2 HttpsConfigurator (com.sun.net.httpserver.HttpsConfigurator)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2