本文整理汇总了Java中org.vertx.java.core.http.HttpServer.requestHandler方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServer.requestHandler方法的具体用法?Java HttpServer.requestHandler怎么用?Java HttpServer.requestHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.vertx.java.core.http.HttpServer
的用法示例。
在下文中一共展示了HttpServer.requestHandler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EmulatorLaunchpad
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param httpPort The HTTP port on which the emulator should run.
*/
public EmulatorLaunchpad(int httpPort) {
vertx = VertxFactory.newVertx();
// Static files
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(new WebResourceHandler());
// Eventbus bridge
JsonObject bridgeConfig = new JsonObject().putString("prefix", EVENTBUS_ADDRESS);
JsonArray credentialsPermitAll = new JsonArray().add(new JsonObject());
vertx.createSockJSServer(httpServer).bridge(bridgeConfig, credentialsPermitAll, credentialsPermitAll);
vertx.eventBus().registerLocalHandler(EVENTBUS_SERVER_HANDLER_ID, eventBusHandler);
System.out.println("Launchpad emulator is ready on http://localhost:" + httpPort + "/");
httpServer.listen(httpPort);
}
示例2: startServer
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
/**
* Start an embedded HTTP server
*
* @param activeProfilers The active profilers
* @param port The port on which to bind the server
*/
public static void startServer(final Map<String, ScheduledFuture<?>> runningProfilers, final Map<String, Profiler> activeProfilers, final int port, final AtomicReference<Boolean> isRunning, final List<String> errors) {
final HttpServer server = VERTX.createHttpServer();
server.requestHandler(RequestHandler.getMatcher(runningProfilers, activeProfilers, isRunning, errors));
server.listen(port, new Handler<AsyncResult<HttpServer>>() {
@Override
public void handle(AsyncResult<HttpServer> event) {
if (event.failed()) {
server.close();
startServer(runningProfilers, activeProfilers, port + 1, isRunning, errors);
} else if (event.succeeded()) {
LOGGER.info("Profiler server started on port " + port);
}
}
});
}
示例3: createHttpServer
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
private void createHttpServer(int listenPort, final String expectedResponseMediaType, final String expectedResponse) {
HttpServer server = vertx.createHttpServer();
server.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(final HttpServerRequest request) {
request.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer body) {
String contentType = request.headers().get("Content-Type");
assertEquals(expectedResponseMediaType, contentType);
assertEquals(expectedResponse, body.toString());
testComplete();
}
});
}
});
server.listen(listenPort);
}
示例4: start
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
public void start() {
RouteMatcher routeMatcher = new RouteMatcher();
// HTTP server
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(routeMatcher);
// SockJS server
JsonArray permitted = new JsonArray();
permitted.add(new JsonObject()); // Let everything through
SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);
sockJSServer.bridge(new JsonObject().putString("prefix", "/eventbus"), permitted, permitted);
httpServer.listen(7777);
System.out.println("Vert.X Core UP");
}
示例5: start
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
// Create a portal server
Server server = new DefaultServer();
// This action is equivalent to socket handler of server.js in the portal repo
// https://github.com/flowersinthesand/portal/blob/1.1.1/test/server.js#L593-L611
server.socketAction(new Action<Socket>() {
@Override
public void on(final Socket socket) {
socket.on("echo", new Action<Object>() {
@Override
public void on(Object data) {
socket.send("echo", data);
}
})
.on("disconnect", new VoidAction() {
@Override
public void on() {
new Timer(true).schedule(new TimerTask() {
@Override
public void run() {
socket.close();
}
}, 100);
}
})
.on("reply-by-server", new Action<Reply<Boolean>>() {
@Override
public void on(Reply<Boolean> reply) {
if (reply.data()) {
reply.done(reply.data());
} else {
reply.fail(reply.data());
}
}
})
.on("reply-by-client", new VoidAction() {
@Override
public void on() {
socket.send("reply-by-client", 1, new Action<String>() {
@Override
public void on(String type) {
socket.send(type);
}
});
}
});
}
});
HttpServer httpServer = vertx.createHttpServer();
// Attach request handler and WebSocket handler first before installation
httpServer.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest req) {
String filename = req.path().equals("/") ? "/index.html" : req.path();
req.response().sendFile("webapp" + filename);
}
});
// Deliver HttpExchange and WebSocket produced by Vert.x to the portal server
new VertxBridge(httpServer, "/test").httpAction(server.httpAction()).websocketAction(server.websocketAction());
// Start a web server after installation
httpServer.listen(8080);
}
示例6: start
import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
address = this.getClass().getName();
logger = container.logger();
JsonObject appConfig = container.config();
HttpServer server = vertx.createHttpServer();
server.requestHandler(this);
start(appConfig, server);
int serverPort = appConfig.getInteger("port", 8080).intValue();
server.listen(serverPort);
postStart(appConfig, server);
}