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


Java HttpServer.createContext方法代码示例

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


在下文中一共展示了HttpServer.createContext方法的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: createServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static HTTPTestServer createServer(HttpProtocolType protocol,
                                    HttpAuthType authType,
                                    HttpTestAuthenticator auth,
                                    HttpSchemeType schemeType,
                                    HttpHandler delegate,
                                    String path)
        throws IOException {
    Objects.requireNonNull(authType);
    Objects.requireNonNull(auth);

    HttpServer impl = createHttpServer(protocol);
    final HTTPTestServer server = new HTTPTestServer(impl, null, delegate);
    final HttpHandler hh = server.createHandler(schemeType, auth, authType);
    HttpContext ctxt = impl.createContext(path, hh);
    server.configureAuthentication(ctxt, schemeType, auth, authType);
    impl.start();
    return server;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:HTTPTestServer.java

示例3: httpd

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Creates and starts an HTTP or proxy server that requires
 * Negotiate authentication.
 * @param scheme "Negotiate" or "Kerberos"
 * @param principal the krb5 service principal the server runs with
 * @return the server
 */
public static HttpServer httpd(String scheme, boolean proxy,
        String principal, String ktab) throws Exception {
    MyHttpHandler h = new MyHttpHandler();
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    HttpContext hc = server.createContext("/", h);
    hc.setAuthenticator(new MyServerAuthenticator(
            proxy, scheme, principal, ktab));
    server.start();
    return server;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:HttpNegotiateServer.java

示例4: startHttpServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Http Server
 */
HttpServer startHttpServer() throws IOException {
    if (debug) {
        Logger logger =
        Logger.getLogger("com.sun.net.httpserver");
        Handler outHandler = new StreamHandler(System.out,
                                 new SimpleFormatter());
        outHandler.setLevel(Level.FINEST);
        logger.setLevel(Level.FINEST);
        logger.addHandler(outHandler);
    }
    HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
    httpServer.createContext("/flis/", new MyHandler(POST_SIZE));
    httpServer.start();
    return httpServer;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:FixedLengthInputStream.java

示例5: 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

示例6: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 10);
    ExecutorService e = Executors.newCachedThreadPool();
    Handler h = new Handler();
    HttpContext serverContext = server.createContext("/test", h);
    int port = server.getAddress().getPort();
    System.out.println("Server port = " + port);

    ClientAuth ca = new ClientAuth();
    ServerAuth sa = new ServerAuth("foo realm");
    serverContext.setAuthenticator(sa);
    server.setExecutor(e);
    server.start();
    HttpClient client = HttpClient.newBuilder()
                                  .authenticator(ca)
                                  .build();

    try {
        URI uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/test/foo");
        HttpRequest req = HttpRequest.newBuilder(uri).GET().build();

        HttpResponse resp = client.send(req, asString());
        ok = resp.statusCode() == 200 && resp.body().equals(RESPONSE);

        if (!ok || ca.count != 1)
            throw new RuntimeException("Test failed");

        // repeat same request, should succeed but no additional authenticator calls

        resp = client.send(req, asString());
        ok = resp.statusCode() == 200 && resp.body().equals(RESPONSE);

        if (!ok || ca.count != 1)
            throw new RuntimeException("Test failed");

        // try a POST

        req = HttpRequest.newBuilder(uri)
                         .POST(fromString(POST_BODY))
                         .build();
        resp = client.send(req, asString());
        ok = resp.statusCode() == 200;

        if (!ok || ca.count != 1)
            throw new RuntimeException("Test failed");
    } finally {
        server.stop(0);
        e.shutdownNow();
    }
    System.out.println("OK");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:BasicAuthTest.java

示例7: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:MissingTrailingSpace.java

示例8: startHttpServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
HttpServer startHttpServer() throws IOException {
    HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
    httpServer.createContext("/chunked/", new ChunkedHandler());
    httpServer.createContext("/fixed/", new FixedHandler());
    httpServer.createContext("/error/", new ErrorHandler());
    httpServer.createContext("/chunkedError/", new ChunkedErrorHandler());
    httpServer.start();
    return httpServer;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:HttpStreams.java

示例9: main

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    banner();
    int port = 8000;
    HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
    server.createContext("/", new HTTPHandler());
    server.setExecutor(null); // creates a default executor
    server.start();
    System.out.println("\nJRE Version: "+System.getProperty("java.version"));
    System.out.println("[INFO]: Listening on port "+port);
    System.out.println();
}
 
开发者ID:joaomatosf,项目名称:JavaDeserH2HC,代码行数:12,代码来源:VulnerableHTTPServer.java

示例10: 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

示例11: createContext

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
private void createContext(HttpServer server, String path, HttpHandler handler, Authenticator auth)
{
	final HttpContext context = server.createContext(path, handler);
	if( auth != null )
	{
		context.setAuthenticator(auth);
	}
	context.getFilters().addAll(filters);
}
 
开发者ID:equella,项目名称:Equella,代码行数:10,代码来源:Main.java

示例12: startHttpServer

import com.sun.net.httpserver.HttpServer; //导入方法依赖的package包/类
/**
 * Http Server
 */
static HttpServer startHttpServer() throws IOException {
    HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
    HttpHandler httpHandler = new SimpleHandler();
    httpServer.createContext("/chunked/", httpHandler);
    httpServer.start();
    return httpServer;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:ChunkedEncodingTest.java

示例13: 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

示例14: runImportFailsHttpServer

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

示例15: 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


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