当前位置: 首页>>代码示例>>Java>>正文


Java CorsHandler类代码示例

本文整理汇总了Java中io.vertx.ext.web.handler.CorsHandler的典型用法代码示例。如果您正苦于以下问题:Java CorsHandler类的具体用法?Java CorsHandler怎么用?Java CorsHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CorsHandler类属于io.vertx.ext.web.handler包,在下文中一共展示了CorsHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: enableCors

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
/**
 * Enables CORS
 *
 * @param allowedOriginPattern allowed origin
 * @param allowCredentials     allow credentials (true/false)
 * @param maxAge               in seconds
 * @param allowedHeaders       set of allowed headers
 * @param methods              list of methods ... if empty all methods are allowed  @return self
 * @return self
 */
public RestBuilder enableCors(String allowedOriginPattern,
                              boolean allowCredentials,
                              int maxAge,
                              Set<String> allowedHeaders,
                              HttpMethod... methods) {

	corsHandler = CorsHandler.create(allowedOriginPattern)
	                         .allowCredentials(allowCredentials)
	                         .maxAgeSeconds(maxAge);

	if (methods == null || methods.length == 0) { // if not given than all
		methods = HttpMethod.values();
	}

	for (HttpMethod method : methods) {
		corsHandler.allowedMethod(method);
	}

	corsHandler.allowedHeaders(allowedHeaders);

	return this;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:33,代码来源:RestBuilder.java

示例2: enableCors

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
/**
 * @param router               to add handler to
 * @param allowedOriginPattern origin pattern
 * @param allowCredentials     allowed credentials
 * @param maxAge               in seconds
 * @param allowedHeaders       set of headers or null for none
 * @param methods              list of methods or empty for all
 */
public void enableCors(Router router,
                       String allowedOriginPattern,
                       boolean allowCredentials,
                       int maxAge,
                       Set<String> allowedHeaders,
                       HttpMethod... methods) {

	CorsHandler handler = CorsHandler.create(allowedOriginPattern)
	                                 .allowCredentials(allowCredentials)
	                                 .maxAgeSeconds(maxAge);

	if (methods == null || methods.length == 0) { // if not given than all
		methods = HttpMethod.values();
	}

	for (HttpMethod method : methods) {
		handler.allowedMethod(method);
	}

	handler.allowedHeaders(allowedHeaders);

	router.route().handler(handler);
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:32,代码来源:RestRouter.java

示例3: register

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
/**
 * Register this but also register the {@link CorsHandler}. The
 * {@link CorsHandler} will deal with the normal CORS headers after it has been
 * processed initially by this handler. {@inheritDoc}
 */
@Override
public void register(final Router router) {

    router.route().handler(this);

    router.route().handler(CorsHandler.create(".+")
        .maxAgeSeconds(600)
        .allowedMethod(HttpMethod.GET)
        .allowedMethod(HttpMethod.POST)
        .allowedMethod(HttpMethod.PUT)
        .allowedMethod(HttpMethod.DELETE)
        .allowedMethod(HttpMethod.OPTIONS)
        .allowedHeader("Content-Type")
        .allowedHeader("Accept")
        .allowedHeader("Accept-Language")
        .allowedHeader("Authorization"));

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:24,代码来源:AuthenticatedClientValidator.java

示例4: enableCorsSupport

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
/**
 * Enable CORS support.
 *
 * @param router router instance
 */
protected void enableCorsSupport(Router router) {
  Set<String> allowHeaders = new HashSet<>();
  allowHeaders.add("x-requested-with");
  allowHeaders.add("Access-Control-Allow-Origin");
  allowHeaders.add("origin");
  allowHeaders.add("Content-Type");
  allowHeaders.add("accept");
  Set<HttpMethod> allowMethods = new HashSet<>();
  allowMethods.add(HttpMethod.GET);
  allowMethods.add(HttpMethod.PUT);
  allowMethods.add(HttpMethod.OPTIONS);
  allowMethods.add(HttpMethod.POST);
  allowMethods.add(HttpMethod.DELETE);
  allowMethods.add(HttpMethod.PATCH);

  router.route().handler(CorsHandler.create("*")
    .allowedHeaders(allowHeaders)
    .allowedMethods(allowMethods));
}
 
开发者ID:sczyh30,项目名称:vertx-blueprint-microservice,代码行数:25,代码来源:RestAPIVerticle.java

示例5: start

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
@Override
public void start() throws Exception {
	Router router = Router.router(vertx);
	
	//Config CORS
	router.route().handler(CorsHandler.create("*")
            .allowedMethod(HttpMethod.GET)
            .allowedHeader("Content-Type"));
	
	// hello endpoint
	router.get("/api/hello/:name").handler(ctx -> {
		ctx.response().end(hello(ctx.request().getParam("name")));
	});
	vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
 
开发者ID:redhat-developer-demos,项目名称:kubernetes-lab,代码行数:16,代码来源:HelloworldVerticle.java

示例6: mount

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
@Override
public void mount(final Router router) {
    // 1. Cookie, Body
    router.route()
            .order(Orders.COOKIE)
            .handler(CookieHandler.create());
    router.route()
            .order(Orders.BODY)
            .handler(BodyHandler.create());
    // 2. Cors Template Solution
    router.route()
            .order(Orders.CORS)
            .handler(CorsHandler.create("*")
                    .allowCredentials(false)
                    .allowedHeaders(new HashSet<String>() {
                        {
                            add(HttpHeaders.AUTHORIZATION);
                            add(HttpHeaders.CONTENT_LENGTH);
                            add(HttpHeaders.CONTENT_TYPE);
                        }
                    })
                    .allowedMethods(new HashSet<HttpMethod>() {
                        {
                            add(HttpMethod.DELETE);
                            add(HttpMethod.GET);
                            add(HttpMethod.POST);
                            add(HttpMethod.PUT);
                        }
                    }));

}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:32,代码来源:RouterAxis.java

示例7: start

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
/**
 * Server starting behaviour
 *
 * @param fut Future that handles the start status
 * @throws NullPointerException if fut is null
 */
@Override
public void start(Future<Void> fut) {
    Objects.requireNonNull(fut);
    Router router = Router.router(vertx);
    router.route().handler(CorsHandler.create("*")
            .allowedMethod(HttpMethod.GET)
            .allowedMethod(HttpMethod.POST)
            .allowedMethod(HttpMethod.OPTIONS)
            .allowedHeader("X-PINGARUNER")
            .allowedHeader("Content-Type")
    );

    router.route("/anomaly*").handler(BodyHandler.create()); // enable reading of request's body
    router.get("/anomaly").handler(this::getAnomalies);
    router.post("/anomaly").handler(this::getAnomalies);
    vertx
            .createHttpServer()
            .requestHandler(router::accept)
            .listen(
                    config().getInteger("http.port", 8081), // default value: 8081
                    result -> {
                        if (result.succeeded()) {
                            fut.complete();
                        } else {
                            fut.fail(result.cause());
                        }
                    }
            );
    LOGGER.info("VertxServer started");
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:37,代码来源:VertxServer.java

示例8: addCorsHandler

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
private static void addCorsHandler(Router router, CorsConfig corsConfig) {
    if (corsConfig != null) {
        CorsHandler corsHandler = CorsHandler.create(corsConfig.getAllowedOriginPattern());

        if (corsConfig.getAllowedMethods() != null) {
            corsHandler.allowedMethods(corsConfig.getAllowedMethods());
        }

        if (corsConfig.getAllowCredentials() != null) {
            corsHandler.allowCredentials(corsConfig.getAllowCredentials());
        }

        if (corsConfig.getAllowedHeaders() != null) {
            corsHandler.allowedHeaders(corsConfig.getAllowedHeaders());
        }

        if (corsConfig.getExposedHeaders() != null) {
            corsHandler.exposedHeaders(corsConfig.getExposedHeaders());
        }

        if (corsConfig.getMaxAgeSeconds() != null) {
            corsHandler.maxAgeSeconds(corsConfig.getMaxAgeSeconds());
        }

        router.route().handler(corsHandler);
    }
}
 
开发者ID:DTeam-Top,项目名称:dfx,代码行数:28,代码来源:PluginManagerVerticle.java

示例9: cors

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
private void cors(Router router) {
  router.route().handler(CorsHandler.create("*")
    .allowedMethod(HttpMethod.GET)
    .allowedMethod(HttpMethod.POST)
    .allowedHeader("Content-Type")
    .allowedHeader("Accept")
  );
}
 
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:9,代码来源:WebVerticle.java

示例10: cors

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
private void cors(Router router) {
    router.route().handler(CorsHandler.create("*")
        .allowedMethod(HttpMethod.GET)
        .allowedMethod(HttpMethod.POST)
        .allowedHeader("Content-Type")
        .allowedHeader("Accept")
    );
}
 
开发者ID:danielpetisme,项目名称:vertx-forge,代码行数:9,代码来源:WebVerticle.java

示例11: checkContainsCors

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
private void checkContainsCors(Router router) {
  if (config().getValue("cors") instanceof JsonObject) {
    JsonObject corsConfig = config().getJsonObject("cors");
    String allowedOriginPattern = corsConfig.getString("allowedOriginPattern", "*");
    CorsHandler corsHandler = CorsHandler.create(allowedOriginPattern);
    if (config().getValue("allowedMethods") instanceof JsonArray) {
      config().getJsonArray("allowedMethods").forEach(o -> {
        if (o instanceof String) {
          String method = (String) o;
          corsHandler.allowedMethod(HttpMethod.valueOf(method.toUpperCase()));
        }
      });
    }
    if (config().getValue("allowedHeaders") instanceof JsonArray) {
      config().getJsonArray("allowedHeaders").forEach(o -> {
        if (o instanceof String) {
          String headerName = (String) o;
          corsHandler.allowedHeader(headerName);
        }
      });
    }
    if (config().getValue("allowCredentials") instanceof Boolean) {
      corsHandler.allowCredentials(config().getBoolean("allowCredentials"));
    }
    if (config().getValue("maxAgeSeconds") instanceof Integer) {
      corsHandler.maxAgeSeconds(config().getInteger("maxAgeSeconds"));
    }
  router.route().handler(corsHandler);
  }
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:31,代码来源:ApiDispatchVerticle.java

示例12: RouterStorage

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
@Inject
public RouterStorage(CorsHandler corsHandler, BodyHandlerImpl bodyHandler, Lazy<BootstrapInitializer> boot, Lazy<Database> db) {
	this.boot = boot;
	this.db = db;
	this.corsHandler = corsHandler;
	this.bodyHandler = bodyHandler;

	/**
	 * Initialize the router storage. This will setup the basic route handlers for /api/v1 and cookie/cors handling.
	 */
	initAPIRouter();
	RouterStorage.instances.add(this);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:14,代码来源:RouterStorage.java

示例13: CORSMiddleware

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
public CORSMiddleware() {
  this.corsHandler = CorsHandler.create(allowedOriginPattern())
      .allowedHeaders(allowedHeaders())
      .allowedMethods(allowedMethods())
      .allowCredentials(allowCredentials())
      .exposedHeaders(exposedHeaders());
}
 
开发者ID:leosilvadev,项目名称:brandenburg,代码行数:8,代码来源:CORSMiddleware.java

示例14: route

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
private Route route(final CorsRoute corsRoute) {
  final CorsHandler corsHandler = CorsHandler.create(corsRoute.getAllowedOriginPattern());

  if (corsRoute.getAllowCredentials() != null)
    corsHandler.allowCredentials(corsRoute.getAllowCredentials());

  if (corsRoute.getAllowHeaders() != null)
    corsHandler.allowedHeaders(corsRoute.getAllowHeaders());

  if (corsRoute.getAllowMethods() != null)
    corsHandler.allowedMethods(corsRoute.getAllowMethods());

  if (corsRoute.getExposeHeaders() != null)
    corsHandler.exposedHeaders(corsRoute.getExposeHeaders());

  if (corsRoute.getFromPath() == null) {
    if (corsRoute.getFromMethod() == null) {
      return router.route().handler(corsHandler);
    } else {
      throw new IllegalArgumentException("Cannot configure CORS for a specific Method without a Path");
    }
  } else if (corsRoute.getFromMethod() == null) {
    return router.route(corsRoute.getFromPath()).handler(corsHandler);
  } else {
    return router.route(corsRoute.getFromMethod(), corsRoute.getFromPath()).handler(corsHandler);
  }
}
 
开发者ID:leosilvadev,项目名称:brandenburg,代码行数:28,代码来源:ProxyRouter.java

示例15: corsHandler

import io.vertx.ext.web.handler.CorsHandler; //导入依赖的package包/类
public void corsHandler(Router router) {
  router
      .route()
      .handler(
          CorsHandler.create("127.0.0.1")
              .allowedMethod(io.vertx.core.http.HttpMethod.GET)
              .allowedMethod(io.vertx.core.http.HttpMethod.POST)
              .allowedMethod(io.vertx.core.http.HttpMethod.OPTIONS)
              .allowedMethod(io.vertx.core.http.HttpMethod.PUT)
              .allowedMethod(io.vertx.core.http.HttpMethod.DELETE)
              .allowedHeader("Content-Type")
              .allowedHeader("X-Requested-With"));
}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:14,代码来源:RestrictedCorsRouterConfig.java


注:本文中的io.vertx.ext.web.handler.CorsHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。