use of io.vertx.ext.web.Router in project yyl_example by Relucent.
the class HelloVertxVerticle method start.
/** 运行 */
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/hello").handler(new Handler<RoutingContext>() {
public void handle(RoutingContext event) {
event.response().putHeader("content-type", "text/html").end("Hello Vert.x");
}
});
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest event) {
router.accept(event);
}
}).listen(//监听端口号
8080);
}
use of io.vertx.ext.web.Router in project java-chassis by ServiceComb.
the class RestServerVerticle method start.
@Override
public void start(Future<Void> startFuture) throws Exception {
super.start();
// 如果本地未配置地址,则表示不必监听,只需要作为客户端使用即可
if (endpointObject == null) {
LOGGER.warn("rest listen address is not configured, will not start.");
startFuture.complete();
return;
}
Router mainRouter = Router.router(vertx);
mainRouter.route().handler(bodyHandler);
VertxRestServer vertxRestServer = new VertxRestServer(mainRouter);
vertxRestServer.setTransport(CseContext.getInstance().getTransportManager().findTransport(Const.RESTFUL));
HttpServer httpServer = createHttpServer();
httpServer.requestHandler(mainRouter::accept);
startListen(httpServer, startFuture);
}
use of io.vertx.ext.web.Router in project java-chassis by ServiceComb.
the class TestVertxRestServer method setUp.
@Before
public void setUp() throws Exception {
Router mainRouter = Router.router(null);
mainRouter.route().handler(BodyHandler.create());
instance = new VertxRestServer(mainRouter) {
@Override
protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
return super.findRestOperation(restRequest);
}
@Override
public void sendFailResponse(RestServerRequestInternal restRequest, HttpServerResponse httpResponse, Throwable throwable) {
}
};
}
use of io.vertx.ext.web.Router in project java-chassis by ServiceComb.
the class GrpcVerticle method startListen.
protected void startListen(Future<Void> startFuture) {
// 如果本地未配置grpc地址,则表示不必监听,只需要作为客户端使用即可
if (StringUtils.isEmpty(this.endpoint)) {
LOGGER.warn("grpc listen address is not configured, will not listen.");
startFuture.complete();
return;
}
Router mainRouter = Router.router(vertx);
mainRouter.route().handler(new GrpcBodyHandler());
new GrpcServer(mainRouter);
HttpServerOptions serverOptions = new HttpServerOptions();
serverOptions.setAcceptBacklog(ACCEPT_BACKLOG);
serverOptions.setSendBufferSize(SEND_BUFFER_SIZE);
serverOptions.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
serverOptions.setUsePooledBuffers(true);
String key = System.getProperty("store.key");
if (key != null && !key.isEmpty()) {
serverOptions.setUseAlpn(true);
serverOptions.setSsl(true);
serverOptions.setKeyStoreOptions(new JksOptions().setPath(System.getProperty("store.key")).setPassword(System.getProperty("store.pass")));
}
HttpServer server = vertx.createHttpServer(serverOptions).requestHandler(mainRouter::accept);
IpPort ipPort = NetUtils.parseIpPortFromURI(this.endpoint);
if (ipPort == null) {
LOGGER.error("wrong grpc listen address {}", this.endpoint);
return;
}
startListen(server, ipPort, startFuture);
}
Aggregations