use of org.glassfish.grizzly.servlet.ServletRegistration 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;
}
Aggregations