use of org.glassfish.grizzly.servlet.WebappContext in project jersey by jersey.
the class GrizzlyWebContainerFactory method create.
private static HttpServer create(URI u, Class<? extends Servlet> c, Servlet servlet, Map<String, String> initParams, Map<String, String> contextInitParams) throws IOException {
if (u == null) {
throw new IllegalArgumentException("The URI must not be null");
}
String path = u.getPath();
if (path == null) {
throw new IllegalArgumentException("The URI path, of the URI " + u + ", must be non-null");
} else if (path.isEmpty()) {
throw new IllegalArgumentException("The URI path, of the URI " + u + ", must be present");
} else 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());
WebappContext context = new WebappContext("GrizzlyContext", path);
ServletRegistration registration;
if (c != null) {
registration = context.addServlet(c.getName(), c);
} else {
registration = context.addServlet(servlet.getClass().getName(), servlet);
}
registration.addMapping("/*");
if (contextInitParams != null) {
for (Map.Entry<String, String> e : contextInitParams.entrySet()) {
context.setInitParameter(e.getKey(), e.getValue());
}
}
if (initParams != null) {
registration.setInitParameters(initParams);
}
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
context.deploy(server);
return server;
}
use of org.glassfish.grizzly.servlet.WebappContext in project ff4j by ff4j.
the class AbstractEmbeddedGrizzlyIntegrationTest method initOnce.
@BeforeClass
public static void initOnce() throws IOException {
// WebContext for testing
webappContext = new WebappContext("Test Context");
ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
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", SampleFF4jJersey2Application.class.getCanonicalName());
servletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
servletRegistration.addMapping("/*");
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(JacksonJsonProvider.class);
clientConfig.register(FF4jJacksonMapper.class);
client = ClientBuilder.newClient(clientConfig);
server = new HttpServer();
NetworkListener listener = new NetworkListener("grizzly2", HOST, PORT);
server.addListener(listener);
webappContext.deploy(server);
}
use of org.glassfish.grizzly.servlet.WebappContext in project narayana by jbosstm.
the class SpdyEnabledHttpServer method create.
public static HttpServer create(URI u, Class<? extends Servlet> c, Servlet servlet, Map<String, String> initParams, Map<String, String> contextInitParams, String trustStoreFile, String trustStorePswd, int poolSize, boolean enableSpdy) throws IOException {
if (u == null) {
throw new IllegalArgumentException("The URI must not be null");
}
String path = u.getPath();
if (path == null) {
throw new IllegalArgumentException("The URI path, of the URI " + u + ", must be non-null");
} else if (path.isEmpty()) {
throw new IllegalArgumentException("The URI path, of the URI " + u + ", must be present");
} else 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());
WebappContext context = new WebappContext("GrizzlyContext", path);
ServletRegistration registration;
if (c != null) {
registration = context.addServlet(c.getName(), c);
} else {
registration = context.addServlet(servlet.getClass().getName(), servlet);
}
registration.addMapping("/*");
if (contextInitParams != null) {
for (Map.Entry<String, String> e : contextInitParams.entrySet()) {
context.setInitParameter(e.getKey(), e.getValue());
}
}
if (initParams == null) {
// registration.setInitParameter(ClassPathResourceConfig.PROPERTY_CLASSPATH,
// System.getProperty("java.class.path").replace(File.pathSeparatorChar, ';'));
} else {
registration.setInitParameters(initParams);
}
// GrizzlyHttpServerFactory.createHttpServer(u);
HttpServer server = createHttpServer(u, null, true, getSSLConfig(trustStoreFile, trustStorePswd), poolSize, enableSpdy);
context.deploy(server);
return server;
}
use of org.glassfish.grizzly.servlet.WebappContext in project Gaffer by gchq.
the class RestApiTestClient method createHttpServer.
private HttpServer createHttpServer() {
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(uriString));
final String webappContextName = "WebappContext";
final WebappContext context = new WebappContext(webappContextName, "/".concat(fullPath));
context.addListener(ServletLifecycleListener.class.getName());
final String servletContainerName = "ServletContainer";
final ServletRegistration registration = context.addServlet(servletContainerName, new ServletContainer(new ResourceConfig(config)));
registration.addMapping("/*");
context.deploy(server);
return server;
}
Aggregations