本文整理汇总了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();
}
示例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);
}
}
});
}
};
}
示例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;
}
});
}
示例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;
}
示例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;
}
示例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;
}
};
}
示例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);
}
示例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();
}
示例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.");
}
示例10: getServletConfig
import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
@Override
protected GuiceServletContextListener getServletConfig() {
return new SystemAServletConfig();
}
示例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.");
}
示例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();
}
示例13: JettyServer
import com.google.inject.servlet.GuiceServletContextListener; //导入依赖的package包/类
public JettyServer(int port, GuiceServletContextListener guiceConfig) {
this.port = port;
this.guiceConfig = guiceConfig;
}
示例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();