本文整理汇总了Java中org.glassfish.grizzly.servlet.WebappContext.deploy方法的典型用法代码示例。如果您正苦于以下问题:Java WebappContext.deploy方法的具体用法?Java WebappContext.deploy怎么用?Java WebappContext.deploy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.servlet.WebappContext
的用法示例。
在下文中一共展示了WebappContext.deploy方法的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: 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;
}
示例9: 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;
}
示例10: 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);
}
示例11: 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);
}
}
示例12: 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;
}
示例13: 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();
}
}
示例14: start
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
/**
* Starts the web server
* @return
*/
public HttpServer start() {
logger.info("Configuring Vidada HttpServer for REST API...");
// Configure the Web server
String serverUrl = "http://0.0.0.0/";
int serverPort = 5555;
HttpServer server = HttpServer.createSimpleServer(serverUrl, serverPort);
// Register a REST handler
WebappContext webappContext = createRESTContext();
webappContext.deploy(server);
// Register a custom Stream handler
server.getServerConfiguration().addHttpHandler(
new MediaStreamHttpHandler(vidadaServer.getMediaService()),
"/stream"); // map the stream handler to /stream
// Register a static http handler for this jar
server.getServerConfiguration().addHttpHandler(
new CLStaticHttpHandler(
this.getClass().getClassLoader(), // ClassLoader of the JAR
"/www/"), // absolute path in the jar (see src/main/resources/www)
"/"); // map the default http to the root
/* Example for specific directory outside of jar
// Register a static http handler for a directory
server.getServerConfiguration().addHttpHandler(new StaticHttpHandler("/var/www/webpage/"), "/xyz");
*/
try {
logger.info("Starting HttpServer @ " + serverUrl + " at port " + serverPort);
server.start();
} catch (IOException e) {
logger.error(e);
}
return server;
}
示例15: createServer
import org.glassfish.grizzly.servlet.WebappContext; //导入方法依赖的package包/类
private HttpServer createServer(ResourceConfig resourceConfig) {
String contextPath = getContextPath();
WebappContext context = new WebappContext("GrizzlyContext", contextPath);
configureContext(context);
addRestApplicationServlet(context, resourceConfig);
URI uri = getBaseUri();
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri);
context.deploy(server);
return server;
}