本文整理匯總了Java中io.vertx.ext.web.handler.BodyHandler.create方法的典型用法代碼示例。如果您正苦於以下問題:Java BodyHandler.create方法的具體用法?Java BodyHandler.create怎麽用?Java BodyHandler.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.ext.web.handler.BodyHandler
的用法示例。
在下文中一共展示了BodyHandler.create方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
Log.create(LOGGER)
.setEvent("dispatch.deploying")
.addData("config", config())
.info();
//讀取命令
Future<Void> importCmdFuture = Future.future();
new CmdRegister().initialize(vertx, config(), importCmdFuture);
//Diapatch
DispatchHandler dispatchHandler = DispatchHandler.create(vertx, config());
Router router = Router.router(vertx);
BodyHandler bodyHandler = BodyHandler.create();
if (config().containsKey("bodyLimit")) {
bodyHandler.setBodyLimit(config().getLong("bodyLimit"));
}
router.route().handler(bodyHandler);
checkContainsCors(router);
router.route().handler(BaseHandler.create());
router.route().handler(ResponseTimeHandler.create());
//API攔截
router.route().handler(dispatchHandler)
.failureHandler(FailureHandler.create());
startHttpServer(router, startFuture);
}
示例2: addRoutes
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
@Override
public void addRoutes(final Router router) {
final String pathWithTenant = String.format("/%s/:%s", CredentialsConstants.CREDENTIALS_ENDPOINT, PARAM_TENANT_ID);
final String pathWithTenantAndDeviceId = String.format("/%s/:%s/:%s",
CredentialsConstants.CREDENTIALS_ENDPOINT, PARAM_TENANT_ID, PARAM_DEVICE_ID);
final String pathWithTenantAndAuthIdAndType = String.format("/%s/:%s/:%s/:%s",
CredentialsConstants.CREDENTIALS_ENDPOINT, PARAM_TENANT_ID, PARAM_AUTH_ID, PARAM_TYPE);
final BodyHandler bodyHandler = BodyHandler.create();
bodyHandler.setBodyLimit(2048); // limit body size to 2kb
// add credentials
router.post(pathWithTenant).handler(bodyHandler);
router.post(pathWithTenant).handler(this::extractRequiredJsonPayload);
router.post(pathWithTenant).handler(this::addCredentials);
// get credentials by auth-id and type
router.get(pathWithTenantAndAuthIdAndType).handler(this::getCredentials);
// get all credentials for a given device
router.get(pathWithTenantAndDeviceId).handler(this::getCredentialsForDevice);
// update credentials by auth-id and type
router.put(pathWithTenantAndAuthIdAndType).handler(bodyHandler);
router.put(pathWithTenantAndAuthIdAndType).handler(this::extractRequiredJsonPayload);
router.put(pathWithTenantAndAuthIdAndType).handler(this::updateCredentials);
// remove credentials by auth-id and type
router.delete(pathWithTenantAndAuthIdAndType).handler(this::removeCredentials);
// remove all credentials for a device
router.delete(pathWithTenantAndDeviceId).handler(this::removeCredentialsForDevice);
}
示例3: addBasicRoute
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
private void addBasicRoute(JsonObject conf) {
router.route().handler(CookieHandler.create());
BodyHandler bh = BodyHandler.create();
bh.setMergeFormAttributes(false);
bh.setUploadsDirectory(this.upload_dir);
// bh.setDeleteUploadedFilesOnEnd(false);
router.route().handler(bh);
String hasSession = conf.getString("session","true");
if("true".equals(hasSession)){
SessionStore sessionStore = null;
if (vertx.isClustered())
sessionStore = ClusteredSessionStore.create(vertx,SessionName);
else
sessionStore = LocalSessionStore.create(vertx,SessionName);
SessionHandler sessionHandler = SessionHandler.create(sessionStore);
sessionHandler.setNagHttps(false).setCookieHttpOnlyFlag(true);
Long sessionTimeount = conf.getLong("session.timeout");
if(sessionTimeount!=null && sessionTimeount>0)
sessionHandler.setSessionTimeout(sessionTimeount);
router.route().handler(sessionHandler);
if(gsetting.hasAuth() && !this.appContain.isEmpty()){
router.route().handler(UserSessionHandler.create(authMgr.authProvider));
GateAuthHandler authHandler = new GateAuthHandler(authMgr);
router.route().handler(authHandler::handle);
}
}
router.route().failureHandler(rc->{
HttpServerResponse response = rc.response();
if(response.ended())
return;
int statusCode = rc.statusCode() == -1 ? 500 : rc.statusCode();
log.error("Error,status code: {}. ",statusCode);
response.setStatusCode(statusCode).end("status code:"+statusCode);
});
}
示例4: build
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
/**
* Builds the.
*/
private void build() {
// Initialize Vert.x if not setted
if (vertx == null) {
vertx = my(VertxManager.class).vertx();
}
// Set default port if not setted to transporter
if (port == 0) {
if (Boolean.valueOf(CONFIG.get(SERVER_PORT_AUTO_KEY, Boolean.FALSE))) {
port = findForAvailablePort();
} else {
port = Integer.valueOf(CONFIG.get(SERVER_PORT_KEY, SERVER_PORT_DEFAULT));
}
}
httpServerOptions.setPort(port);
// Prepare SSL if available
if (!httpServerOptions.isSsl() && Boolean.valueOf(CONFIG.get(SSL_ENABLE, Boolean.FALSE))) {
httpServerOptions.setSsl(true).setKeyStoreOptions(new JksOptions().setPath(CONFIG.get(SSL_KEYSTORE_KEY, SSL_KEYSTORE_PATH))
.setPassword(CONFIG.get(SSL_KEYSTORE_PASSWORD_KEY, SSL_KEYSTORE_PASSWORD)));
}
// Initialize Router if not setted
if (router == null) {
router = Router.router(vertx);
}
//Create or define the defaut route handler
if(this.routeHandlerClass == null){
this.routeHandlerClass = DefaultHandler.class;
}
// Create default Handler to handle file uploads and body
if(this.bodyHandler == null){
this.bodyHandler = BodyHandler.create(FILE_UPLOADS_PATH);
}
if(!ignoreBodyHandler){
router.route().handler(bodyHandler);
}
// Collect all Middleware Handlers
handlers.forEach(h -> HandlerWrapper.prepareHandler(router, h));
// Collect all handlers adding to router
collectHandlers().forEach(hd -> HandlerWrapper.prepareHandler(router, hd));
// Initialize http server if not setted
if (httpServer == null) {
httpServer = vertx.createHttpServer(httpServerOptions);
}
// Deploy this verticle on Vert.x
vertx.deployVerticle(this);
}
示例5: bodyHandler
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
public BodyHandler bodyHandler() {
return BodyHandler.create();
}
示例6: bodyHandlerForTokenRequest
import io.vertx.ext.web.handler.BodyHandler; //導入方法依賴的package包/類
private Handler<RoutingContext> bodyHandlerForTokenRequest() {
return BodyHandler.create();
}