Java 类com.google.inject.servlet.GuiceFilter 实例源码

项目:dropwizard-guice    文件:GuiceBootstrap.java   
@Override
public void run(final T config, final Environment environment) throws Exception {
    Module bootstrapModule = new AbstractModule() {
        @Override
        protected void configure() {
            install(new DropwizardModule());
            if (mainModule != null)
                install(mainModule);

            bind(Configuration.class).toInstance(config);
            bind(configClass).toInstance(config);
            bind(Environment.class).toInstance(environment);
        }
    };

    environment.servlets() //
            .addFilter("guice-request-scope", new GuiceFilter()) //
            .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

    Guice.createInjector(bootstrapModule).getInstance(applicationClass).run();
}
项目:nexus-public    文件:SiestaTestSupport.java   
@Before
public void startJetty() throws Exception {
  servletTester = new ServletTester();
  servletTester.getContext().addEventListener(new GuiceServletContextListener()
  {
    final Injector injector = Guice.createInjector(new TestModule());

    @Override
    protected Injector getInjector() {
      return injector;
    }
  });

  url = servletTester.createConnector(true) + TestModule.MOUNT_POINT;
  servletTester.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
  servletTester.addServlet(DummyServlet.class, "/*");
  servletTester.start();

  client = ClientBuilder.newClient();
}
项目:nexus-public    文件:NexusContextModule.java   
@Override
protected void configure() {

  // we will look these up later...
  requireBinding(GuiceFilter.class);
  requireBinding(BeanManager.class);

  bind(ManagedLifecycleManager.class).to(NexusLifecycleManager.class);

  bind(ServletContext.class).toInstance(servletContext);
  bind(ParameterKeys.PROPERTIES).toInstance(nexusProperties);

  install(new StateGuardModule());
  install(new TransactionModule());
  install(new TimeTypeConverter());
  install(new WebSecurityModule(servletContext));

  // enable OSGi service lookup of Karaf components
  final MutableBeanLocator locator = new DefaultBeanLocator();
  locator.add(new ServiceBindings(bundleContext, ALLOW_SERVICES, IGNORE_SERVICES, Integer.MIN_VALUE));
  bind(MutableBeanLocator.class).toInstance(locator);
}
项目:kafka-ws    文件:JettyServer.java   
public void run() {
  try {
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);

    connector.setPort(port);

    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath(contextPath);
    context.addFilter(GuiceFilter.class, "/api/*", null);
    server.setHandler(context);

    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
    KafkaWebsocketEndpoint.Configurator.setKafkaProps(consumerProps, producerProps);
    wsContainer.addEndpoint(KafkaWebsocketEndpoint.class);

    server.start();
    server.join();
  } catch (Exception e) {
    logger.error("Failed to start the server: ", e);
  }
}
项目:jersey-guice-jetty-angular-seed    文件:Main.java   
public void startServer() throws Exception {
    int serverPort = propertiesConfiguration.getInt("server.port.http");
    Server server = new Server(serverPort);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("/web"));

    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/api");
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

    initGuiceInjector();

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(resourceHandler);
    handlerList.addHandler(servletContextHandler);
    server.setHandler(handlerList);

    server.start();
    server.join();
}
项目:microservice-java    文件:SampleMain.java   
public static void main(String[] args) throws Exception {
    final Server server = new Server();

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(PORT);
    server.setConnectors(new Connector[] { connector });

    // Configure the Guice application.
    ServletContextHandler servletHandler = new ServletContextHandler();
    servletHandler.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    servletHandler.addEventListener(new SampleServletContextListener());
    server.setHandler(servletHandler);

    // Start the server and wait for it.
    server.start();
    server.join();
}
项目:codeine    文件:AbstractCodeineBootstrap.java   
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();
}
项目:jersey2-guice-example    文件:ServerBuilder.java   
public Server build() {
  ServiceLocator locator = BootstrapUtils.newServiceLocator();
  Injector injector = BootstrapUtils.newInjector(locator, Arrays.asList(new ServletModule(), new MyModule()));

  BootstrapUtils.install(locator);

  Server server = new Server(port);

  ResourceConfig config = ResourceConfig.forApplication(new MyApplication());

  ServletContainer servletContainer = new ServletContainer(config);

  ServletHolder sh = new ServletHolder(servletContainer);
  ServletContextHandler context = new ServletContextHandler(
      ServletContextHandler.SESSIONS);
  context.setContextPath("/");

  FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
  context.addFilter(filterHolder, "/*",
                    EnumSet.allOf(DispatcherType.class));

  context.addServlet(sh, "/*");
  server.setHandler(context);
  return server;
}
项目:jersey-new-relic    文件:FullStackTest.java   
@Test
public void testInvokeResourceWithCategory() throws Exception {
    final Map<String, String> initParams = new HashMap<>();
    initParams.put(NewRelicResourceFilterFactory.TRANSACTION_CATEGORY_PROP, "someCategory");
    initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
        NewRelicResourceFilterFactory.class.getCanonicalName());

    server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
    server.start();

    Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo").execute().get();

    assertEquals(200, response.getStatusCode());

    assertEquals(newArrayList("someCategory:/foo GET"), wrapper.getNames());
    assertTrue(wrapper.getThrowables().isEmpty());
}
项目:jersey-new-relic    文件:FullStackTest.java   
@Test
public void testInvokeResourceWithoutCategory() throws Exception {
    final Map<String, String> initParams = new HashMap<>();
    initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
        NewRelicResourceFilterFactory.class.getCanonicalName());

    server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
    server.start();

    Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo").execute().get();

    assertEquals(200, response.getStatusCode());

    assertEquals(newArrayList("/foo GET"), wrapper.getNames());
    assertTrue(wrapper.getThrowables().isEmpty());
}
项目:jersey-new-relic    文件:FullStackTest.java   
@Test
public void testInvokeThrowsResource() throws Exception {
    final Map<String, String> initParams = new HashMap<>();
    initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
        NewRelicResourceFilterFactory.class.getCanonicalName());

    server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
    server.start();

    Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo/throw").execute().get();

    assertEquals(500, response.getStatusCode());

    assertEquals(newArrayList("/foo/throw GET"), wrapper.getNames());
    assertEquals(1, wrapper.getThrowables().size());
    assertEquals("zomg", wrapper.getThrowables().get(0).getMessage());
}
项目:jersey-new-relic    文件:FullStackTest.java   
@Test
public void testInvokeThrowsMappedResource() throws Exception {
    final Map<String, String> initParams = new HashMap<>();
    initParams.put(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
        NewRelicResourceFilterFactory.class.getCanonicalName());

    server = getServer(getInjector(initParams).getInstance(GuiceFilter.class));
    server.start();

    Response response = httpClient.prepareGet("http://localhost:" + PORT + "/foo/throwMapped").execute().get();

    assertEquals(javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());

    assertEquals(newArrayList("/foo/throwMapped GET"), wrapper.getNames());
    assertEquals(1, wrapper.getThrowables().size());
    assertEquals("asdf", wrapper.getThrowables().get(0).getMessage());
}
项目:jersey-new-relic    文件:FullStackTest.java   
private Server getServer(GuiceFilter filter) {
    Server server = new Server(PORT);
    ServletContextHandler servletHandler = new ServletContextHandler();

    servletHandler.addServlet(new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            resp.setContentType("text/plain");
            resp.setContentType("UTF-8");
            resp.getWriter().append("404");
        }
    }), "/*");

    // add guice servlet filter
    servletHandler.addFilter(new FilterHolder(filter), "/*", EnumSet.allOf(DispatcherType.class));

    server.setHandler(servletHandler);

    return server;
}
项目:jersey-guice-dispatch-wrapper    文件:ResourceMethodWrappedDispatchTest.java   
@Test
public void testWorksWithoutBindingAnyWrapperFactories() throws Exception {

    Injector injector = getInjector(new AbstractModule() {
        @Override
        protected void configure() {
            // no op
        }
    });

    server = getServer(injector.getInstance(GuiceFilter.class));
    server.start();

    FooResource resource = injector.getInstance(FooResource.class);

    com.ning.http.client.Response response =
        httpClient.preparePost("http://localhost:" + PORT + "/foo").execute().get();

    assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusCode());
    assertEquals(1, resource.counter.get());
}
项目:jersey-guice-dispatch-wrapper    文件:ResourceMethodWrappedDispatchTest.java   
private Server getServer(GuiceFilter filter) {
    Server server = new Server(PORT);
    ServletContextHandler servletHandler = new ServletContextHandler();

    servletHandler.addServlet(new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            resp.setContentType("text/plain");
            resp.setContentType("UTF-8");
            resp.getWriter().append("404");
        }
    }), "/*");

    // add guice servlet filter
    servletHandler.addFilter(new FilterHolder(filter), "/*", EnumSet.allOf(DispatcherType.class));

    server.setHandler(servletHandler);

    return server;
}
项目:jersey-guice-dispatch-wrapper    文件:ResourceMethodWrappedDispatchTest.java   
private static Injector getInjector(final Module module) {
    return Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
            binder().requireExplicitBindings();
            install(new ResourceMethodWrappedDispatchModule());
            install(new ServletModule() {
                @Override
                protected void configureServlets() {
                    serve("/*").with(GuiceContainer.class);
                }
            });
            install(new JerseyServletModule());
            bind(GuiceFilter.class);
            bind(GuiceContainer.class);
            bind(FooResource.class);
            install(module);
        }
    });
}
项目:jersey-metrics-filter    文件:FullStackTest.java   
private Server getServer(GuiceFilter filter) {
    Server server = new Server(PORT);
    ServletContextHandler servletHandler = new ServletContextHandler();

    servletHandler.addServlet(new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
            IOException {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            resp.setContentType("text/plain");
            resp.setContentType("UTF-8");
            resp.getWriter().append("404");
        }
    }), "/*");

    // add guice servlet filter
    servletHandler.addFilter(new FilterHolder(filter), "/*", EnumSet.allOf(DispatcherType.class));

    server.setHandler(servletHandler);

    return server;
}
项目:jetty-guice    文件:JettyServer.java   
public void start() throws Exception {
        server = new Server(port);

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.addFilter(GuiceFilter.class, "/*", null);
        context.addEventListener(guiceConfig);

//        ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
//        servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
//        servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.gdiama");
//        servletHolder.setInitParameter("com.sun.jersey.config.feature.Debug", "true");
//        servletHolder.setInitParameter("com.sun.jersey.config.feature.Trace", "true");
//        servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//        servletHolder.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
//        context.addServlet(servletHolder, "/rest/*");


        context.setServer(server);
        ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
        wscontainer.addEndpoint(WebsocketEndpoint.class);

        server.setHandler(context);
        server.start();
    }
项目:joynr    文件:AbstractJoynrServletModule.java   
@Override
final protected void configureServlets() {

    // GuiceFilter is instantiated here instead of configured in
    // web.xml to allow for more than one servlet per servlet
    // container.
    // See documentation of web.xml for details.
    bind(GuiceFilter.class);

    configureJoynrServlets();

    // Route all requests through GuiceContainer
    bindStaticWebResources();
    bindJoynrServletClass();

    bindAnnotatedFilters();
}
项目:dropwizard-bundle-guice    文件:GuiceBundle.java   
@Override
public void run(final T configuration, final Environment environment)
{
    final Iterable<Module> configedModules = configureModules(configuration, modules);
    final DropwizardModule<T> dwModule = new DropwizardModule<T>(configuration, environment);

    final Injector injector = parentInjector.or(Guice.createInjector())
            .createChildInjector(Iterables.concat(of(dwModule), configedModules));

    environment.addFilter(injector.getInstance(GuiceFilter.class), "*");

    // Support Module definition of health checks
    if (!injector.findBindingsByType(healthChecksKey.getTypeLiteral()).isEmpty()) {
        final Set<HealthCheck> healthChecks = injector.getInstance(healthChecksKey);
        for (HealthCheck hc : healthChecks) {
            environment.addHealthCheck(hc);
        }
    }

}
项目:Nicobar    文件:ExplorerAppTest.java   
@BeforeClass
public void init() throws Exception {
    System.setProperty("archaius.deployment.applicationId","scriptmanager-app");
    System.setProperty("archaius.deployment.environment","dev");

    server = new Server(TEST_LOCAL_PORT);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addEventListener(new KaryonGuiceContextListener());

    context.addFilter(GuiceFilter.class, "/*", 1);
    context.addServlet(DefaultServlet.class, "/");

    server.setHandler(context);

    server.start();
}
项目:ja-micro    文件:JettyComposer.java   
public static void compose(Server server) {
    //Servlets + Guice
    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    servletContextHandler.addServlet(DefaultServlet.class, "/");

    //JMX stuff...
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addEventListener(mbContainer);
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
}
项目:webserver    文件:ServletContextHandlerProvider.java   
public Handler get() {
  ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  handler.setContextPath("/");
  handler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
  handler.addServlet(servletHolder, "/*");

  return handler;
}
项目:abhot    文件:WebServletModule.java   
@Override
protected void configureServlets()
{
    binder().requireExplicitBindings();
    bind(GuiceFilter.class);

    //Bind web server
    bind(WebServer.class);

    //Bind resource classes here
    bind(MetricsResource.class).in(Scopes.SINGLETON);

    bind(GuiceContainer.class);

    ImmutableMap<String, String> params = new ImmutableMap.Builder<String, String>()
            .put("mimeTypes", MediaType.APPLICATION_JSON)
            .put("methods", "GET,POST")
            .build();
    bind(GzipFilter.class).in(Scopes.SINGLETON);
    filter("/*").through(GzipFilter.class, params);

    bind(LoggingFilter.class).in(Scopes.SINGLETON);
    filter("/*").through(LoggingFilter.class);

    // hook Jackson into Jersey as the POJO <-> JSON mapper
    bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);
    serve("/*").with(GuiceContainer.class);


}
项目:conductor    文件:ConductorServer.java   
public synchronized void start(int port, boolean join) throws Exception {

    if(server != null) {
        throw new IllegalStateException("Server is already running");
    }

    Guice.createInjector(sm);

    //Swagger
    String resourceBasePath = Main.class.getResource("/swagger-ui").toExternalForm();
    this.server = new Server(port);

    ServletContextHandler context = new ServletContextHandler();
    context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    context.setResourceBase(resourceBasePath);
    context.setWelcomeFiles(new String[] { "index.html" });

    server.setHandler(context);


    DefaultServlet staticServlet = new DefaultServlet();
    context.addServlet(new ServletHolder(staticServlet), "/*");

    server.start();
    System.out.println("Started server on http://localhost:" + port + "/");
    try {
        boolean create = Boolean.getBoolean("loadSample");
        if(create) {
            System.out.println("Creating kitchensink workflow");
            createKitchenSink(port);
        }
    }catch(Exception e) {
        logger.error(e.getMessage(), e);
    }

    if(join) {
        server.join();
    }

}
项目:ccow    文件:ClientTestSuite.java   
@BeforeClass
public static void beforeClass() throws Exception {
    server = new Server(port);
    final ServletContextHandler sch = new ServletContextHandler(server, "/");
    sch.addEventListener(new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule()));
    sch.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    sch.addServlet(DefaultServlet.class, "/");
    server.start();
}
项目:opengse    文件:Main.java   
public static void main(String[] args) throws Exception {
  // This object will create our webapp's configuration for us
  WebAppConfigurationBuilder configBuilder = new WebAppConfigurationBuilder();
  // register our servlet to respond to the "/bar" pattern
  configBuilder.addFilter(GuiceFilter.class, "/*");
  configBuilder.addServlet(BasicServlet.class, "/bar");
  // we need to be able to return a directory
  // when javax.servlet.ServletContext.getRealPath("/") is called
  // hence the need for a context directory
  File contextDir = new File(System.getProperty("java.io.tmpdir"));
  // We want "" to be returned by
  // javax.servlet.http.HttpServletRequest.getContextPath() (ie. the root context)
  // so we use the "ROOT" context name (this is so we can have files called ROOT.war and not
  // "".war
  String context = "ROOT";
  // create a collection of webapps that just contains a single webapp
  WebAppCollection webapps
    = WebAppCollectionFactory.createWebAppCollectionWithOneContext(contextDir,
      context, configBuilder.getConfiguration());
  // start all of the webapps
  webapps.startAll();
  // create servlet engine configuration object
  ServletEngineConfiguration config
      = ServletEngineConfigurationImpl.create(PORT, MAX_THREADS);
  // the collection of webapps is our "request sink" (just done to illustrate)
  FilterChain requestSink = webapps;
  // create an engine using the engine configuration and send all requests
  // to our request sink
  ServletEngine engine = ServletEngineImpl.create(requestSink, config);
  // run it
  engine.run();
}
项目:nexus-public    文件:NexusContextListener.java   
/**
 * Register our dynamic filter with the bootstrap listener.
 */
private void registerNexusFilter() {
  if (registration == null) {
    final Filter filter = injector.getInstance(GuiceFilter.class);
    final Dictionary<String, ?> filterProperties = new Hashtable<>(singletonMap("name", "nexus"));
    registration = bundleContext.registerService(Filter.class, filter, filterProperties);
  }
}
项目:nexus-public    文件:WebModule.java   
@Override
protected void configure() {
  bind(GuiceFilter.class).to(DynamicGuiceFilter.class);

  // our configuration needs to be first-most when calculating order (some fudge room for edge-cases)
  final Binder highPriorityBinder = binder().withSource(Sources.prioritize(0x70000000));

  highPriorityBinder.install(new ServletModule()
  {
    @Override
    protected void configureServlets() {
      bind(HeaderPatternFilter.class);
      bind(EnvironmentFilter.class);
      bind(ErrorPageFilter.class);

      filter("/*").through(HeaderPatternFilter.class);
      filter("/*").through(EnvironmentFilter.class);
      filter("/*").through(ErrorPageFilter.class);

      bind(ErrorPageServlet.class);

      serve("/error.html").with(ErrorPageServlet.class);
      serve("/throw.html").with(ThrowServlet.class);
    }
  });

  highPriorityBinder.install(new MetricsModule());

  install(new OrientModule());
}
项目:fathom    文件:Server.java   
protected DeploymentManager createFathomDeploymentManager() throws ServletException {

        DeploymentInfo info = Servlets.deployment();
        info.setDeploymentName("Fathom");
        info.setClassLoader(this.getClass().getClassLoader());
        info.setContextPath(settings.getContextPath());
        info.setIgnoreFlush(true);
        info.setDefaultEncoding("UTF-8");

        FilterInfo guiceFilter = new FilterInfo("GuiceFilter", GuiceFilter.class);
        guiceFilter.setAsyncSupported(true);

        info.addFilterUrlMapping("GuiceFilter", "/*", DispatcherType.REQUEST);
        info.addFilters(guiceFilter);

        ServletInfo defaultServlet = new ServletInfo("DefaultServlet", DefaultServlet.class);
        defaultServlet.setAsyncSupported(true);
        defaultServlet.addMapping("/");

        ServletContextListener fathomListener = new ServletContextListener(settings);

        info.addListeners(new ListenerInfo(ServletContextListener.class, new ImmediateInstanceFactory<>(fathomListener)));

        MultipartConfigElement multipartConfig = new MultipartConfigElement(settings.getUploadFilesLocation(), settings.getUploadFilesMaxSize(), -1L, 0);
        defaultServlet.setMultipartConfig(multipartConfig);
        info.addServlets(defaultServlet);

        DeploymentManager deploymentManager = Servlets.defaultContainer().addDeployment(info);
        deploymentManager.deploy();

        return deploymentManager;
    }
项目:guiceberry    文件:MyPetStoreServer.java   
public MyPetStoreServer(int portNumber) {
  this.portNumber = portNumber;
  server = new Server(portNumber);    
  Context root = new Context(server, "/", Context.SESSIONS);

  root.addFilter(GuiceFilter.class, "/*", 0);
  root.addServlet(DefaultServlet.class, "/");
}
项目:guiceberry    文件:PetStoreServer.java   
@Inject
public PetStoreServer(int portNumber) {
  server = new Server(portNumber);
  Context root = new Context(server, "/", Context.SESSIONS);

  root.addFilter(GuiceFilter.class, "/*", 0);
  root.addServlet(DefaultServlet.class, "/");
}
项目:gerrit    文件:HttpPluginServlet.java   
private void install(Plugin plugin) {
  GuiceFilter filter = load(plugin);
  final String name = plugin.getName();
  final PluginHolder holder = new PluginHolder(plugin, filter);
  plugin.add(
      new RegistrationHandle() {
        @Override
        public void remove() {
          plugins.remove(name, holder);
        }
      });
  plugins.put(name, holder);
}
项目:gerrit    文件:LfsPluginServlet.java   
private void install(Plugin plugin) {
  if (!plugin.getName().equals(pluginName)) {
    return;
  }
  final GuiceFilter guiceFilter = load(plugin);
  plugin.add(
      new RegistrationHandle() {
        @Override
        public void remove() {
          filter.compareAndSet(guiceFilter, null);
        }
      });
  filter.set(guiceFilter);
}
项目:funsteroid    文件:TomcatServer.java   
private void createGuiceFilter(Context context) {
    FilterDef filterDefinition = new FilterDef();
    filterDefinition.setFilterName(GuiceFilter.class.getSimpleName());
    filterDefinition.setFilterClass(GuiceFilter.class.getName());
    context.addFilterDef(filterDefinition);

    FilterMap filterMapping = new FilterMap();
    filterMapping.setFilterName(GuiceFilter.class.getSimpleName());
    filterMapping.addURLPattern("/*");
    context.addFilterMap(filterMapping);
}
项目:funsteroid    文件:JettyServer.java   
public Server run() throws Exception{
    Server server = new Server(port);

    FunsteroidModule funsteroidModule=new FunsteroidModule()
            .withFilter(filterConfiguration)
            .withFilter(filter)
            .withRoutes(route)
            .withRoutes(routeProvider)
            .withMacros(macroRegister)
            .withMacros(macroRegisterInstance);

    HandlerList handlers = new HandlerList();

    ResourceHandler resourceHandler=new ResourceHandler(){
        protected void doDirectory(HttpServletRequest request,HttpServletResponse response, Resource resource) throws IOException{
             response.sendError(HttpStatus.NOT_FOUND_404);
        }

    };
    resourceHandler.setDirectoriesListed(false);
    resourceHandler.setResourceBase(getWebAppPath());

    WebAppContext context = new WebAppContext();
       //TODO: Locate path before setup depending on enviroment execution
       context.setResourceBase(getWebAppPath());

       context.setContextPath("/");
       context.setParentLoaderPriority(true);
       context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
       context.addEventListener(new GuiceConfigListener(funsteroidModule));
       context.addFilter(GuiceFilter.class, "/*", null);
       handlers.addHandler(resourceHandler);
       handlers.addHandler(context);

       server.setHandler(handlers);
       server.start();
       server.join();
       return server;
}
项目:MoodCat.me-Core    文件:MoodcatHandler.java   
@Override
protected void withInjector(final Injector injector) {
    final FilterHolder guiceFilterHolder = new FilterHolder(
            injector.getInstance(GuiceFilter.class));
    MoodcatHandler.this.addFilter(guiceFilterHolder, "/*",
            EnumSet.allOf(DispatcherType.class));
    MoodcatHandler.this.app.getInjectorAtomicReference().set(injector);
}
项目:hapi-fhir    文件:ServerStartup.java   
public static void main(final String[] args) throws Exception {

        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        final Server server = new Server(9090);
        final ServletContextHandler sch = new ServletContextHandler(server, "/");
        sch.addEventListener(new ContextListener());
        sch.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
        sch.addServlet(DefaultServlet.class, "/");
        server.start();

        // Service is now accessible through
        // http://localhost:9090/model/Practitioner
    }
项目:dropwizardry    文件:GuiceSupport.java   
@Override
    public void run(final T configuration, final Environment environment) {
        if (configurationClass.isPresent()) {
            dropwizardEnvironmentModule = new DropwizardEnvironmentModule<T>(configurationClass.get(), configuration, environment);
        } else {
            dropwizardEnvironmentModule = new DropwizardEnvironmentModule<Configuration>(Configuration.class, configuration, environment);
        }

//        setEnvironment(configuration, environment);

        container = new GuiceContainer();
        JerseyContainerModule jerseyContainerModule = new JerseyContainerModule(container);

        modules.add(jerseyContainerModule);
        modules.add(dropwizardEnvironmentModule);

        initInjector();

        container.setResourceConfig(environment.jersey().getResourceConfig());
        environment.jersey().replace(new Function<ResourceConfig, ServletContainer>() {
            @Nullable
            @Override
            public ServletContainer apply(ResourceConfig resourceConfig) {
                return container;
            }
        });
        environment.servlets().addFilter("Guice Filter", GuiceFilter.class)
                .addMappingForUrlPatterns(null, false, environment.getApplicationContext().getContextPath() + "*");

    }
项目:Artemis    文件:ServerModule.java   
@Provides
@Singleton
protected ServletContextHandler providesServletContextHandler() {
    ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.addServlet(DefaultServlet.class, "/*");
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    return servletContextHandler;
}