private void createAndRegisterServlet(final String servletName, final String... urlPatterns)
     throws Exception {
   // Create and deploy the Web app context
   final WebappContext ctx = new WebappContext(servletName);
   ctx.addServlet(servletName, new HttpFrameworkServlet(new LdapHttpApplication(this)))
       .addMapping(urlPatterns);
   ctx.deploy(this.httpServer);
 }
 private void addExplicitlyDeclaredServlets(WebappContext webappContext) {
   for (ServletData servletData : servletData) {
     ServletRegistration servletReg =
         webappContext.addServlet(servletData.getServletName(), servletData.getServlet());
     servletReg.addMapping(servletData.getMapping());
     logServlet(servletData);
   }
 }
  public static void main(String[] args) throws Exception {

    HttpServer server = HttpServer.createSimpleServer("/", 8080);
    WebappContext ctx = new WebappContext("api");
    ServletRegistration jerseyServlet =
        ctx.addServlet("jersey", org.glassfish.jersey.servlet.ServletContainer.class);
    jerseyServlet.addMapping("/api/*");
    jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.resource");
    jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    ctx.deploy(server);
    try {
      server.start();
      System.out.println("Press any key to stop the server....");
      System.in.read();
    } finally {
      server.shutdownNow();
    }
  }
  @Override
  public void startServer() throws Exception {
    server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI));

    AtmosphereServlet atmoServlet = new AtmosphereServlet();

    WebappContext context = new WebappContext("Chatty", "/chatty");

    ServletRegistration atmosphereRegistration = context.addServlet("Atmosphere", atmoServlet);
    atmosphereRegistration.addMapping("/atmos/*");

    ServletContainer jerseyContainer = new ServletContainer(resourceConfig);
    ServletRegistration jerseyRegistration = context.addServlet("Jersey", jerseyContainer);
    jerseyRegistration.addMapping("/api/*");

    context.deploy(server);

    server.start();
  }
    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;
    }
 private void addAutoDiscoveredServlets(WebappContext webappContext) {
   serverData
       .getRootContext()
       .getBeansOfType(ServletConfiguration.class)
       .values()
       .forEach(
           servlet -> {
             setInitParameters(
                     webappContext.addServlet(getName(servlet), getServlet(servlet)), servlet)
                 .addMapping(servlet.getMapping());
             logServlet(servlet);
           });
 }
Beispiel #7
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();
  }