本文整理汇总了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");
}
}
示例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();
}
}
示例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();
}
示例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;
}
示例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" );
}
示例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.");
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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");
}
示例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;
}
示例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");
}