Java Code Examples for fi.iki.elonen.NanoHTTPD#start()

The following examples show how to use fi.iki.elonen.NanoHTTPD#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerRunner.java    From VBrowser-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void executeInstance(NanoHTTPD server) {
    try {
        server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
    } catch (IOException ioe) {
        System.err.println("Couldn't start server:\n" + ioe);
        System.exit(-1);
    }

    System.out.println("Server started, Hit Enter to stop.\n");

    try {
        System.in.read();
    } catch (Throwable ignored) {
    }

    server.stop();
    System.out.println("Server stopped.\n");
}
 
Example 2
Source File: WebDriverProxyTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public void startServer() throws IOException {
    System.out.println("WebDriverProxyTest.startServer()");
    serverPort = findPort();
    server = new NanoHTTPD(serverPort) {
        @Override
        public Response serve(IHTTPSession session) {
            try {
                String data = IOUtils.toString(WebDriverProxyTest.class.getResourceAsStream("form.html"),
                        Charset.defaultCharset());
                return newFixedLengthResponse(data);
            } catch (IOException e) {
                return super.serve(session);
            }
        }
    };
    server.start();
}
 
Example 3
Source File: OpenGraphApiTest.java    From mattermost4j with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setupServer() throws IOException {
  if (!useLocalDummyServer()) {
    return;
  }
  server = new NanoHTTPD("0.0.0.0", dummyHttpServerPort()) {
    @Override
    public Response serve(IHTTPSession session) {
      List<String> contents = Arrays.asList("<html><head>", "<meta property=\"og:type\" content=\"article\" />",
          "<meta property=\"og:title\" content=\"The Great WebSite\" />",
          "<meta property=\"og:url\" content=\"http://localhost:8888/\" />",
          "</head><body>Hello World!</body></html>");
      return newFixedLengthResponse(StringUtils.join(contents, StringUtils.CR + StringUtils.LF));
    }
  };
  server.start();
}
 
Example 4
Source File: ServerRunner.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
public static void executeInstance(NanoHTTPD server) {
    try {
        server.start();
    } catch (IOException ioe) {
        System.err.println("Couldn't start server:\n" + ioe);
        System.exit(-1);
    }

    System.out.println("Server started, Hit Enter to stop.\n");

    try {
        System.in.read();
    } catch (Throwable ignored) {
    }

    server.stop();
    System.out.println("Server stopped.\n");
}
 
Example 5
Source File: ServerRunner.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
public static void executeInstance(NanoHTTPD server) {
    try {
        server.start();
    } catch (IOException ioe) {
        System.err.println("Couldn't start server:\n" + ioe);
        System.exit(-1);
    }

    System.out.println("Server started, Hit Enter to stop.\n");

    try {
        System.in.read();
    } catch (Throwable ignored) {
    }

    server.stop();
    System.out.println("Server stopped.\n");
}
 
Example 6
Source File: Server.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080;
    NanoHTTPD server = new Server(port);
    server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
}