Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpServer


         * the complete URI of the HTTP request!!
         *
         * TODO this is missing the user information component, how
         * can this be obtained?
         */
        HttpServer server = exchange.getHttpContext().getServer();
        String scheme = (server instanceof HttpsServer) ? "https" : "http";
        InetSocketAddress addr = exchange.getLocalAddress();
        URI baseUri = null;
        try {
            baseUri = new URI(scheme, null, addr.getHostName(), addr.getPort(),
View Full Code Here


        }
    }

    public static DomainHttpServer create(InetSocketAddress socket, int backlog, ModelController modelController,
            Executor executor, File serverTempDir) throws IOException {
        HttpServer server = HttpServer.create(socket, backlog);
        DomainHttpServer me = new DomainHttpServer(server, modelController, serverTempDir);
        server.createContext(DOMAIN_API_CONTEXT, me);
        server.createContext(ConsoleHandler.CONTEXT, new ConsoleHandler());
        server.setExecutor(executor);

        return new DomainHttpServer(server, modelController, serverTempDir);
    }
View Full Code Here

        else if (path.charAt(0) != '/')
            throw new IllegalArgumentException("The URI path, of the URI " + u +
                    ". must start with a '/'");
       
        final int port = (u.getPort() == -1) ? 80 : u.getPort();   
        final HttpServer server = (scheme.equalsIgnoreCase("http")) ?
            HttpServer.create(new InetSocketAddress(port), 0) :
            HttpsServer.create(new InetSocketAddress(port), 0);

        server.setExecutor(Executors.newCachedThreadPool());
        server.createContext(path, handler);       
        return server;
    }
View Full Code Here

            addr = parts.get(0);
            if (parts.size() > 1) {
                port = Integer.parseInt(parts.get(1));
            }
        }
        HttpServer server = HttpServer.create(new InetSocketAddress(addr, port), 2);
        server.createContext("/", new WebhookHandler());
        server.setExecutor(null);
        server.start();
    }
View Full Code Here

   * @return new instance of the lightweight HTTP server
   * @throws IOException
   */
  static HttpServer startServer() throws IOException {
    // create a new server listening at port 8080
    HttpServer server = HttpServer.create(new InetSocketAddress(getBaseURI().getPort()), 0);

    // create a handler wrapping the JAX-RS application
    HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint(new JaxRsApplication(), HttpHandler.class);

    // map JAX-RS handler to the server root
    server.createContext(getBaseURI().getPath(), handler);

    // start the server
    server.start();

    return server;
  }
View Full Code Here

   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    System.out.println("Swagger Doclet Jersey 2 Example Application");

    HttpServer server = startServer();

    System.out.println("Application started.\n" + "Try accessing " + getBaseURI() + "beanparam in the browser.\n" + "Hit enter to stop the application...");
    System.in.read();
    server.stop(0);
  }
View Full Code Here

        }
    }

    private static void initHttpServer() throws Exception {
        // Setup default endpoints
        final HttpServer server = HttpServer.create();
        server.createContext("/echo", new EchoHandler());

        // Hook to allow for graceful exit
        final Closeable c = new Closeable() {
            public void close() throws IOException {
                PollScheduler.getInstance().stop();
                server.stop(5);
            }
        };
        server.createContext("/exit", new ExitHandler(c));

        // Bind and start server
        server.bind(new InetSocketAddress(Config.getPort()), 0);
        server.start();
    }
View Full Code Here

    private String getRepoUrl(int allocatedPort) {
        return "http://localhost:"+allocatedPort+"/repo";
    }
   
    private HttpServer startServer(int port, File repo, boolean herd, RequestCounter rq) throws IOException{
        HttpServer server = HttpServer.create(new InetSocketAddress(port), 1);
        server.createContext("/repo", new RepoFileHandler(repo.getPath(), herd, rq));
        // make sure we serve at least two concurrent connections, as each one might take a few ms to close
        ThreadPoolExecutor tpool = (ThreadPoolExecutor)Executors.newFixedThreadPool(2);
        server.setExecutor(tpool);
        server.start();
        return server;
    }
View Full Code Here

        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
View Full Code Here

        final int port = allocPortForTest();
        final String repoAURL = getRepoUrl(port);
       
        // now serve the first repo over HTTP
        HttpServer server = startServer(port, repo, herd, rq);
       
        try{
            // then try to compile our module by outputting to HTTP
            Boolean result = getCompilerTask(Arrays.asList("-out", repoAURL, "-verbose:cmr"), "modules/single/module.ceylon").call();
            Assert.assertEquals(Boolean.TRUE, result);

        }finally{
            server.stop(1);
        }
       
        File carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.single", "6.6.6", repo.getPath());
        assertTrue(carFile.exists());
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.