private static HttpServer create(
        URI u,
        Servlet servlet,
        Map<String, String> initParams,
        Map<String, String> contextParams,
        List<String> listeners,
        List<String> urlMappings)
        throws IOException {
      if (u == null) {
        throw new IllegalArgumentException("The URI must not be null");
      }

      String path = u.getPath();

      WebappContext context = new WebappContext("GrizzlyContext", path);

      for (String listener : listeners) {
        context.addListener(listener);
      }

      ServletRegistration registration = context.addServlet(servlet.getClass().getName(), servlet);

      for (String mapping : urlMappings) {
        registration.addMapping(mapping);
      }

      if (contextParams != null) {
        for (Map.Entry<String, String> e : contextParams.entrySet()) {
          context.setInitParameter(e.getKey(), e.getValue());
        }
      }

      if (initParams != null) {
        registration.setInitParameters(initParams);
      }

      HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
      context.deploy(server);

      return server;
    }
コード例 #2
0
 private ServletRegistration setInitParameters(
     ServletRegistration addServlet, ServletConfiguration servlet) {
   addServlet.setInitParameters(servlet.getInitParameters());
   return addServlet;
 }