Java Code Examples for org.eclipse.jetty.servlet.ServletHolder#setInitOrder()

The following examples show how to use org.eclipse.jetty.servlet.ServletHolder#setInitOrder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerMain.java    From wisp with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");

        Server jettyServer = new Server(8067);
        jettyServer.setHandler(context);

        ServletHolder jerseyServlet = context.addServlet(
                org.glassfish.jersey.servlet.ServletContainer.class, "/*");
        jerseyServlet.setInitOrder(0);

        // Tells the Jersey Servlet which REST service/class to load.
        jerseyServlet.setInitParameter(
                "jersey.config.server.provider.classnames",
                EntryPointTestHandler.class.getCanonicalName());

        try {
            jettyServer.start();
            jettyServer.join();
        } finally {
            jettyServer.destroy();
        }
    }
 
Example 2
Source File: ExplorerServer.java    From Explorer with Apache License 2.0 6 votes vote down vote up
/**
 * Swagger core handler - Needed for the RestFul api documentation
 *
 * @return ServletContextHandler of Swagger
 */
private static ServletContextHandler setupSwaggerContextHandler(int port) {
    // Configure Swagger-core
    final ServletHolder SwaggerServlet = new ServletHolder(
            new com.wordnik.swagger.jersey.config.JerseyJaxrsConfig());
    SwaggerServlet.setName("JerseyJaxrsConfig");
    SwaggerServlet.setInitParameter("api.version", "1.0.0");
    SwaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:" + port + "/api");
    SwaggerServlet.setInitOrder(2);

    // Setup the handler
    final ServletContextHandler handler = new ServletContextHandler();
    handler.setSessionHandler(new SessionHandler());
    handler.addServlet(SwaggerServlet, "/api-docs/*");
    return handler;
}
 
Example 3
Source File: JettyHttpServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public JettyHttpServer(URL url, final HttpHandler handler) {
    super(url, handler);
    DispatcherServlet.addHttpHandler(url.getPort(), handler);

    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(threads);
    threadPool.setMinThreads(threads);

    server = new Server(threadPool);

    // HTTP connector
    ServerConnector connector = new ServerConnector(server);
    if (!url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
        connector.setHost(url.getHost());
    }
    connector.setPort(url.getPort());
    // connector.setIdleTimeout(30000);
    server.addConnector(connector);

    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);

    server.insertHandler(servletHandler);

    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                + e.getMessage(), e);
    }
}
 
Example 4
Source File: App.java    From mysql_perf_analyzer with Apache License 2.0 5 votes vote down vote up
private ServletHolder jspServletHolder() {
	ServletHolder holderJsp = new ServletHolder("jsp",
			JettyJspServlet.class);
	holderJsp.setInitOrder(0);
	holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
	holderJsp.setInitParameter("fork", "false");
	holderJsp.setInitParameter("xpoweredBy", "false");
	holderJsp.setInitParameter("compilerTargetVM", "1.8");
	holderJsp.setInitParameter("compilerSourceVM", "1.8");
	holderJsp.setInitParameter("keepgenerated", "true");
	return holderJsp;
}
 
Example 5
Source File: HttpClientSetUp.java    From product-private-paas with Apache License 2.0 5 votes vote down vote up
public HttpClientSetUp() {
    // Create Server
    ServletContextHandler context = new ServletContextHandler();
    server.setHandler(context);
    ServletHolder jerseyServlet = context
            .addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/stratos/*");
    jerseyServlet.setInitOrder(0);
    jerseyServlet
            .setInitParameter("jersey.config.server.provider.classnames", StratosV400Mock.class.getCanonicalName());
    ServletHolder jerseyServlet2 = context
            .addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/migration/*");
    jerseyServlet2.setInitOrder(0);
    jerseyServlet2
            .setInitParameter("jersey.config.server.provider.classnames", StratosV400Mock.class.getCanonicalName());
    server.setHandler(context);

    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme("https");
    https_config.setSecurePort(Integer.getInteger("https.port"));
    https_config.setOutputBufferSize(TestConstants.BUFFER_SIZE);
    https_config.addCustomizer(new SecureRequestCustomizer());

    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(TestConstants.KEYSTORE_PATH);
    sslContextFactory.setKeyStorePassword("wso2carbon");
    sslContextFactory.setKeyManagerPassword("wso2carbon");

    ServerConnector https = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
            new HttpConnectionFactory(https_config));
    https.setPort(Integer.getInteger("https.port"));
    https.setIdleTimeout(TestConstants.IDLE_TIMEOUT);

    // Set the connectors
    server.setConnectors(new Connector[] { https });

}
 
Example 6
Source File: HttpServer.java    From heroic with Apache License 2.0 5 votes vote down vote up
private HandlerCollection setupHandler() throws Exception {
    final ResourceConfig resourceConfig = setupResourceConfig();
    final ServletContainer servlet = new ServletContainer(resourceConfig);

    final ServletHolder jerseyServlet = new ServletHolder(servlet);
    // Initialize and register Jersey ServletContainer

    jerseyServlet.setInitOrder(1);

    // statically provide injector to jersey application.
    final ServletContextHandler context =
        new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/");

    GzipHandler gzip = new GzipHandler();
    gzip.setIncludedMethods("POST");
    gzip.setMinGzipSize(860);
    gzip.setIncludedMimeTypes("application/json");
    context.setGzipHandler(gzip);

    context.addServlet(jerseyServlet, "/*");
    context.addFilter(new FilterHolder(new ShutdownFilter(stopping, mapper)), "/*", null);
    context.setErrorHandler(new JettyJSONErrorHandler(mapper));

    final RequestLogHandler requestLogHandler = new RequestLogHandler();

    requestLogHandler.setRequestLog(new Slf4jRequestLog());

    final RewriteHandler rewrite = new RewriteHandler();
    makeRewriteRules(rewrite);

    final HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers(new Handler[]{rewrite, context, requestLogHandler});

    return handlers;
}
 
Example 7
Source File: JettyLauncher.java    From logsniffer with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create JSP Servlet (must be named "jsp")
 */
private ServletHolder jspServletHolder() {
	ServletHolder holderJsp = new ServletHolder("jsp", JettyJspServlet.class);
	holderJsp.setInitOrder(0);
	holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
	holderJsp.setInitParameter("fork", "false");
	holderJsp.setInitParameter("xpoweredBy", "false");
	holderJsp.setInitParameter("compilerTargetVM", "1.7");
	holderJsp.setInitParameter("compilerSourceVM", "1.7");
	holderJsp.setInitParameter("keepgenerated", "true");
	return holderJsp;
}
 
Example 8
Source File: JettyHttpServer.java    From dubbo-rpc-jsonrpc with Apache License 2.0 5 votes vote down vote up
public JettyHttpServer(URL url, final HttpHandler handler) {
    super(url, handler);
    DispatcherServlet.addHttpHandler(url.getPort(), handler);

    int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(threads);
    threadPool.setMinThreads(threads);

    server = new Server(threadPool);

    // HTTP connector
    ServerConnector connector = new ServerConnector(server);
    if (!url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) {
        connector.setHost(url.getHost());
    }
    connector.setPort(url.getPort());
    // connector.setIdleTimeout(30000);
    server.addConnector(connector);

    ServletHandler servletHandler = new ServletHandler();
    ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
    servletHolder.setInitOrder(2);

    server.insertHandler(servletHandler);

    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: "
                + e.getMessage(), e);
    }
}
 
Example 9
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupTest() throws Exception {
	int port = findAvailableTcpPort(10000);
	URI baseUri = UriBuilder.fromUri("http://localhost").port(port).build();
	// Create Server
	server = new Server(port);
	// Configure ServletContextHandler
	ServletContextHandler context = new ServletContextHandler(
			ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);
	// Create Servlet Container
	ServletHolder jerseyServlet = context
			.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*");
	jerseyServlet.setInitOrder(0);
	// Tells the Jersey Servlet which REST service/class to load.
	jerseyServlet.setInitParameter("jersey.config.server.provider.classnames",
			FraudDetectionController.class.getCanonicalName());
	// Start the server
	server.start();
	ClientConfig clientConfig = new ClientConfig();
	client = ClientBuilder.newClient(clientConfig);
	webTarget = client.target(baseUri);
	try {
		server.start();
	}
	catch (Exception ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 10
Source File: ApacheCXFHelper.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
public static void initServletContext(ServletContextHandler context) {
  ServletHolder apacheCXFServlet = context.addServlet(
      org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.class, "/*");
  apacheCXFServlet.setInitOrder(0);

  apacheCXFServlet.setInitParameter(
      "javax.ws.rs.Application", InstrumentedRestApplication.class.getCanonicalName());
}
 
Example 11
Source File: AmforeasJetty.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
private void setupJerseyServlet (final AmforeasConfiguration conf, final Server server) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/");

    ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, conf.getServerRoot());
    jerseyServlet.setInitOrder(0);
    jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "amforeas.rest, amforeas.filter");

    server.setHandler(context);
}
 
Example 12
Source File: RestEasyHelper.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
public static void initServletContext(ServletContextHandler context) {
    ServletHolder restEasyServlet = context.addServlet(
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class, "/*");
    restEasyServlet.setInitOrder(0);

    restEasyServlet.setInitParameter(
            "javax.ws.rs.Application", InstrumentedRestApplication.class.getCanonicalName());
}
 
Example 13
Source File: Starter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void start() {

		Server server = new Server(9080);
		ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
		servletContextHandler.setContextPath("/");
		servletContextHandler.setResourceBase("src/main/webapp");

		final String webAppDirectory = JumbuneInfo.getHome() + "modules/webapp";
		final ResourceHandler resHandler = new ResourceHandler();
		resHandler.setResourceBase(webAppDirectory);
		final ContextHandler ctx = new ContextHandler("/");
		ctx.setHandler(resHandler);
		servletContextHandler.setSessionHandler(new SessionHandler());

		ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/apis/*");
		servletHolder.setInitOrder(0);
		servletHolder.setAsyncSupported(true);
		servletHolder.setInitParameter("jersey.config.server.provider.packages", "org.jumbune.web.services");
		servletHolder.setInitParameter("jersey.config.server.provider.classnames",
				"org.glassfish.jersey.media.multipart.MultiPartFeature");

		try {
			server.insertHandler(servletContextHandler);
			server.insertHandler(resHandler);
			server.start();
			server.join();
		} catch (Exception e) {
			LOGGER.error("Error occurred while starting Jetty", e);
			System.exit(1);
		}
	}
 
Example 14
Source File: ManagementApiServer.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public void attachHandlers() {

        // Create the servlet context
        final ServletContextHandler context = new ServletContextHandler(this.server, entrypoint, ServletContextHandler.SESSIONS);

        // REST configuration
        final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
        servletHolder.setInitParameter("javax.ws.rs.Application", ManagementApplication.class.getName());
        servletHolder.setInitOrder(1);
        servletHolder.setAsyncSupported(true);

        AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
        webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
        webApplicationContext.setParent(applicationContext);
        webApplicationContext.setServletContext(context.getServletContext());

        webApplicationContext.register(ManagementConfiguration.class);

        context.addEventListener(new ContextLoaderListener(webApplicationContext));
        context.addServlet(servletHolder, "/*");
        context.addServlet(new ServletHolder(new DispatcherServlet(webApplicationContext)), "/auth/*");

        // X-Forwarded-* support
        context.addFilter(ForwardedHeaderFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

        // Spring Security filter
        context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class));
    }
 
Example 15
Source File: JettyTransport.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
public void registerServlet(String path, Servlet servletContainer) {
  ServletHolder servletHolder = new ServletHolder(Source.EMBEDDED);
  servletHolder.setName("Data Transfer Project");
  servletHolder.setServlet(servletContainer);
  servletHolder.setInitOrder(1);

  ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  handler.setContextPath("/");

  handlers.add(handler);

  handler.getServletHandler().addServletWithMapping(servletHolder, path);
}
 
Example 16
Source File: MonetaDropwizardApplication.java    From moneta with Apache License 2.0 4 votes vote down vote up
@Override
public void run(MonetaDropwizardConfiguration configuration,
		Environment environment) throws Exception {

	/*
	 * The ServletHolder allows you to specify init parameters and other
	 * servlet configuration itmes in the web.xml. Setting the order means
	 * that the servlet is initialized on startup; by default it is not.
	 */
	ServletHolder topicHolder = new ServletHolder(Source.EMBEDDED);
	topicHolder.setHeldClass(MonetaServlet.class);
	topicHolder.setInitOrder(0);
	topicHolder.setInitParameter(
			MonetaServlet.CONFIG_IGNORED_CONTEXT_PATH_NODES, "moneta,topic");
	environment.getApplicationContext()
	.getServletHandler()
	.addServletWithMapping(topicHolder, "/moneta/topic/*");

	// Will be initialized on first use by default.
	environment.getApplicationContext()
	.addServlet(MonetaTopicListServlet.class, "/moneta/topics/*");

	/*
	 * Install thread contention monitoring -- withdrawn after issue with
	 * Jetty discovered.
	 */
	// ServletHolder threadContentionHolder = new
	// ServletHolder(Source.EMBEDDED);
	// threadContentionHolder.setHeldClass(ThreadMonitorStartupServlet.class);
	// threadContentionHolder.setInitOrder(0);
	// environment.getApplicationContext()
	// .getServletHandler()
	// .addServlet(threadContentionHolder);

	/*
	 * Install memory alert monitoring
	 */
	ServletHolder memoryAlertHolder = new ServletHolder(Source.EMBEDDED);
	memoryAlertHolder.setHeldClass(MemoryMonitorStartupServlet.class);
	memoryAlertHolder.setInitOrder(0);
	environment.getApplicationContext()
	.getServletHandler()
	.addServlet(memoryAlertHolder);

	/*
	 * Install the performance filter
	 */
	FilterHolder perfFilterHolder = new FilterHolder(Holder.Source.EMBEDDED);
	perfFilterHolder.setHeldClass(MonetaPerformanceFilter.class);
	perfFilterHolder.setInitParameter(
			MonetaPerformanceFilter.PARM_MAX_TRNASACTION_TIME_THRESHOLD_IN_MILLIS,
			"3000");
	environment.getApplicationContext()
	.addFilter(perfFilterHolder, "/moneta/*", null);

	/*
	 * Install RequestCorrelation filter so I can get a correlation id in
	 * the logs
	 */
	FilterHolder correlationFilterHolder = new FilterHolder(
			Holder.Source.EMBEDDED);
	correlationFilterHolder.setHeldClass(RequestCorrelationFilter.class);

	// Install healthchecks
	MonetaConfiguration config = new MonetaConfiguration();
	for (String checkName : config.getHealthChecks()
			.keySet()) {
		environment.healthChecks()
		.register(checkName, config.getHealthChecks()
				.get(checkName));
	}

	final JmxReporter jmxReporter = JmxReporter.forRegistry(
			environment.metrics())
			.build();
	jmxReporter.start();
}
 
Example 17
Source File: ProxyServerFactory.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static Server of(String proxyTo, int port, File keystoreFile, String keystorePassword) {
  Server proxy = new Server();
  logger.info("Setting up HTTPS connector for web server");

  final SslContextFactory sslContextFactory = new SslContextFactory.Client();

  sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
  sslContextFactory.setKeyStorePassword(keystorePassword);

  // SSL Connector
  final ServerConnector sslConnector = new ServerConnector(proxy,
      new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString()),
      new HttpConnectionFactory(new HttpConfiguration()));
  // regular http connector if one needs to inspect the wire. Requires tweaking the ElasticsearchPlugin to use http
  // final ServerConnector sslConnector = new ServerConnector(embeddedJetty,
  //   new HttpConnectionFactory(new HttpConfiguration()));
  sslConnector.setPort(port);
  proxy.addConnector(sslConnector);

  // root handler with request logging
  final RequestLogHandler rootHandler = new RequestLogHandler();
  proxy.setHandler(rootHandler);

  final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  servletContextHandler.setContextPath("/");
  rootHandler.setHandler(servletContextHandler);

  // error handler
  ProxyServlet.Transparent proxyServlet = new ProxyServlet.Transparent() {
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
      try {
        HttpServletRequest hr = (HttpServletRequest) req;
        logger.debug("incoming {} {}://{}:{} {}",
            hr.getMethod(),
            req.getScheme(),
            req.getServerName(),
            req.getServerPort(),
            hr.getRequestURL());
        super.service(req, res);
      } catch (Exception e) {
        logger.error("can't proxy " + req, e);
        throw new RuntimeException(e);
      }
    }

    @Override
    protected String rewriteTarget(HttpServletRequest clientRequest) {
      final String serverName = clientRequest.getServerName();
      final int serverPort = clientRequest.getServerPort();
      final String query = clientRequest.getQueryString();

      String result = super.rewriteTarget(clientRequest);

      logger.debug("Proxying {}://{}:{}{} to {}\n",
          clientRequest.getScheme(),
          serverName,
          serverPort,
          query != null ? '?' + query : "",
          result);

      return result;
    }
  };
  // Rest API
  final ServletHolder proxyHolder = new ServletHolder(proxyServlet);
  proxyHolder.setInitParameter("proxyTo", proxyTo);
  proxyHolder.setInitOrder(1);

  servletContextHandler.addServlet(proxyHolder, "/*");

  return proxy;
}
 
Example 18
Source File: TopologyServerUnify.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
@Override
public void run() 
{
	log.info("Unify Topology Server");
	
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       log.info("Service-Topology Port: "+params.getExportUnifyPort());
       Server jettyServer = new Server(params.getExportUnifyPort());
       jettyServer.setHandler(context);
       ServletHolder jerseyServlet =  
       		context.addServlet( com.sun.jersey.spi.container.servlet.ServletContainer.class, "/*");


       jerseyServlet.setInitParameter(
               "com.sun.jersey.config.property.packages",
               "io.swagger.jaxrs.json;io.swagger.jaxrs.listing;es.tid.topologyModuleBase.UnifyTopoModel.api");
       
       jerseyServlet.setInitParameter(
               "com.sun.jersey.spi.container.ContainerRequestFilters",
               "com.sun.jersey.api.container.filter.PostReplaceFilter");
       
       jerseyServlet.setInitParameter(
               "com.sun.jersey.api.json.POJOMappingFeatures",
               "true");
       
       jerseyServlet.setInitOrder(1);
	
       
       try {
       	isRunning=true;
           jettyServer.start();
           //jettyServer.dumpStdErr();
           jettyServer.join();
       } catch(Exception e){
       	log.severe(e.getStackTrace().toString());
       }finally {     
           jettyServer.destroy();
       }
	
}
 
Example 19
Source File: TopologyServerCOP.java    From netphony-topology with Apache License 2.0 4 votes vote down vote up
@Override
public void run() 
{
	log.info("Acting as BGP Peer");
	
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       log.info("Service-Topology Port: "+params.getExportCOPPort());
       Server jettyServer = new Server(params.getExportCOPPort());
       jettyServer.setHandler(context);
       ServletHolder jerseyServlet =  
       		context.addServlet( com.sun.jersey.spi.container.servlet.ServletContainer.class, "/*");


       jerseyServlet.setInitParameter(
               "com.sun.jersey.config.property.packages",
               "io.swagger.jaxrs.json;io.swagger.jaxrs.listing;es.tid.topologyModuleBase.COPServiceTopology.server.api");
       
       jerseyServlet.setInitParameter(
               "com.sun.jersey.spi.container.ContainerRequestFilters",
               "com.sun.jersey.api.container.filter.PostReplaceFilter");
       
       jerseyServlet.setInitParameter(
               "com.sun.jersey.api.json.POJOMappingFeatures",
               "true");
       
       jerseyServlet.setInitOrder(1);
	
       
       try {
       	isRunning=true;
           jettyServer.start();
           //jettyServer.dumpStdErr();
           jettyServer.join();
       } catch(Exception e){
       	log.severe(e.getStackTrace().toString());
       }finally {     
           jettyServer.destroy();
       }
	
}
 
Example 20
Source File: JettyEmbeddedContainer.java    From gravitee-management-rest-api with Apache License 2.0 3 votes vote down vote up
protected ServletContextHandler configureAPI(String apiContextPath, String applicationName, Class<? extends GlobalAuthenticationConfigurerAdapter> securityConfigurationClass) {
    final ServletContextHandler childContext = new ServletContextHandler(server, apiContextPath, ServletContextHandler.SESSIONS);

    final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
    servletHolder.setInitParameter("javax.ws.rs.Application", applicationName);
    servletHolder.setInitOrder(0);
    childContext.addServlet(servletHolder, "/*");

    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(securityConfigurationClass);

    webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
    webApplicationContext.setParent(applicationContext);

    childContext.addEventListener(new ContextLoaderListener(webApplicationContext));

    // Spring Security filter
    childContext.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")),"/*", EnumSet.allOf(DispatcherType.class));
    return childContext;


}