本文整理汇总了Java中org.glassfish.grizzly.servlet.WebappContext类的典型用法代码示例。如果您正苦于以下问题:Java WebappContext类的具体用法?Java WebappContext怎么用?Java WebappContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebappContext类属于org.glassfish.grizzly.servlet包,在下文中一共展示了WebappContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebServer
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
public WebServer(URI endpoint) throws IOException {
this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
rspns.getWriter().write("404: not found");
}
});
WebappContext context = new WebappContext("WebappContext", BASE_PATH);
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
StringJoiner sj = new StringJoiner(",");
for (String s : PACKAGES) {
sj.add(s);
}
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
registration.addMapping(BASE_PATH);
context.deploy(server);
}
示例2: start
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
@Override
public void start() {
System.out.println("Starting GrizzlyTestContainer...");
try {
this.server = GrizzlyHttpServerFactory.createHttpServer(uri, rc);
// Initialize and register Jersey Servlet
WebappContext context = new WebappContext("WebappContext", "");
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter("javax.ws.rs.Application", rc.getClass().getName());
// Add an init parameter - this could be loaded from a parameter in the constructor
registration.setInitParameter("myparam", "myvalue");
registration.addMapping("/*");
context.deploy(server);
} catch (ProcessingException e) {
throw new TestContainerException(e);
}
}
示例3: 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);
}
}
示例4: start
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
public static void start() {
WebappContext webappContext = new WebappContext("TestContext");
ServletRegistration registration = webappContext.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, "org.moskito.central.connectors.rest;org.codehaus.jackson.jaxrs");
registration.addMapping("/*");
SSLContextConfigurator sslConfigurator = new SSLContextConfigurator();
sslConfigurator.setKeyStoreFile("./target/test-classes/central_server_keystore.jks");
sslConfigurator.setKeyStorePass("moskito");
SSLContext sslContext = sslConfigurator.createSSLContext();
try {
server = GrizzlyServerFactory.createHttpServer(
getBaseURI(),
null,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
);
webappContext.deploy(server);
server.start();
} catch (Exception e) {
System.out.println("Error while starting the test server: " + e);
}
}
示例5: start
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
public void start() throws Exception {
HttpServer server = GrizzlyWebContainerFactory.create(URI.create(url));
WebappContext webapp = new WebappContext("GrizzlyContext", context);
if (servlet == null) {
servlet = DummyServlet.class;
}
if (servlet != null) {
registerServlet(webapp);
}
if (filter != null) {
registerFilter(webapp);
}
if (listener != null) {
registerListener(webapp);
}
webapp.deploy(server);
System.out.println(String.format("Jersey application started at %s\nHit enter to stop it...", url));
System.in.read();
server.shutdownNow();
}
示例6: 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);
}
}
示例7: startServer
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
public HttpServer startServer() throws IOException {
HttpServer theServer;
// String[] packages = { "streams.prometheus.exporter.rest.resources",
// "streams.prometheus.exporter.rest.errorhandling",
// "streams.prometheus.exporter.rest.serializers" };
//final ResourceConfig rc = new ResourceConfig().packages(packages);
// Enable JSON media conversions
//rc.register(JacksonFeature.class);
WebappContext context = new WebappContext("WebappContext","");
ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter("jersey.config.server.provider.packages",
"streams.metric.exporter.rest.resources;streams.metric.exporter.rest.errorhandling;streams.metric.exporter.rest.serializers");
registration.addMapping("/*");
//if (this.serverProtocol.equalsIgnoreCase("https")) {
if (this.serverProtocol == Protocol.HTTPS) {
LOGGER.debug("Using https protocol");
theServer = createHttpsServer();
} else {
LOGGER.debug("Using http protcol");
theServer = createHttpServer();
}
// Prometheus servlet
// FUTURE: if we go with plugin this needs to be variant if it is created or not
//ServletRegistration prometheus = context.addServlet("PrometheusContainer",new MetricsServlet());
//prometheus.addMapping("/prometheus");
context.deploy(theServer);
theServer.start();
return theServer;
}
示例8: 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);
}
示例9: 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, "/*");
}
示例10: _createContext
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
@Nonnull
private static WebappContext _createContext (final URI u,
final Class <? extends Servlet> aServletClass,
final Servlet aServlet,
final Map <String, String> aInitParams,
final Map <String, String> aContextInitParams)
{
String path = u.getPath ();
if (path == null)
throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be non-null");
if (path.isEmpty ())
throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be present");
if (path.charAt (0) != '/')
throw new IllegalArgumentException ("The URI path, of the URI " + u + ". must start with a '/'");
path = String.format ("/%s", UriComponent.decodePath (u.getPath (), true).get (1).toString ());
final WebappContext aContext = new WebappContext ("GrizzlyContext", path);
ServletRegistration registration;
if (aServletClass != null)
registration = aContext.addServlet (aServletClass.getName (), aServletClass);
else
registration = aContext.addServlet (aServlet.getClass ().getName (), aServlet);
registration.addMapping ("/*");
if (aContextInitParams != null)
for (final Map.Entry <String, String> e : aContextInitParams.entrySet ())
aContext.setInitParameter (e.getKey (), e.getValue ());
if (aInitParams != null)
registration.setInitParameters (aInitParams);
return aContext;
}
示例11: startRegularServer
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this
* application.
*
* @return Grizzly HTTP server.
*/
@Nonnull
public static HttpServer startRegularServer ()
{
final WebappContext aContext = _createContext (BASE_URI_HTTP);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
final HttpServer ret = GrizzlyHttpServerFactory.createHttpServer (URI.create (BASE_URI_HTTP));
aContext.deploy (ret);
return ret;
}
示例12: startSecureServer
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this
* application.
*
* @return Grizzly HTTP server.
*/
public static HttpServer startSecureServer ()
{
if (false)
System.setProperty ("javax.net.debug", "all");
final WebappContext aContext = _createContext (BASE_URI_HTTPS);
final SSLContextConfigurator aSSLContext = new SSLContextConfigurator ();
aSSLContext.setKeyStoreFile ("src/test/resources/test-https-keystore.jks");
aSSLContext.setKeyStorePass ("password");
aSSLContext.setKeyStoreType ("JKS");
aSSLContext.setTrustStoreBytes (StreamHelper.getAllBytes (new ClassPathResource (PeppolKeyStoreHelper.TRUSTSTORE_COMPLETE_CLASSPATH)));
aSSLContext.setTrustStorePass (PeppolKeyStoreHelper.TRUSTSTORE_PASSWORD);
aSSLContext.setTrustStoreType ("JKS");
aSSLContext.setSecurityProtocol ("TLSv1.2");
final SSLEngineConfigurator aSSLEngine = new SSLEngineConfigurator (aSSLContext);
aSSLEngine.setClientMode (false);
aSSLEngine.setNeedClientAuth (true);
aSSLEngine.setEnabledCipherSuites (new String [] { "TLS_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
"TLS_RSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
"TLS_RSA_WITH_AES_128_CBC_SHA" });
// create and start a new instance of grizzly https server
// exposing the Jersey application at BASE_URI
final HttpServer ret = GrizzlyHttpServerFactory.createHttpServer (URI.create (BASE_URI_HTTPS),
(GrizzlyHttpContainer) null,
true,
aSSLEngine,
true);
aContext.deploy (ret);
return ret;
}
示例13: LensServer
import org.glassfish.grizzly.servlet.WebappContext; //导入依赖的package包/类
/**
* Instantiates a new lens server.
*
* @param conf the conf
* @throws IOException Signals that an I/O exception has occurred.
*/
private LensServer(HiveConf conf) throws IOException {
startServices(conf);
String baseURI = conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri(baseURI).build(), getApp(),
false);
int corePoolSize = conf.getInt(LensConfConstants.GRIZZLY_CORE_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_CORE_POOL_SIZE);
int maxPoolSize = conf.getInt(LensConfConstants.GRIZZLY_MAX_POOL_SIZE,
LensConfConstants.DEFAULT_GRIZZLY_MAX_POOL_SIZE);
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig();
config.setPoolName("lensserver-pool");
config.setCorePoolSize(corePoolSize);
config.setMaxPoolSize(maxPoolSize);
config.setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d")
.setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());
NetworkListener listener = server.getListeners().iterator().next();
listener.getTransport().setWorkerThreadPoolConfig(config);
serverList.add(server);
WebappContext adminCtx = new WebappContext("admin", "");
MetricsServiceImpl metricsService = LensServices.get().getService(MetricsService.NAME);
adminCtx
.setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", (metricsService.getMetricRegistry()));
adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck());
final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
sgMetrics.addMapping("/admin/*");
adminCtx.deploy(server);
}
示例14: 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);
}
}
示例15: 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;
}