Search in sources :

Example 1 with WebappContext

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;
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Map(java.util.Map)

Example 2 with WebappContext

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);
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) HttpServer(org.glassfish.grizzly.http.server.HttpServer) SampleFF4jJersey2Application(org.ff4j.web.api.test.SampleFF4jJersey2Application) ClientConfig(org.glassfish.jersey.client.ClientConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) BeforeClass(org.junit.BeforeClass)

Example 3 with WebappContext

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;
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Map(java.util.Map)

Example 4 with WebappContext

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;
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Aggregations

HttpServer (org.glassfish.grizzly.http.server.HttpServer)4 ServletRegistration (org.glassfish.grizzly.servlet.ServletRegistration)4 WebappContext (org.glassfish.grizzly.servlet.WebappContext)4 Map (java.util.Map)2 SampleFF4jJersey2Application (org.ff4j.web.api.test.SampleFF4jJersey2Application)1 NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1 BeforeClass (org.junit.BeforeClass)1