Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpServer


        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/mixed/JavaClass.java").call();
            Assert.assertEquals(Boolean.TRUE, result);
            result = getCompilerTask(Arrays.asList("-out", repoAURL, "-verbose:cmr"), "modules/mixed/CeylonClass.ceylon").call();
            Assert.assertEquals(Boolean.TRUE, result);

        }finally{
            server.stop(1);
        }

        File carFile = getModuleArchive("com.redhat.ceylon.compiler.java.test.cmr.modules.mixed", "6.6.6", repo.getPath());
        assertTrue(carFile.exists());
View Full Code Here


        externalLinks(repoUrl, "file://not-existing-dir", "https://not-existing-url", repoUrl);
    }
   
    @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);
        }
    }   
View Full Code Here

     * it uses that server to create a context. Otherwise, it creates a new
     * HTTP server. This sever is added to servers Map.
     */
    /*package*/ HttpContext createContext(String address) {
        try {
            HttpServer server;
            ServerState state;
            URL url = new URL(address);
            int port = url.getPort();
            if (port == -1) {
                port = url.getDefaultPort();
            }
            InetSocketAddress inetAddress = new InetSocketAddress(url.getHost(),
                port);
            synchronized(servers) {
                state = servers.get(inetAddress);
                if (state == null) {
                    logger.fine("Creating new HTTP Server at "+inetAddress);
                    server = HttpServer.create(inetAddress, 5);
                    server.setExecutor(Executors.newCachedThreadPool());
                    String path = url.toURI().getPath();
                    logger.fine("Creating HTTP Context at = "+path);
                    HttpContext context = server.createContext(path);
                    server.start();
                    logger.fine("HTTP server started = "+inetAddress);
                    state = new ServerState(server);
                    servers.put(inetAddress, state);
                    return context;
                }
            }
            server = state.getServer();
            logger.fine("Creating HTTP Context at = "+url.getPath());
            HttpContext context = server.createContext(url.getPath());
            state.oneMoreContext();
            return context;
        } catch(Exception e) {
            throw new ServerRtException("server.rt.err",e );
        }
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

    @SuppressWarnings("ResultOfMethodCallIgnored")
    public static void main(String[] args) throws IOException {
        System.out.println("\"Hello World\" Jersey Example Application");

        HttpServer server = startServer();

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

        modelController = null;
    }

    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

            if(factory == null) {
                s_logger.error("Unable to load HTTP server factory");
                System.exit(1);
            }
           
            HttpServer server = factory.createHttpServerInstance(httpListenPort);
            server.createContext("/getscreen", new ConsoleProxyThumbnailHandler());
            server.createContext("/resource/", new ConsoleProxyResourceHandler());
            server.createContext("/ajax", new ConsoleProxyAjaxHandler());
            server.createContext("/ajaximg", new ConsoleProxyAjaxImageHandler());
            server.setExecutor(new ThreadExecutor()); // creates a default executor
            server.start();
        } catch(Exception e) {
            s_logger.error(e.getMessage(), e);
            System.exit(1);
        }
    }
View Full Code Here

    }
   
    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());
            cmdServer.setExecutor(new ThreadExecutor()); // creates a default executor
            cmdServer.start();
        } catch(Exception e) {
            s_logger.error(e.getMessage(), e);
            System.exit(1);
        }
    }
View Full Code Here

   
  }
 
  public void startServer() {
        InetSocketAddress addr = new InetSocketAddress(8080);
        HttpServer server;
    try {
      server = HttpServer.create(addr, 0);
          server.createContext("/", new GEHttpHandler());
          server.setExecutor(Executors.newCachedThreadPool());
          server.start();
         
          BufferedReader reader = new BufferedReader(new FileReader("kml.xml"));
          StringBuilder sb = new StringBuilder();
          String line = null;
          while((line = reader.readLine()) != null) {
View Full Code Here

      if (split[0].equalsIgnoreCase("--port")) {
        port = Integer.parseInt(split[1]);
      }
    }
    InetSocketAddress addr = new InetSocketAddress(port);
    HttpServer server = HttpServer.create(addr, 0);

    server.createContext("/", new DaisyDiffHandler());
    server.setExecutor(Executors.newCachedThreadPool());
    server.start();
    System.out.println("Server is listening on port " + port);
  }
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.