private void addExplicitlyDeclaredServlets(WebappContext webappContext) {
   for (ServletData servletData : servletData) {
     ServletRegistration servletReg =
         webappContext.addServlet(servletData.getServletName(), servletData.getServlet());
     servletReg.addMapping(servletData.getMapping());
     logServlet(servletData);
   }
 }
    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;
    }
Exemple #3
0
  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    clientUtil = new ClientUtil(target());

    wiser = new Wiser();
    wiser.setPort(2500);
    wiser.start();

    // Force shutdown
    DBIF.reset();

    String httpRoot =
        URLDecoder.decode(
            new File(getClass().getResource("/").getFile()).getAbsolutePath(), "utf-8");
    httpServer = HttpServer.createSimpleServer(httpRoot, "localhost", getPort());
    WebappContext context = new WebappContext("GrizzlyContext", "/music");
    context
        .addFilter("requestContextFilter", RequestContextFilter.class)
        .addMappingForUrlPatterns(null, "/*");
    context
        .addFilter("tokenBasedSecurityFilter", TokenBasedSecurityFilter.class)
        .addMappingForUrlPatterns(null, "/*");
    ServletRegistration reg = context.addServlet("jerseyServlet", ServletContainer.class);
    reg.setInitParameter(
        "jersey.config.server.provider.packages", "com.sismics.music.rest.resource");
    reg.setInitParameter(
        "jersey.config.server.provider.classnames",
        "org.glassfish.jersey.media.multipart.MultiPartFeature");
    reg.setInitParameter("jersey.config.server.response.setStatusOverSendError", "true");
    reg.setLoadOnStartup(1);
    reg.addMapping("/*");
    reg.setAsyncSupported(true);
    context.deploy(httpServer);
    httpServer.start();
  }