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


Java CrossOriginFilter类代码示例

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


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

示例1: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(@Nonnull final GraphiakConfiguration configuration,
        @Nonnull final Environment environment) throws Exception {

    // Enable CORS
    final FilterRegistration.Dynamic cors = environment.servlets()
            .addFilter("cors", CrossOriginFilter.class);
    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true,
            "/*");

    // get Riak client
    final RiakClient client = configuration.getRiak().build();

    final MetricStore store = new MetricStore(client);
    environment.lifecycle().manage(new MetricStoreManager(store));

    // Configure the Netty TCP server
    configuration.getNetty().build(environment, store);

    // Resources
    environment.jersey().register(new DashboardResource());
    environment.jersey().register(new MetricsResource(store));
    environment.jersey().register(new EventsResource());
    environment.jersey().register(new PingResource());
    environment.jersey().register(new VersionResource());
}
 
开发者ID:smoketurner,项目名称:graphiak,代码行数:27,代码来源:GraphiakApplication.java

示例2: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(BlogConfiguration blogConfiguration, Environment environment) throws Exception {
    final BlogDao blogDao = new BlogDao(hibernate.getSessionFactory());

    // Register all resources here.
    environment.jersey().register(new BlogResources(blogDao));
    environment.jersey().register(new UploadResources());
    environment.jersey().register(new UnitTestResources());

    // Register MultiPartFeature.class to support mime type "multipart/form-data."
    environment.jersey().getResourceConfig().register(MultiPartFeature.class);

    // All Filter
    // CORS enable
    Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);
    filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
    filter.setInitParameter("allowCredentials", "true");

}
 
开发者ID:zslucky,项目名称:dropwizard-myblog,代码行数:24,代码来源:BlogApplication.java

示例3: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(HelloWorldConfiguration configuration,
        Environment environment) throws Exception {

    // Enable CORS to allow GraphiQL on a separate port to reach the API
    final FilterRegistration.Dynamic cors = environment.servlets()
            .addFilter("cors", CrossOriginFilter.class);
    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true,
            "/*");

    final HelloWorldResource resource = new HelloWorldResource(
            configuration.getTemplate(), configuration.getDefaultName());
    environment.jersey().register(resource);
}
 
开发者ID:smoketurner,项目名称:dropwizard-graphql,代码行数:15,代码来源:HelloWorldApplication.java

示例4: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(AppConfiguration configuration,
                Environment environment) throws Exception {

    /* Configure WebSockets */
    ServerEndpointConfig serverEndpointConfig = ServerEndpointConfig.Builder.create(WebCrawlerEndpoint.class, "/webCrawler").build();
    serverEndpointConfig.getUserProperties().put("config", configuration.webCrawler);
    websocketBundle.addEndpoint(serverEndpointConfig);

    final FilterRegistration.Dynamic cors =
            environment.servlets().addFilter("CORS", CrossOriginFilter.class);

    /* Configure CORS parameters */
    cors.setInitParameter("allowedOrigins", "*");
    cors.setInitParameter("allowedHeaders", "*");
    cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");

    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    environment.healthChecks().register("dummy", new DummyHealthCheck());
}
 
开发者ID:avoloshko,项目名称:WebCrawler,代码行数:22,代码来源:WebApp.java

示例5: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(AppConfiguration configuration, Environment environment) throws Exception {
    SessionFactory sessionFactory = hibernate.getSessionFactory();
    MemoDAO memoDAO = new MemoDAO(sessionFactory);

    ConnectionFactory connectionFactory = QueueHelper.getQueue(configuration.getQueueConfig());

    environment.healthChecks().register("RabbitMQHealthCheck", new QueueHealthCheck(connectionFactory));

    environment.jersey().register(new MemoResource(configuration.getQueueConfig(), memoDAO));

    // CORS Settings to allow cross origin requests
    FilterRegistration.Dynamic filter = environment.servlets().addFilter("CORS", CrossOriginFilter.class);

    filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET,PUT,POST,DELETE,OPTIONS");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    filter.setInitParameter("allowedHeaders", "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin");
    filter.setInitParameter("allowCredentials", "true");
}
 
开发者ID:aytechnologies,项目名称:heroku-gradle-dropwizard,代码行数:22,代码来源:WebApplication.java

示例6: testCrossOriginFilterAddedWhenOn

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Test
public void testCrossOriginFilterAddedWhenOn() throws Exception {
    // setup
    CometdComponent component = context.getComponent("cometd", CometdComponent.class);
    Server server = new Server();

    when(endpoint.isCrossOriginFilterOn()).thenReturn(true);
    when(endpoint.getFilterPath()).thenReturn(FILTER_PATH);
    when(endpoint.getAllowedOrigins()).thenReturn(ALLOWED_ORIGINS);

    // act
    component.createServletForConnector(server, connector, endpoint);

    // assert
    ServletContextHandler handler = (ServletContextHandler) server.getHandler();
    assertEquals(1, handler.getServletHandler().getFilters().length);

    FilterHolder filterHolder = handler.getServletHandler().getFilters()[0];
    Filter filter = filterHolder.getFilter();
    assertTrue(filter instanceof CrossOriginFilter);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CometdCrossOriginConsumerTest.java

示例7: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
public int run() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(port);
    HandlerList handlerList = new HandlerList();

    ServletContextHandler servletContextHandler = new ServletContextHandler();
    FilterHolder cof = new FilterHolder(new CrossOriginFilter());
    cof.setInitParameter(
            CrossOriginFilter.EXPOSED_HEADERS_PARAM,
            "Date");
    servletContextHandler.addFilter(cof, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
    servletContextHandler.addServlet(new ServletHolder(new SmoothStreamingServlet(dataDir)), "/*");
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("supportfiles"));
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    server.start();
    server.dumpStdErr();
    server.join();
    return 0;
}
 
开发者ID:sannies,项目名称:ismv-server,代码行数:23,代码来源:Server.java

示例8: initJerseyServlet

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
/**
 * Initializes the Jersey Servlet.
 */
private void initJerseyServlet() {
  servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
  servletContext.setContextPath("/");
  // This is used for allowing access to different domains/ports.
  FilterHolder filterHolder = new FilterHolder(CrossOriginFilter.class);
  filterHolder.setInitParameter("allowedOrigins", "*");
  filterHolder.setInitParameter("allowedMethods", "GET, POST");
  servletContext.addFilter(filterHolder, "/*", null);

  jerseyServlet = servletContext.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
  jerseyServlet.setInitOrder(0);

  // Tell the Jersey Servlet which REST class to load.
  jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
      ProvisioningAction.class.getCanonicalName());
}
 
开发者ID:google,项目名称:account-provisioning-for-google-apps,代码行数:20,代码来源:RESTApp.java

示例9: provideCrossOriginFilter

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Provides(type = Type.SET)
ContextConfigurator provideCrossOriginFilter(final Configuration conf) {
  return new ContextConfigurator() {
    @Override
    public void init(ServletContextHandler context) {
      FilterHolder crossOriginFilter = new FilterHolder(CrossOriginFilter.class);
      Map<String, String> params = new HashMap<>();

      params.put(CrossOriginFilter.ALLOWED_ORIGINS_PARAM,
          conf.get(CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_ORIGIN,
              CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_ORIGIN_DEFAULT));

      params.put(CrossOriginFilter.ALLOWED_METHODS_PARAM,
          conf.get(CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_METHODS,
              CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_METHODS_DEFAULT));

      params.put(CrossOriginFilter.ALLOWED_HEADERS_PARAM,
          conf.get(CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_HEADERS,
              CORSConstants.HTTP_ACCESS_CONTROL_ALLOW_HEADERS_DEFAULT));

      crossOriginFilter.setInitParameters(params);
      context.addFilter(crossOriginFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
    }
  };
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:26,代码来源:WebServerModule.java

示例10: testCORSGetRequest

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
private void testCORSGetRequest(String userInfoURI) throws Exception {
  HttpAuthenticationFeature authenticationFeature = HttpAuthenticationFeature.basic("admin", "admin");
  Response response = ClientBuilder.newClient()
      .target(userInfoURI)
      .register(authenticationFeature)
      .request()
      .header("Origin", "http://example.com")
      .header("Access-Control-Request-Method", "GET")
      .get();

  Assert.assertEquals(200, response.getStatus());

  MultivaluedMap<String, Object> responseHeader = response.getHeaders();

  List<Object> allowOriginHeader = responseHeader.get(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER);
  Assert.assertNotNull(allowOriginHeader);
  Assert.assertEquals(1, allowOriginHeader.size());
  Assert.assertEquals("http://example.com", allowOriginHeader.get(0));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:TestHttpAccessControl.java

示例11: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(StripeChargeDropwizardConfiguration configuration, Environment environment) {

    final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class);

    // Configure CORS parameters
    cors.setInitParameter("allowedOrigins", configuration.getCoreAllowedOrigin());
    cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin");
    cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");

    // Add URL mapping
    cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    final ChargeResource resource = new ChargeResource(configuration.getStripeSecretKey());

    final StripeAPIHealthCheck healthCheck = new StripeAPIHealthCheck();
    environment.healthChecks().register("stripeApi", healthCheck);

    environment.jersey().register(resource);
}
 
开发者ID:mischat,项目名称:stripe-charge-dropwizard,代码行数:21,代码来源:StripeChargeDropwizardApplication.java

示例12: run

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Override
public void run(AgonConfiguration configuration, Environment environment) throws Exception {

    guiceBundle.getInjector().getInstance(ActionListEventListener.class);

    // CORS support
    FilterRegistration.Dynamic filter = environment.servlets().addFilter("Cross Origin Filter", CrossOriginFilter.class);
    filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "Authorization,X-Requested-With,Content-Type,Accept,Origin");
    filter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD");

    environment.jersey().register(ActionResource.class);
    environment.jersey().register(BadgeResource.class);
    environment.jersey().register(EventResource.class);
    environment.jersey().register(EventTypeResource.class);
    environment.jersey().register(OAuthResource.class);

    environment.jersey().register(new RateLimitExceededExceptionMapper());
    swaggerDropwizard.onRun(configuration, environment, "localhost");
}
 
开发者ID:rridgley1,项目名称:agon,代码行数:22,代码来源:MainApplication.java

示例13: execute1

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
protected void execute1(String component) throws Exception {
	System.out.println("Starting codeine "+component+" at version " + CodeineVersion.get());
	injector = Guice.createInjector(getModules(component));
	FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));
	ServletContextHandler handler = createServletContextHandler();
	handler.setContextPath("/");
	FilterHolder crossHolder = new FilterHolder(new CrossOriginFilter());
	crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "GET, POST, PUT, DELETE");
	crossHolder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Origin,Content-Type,Accept,api_token");
	handler.addFilter(crossHolder, "/api/*", EnumSet.allOf(DispatcherType.class));
	handler.addFilter(crossHolder, "/api-with-token/*", EnumSet.allOf(DispatcherType.class));
	handler.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));
	createAdditionalServlets(handler);
	ContextHandlerCollection contexts = createFileServerContexts();
	contexts.addHandler(handler);
	int port = startServer(contexts);
	log.info("jetty started on port " + port);
	injector.getInstance(CodeineRuntimeInfo.class).setPort(port);
	execute();
}
 
开发者ID:codeine-cd,项目名称:codeine,代码行数:21,代码来源:AbstractCodeineBootstrap.java

示例14: setUp

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
@Before
public void setUp() {

    when(mongoConfiguration.getLocateDatabase()).thenReturn("locate");
    when(mongoConfiguration.getCredentialsDatabase()).thenReturn("locate");
    when(mongoConfiguration.getHosts()).thenReturn("localhost");
    when(mongoConfiguration.getPort()).thenReturn(27017);

    when(configuration.getMongoConfiguration()).thenReturn(mongoConfiguration);

    when(filterBuilder.setInitParam(anyString(), anyString())).thenReturn(filterBuilder);
    when(environment.addFilter(CrossOriginFilter.class, "*")).thenReturn(filterBuilder);
    when(environment.getJerseyResourceConfig()).thenReturn(resourceConfig);
    when(environment.getObjectMapperFactory()).thenReturn(objectMapperFactory);
    when(resourceConfig.getSingletons()).thenReturn(Collections.EMPTY_SET);
}
 
开发者ID:alphagov,项目名称:locate-api,代码行数:17,代码来源:LocateApiServiceTest.java

示例15: JettyCrosServer

import org.eclipse.jetty.servlets.CrossOriginFilter; //导入依赖的package包/类
public JettyCrosServer() throws Exception {
	server = new Server(80);
	HandlerList handlers = new HandlerList();
       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[] { "index.html" });
       resource_handler.setBaseResource(Resource.newClassPathResource("web"));
	
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setInitParameter("maxInterval", "1000");
       context.setInitParameter("logLevel", "2");
               
       handlers.setHandlers(new Handler[] { resource_handler, context});
       
       server.setHandler(handlers);
       
       
       FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
       filterHolder.getInitParameters().put(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
       context.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class));
       
       context.addServlet(new ServletHolder(new JsonServlet()), "/t.json");
       context.addServlet(new ServletHolder(new DefaultServlet()), "/*");
       
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:27,代码来源:JettyCrosServer.java


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