本文整理了Java中org.glassfish.grizzly.servlet.WebappContext.<init>()
方法的一些代码示例,展示了WebappContext.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebappContext.<init>()
方法的具体详情如下:
包路径:org.glassfish.grizzly.servlet.WebappContext
类名称:WebappContext
方法名:<init>
[英]Creates a simple WebappContext
with the root being "/".
[中]创建根为“/”的简单WebappContext
。
代码示例来源:origin: jersey/jersey
WebappContext context = new WebappContext("GrizzlyContext", path);
ServletRegistration registration;
if (c != null) {
代码示例来源:origin: jersey/jersey
final WebappContext context = new WebappContext("TestContext", contextPathLocal);
代码示例来源:origin: aol/micro-server
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) {
WebappContext webappContext = new WebappContext("WebappContext", "");
new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData);
jaxRsConfigurer.addServlet(this.serverData,webappContext);
new ServletConfigurer(serverData, servletData).addServlets(webappContext);
new FilterConfigurer(serverData, this.filterData).addFilters(webappContext);
addListeners(webappContext);
HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort());
serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer));
addAccessLog(httpServer);
addSSL(httpServer);
startServer(webappContext, httpServer, start, end);
}
代码示例来源:origin: uber/AthenaX
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);
}
代码示例来源:origin: stackoverflow.com
WebappContext webappContext = new WebappContext("myWebappContext");
webappContext.addListener(new ServletContextListener() {
@Override
public void contextInitialized(ServletContextEvent sce) {
sce.getServletContext().setAttribute(ServletProperties.SERVICE_LOCATOR, MY_SERVICE_LOCATOR);
}
@Override
public void contextDestroyed(ServletContextEvent sce) { }
});
ServletRegistration servlet = webappContext.addServlet("myAppplication", new ServletContainer(resourceConfig));
servlet.addMapping("/application/*");
ServletRegistration hello = webappContext.addServlet("myServlet", MyServlet.class);
hello.addMapping("/servlet/*");
HttpServer createHttpServer = GrizzlyHttpServerFactory.createHttpServer(MY_URI, false);
webappContext.deploy(createHttpServer);
createHttpServer.start();
代码示例来源:origin: stackoverflow.com
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI());
WebappContext context = new WebappContext("WebappContext", "/api");
ServletRegistration registration = context.addServlet("ServletContainer",
new ServletContainer(config));
registration.addMapping("/*");
context.deploy(httpServer);
代码示例来源:origin: stackoverflow.com
private static HttpServer create(URI u, Servlet servlet) throws IOException {
String path = u.getPath();
path = String.format("/%s", UriComponent.decodePath(u.getPath(), true)
.get(1).toString());
WebappContext context = new WebappContext("GrizzlyContext", path);
context.addListener(MyListener.class);
ServletRegistration registration;
registration = context.addServlet(servlet.getClass().getName(), servlet);
registration.addMapping("/*");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
context.deploy(server);
return server;
}
代码示例来源:origin: stackoverflow.com
@Before
public void setUp() throws Exception {
if (server == null) {
System.out.println("Initializing an instance of Grizzly Container");
final ResourceConfig rc = new ResourceConfig(A.class, B.class);
WebappContext ctx = new WebappContext() {};
ctx.addContextInitParameter("contextConfigLocation", "classpath:applicationContext.xml");
ctx.addListener("com.package.something.AServletContextListener");
server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
ctx.deploy(server);
}
}
代码示例来源:origin: stackoverflow.com
@Before
public void setup() throws Exception {
if (server == null) {
System.out.println("Initializing an instance of Grizzly Container ...");
final ResourceConfig rc = new ResourceConfig(ResourceEndpointIntegrationTest.class, ..., ..., ...); //update
WebappContext ctx = new WebappContext("IntegrationTestContext");
//register your listeners from web.xml in here
ctx.addListener("com.xxx.yyy.XEndpointServletContextListener");
//register your applicationContext.xml here
ctx.addContextInitParameter("contextConfigLocation", "classpath:applicationContext.xml");
//ServletRegistration is needed to load the ResourceConfig rc inside ServletContainer or you will have no
//Servlet-based features available
ServletRegistration registration = ctx.addServlet("ServletContainer",
new ServletContainer(rc));
//Initialize the Grizzly server passing it base URL
server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI));
//Deploy the server using our custom context
ctx.deploy(server);
}
}
代码示例来源:origin: stackoverflow.com
WebappContext context = new WebappContext("context");
ServletRegistration registration =
context.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter("com.sun.jersey.config.property.packages",
"com.sun.jersey.samples.https_grizzly.resource;com.sun.jersey.samples.https_grizzly.auth");
// add security filter (which handles http basic authentication)
registration.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
"com.sun.jersey.samples.https_grizzly.auth.SecurityFilter;com.sun.jersey.api.container.filter.LoggingFilter");
registration.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS,
LoggingFilter.class.getName());
try {
webServer = GrizzlyServerFactory.createHttpServer(
getBaseURI()
);
// start Grizzly embedded server //
System.out.println("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
context.deploy(webServer);
webServer.start();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
代码示例来源:origin: stackoverflow.com
WebappContext webappContext = new WebappContext("grizzly web context", "");
FilterRegistration testFilterReg = webappContext.addFilter("TestFilter", TestFilter.class);
testFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), "/*");
ServletRegistration servletRegistration = webappContext.addServlet("Jersey", org.glassfish.jersey.servlet.ServletContainer.class);
servletRegistration.addMapping("/myapp/*");
servletRegistration.setInitParameter("jersey.config.server.provider.packages", "com.example");
HttpServer server = HttpServer.createSimpleServer();
webappContext.deploy(server);
server.start();
代码示例来源:origin: stackoverflow.com
private static String API_PACKAGE = "package where TestRESTService class";
public static final URI BASE_URI = UriBuilder
.fromUri("http://localhost/")
.port(8000)
.build();
private static HttpServer initServer() throws IOException {
System.out.println("Starting grizzly... " + BASE_URI);
HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, new HttpHandler() {
@Override
public void service(Request rqst, Response rspns) throws Exception {
rspns.sendError(404);
}
});
// Initialize and register Jersey Servlet
WebappContext context = new WebappContext("GrizzlyContext", "/");
ServletRegistration registration = context.addServlet(
ServletContainer.class.getName(), ServletContainer.class);
registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
PackagesResourceConfig.class.getName());
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, API_PACKAGE);
registration.addMapping("/*");
context.deploy(httpServer);
return httpServer;
}
代码示例来源:origin: javaee/grizzly
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: javaee/grizzly
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: org.mule.glassfish.grizzly/grizzly-websockets
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: org.glassfish.grizzly/grizzly-websockets-server
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: javaee/grizzly
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: javaee/grizzly
public void initialize(final Request request,
final HttpServletResponseImpl servletResponse,
final WebSocketMappingData mappingData) throws IOException {
if (mappingData != null) {
updatePaths(mappingData);
} else {
contextPath = request.getContextPath();
}
if (mappingData != null && mappingData.isGlassfish) {
glassfishSupport = new GlassfishSupport(mappingData.context,
mappingData.wrapper, this);
} else {
glassfishSupport = new GlassfishSupport();
}
super.initialize(request, servletResponse,
new WebappContext("web-socket-ctx", contextPath));
}
代码示例来源:origin: com.aol.microservices/micro-grizzly
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) {
WebappContext webappContext = new WebappContext("WebappContext", "");
new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData);
jaxRsConfigurer.addServlet(this.serverData,webappContext);
new ServletConfigurer(serverData, servletData).addServlets(webappContext);
new FilterConfigurer(serverData, this.filterData).addFilters(webappContext);
addListeners(webappContext);
HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort());
serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer));
addAccessLog(httpServer);
addSSL(httpServer);
startServer(webappContext, httpServer, start, end);
}
代码示例来源:origin: com.oath.microservices/micro-grizzly
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) {
WebappContext webappContext = new WebappContext("WebappContext", "");
new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData);
jaxRsConfigurer.addServlet(this.serverData,webappContext);
new ServletConfigurer(serverData, servletData).addServlets(webappContext);
new FilterConfigurer(serverData, this.filterData).addFilters(webappContext);
addListeners(webappContext);
HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort());
serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer));
addAccessLog(httpServer);
addSSL(httpServer);
startServer(webappContext, httpServer, start, end);
}
内容来源于网络,如有侵权,请联系作者删除!