本文整理汇总了Java中org.glassfish.grizzly.servlet.ServletRegistration.setInitParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRegistration.setInitParameter方法的具体用法?Java ServletRegistration.setInitParameter怎么用?Java ServletRegistration.setInitParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.servlet.ServletRegistration
的用法示例。
在下文中一共展示了ServletRegistration.setInitParameter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebServer
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的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.ServletRegistration; //导入方法依赖的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: start
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的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);
}
}
示例4: startServer
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的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;
}
示例5: main
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的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.ServletRegistration; //导入方法依赖的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: createRESTContext
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的package包/类
/***************************************************************************
* *
* Private Methods *
* *
**************************************************************************/
private WebappContext createRESTContext(){
WebappContext webappContext = new WebappContext("Grizzly Web Context", "");
ServletRegistration servletRegistration = webappContext.addServlet(SERVLET_JERSEY, org.glassfish.jersey.servlet.ServletContainer.class);
servletRegistration.addMapping("/api/*"); // map the REST API to the /api
servletRegistration.setInitParameter(
ServerProperties.PROVIDER_PACKAGES,
"vidada.server.rest.resource;" + // scan this package for resource classes
"vidada.server.rest.provider"); // Specail Providers for server such as Authentication
return webappContext;
}
示例8: startEmbeddedServer
import org.glassfish.grizzly.servlet.ServletRegistration; //导入方法依赖的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();
}
}