本文整理匯總了Java中io.vertx.ext.web.handler.StaticHandler類的典型用法代碼示例。如果您正苦於以下問題:Java StaticHandler類的具體用法?Java StaticHandler怎麽用?Java StaticHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StaticHandler類屬於io.vertx.ext.web.handler包,在下文中一共展示了StaticHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
int serverPort = Config.getIntValue("serverPort");
router.route().handler(BodyHandler.create().setUploadsDirectory("files"));
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
Routing.route(router, "com.planb.restful");
router.route().handler(StaticHandler.create());
new Parser().start();
Log.info("Server Started At : " + serverPort);
vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
示例2: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
int serverPort = Config.getIntValue("serverPort");
router.route().handler(BodyHandler.create().setUploadsDirectory("files"));
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(CORSHandler.create());
router.route().handler(LogHandler.create());
Routing.route(router, "com.planb.restful");
router.route().handler(StaticHandler.create());
Log.info("Server Started At : " + serverPort);
vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
示例3: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void start() {
// Create a router object for web ui
Router routerWeb = Router.router(vertx);
// Bind new web ui
routerWeb.route("/dfa/*").handler(StaticHandler.create("dfa").setCachingEnabled(false));
// Bind api doc
routerWeb.route("/api/*").handler(StaticHandler.create("apidoc").setCachingEnabled(true));
// Bind landing page
routerWeb.route("/*").handler(StaticHandler.create("landing").setCachingEnabled(true));
// Create the HTTP server to serve the web ui
vertx.createHttpServer().requestHandler(routerWeb::accept)
.listen(config().getInteger("http.port.df.processor", 8000));
try {
LOG.info("DataFibers Welcome You @ http://" + InetAddress.getLocalHost().getHostAddress() + ":" +
config().getInteger("http.port.df.processor", 8000));
} catch (UnknownHostException e) {
LOG.error(DFAPIMessage.logResponseMessage(9019,
"NetworkHostException - " + e.getCause()));
}
}
示例4: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
public void start() throws Exception {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create().setUploadsDirectory("upload-files"));
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)).setNagHttps(false));
router.route().handler(RequestSecurePreprocessor.create());
RouteRegister.registerRouters(router, "com.dms.secure", "com.dms.api", "com.dms.templates");
router.route("/js/*").handler(StaticHandler.create().setCachingEnabled(false).setWebRoot("WEB-INF/js/"));
/*
* @see com.dms.planb.support .TableDropper
*/
HttpServerOptions httpOpts = new HttpServerOptions();
/*System.out.println(SecureConfig.get("SSL_PATH"));
System.out.println(SecureConfig.get("SSL"));
httpOpts.setSsl(true)
.setKeyStoreOptions(new JksOptions().setPath(SecureConfig.get("SSL_PATH")).setPassword(SecureConfig.get("SSL")))
.setTrustStoreOptions(new JksOptions().setPath(SecureConfig.get("SSL_PATH")).setPassword(SecureConfig.get("SSL")));
*/
vertx.createHttpServer(httpOpts).requestHandler(router::accept).listen(Integer.parseInt(SecureConfig.get("SERVER_PORT")));
}
示例5: initStaticResourceHandler
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
private void initStaticResourceHandler() {
StaticHandler staticHandler = StaticHandler.create();
if (nonNull(System.getProperty("domino.webroot.location"))) {
staticHandler.setAllowRootFileSystemAccess(true);
staticHandler.setWebRoot(systemWebRoot());
} else {
staticHandler.setWebRoot(webroot);
}
router.route("/").order(Integer.MAX_VALUE - 2)
.handler(this::serveIndexPage);
router.route("/static/*").order(Integer.MAX_VALUE - 1)
.handler(staticHandler)
.failureHandler(this::serveResource);
router.route("/*").order(Integer.MAX_VALUE)
.handler(this::serveResource);
}
示例6: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
public void start() throws Exception {
Router router = Router.router(vertx);
int serverPort = Config.getIntValue("serverPort");
router.route().handler(BodyHandler.create().setUploadsDirectory("upload-files"));
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(CORSHandler.create());
router.route().handler(LogHandler.create());
Routing.route(router, "com.planb.restful");
router.route().handler(StaticHandler.create());
// new ParserThread().start();
Log.info("Server Started");
vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
示例7: addStaticFileHandlers
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
static void addStaticFileHandlers(Router router) {
router.get(Uris.resourcesUri + "/*").handler(
StaticHandler
.create(
"/" + module.require(ServerConfig.class).getUploadDir()
)
.setDirectoryListing(true)
);
router.get(Uris.publicUri + "/*").handler(
StaticHandler
.create(
"/" + module.require(ServerConfig.class).getPublicDir()
)
.setDirectoryListing(true)
);
}
示例8: init
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void init(CoreContext core) {
router = Router.router(core.vertx());
router.route().handler(BodyHandler.create());
RestHelper.addHeaders(router, settings.get().isSecure());
// enable routing for static resources.
if (regex != null && path != null) {
router.routeWithRegex(regex).handler(StaticHandler.create()
//.setCachingEnabled(false) -- set in HttpOptions.
.setWebRoot(path));
}
router.route().handler(this::packet);
handler.init(core);
this.core = core;
}
示例9: mainRouter
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Bean
public Router mainRouter() {
Router router = Router.router(vertx);
Path jbakeryHome = Paths.get(jbakeryHomeProp);
router.route().handler(BodyHandler.create().setBodyLimit(50 * MB));
router.route().handler(LoggerHandler.create());
router.route().handler(ResponseTimeHandler.create());
router.mountSubRouter(PREFIX, jbakery(Vertx.vertx()));
router.route().handler(StaticHandler.create("output")
.setIndexPage("index.html")
.setCachingEnabled(false));
return router;
}
示例10: jbakery
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
public Router jbakery(Vertx vertx) {
Router router = Router.router(vertx);
Path jbakeryHome = Paths.get(jbakeryHomeProp);
router.route("/static/*")
.handler(StaticHandler.create()
.setAllowRootFileSystemAccess(true)
.setWebRoot(jbakeryHome.resolve("webroot").toString())
.setIndexPage("index.html")
.setCachingEnabled(false));
router.route().handler(TemplateHandler.create(thymeleafTemplateEngine, "", "text/html"));
return router;
}
示例11: setUpRouter
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
private void setUpRouter(Router paramRouter) {
router = paramRouter;
router.route().failureHandler(failureHandler);
if (locResolver != null) {
locResolver.getAvailableLocales().forEach(this::loadResourceBundle);
if (locResolver.getDefaultLocale() != null) {
loadResourceBundle(locResolver.getDefaultLocale());
}
}
if (config.getAuthProvider() != null) {
registerAnnotationProcessor(Auth.class, new AuthProcessorFactory());
}
new RouteFactory(router, config).createHandlers();
new SocketFactory(router, config).createHandlers();
new EventBusBridgeFactory(router, config).createHandlers();
StaticHandler staticHandler;
final String webroot = config.getWebroot();
if (webroot != null) {
staticHandler = StaticHandler.create(webroot);
} else {
staticHandler = StaticHandler.create();
}
router.route(config.getAssetsPath() + "/*").handler(staticHandler);
}
示例12: registerWithRouter
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void registerWithRouter(Router router) {
StaticHandler staticHandler = StaticHandler.create();
staticHandler.setWebRoot("META-INF/resources/webjars");
router.route("/static/*").handler(staticHandler);
// Disable caching so you don't need to clear cache everytime yaml changes.
StaticHandler swaggerHandler =
StaticHandler.create().setWebRoot("webroot/swagger").setCachingEnabled(false);
router.route("/doc/*").handler(swaggerHandler);
}
示例13: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/prices/:name").handler(rc -> {
String name = rc.pathParam("name");
Double price = prices.computeIfAbsent(name, k -> (double) random.nextInt(50));
rc.response().end(new JsonObject().put("name", name).put("price", price).encodePrettily());
});
router.route().handler(BodyHandler.create());
router.post("/prices").handler(rc -> {
if (slow) {
vertx.setTimer(5000, l -> computeResponse(rc));
} else {
computeResponse(rc);
}
});
router.get("/health").handler(rc -> rc.response().end("OK"));
router.get("/toggle").handler(rc -> {
slow = ! slow;
rc.response().end((slow ? "Slow" : "Normal") + " mode enabled");
});
router.get("/assets*").handler(StaticHandler.create());
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}
示例14: mountSubRouters
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
/**
* 掛載所有子路由
*/
private void mountSubRouters() {
//請求體解析
mainRouter.route().handler(BodyHandler.create());
//靜態資源路由
mainRouter.get("/").handler(ctx -> ctx.reroute("/static/index.html"));
mainRouter.get("/favicon.ico").handler(this::getLogo);
mainRouter.get("/README.md").handler(this::getReadme);
mainRouter.get("/static/page/sys/img/*").handler(this::getReadmeImg);
mainRouter.get("/MP_verify_*").handler(this::getWechatVerify);
mainRouter.get("/static/*").handler(StaticHandler.create().setWebRoot("static"));
//授權服務的子路由
mainRouter.mountSubRouter("/oauth/wx", factory.create(WECHAT_OAUTH));
mainRouter.mountSubRouter("/oauth/zfb", factory.create(ALIPAY_OAUTH));//TODO 支付寶授權
//支付服務子路由
mainRouter.mountSubRouter("/pay/wx", factory.create(WECHAT_PAY));
mainRouter.mountSubRouter("/pay/zfb", factory.create(ALIPAY_PAY));
//消息發送服務子路由
mainRouter.mountSubRouter("/msg/wx", factory.create(WECHAT_MSG));
mainRouter.mountSubRouter("/msg/zfb", factory.create(ALIPAY_MSG));
//JsTicket和AccessTOken服務子路由
mainRouter.mountSubRouter("/tk/wx", factory.create(WECHAT_TOKEN));
//登錄BMS的子路由
mainRouter.mountSubRouter("/bms/login", factory.create(BMS_LOGIN));
//公眾號配置子路由
mainRouter.mountSubRouter("/bms/offAcc", factory.create(BMS_ACCOUNT));
//支付配置子路由
mainRouter.mountSubRouter("/bms/pay", factory.create(BMS_PAY));
}
示例15: start
import io.vertx.ext.web.handler.StaticHandler; //導入依賴的package包/類
@Override
public void start() throws Exception {
JsonObject config = config();
JsonArray urls = config.getJsonArray(CommonConstants.HE_RSS_URL_LIST_ENV);
urls.iterator().forEachRemaining(o -> {
String url = (String) o;
HEEndpointModel model = new HEEndpointModel();
String label = stripAndFormatSuffix(url);
model.setLabel(label);
model.setUrl(url);
model.setPollingPeriod(30000);
model.setActive(false);
endpoints.put(label, model);
});
Router router = Router.router(vertx);
HealthCheckHandler healthCheckHandler = HealthCheckHandler.create(vertx).register("server-online",
fut -> fut.complete(online ? Status.OK() : Status.KO()));
router.get("/api/health/readiness").handler(rc -> rc.response().end(CommonConstants.OK));
router.get("/api/health/liveness").handler(healthCheckHandler);
router.get("/api/get/count/:term").handler(this::getIncidentCountsForType);
router.get("/api/get/count/:term/:id").handler(this::getIncidentCountsForTypeWithId);
router.get("/api/get/detail/:term/:id").handler(this::getIncidentDetailsById);
router.get("/api/config/endpoint/all").handler(this::getEndpointStatus);
router.get("/api/config/endpoint/:label").handler(this::getEndpointStatusById);
router.get("/*").handler(StaticHandler.create());
router.post("/api/config/endpoint/:label/:state").handler(this::setEndpointStatusById);
HttpServer server = vertx.createHttpServer().requestHandler(router::accept)
.listen(config().getInteger("http.port", 8080), ar -> {
online = ar.succeeded();
});
}