本文整理汇总了Java中org.glassfish.grizzly.servlet.WebappContext.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java WebappContext.addListener方法的具体用法?Java WebappContext.addListener怎么用?Java WebappContext.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.servlet.WebappContext
的用法示例。
在下文中一共展示了WebappContext.addListener方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
public <T extends DaggerServletContextListener> void startServer(Class<T> listenerClass) {
LOGGER.info("Starting test server");
WebappContext context = new WebappContext("Test", getUri().getRawPath());
context.addListener(listenerClass);
daggerFilter = new DaggerFilter();
FilterRegistration filterRegistration = context.addFilter("daggerFilter", daggerFilter);
filterRegistration.addMappingForUrlPatterns(null, "/*");
ServletRegistration servletRegistration = context.addServlet("TestServlet", new HttpServlet() {
});
servletRegistration.addMapping("/dagger-jersey/*");
try {
httpServer = GrizzlyServerFactory.createHttpServer(getUri(), (HttpHandler) null);
context.deploy(httpServer);
httpServer.start();
LOGGER.info("Test server started");
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
示例2: startServer
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
/**
* Starts Grizzly HTTP server exposing SMAPH JAX-RS resources.
*
* @throws URISyntaxException
* @throws ProcessingException
*/
public static void startServer(String serverUri, Path storageBase, String watGcubeToken) throws ProcessingException, URISyntaxException {
LOG.info("Initializing SMAPH services.");
LOG.info("Storage path: {}", storageBase.toAbsolutePath());
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(new URI(serverUri));
httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("src/main/webapp/"), "/*");
WebappContext context = new WebappContext("smaph");
ResourceConfig rc = new ResourceConfig().packages("it.unipi.di.acube.smaph.servlet");
ServletRegistration registration = context.addServlet("ServletContainer", new ServletContainer(rc));
registration.addMapping("/smaph/*");
context.addListener(SmaphContextListener.class);
context.setInitParameter(SmaphContextListener.WIKI_PAGES_DB, storageBase.resolve("mapdb/wikipedia_pages.db").toString());
context.setInitParameter(SmaphContextListener.FREEBASE_DIR, storageBase.resolve("mapdb/freebase.db").toString());
context.setInitParameter(SmaphContextListener.ENTITY_TO_ANCHORS_DB, storageBase.resolve("mapdb/e2a.db").toString());
context.setInitParameter(SmaphContextListener.WAT_GCUBE_TOKEN, watGcubeToken);
context.deploy(httpServer);
try {
httpServer.start();
LOG.info("Smaph started with WADL available at " + "{}application.wadl\nPress CTRL^C (SIGINT) to terminate.",
serverUri);
Thread.currentThread().join();
LOG.info("Shutting server down..");
} catch (Exception e) {
LOG.error("There was an error while starting Grizzly HTTP server.", e);
}
}
示例3: configureContext
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
protected void configureContext(WebappContext context) {
context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, AnnotationConfigWebApplicationContext.class.getName());
context.setInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, ExtendedApplicationContextInitializer.class.getName());
if (javaConfigClass != null) {
context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, javaConfigClass.getName());
}
context.addListener(SLF4JLoggingListener.class);
context.addListener(ContextLoaderListener.class);
}
示例4: configureContext
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
protected void configureContext(WebappContext context) {
context.setInitParameter(ContextLoader.CONTEXT_CLASS_PARAM, AnnotationConfigWebApplicationContext.class.getName());
context.setInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, ExtendedApplicationContextInitializer.class.getName());
if (javaConfigClass != null) {
context.setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, javaConfigClass.getName());
}
context.addListener(SLF4JLoggingListener.class);
context.addListener(ContextLoaderListener.class);
context.addFilter("openEntityManagerInViewFilter", new OpenEntityManagerInViewFilter())
.addMappingForUrlPatterns(null, "/*");
}
示例5: main
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, false);
// Creating a webapp context for the resources / DI container
final WebappContext webappContext = new WebappContext("Widow analyze");
webappContext.addListener(new WidowAnalyzeServletContextListener());
ServletRegistration servletRegistration = webappContext.addServlet("ServletContainer", ServletContainer.class);
servletRegistration.addMapping("/REST/*");
servletRegistration.setInitParameter("javax.ws.rs.Application",
"com.widowcrawler.analyze.startup.WidowAnalyzeResourceConfig");
final FilterRegistration registration = webappContext.addFilter("GuiceFilter", GuiceFilter.class);
registration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), "/REST/*");
webappContext.deploy(server);
// static assets
CLStaticHttpHandler clStaticHttpHandler = new CLStaticHttpHandler(
Main.class.getClassLoader(),
"/", "/lib/", "/js/", "/css/", "/templates/");
server.getServerConfiguration().addHttpHandler(clStaticHttpHandler);
server.start();
System.out.println(String.format("Application started.\nTry out %s%s\nHit enter to stop it...",
BASE_URI, ROOT_PATH));
while(System.in.read() != 32);
server.shutdownNow();
} catch (Exception ex) {
logger.error("Error: " + ex.getMessage(), ex);
}
}
示例6: setupHttpServer
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的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;
}
示例7: startEmbeddedServer
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
static void startEmbeddedServer() throws IOException {
// Create test web application context.
WebappContext webappContext = new WebappContext("Test Context");
webappContext
.addContextInitParameter("contextClass",
"org.springframework.web.context.support.XmlWebApplicationContext");
webappContext.addContextInitParameter("contextConfigLocation",
"classpath*:spring-context.xml");
webappContext
.addListener("org.springframework.web.context.ContextLoaderListener");
// Create a servlet registration for the web application in order to wire up Spring managed collaborators to Jersey resources.
ServletRegistration servletRegistration = webappContext.addServlet(
"jersey-servlet", ServletContainer.class);
// The logging filters for server logging.
servletRegistration
.setInitParameter(
"com.sun.jersey.spi.container.ContainerResponseFilters",
"com.sun.jersey.api.container.filter.LoggingFilter");
servletRegistration.setInitParameter(
"com.sun.jersey.spi.container.ContainerRequestFilters",
"com.sun.jersey.api.container.filter.LoggingFilter");
servletRegistration.setInitParameter("javax.ws.rs.Application",
"com.test.MyDemoApplication");
servletRegistration.setInitParameter(
"com.sun.jersey.config.property.packages", "com.test");
servletRegistration.setInitParameter(
"com.sun.jersey.api.json.POJOMappingFeature", "true");
servletRegistration.addMapping("/*");
HttpServer server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2", "localhost",
3388);
server.addListener(listener);
webappContext.deploy(server);
try {
server.start();
System.out.println("Press enter to stop the server...");
System.in.read();
} finally {
server.shutdownNow();
}
}
示例8: registerListener
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
private void registerListener(final WebappContext webapp) {
webapp.addListener(listener);
}