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


Java GuiceServletContextListener类代码示例

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


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

示例1: startJetty

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@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();
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:21,代码来源:SiestaTestSupport.java

示例2: makeServletContextListener

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@VisibleForTesting
static ServletContextListener makeServletContextListener(
    final Injector parentInjector,
    final Module childModule) {

  return new GuiceServletContextListener() {
    @Override
    protected Injector getInjector() {
      return parentInjector.createChildInjector(
          childModule,
          new JerseyServletModule() {
            @Override
            protected void configureServlets() {
              bind(HttpStatsFilter.class).in(Singleton.class);
              filter("*").through(HttpStatsFilter.class);

              bind(LeaderRedirectFilter.class).in(Singleton.class);
              filterRegex(allOf(LEADER_ENDPOINTS))
                  .through(LeaderRedirectFilter.class);

              bind(GuiceContainer.class).in(Singleton.class);
              filterRegex(allOf(ImmutableSet.copyOf(JAX_RS_ENDPOINTS.values())))
                  .through(GuiceContainer.class, GUICE_CONTAINER_PARAMS);

              filterRegex("/assets/scheduler(?:/.*)?").through(LeaderRedirectFilter.class);

              serve("/assets", "/assets/*")
                  .with(new DefaultServlet(), ImmutableMap.of(
                      "resourceBase", STATIC_ASSETS_ROOT,
                      "dirAllowed", "false"));

              for (Class<?> jaxRsHandler : JAX_RS_ENDPOINTS.keySet()) {
                bind(jaxRsHandler);
              }
            }
          });
    }
  };
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:40,代码来源:JettyServerModule.java

示例3: createServletEventListener

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
private void createServletEventListener(Environment environment, final Injector injector) {
    environment.getApplicationContext().addEventListener(new GuiceServletContextListener() {
        @Override
        protected Injector getInjector() {
            return injector;
        }
    });
}
 
开发者ID:robeio,项目名称:robe,代码行数:9,代码来源:ServletScanner.java

示例4: setupHttpServer

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
private static HttpServer setupHttpServer(URI baseUri, final Injector injector) {
    final HttpServer serverLocal = GrizzlyHttpServerFactory
            .createHttpServer(baseUri, false);

    final WebappContext context = new WebappContext("Guice Webapp sample",
            "");

    context.addListener(new GuiceServletContextListener(){
        @Override
        protected Injector getInjector() {
            return injector;
        }
    });

    // Initialize and register Jersey ServletContainer
    final ServletRegistration servletRegistration = context.addServlet(
            "ServletContainer", ServletContainer.class);
    servletRegistration.addMapping("/*");
    servletRegistration.setInitParameter("javax.ws.rs.Application",
            WebApp.class.getName());

    // Initialize and register GuiceFilter
    final FilterRegistration registration = context.addFilter(
            "GuiceFilter", GuiceFilter.class);
    registration.addMappingForUrlPatterns(
            EnumSet.allOf(DispatcherType.class), "/*");

    context.deploy(serverLocal);

    return serverLocal;
}
 
开发者ID:udoprog,项目名称:exposr,代码行数:32,代码来源:Main.java

示例5: servletContext

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@Provides
public ServletContextHandler servletContext(GuiceResteasyBootstrapServletContextListener resteasyListener,
                                            GuiceFilter guiceFilter,
                                            GuiceServletContextListener guiceServletContextListener) {
    final FilterHolder guiceFilterHolder = new FilterHolder(guiceFilter);
    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addFilter(guiceFilterHolder, "/*", EnumSet.allOf(DispatcherType.class));
    context.addEventListener(resteasyListener);
    context.addEventListener(guiceServletContextListener);
    return context;
}
 
开发者ID:benhardy,项目名称:lilrest,代码行数:12,代码来源:JaxRsServerModule.java

示例6: getGuiceServletContextListener

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@Provides
private GuiceServletContextListener getGuiceServletContextListener(final Injector injector) {
    return new GuiceServletContextListener() {
        @Override
        protected Injector getInjector() {
            return injector;
        }
    };
}
 
开发者ID:benhardy,项目名称:lilrest,代码行数:10,代码来源:JaxRsServerModule.java

示例7: setUp

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

    // starts the server with a random port
    jettyServer = new Server(0);

    WebAppContext bpCtrlWebapp = new WebAppContext();
    bpCtrlWebapp.setResourceBase("./src/main/java");
    bpCtrlWebapp.setParentLoaderPriority(true);

    bpCtrlWebapp.addFilter(GuiceFilter.class, "/*", null);
    bpCtrlWebapp.addEventListener(new GuiceServletContextListener() {

        private Injector injector;

        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
            injector = Guice.createInjector(getServletTestModule());
            super.contextInitialized(servletContextEvent);
        }

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

    jettyServer.setHandler(bpCtrlWebapp);

    jettyServer.start();

    int port = ((ServerConnector) jettyServer.getConnectors()[0]).getLocalPort();
    serverUrl = String.format("http://localhost:%d", port);
}
 
开发者ID:bmwcarit,项目名称:joynr,代码行数:35,代码来源:AbstractServiceInterfaceTest.java

示例8: main

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    System.setProperty(Sdk.DISABLE_REQUEST_SIGNATURE_CHECK_SYSTEM_PROPERTY, "true");

    String envPort = System.getenv("PORT");
    int port = envPort == null || envPort.isEmpty() ? 8000 : Integer.valueOf(envPort);


    // Configure server and its associated servlets
    Server server = new Server(port);

    ServletContextHandler context = new ServletContextHandler();
    context.addEventListener(new GuiceServletContextListener() {
        @Override
        protected Injector getInjector() {
            Module services = new AbstractModule() {
                @Override
                protected void configure() {
                    bind(SpeechRouter.class).toProvider(new Provider<SpeechRouter>() {
                        @Inject Injector injector;

                        @Override
                        public SpeechRouter get() {
                            try {
                                return SpeechRouter.create(injector, "rottentomatoes");
                            } catch (Exception e) {
                                e.printStackTrace();
                                return null;
                            }
                        }
                    }).in(Singleton.class);
                    bind(AlexaSessionProvider.class).in(RequestScoped.class);
                    bind(RequestContextProvider.class).in(RequestScoped.class);
                    bind(SpeechletServlet.class).toProvider(new Provider<SpeechletServlet>() {
                        @Inject SpeechRouter router;
                        @Inject Injector injector;

                        @Override
                        public SpeechletServlet get() {
                            SpeechletServlet servlet = new SpeechletServlet();
                            servlet.setSpeechlet(new RoutingSpeechlet(router, injector));
                            return servlet;
                        }
                    }).in(Singleton.class);
                }
            };

            return Guice.createInjector(services, new ServletModule() {
                @Override
                protected void configureServlets() {
                    serve("/sample-utterances").with(SampleUtterancesServlet.class);
                    serve("/intent-schema").with(IntentSchemaServlet.class);
                    serve("/rotten-tomatoes").with(SpeechletServlet.class);
                }
            });
        }
    });
    context.addFilter(GuiceFilter.class, "/*", null);
    context.addServlet(DefaultServlet.class, "/");
    server.setHandler(context);
    server.start();
    server.join();
}
 
开发者ID:rs22,项目名称:alexa-routing,代码行数:63,代码来源:Main.java

示例9: startWebSocketServer

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public void startWebSocketServer(final Injector injector) {
  httpServer = new Server();

  List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
  if (connectors.isEmpty()) {
    LOG.severe("No valid http end point address provided!");
  }
  for (Connector connector : connectors) {
    httpServer.addConnector(connector);
  }
  final WebAppContext context = new WebAppContext();

  context.setParentLoaderPriority(true);

  if (jettySessionManager != null) {
    // This disables JSessionIDs in URLs redirects
    // see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
    // and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
    jettySessionManager.setSessionIdPathParameterName(null);

    context.getSessionHandler().setSessionManager(jettySessionManager);
  }
  final ResourceCollection resources = new ResourceCollection(resourceBases);
  context.setBaseResource(resources);

  addWebSocketServlets();

  try {
    final Injector parentInjector = injector;

    final ServletModule servletModule = getServletModule(parentInjector);

    ServletContextListener contextListener = new GuiceServletContextListener() {

      private final Injector childInjector = parentInjector.createChildInjector(servletModule);

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

    context.addEventListener(contextListener);
    context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
    httpServer.setHandler(context);

    httpServer.start();
    restoreSessions();

  } catch (Exception e) { // yes, .start() throws "Exception"
    LOG.severe("Fatal error starting http server.", e);
    return;
  }
  LOG.fine("WebSocket server running.");
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:57,代码来源:ServerRpcProvider.java

示例10: getServletConfig

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@Override
protected GuiceServletContextListener getServletConfig() {
	return new SystemAServletConfig();
}
 
开发者ID:bioko,项目名称:system-a-test,代码行数:5,代码来源:SystemATestAbstract.java

示例11: startWebSocketServer

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public void startWebSocketServer(final Injector injector) {
  httpServer = new Server();

  List<Connector> connectors = getSelectChannelConnectors(httpAddresses);
  if (connectors.isEmpty()) {
    LOG.severe("No valid http end point address provided!");
  }
  for (Connector connector : connectors) {
    httpServer.addConnector(connector);
  }
  final WebAppContext context = new WebAppContext();

  context.setParentLoaderPriority(true);

  if (jettySessionManager != null) {
    // This disables JSessionIDs in URLs redirects
    // see: http://stackoverflow.com/questions/7727534/how-do-you-disable-jsessionid-for-jetty-running-with-the-eclipse-jetty-maven-plu
    // and: http://jira.codehaus.org/browse/JETTY-467?focusedCommentId=114884&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-114884
    jettySessionManager.setSessionIdPathParameterName(null);

    context.getSessionHandler().setSessionManager(jettySessionManager);
  }
  final ResourceCollection resources = new ResourceCollection(resourceBases);
  context.setBaseResource(resources);

  addWebSocketServlets();

  try {

    final ServletModule servletModule = getServletModule();

    ServletContextListener contextListener = new GuiceServletContextListener() {

      private final Injector childInjector = injector.createChildInjector(servletModule);

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

    context.addEventListener(contextListener);
    context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    context.addFilter(GzipFilter.class, "/webclient/*", EnumSet.allOf(DispatcherType.class));
    httpServer.setHandler(context);

    httpServer.start();
    restoreSessions();

  } catch (Exception e) { // yes, .start() throws "Exception"
    LOG.severe("Fatal error starting http server.", e);
    return;
  }
  LOG.fine("WebSocket server running.");
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:56,代码来源:ServerRpcProvider.java

示例12: start

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public void start() throws Exception {
    ((ServerConnector) server.getConnectors()[0]).setReuseAddress(true);

    // Root context
    context.setContextPath("/abnormal");

    // Setup static content
    context.setResourceBase("src/main/webapp/");
    context.addServlet(DefaultServlet.class, "/");

    // Enable Jersey debug output
    context.setInitParameter("com.sun.jersey.config.statistic.Trace", "true");

    // Enable CORS - cross origin resource sharing
    FilterHolder cors = new FilterHolder();
    cors.setInitParameter("allowedOrigins", "https?://localhost:*, https?://*.e-navigation.net:*");
    cors.setInitParameter("allowedHeaders", "*");
    cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");
    cors.setFilter(new CrossOriginFilter());
    context.addFilter(cors, "*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.INCLUDE));

    // Little hack to satisfy OpenLayers URLs in DMA context
    RewritePatternRule openlayersRewriteRule = new RewritePatternRule();
    openlayersRewriteRule.setPattern("/abnormal/theme/*");
    openlayersRewriteRule.setReplacement("/abnormal/js/theme/");

    RewriteHandler rewrite = new RewriteHandler();
    rewrite.setRewriteRequestURI(true);
    rewrite.setRewritePathInfo(false);
    rewrite.setOriginalPathAttribute("requestedPath");
    rewrite.addRule(openlayersRewriteRule);
    rewrite.setHandler(context);
    server.setHandler(rewrite);

    // Setup Guice-Jersey integration
    context.addEventListener(new GuiceServletContextListener() {
        @Override
        protected Injector getInjector() {
            return Guice.createInjector(new RestModule(
                    repositoryName,
                    pathToEventDatabase,
                    eventRepositoryType,
                    eventDataDbHost,
                    eventDataDbPort,
                    eventDataDbName,
                    eventDataDbUsername,
                    eventDataDbPassword
            ));
        }
    });
    context.addFilter(com.google.inject.servlet.GuiceFilter.class, "/rest/*", EnumSet.allOf(DispatcherType.class));

    // Start the server
    server.start();
}
 
开发者ID:dma-ais,项目名称:AisAbnormal,代码行数:56,代码来源:WebServer.java

示例13: JettyServer

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public JettyServer(int port, GuiceServletContextListener guiceConfig) {
    this.port = port;
    this.guiceConfig = guiceConfig;
}
 
开发者ID:enigma11,项目名称:jetty-guice,代码行数:5,代码来源:JettyServer.java

示例14: getServletConfig

import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
/**
 * Java version of the web.xml snippet:
 * <pre>
 * {@code
 * <listener>
 *   <listener-class>it.bioko.mysystem.injection.MySystemServletConfig</listener-class>
 * </listener>
 * }
 * <pre>
 * @return An instance of a subclass of {@link GuiceServletContextListener}
 */
protected abstract GuiceServletContextListener getServletConfig();
 
开发者ID:bioko,项目名称:http-test,代码行数:13,代码来源:WebAppTest.java


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