当前位置: 首页>>代码示例>>Java>>正文


Java HttpServer.setExecutor方法代码示例

本文整理汇总了Java中com.sun.net.httpserver.HttpServer.setExecutor方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.setExecutor方法的具体用法?Java HttpServer.setExecutor怎么用?Java HttpServer.setExecutor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.net.httpserver.HttpServer的用法示例。


在下文中一共展示了HttpServer.setExecutor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Starts the http server for Graphflow web UI.
 */
@Override
public void run() {
    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(HTTP_HOST, HTTP_PORT), 0);
        // Create a route for input query
        server.createContext("/query", new PlanViewerHttpHandler());
        // Create a default executor
        server.setExecutor(null);
        server.start();
        File webViewer = new File(PLAN_VIEWER_HTML_PATH);
        logger.info("Please open the Graphflow UI (link below) in a browser:");
        logger.info("file://" + webViewer.getAbsolutePath());
    } catch (IOException exception) {
        logger.error("GraphflowUIHttpServer: failed to start");
    }
}
 
开发者ID:graphflow,项目名称:graphflow,代码行数:20,代码来源:PlanViewerHttpServer.java

示例2: runSample

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Main function which runs the actual sample.
 * @param authFile the auth file backing the web server
 * @return true if sample runs successfully
 * @throws Exception exceptions running the server
 */
public static boolean runSample(File authFile) throws Exception {
    final String redirectUrl = "http://localhost:8000";
    final ExecutorService executor = Executors.newCachedThreadPool();

    try {
        DelegatedTokenCredentials credentials = DelegatedTokenCredentials.fromFile(authFile, redirectUrl);

        HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
        HttpContext context = server.createContext("/", new MyHandler());
        context.getAttributes().put("credentials", credentials);
        server.setExecutor(Executors.newCachedThreadPool()); // creates a default executor
        server.start();

        // Use a browser to login within a minute
        Thread.sleep(60000);
        return true;
    } finally {
        executor.shutdown();
    }
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:27,代码来源:WebServerWithDelegatedCredentials.java

示例3: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  HttpServer server = HttpServer.create(new InetSocketAddress(HTTP_SERVER_PORT), 0);

  HttpContext secureContext = server.createContext(DEMO_REST_BASIC_AUTH, new RestDemoHandler());
  secureContext.setAuthenticator(new BasicAuthenticator("demo-auth") {
    @Override
    public boolean checkCredentials(String user, String pwd) {
      return user.equals(USERNAME) && pwd.equals(PASSWORD);
    }
  });

  server.createContext(DEMO_REST_NO_AUTH, new RestDemoHandler());
  server.setExecutor(null);
  System.out.println("[*] Waiting for messages.");
  server.start();
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:17,代码来源:RestApiCallDemoClient.java

示例4: createServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
static HttpServer createServer() throws Exception {
    HttpServer s = HttpServer.create(new InetSocketAddress(0), 0);
    if (s instanceof HttpsServer)
        throw new RuntimeException ("should not be httpsserver");

    String root = System.getProperty("test.src") + "/docs";
    s.createContext("/files", new FileServerHandler(root));
    s.setExecutor(serverExecutor);
    s.start();

    return s;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:APIErrors.java

示例5: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
    server.createContext("/", new LandingPageHandler());
    server.createContext("/post", new PostHandler());
    server.createContext("/json", new JSONHandler());
    server.createContext("/favicon.ico", new IgnoreHandler());

    server.setExecutor(Executors.newCachedThreadPool());
    server.start();

    System.out.println("Server started on port 8080" );
}
 
开发者ID:zupzup,项目名称:java-0-deps-webapp,代码行数:13,代码来源:WebApp.java

示例6: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    try {
        server.setExecutor(Executors.newFixedThreadPool(1));
        server.createContext(someContext, new HttpHandler() {
            @Override
            public void handle(HttpExchange msg) {
                try {
                    try {
                        msg.sendResponseHeaders(noMsgCode, -1);
                    } catch(IOException ioe) {
                        ioe.printStackTrace();
                    }
                } finally {
                    msg.close();
                }
            }
        });
        server.start();
        System.out.println("Server started at port "
                           + server.getAddress().getPort());

        runRawSocketHttpClient("localhost", server.getAddress().getPort());
    } finally {
        ((ExecutorService)server.getExecutor()).shutdown();
        server.stop(0);
    }
    System.out.println("Server finished.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:MissingTrailingSpace.java

示例7: startServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
private static void startServer(HttpServer server, JSONObject config) throws NoSuchAlgorithmException {
        server.createContext("/api", new Server(config));
//        server.createContext("/" + config.getString("sslHost"), new HTTPSConfirmHandler(config.getString("sslTarget")));
        int poolSize = Runtime.getRuntime().availableProcessors() + 1;
        server.setExecutor(Executors.newFixedThreadPool(poolSize));
//        server.setExecutor(null);
        server.start();
    }
 
开发者ID:sherisaac,项目名称:TurteTracker_APIServer,代码行数:9,代码来源:Server.java

示例8: runContentSizeLyingHttpServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
private HttpServer runContentSizeLyingHttpServer(String path) {
    final int port = 15999;
    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
        server.createContext(path, new ContentSizeLyingHandler());
        server.setExecutor(null);
        server.start();
        return server;
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    return null;
}
 
开发者ID:pilosa,项目名称:java-pilosa,代码行数:14,代码来源:PilosaClientIT.java

示例9: runContentSizeLyingHttpServer400

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
private HttpServer runContentSizeLyingHttpServer400(String path) {
    final int port = 15999;
    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
        server.createContext(path, new ContentSizeLyingHandler(400));
        server.setExecutor(null);
        server.start();
        return server;
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    return null;
}
 
开发者ID:pilosa,项目名称:java-pilosa,代码行数:14,代码来源:PilosaClientIT.java

示例10: runContent0HttpServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
private HttpServer runContent0HttpServer(String path, int statusCode) {
    final int port = 15999;
    try {
        HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
        server.createContext(path, new Content0Handler(statusCode));
        server.setExecutor(null);
        server.start();
        return server;
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    return null;
}
 
开发者ID:pilosa,项目名称:java-pilosa,代码行数:14,代码来源:PilosaClientIT.java

示例11: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
  String portString = System.getenv("PORT");
  int port = portString == null ? 8080 : Integer.valueOf(portString);
  HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
  server.createContext("/", new MyHandler());
  server.setExecutor(null); // creates a default executor
  server.start();
}
 
开发者ID:kissaten,项目名称:gradle-multi-project-example,代码行数:9,代码来源:Server.java

示例12: listen

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Starts a server on the given port and listen for connections.
 * @param port a TCP port
 * @throws IOException if an I/O error occurs.
 */
public void listen(int port) throws IOException {
  HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
  server.createContext("/", exchange -> {
    callback.accept(() -> exchange, () -> exchange);
    exchange.close();
  });
  server.setExecutor(null);
  server.start();
}
 
开发者ID:forax,项目名称:jexpress,代码行数:15,代码来源:JExpress.java

示例13: setupServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void setupServer() throws IOException
{		
	HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
   	server.createContext("/f.html", new LoadBalancer.MyHandler());
   	server.setExecutor(null); // creates a default executor
   	server.start();
   	System.out.println("Load Balancer ready");
}
 
开发者ID:carlosfaria94,项目名称:CloudPrime,代码行数:9,代码来源:Connection.java

示例14: createServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
static HttpServer createServer(ExecutorService e, BasicAuthenticator sa) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 10);
    Handler h = new Handler();
    HttpContext serverContext = server.createContext("/test", h);
    serverContext.setAuthenticator(sa);
    server.setExecutor(e);
    server.start();
    return server;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MultiAuthTest.java

示例15: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    Handler handler = new Handler();
    InetSocketAddress addr = new InetSocketAddress (0);
    HttpServer server = HttpServer.create(addr, 0);
    HttpContext ctx = server.createContext("/test", handler);
    BasicAuthenticator a = new BasicAuthenticator("[email protected]") {
        @Override
        public boolean checkCredentials (String username, String pw) {
            return "fred".equals(username) && pw.charAt(0) == 'x';
        }
    };

    ctx.setAuthenticator(a);
    ExecutorService executor = Executors.newCachedThreadPool();
    server.setExecutor(executor);
    server.start ();
    java.net.Authenticator.setDefault(new MyAuthenticator());

    System.out.print("Deadlock: " );
    for (int i=0; i<2; i++) {
        Runner t = new Runner(server, i);
        t.start();
        t.join();
    }
    server.stop(2);
    executor.shutdown();
    if (error) {
        throw new RuntimeException("test failed error");
    }

    if (count != 2) {
        throw new RuntimeException("test failed count = " + count);
    }
    System.out.println("OK");

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:37,代码来源:Deadlock.java


注:本文中的com.sun.net.httpserver.HttpServer.setExecutor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。