Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpServer


            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

     * 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);
                    // Creates server with default socket backlog
                    server = HttpServer.create(inetAddress, 0);
                    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

            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

        } else if (path.charAt(0) != '/') {
            throw new IllegalArgumentException(LocalizationMessages.ERROR_CONTAINER_URI_PATH_START(uri));
        }

        final int port = (uri.getPort() == -1) ? 80 : uri.getPort();
        HttpServer server;
        try {
            server = (scheme.equalsIgnoreCase("http"))
                    ? HttpServer.create(new InetSocketAddress(port), 0)
                    : HttpsServer.create(new InetSocketAddress(port), 0);
        } catch (IOException ioe) {
            throw new ProcessingException(LocalizationMessages.ERROR_CONTAINER_EXCEPTION_IO(), ioe);
        }

        server.setExecutor(Executors.newCachedThreadPool());
        server.createContext(path, handler);
        server.start();
        handler.onServerStart();

        return server;
    }
View Full Code Here

     * Entry point
     */
    public static void main(String[] args) throws IOException
    {
        final InetSocketAddress addr;
        final HttpServer server;

        String address = InetAddress.getLocalHost().getHostAddress();

        addr = new InetSocketAddress(address, port);

        server = HttpServer.create(addr, 10);

        server.createContext("/ATOM", new GenericHandler("public_timeline.atom"));
        server.createContext("/RSS", new GenericHandler("public_timeline.rss"));
        server.createContext("/SOAP", new GenericHandler("simple_soap.xml"));
        server.createContext("/JSON", new GenericHandler("public_timeline.json"));
        server.createContext("/XML", new GenericHandler("public_timeline.xml"));

        server.createContext("/TEXT", new TEXTHandler());
        server.createContext("/TEXT2", new TEXTHandler());

        server.start();

        System.out.println("Server started on IP: " + address + ":" + port + " at " + df.format(new Date()));
        String serverUri = "http://" + address + ":" + port;

        String statusInfo = String.format("\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s", "Listening for requests:", serverUri + "/ATOM", serverUri
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

  /* TODO(jlacey): Verify that the timeout exception skips the document. */
  public void testReadTimeoutInHeaders()
      throws RepositoryException, IOException {
    // Sleep 2 seconds and timeout after 1 second.
    out.setReadTimeout(1);
    HttpServer server = createSleepyServer(2, SleepyLocation.HEADERS);
    server.start();

    try {
      out.getInputStream(0, 0, 0, 0).close();
      fail("Expected a SocketTimeoutException");
    } catch (LivelinkException expected) {
      assertNotNull(expected.toString(), expected.getCause());
      assertTrue(expected.getCause().toString(),
          expected.getCause() instanceof SocketTimeoutException);
    } finally {
      server.stop(0);
    }
  }
View Full Code Here

   */
  /* TODO(jlacey): Verify that the timeout exception skips the document. */
  public void testReadTimeoutInBody() throws RepositoryException, IOException {
    // Sleep 2 seconds and timeout after 1 second.
    out.setReadTimeout(1);
    HttpServer server = createSleepyServer(2, SleepyLocation.BODY);
    server.start();

    InputStream in = out.getInputStream(0, 0, 0, 0);
    try {
      in.read();
      fail("Expected a SocketTimeoutException");
    } catch (SocketTimeoutException expected) {
    } finally {
      in.close();
      server.stop(0);
    }
  }
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.