registration = context.addServlet(servlet.getClass().getName(), servlet); registration.addMapping("/*");
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); }
@Nonnull private static WebappContext _createContext (final URI u, final Class <? extends Servlet> aServletClass, final Servlet aServlet, final Map <String, String> aInitParams, final Map <String, String> aContextInitParams) { String path = u.getPath (); if (path == null) throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be non-null"); if (path.isEmpty ()) throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be present"); 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 ()); final WebappContext aContext = new WebappContext ("GrizzlyContext", path); ServletRegistration aRegistration; if (aServletClass != null) aRegistration = aContext.addServlet (aServletClass.getName (), aServletClass); else aRegistration = aContext.addServlet (aServlet.getClass ().getName (), aServlet); aRegistration.addMapping ("/*"); if (aContextInitParams != null) for (final Map.Entry <String, String> e : aContextInitParams.entrySet ()) aContext.setInitParameter (e.getKey (), e.getValue ()); if (aInitParams != null) aRegistration.setInitParameters (aInitParams); return aContext; }
@Nonnull private static WebappContext _createContext (final URI u, final Class <? extends Servlet> aServletClass, final Servlet aServlet, final Map <String, String> aInitParams, final Map <String, String> aContextInitParams) { String path = u.getPath (); if (path == null) throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be non-null"); if (path.isEmpty ()) throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be present"); 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 ()); final WebappContext aContext = new WebappContext ("GrizzlyContext", path); ServletRegistration aRegistration; if (aServletClass != null) aRegistration = aContext.addServlet (aServletClass.getName (), aServletClass); else aRegistration = aContext.addServlet (aServlet.getClass ().getName (), aServlet); aRegistration.addMapping ("/*"); if (aContextInitParams != null) for (final Map.Entry <String, String> e : aContextInitParams.entrySet ()) aContext.setInitParameter (e.getKey (), e.getValue ()); if (aInitParams != null) aRegistration.setInitParameters (aInitParams); return aContext; }
registration.addMapping("/*");
registration.addMapping("/*");
registration.addMapping(servletPathLocal); } else { ServletRegistration registration = registration.addMapping("");
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration);
registration.addMapping("/*"); } else { httpServer = createHttpServer(url, rc, settings.isSecure(),
adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck()); final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet()); sgMetrics.addMapping("/admin/*"); adminCtx.deploy(server);