Search in sources :

Example 6 with ServletContainer

use of com.sun.jersey.spi.container.servlet.ServletContainer in project nuxeo-filesystem-connectors by nuxeo.

the class WebDavServerFeature method setUpTomcat.

protected void setUpTomcat() throws Exception {
    tomcat = new Tomcat();
    // for tmp dir
    tomcat.setBaseDir(".");
    tomcat.setHostname(HOST);
    tomcat.setPort(PORT);
    ProtocolHandler p = tomcat.getConnector().getProtocolHandler();
    AbstractEndpoint<?> endpoint = (AbstractEndpoint<?>) getFieldValue(p, "endpoint");
    // vital for clean shutdown
    endpoint.setMaxKeepAliveRequests(1);
    File docBase = new File(".");
    Context context = tomcat.addContext(CONTEXT, docBase.getAbsolutePath());
    Application app = new org.nuxeo.ecm.webdav.Application();
    ApplicationAdapter conf = new ApplicationAdapter(app);
    conf.getFeatures().put(ResourceConfig.FEATURE_MATCH_MATRIX_PARAMS, Boolean.TRUE);
    String servletName = "testServlet";
    Servlet servlet = new ServletContainer(conf);
    tomcat.addServlet(CONTEXT, servletName, servlet);
    context.addServletMappingDecoded("/*", servletName);
    addFilter(context, servletName, "RequestContextFilter", new RequestContextFilter());
    addFilter(context, servletName, "SessionCleanupFilter", new SessionCleanupFilter());
    addFilter(context, servletName, "NuxeoAuthenticationFilter", new NuxeoAuthenticationFilter());
    addFilter(context, servletName, "WebEngineFilter", new WebEngineFilter());
    tomcat.start();
}
Also used : Context(org.apache.catalina.Context) AbstractEndpoint(org.apache.tomcat.util.net.AbstractEndpoint) Tomcat(org.apache.catalina.startup.Tomcat) RequestContextFilter(org.nuxeo.ecm.webengine.jaxrs.context.RequestContextFilter) SessionCleanupFilter(org.nuxeo.ecm.webengine.jaxrs.session.SessionCleanupFilter) WebEngineFilter(org.nuxeo.ecm.webengine.app.WebEngineFilter) ProtocolHandler(org.apache.coyote.ProtocolHandler) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) Servlet(javax.servlet.Servlet) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter) NuxeoAuthenticationFilter(org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter) File(java.io.File) Application(javax.ws.rs.core.Application)

Example 7 with ServletContainer

use of com.sun.jersey.spi.container.servlet.ServletContainer in project SSM by Intel-bigdata.

the class SmartZeppelinServer method setupRestApiContextHandler.

private void setupRestApiContextHandler(WebAppContext webApp) throws Exception {
    webApp.setSessionHandler(new SessionHandler());
    // There are two sets of rest api: Zeppelin's and SSM's. They have different path.
    ResourceConfig smartConfig = new ApplicationAdapter(new SmartRestApp());
    ServletHolder smartServletHolder = new ServletHolder(new ServletContainer(smartConfig));
    webApp.addServlet(smartServletHolder, SMART_PATH_SPEC);
    ResourceConfig zeppelinConfig = new ApplicationAdapter(new ZeppelinRestApp());
    ServletHolder zeppelinServletHolder = new ServletHolder(new ServletContainer(zeppelinConfig));
    webApp.addServlet(zeppelinServletHolder, ZEPPELIN_PATH_SPEC);
    String shiroIniPath = zconf.getShiroPath();
    if (!StringUtils.isBlank(shiroIniPath)) {
        webApp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
        SecurityUtils.initSecurityManager(shiroIniPath);
        webApp.addFilter(ShiroFilter.class, ZEPPELIN_PATH_SPEC, EnumSet.allOf(DispatcherType.class));
        // To make shiro configuration (authentication, etc.) take effect for smart rest api as well.
        webApp.addFilter(ShiroFilter.class, SMART_PATH_SPEC, EnumSet.allOf(DispatcherType.class));
        webApp.addEventListener(new EnvironmentLoaderListener());
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 8 with ServletContainer

use of com.sun.jersey.spi.container.servlet.ServletContainer in project zookeeper by apache.

the class RestMain method createJerseyAdapter.

private ServletAdapter createJerseyAdapter(Endpoint e) {
    ServletAdapter jersey = new ServletAdapter();
    jersey.setServletInstance(new ServletContainer());
    jersey.addInitParameter("com.sun.jersey.config.property.packages", "org.apache.zookeeper.server.jersey.resources");
    jersey.setContextPath(e.getContext());
    Credentials c = Credentials.join(e.getCredentials(), cfg.getCredentials());
    if (!c.isEmpty()) {
        jersey.addFilter(new HTTPBasicAuth(c), e.getContext() + "-basic-auth", null);
    }
    return jersey;
}
Also used : ServletAdapter(com.sun.grizzly.http.servlet.ServletAdapter) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) HTTPBasicAuth(org.apache.zookeeper.server.jersey.filters.HTTPBasicAuth) Credentials(org.apache.zookeeper.server.jersey.cfg.Credentials)

Example 9 with ServletContainer

use of com.sun.jersey.spi.container.servlet.ServletContainer in project hive by apache.

the class Main method runServer.

public Server runServer(int port) throws Exception {
    // Authenticate using keytab
    if (UserGroupInformation.isSecurityEnabled()) {
        String serverPrincipal = SecurityUtil.getServerPrincipal(conf.kerberosPrincipal(), "0.0.0.0");
        UserGroupInformation.loginUserFromKeytab(serverPrincipal, conf.kerberosKeytab());
    }
    // Create the Jetty server. If jetty conf file exists, use that to create server
    // to have more control.
    Server server = null;
    if (StringUtils.isEmpty(conf.jettyConfiguration())) {
        server = new Server(port);
    } else {
        FileInputStream jettyConf = new FileInputStream(conf.jettyConfiguration());
        XmlConfiguration configuration = new XmlConfiguration(jettyConf);
        server = (Server) configuration.configure();
    }
    ServletContextHandler root = new ServletContextHandler(server, "/");
    // Add the Auth filter
    FilterHolder fHolder = makeAuthFilter();
    EnumSet<DispatcherType> dispatches = EnumSet.of(DispatcherType.REQUEST);
    /* 
     * We add filters for each of the URIs supported by templeton.
     * If we added the entire sub-structure using '/*', the mapreduce 
     * notification cannot give the callback to templeton in secure mode.
     * This is because mapreduce does not use secure credentials for 
     * callbacks. So jetty would fail the request as unauthorized.
     */
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/ddl/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/pig/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/hive/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/sqoop/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/queue/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/jobs/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/mapreduce/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/status/*", dispatches);
    root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/version/*", dispatches);
    if (conf.getBoolean(AppConfig.XSRF_FILTER_ENABLED, false)) {
        root.addFilter(makeXSRFFilter(), "/" + SERVLET_PATH + "/*", dispatches);
        LOG.debug("XSRF filter enabled");
    } else {
        LOG.warn("XSRF filter disabled");
    }
    root.addFilter(makeFrameOptionFilter(), "/" + SERVLET_PATH + "/*", dispatches);
    // Connect Jersey
    ServletHolder h = new ServletHolder(new ServletContainer(makeJerseyConfig()));
    root.addServlet(h, "/" + SERVLET_PATH + "/*");
    // Add any redirects
    addRedirects(server);
    // Set handling for low resource conditions.
    final LowResourceMonitor low = new LowResourceMonitor(server);
    low.setLowResourcesIdleTimeout(10000);
    server.addBean(low);
    server.addConnector(createChannelConnector());
    // Start the server
    server.start();
    this.server = server;
    return server;
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) LowResourceMonitor(org.eclipse.jetty.server.LowResourceMonitor) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) FileInputStream(java.io.FileInputStream)

Example 10 with ServletContainer

use of com.sun.jersey.spi.container.servlet.ServletContainer in project neo4j by neo4j.

the class JaxRsServletHolderFactory method create.

public ServletHolder create(Collection<InjectableProvider<?>> defaultInjectables, boolean wadlEnabled) {
    Collection<InjectableProvider<?>> injectableProviders = mergeInjectables(defaultInjectables, injectables);
    ServletContainer container = new NeoServletContainer(injectableProviders);
    ServletHolder servletHolder = new ServletHolder(container);
    servletHolder.setInitParameter(ResourceConfig.FEATURE_DISABLE_WADL, String.valueOf(!wadlEnabled));
    configure(servletHolder, toCommaSeparatedList(items));
    servletHolder.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, AllowAjaxFilter.class.getName());
    servletHolder.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, getRequestFilterConfig());
    return servletHolder;
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) InjectableProvider(org.neo4j.server.database.InjectableProvider) AllowAjaxFilter(org.neo4j.server.rest.web.AllowAjaxFilter)

Aggregations

ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)14 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)9 Server (org.eclipse.jetty.server.Server)7 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)7 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)6 DefaultResourceConfig (com.sun.jersey.api.core.DefaultResourceConfig)4 DispatcherType (javax.servlet.DispatcherType)3 MediaType (javax.ws.rs.core.MediaType)3 AbstractSessionManager (org.eclipse.jetty.server.session.AbstractSessionManager)3 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)3 ApplicationAdapter (com.sun.jersey.api.core.ApplicationAdapter)2 File (java.io.File)2 EnvironmentLoaderListener (org.apache.shiro.web.env.EnvironmentLoaderListener)2 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)2 Bean (org.springframework.context.annotation.Bean)2 DelegatingFilterProxy (org.springframework.web.filter.DelegatingFilterProxy)2 AnnisRunnerException (annis.AnnisRunnerException)1 MultipleIniWebEnvironment (annis.security.MultipleIniWebEnvironment)1 StorageApplication (com.emc.storageos.api.service.impl.resource.StorageApplication)1 DataObject (com.emc.storageos.db.client.model.DataObject)1