Search in sources :

Example 1 with ApplicationAdapter

use of com.sun.jersey.api.core.ApplicationAdapter in project camunda-bpm-platform by camunda.

the class JerseyServerBootstrap method setupServer.

private void setupServer(Application application) {
    ResourceConfig rc = new ApplicationAdapter(application);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(ResourceConfig.FEATURE_TRACE, "true");
    rc.setPropertiesAndFeatures(properties);
    Properties serverProperties = readProperties();
    int port = Integer.parseInt(serverProperties.getProperty(PORT_PROPERTY));
    URI serverUri = UriBuilder.fromPath(ROOT_RESOURCE_PATH).scheme("http").host("localhost").port(port).build();
    try {
        server = GrizzlyServerFactory.createHttpServer(serverUri, rc);
    } catch (IllegalArgumentException e) {
        throw new ServerBootstrapException(e);
    } catch (NullPointerException e) {
        throw new ServerBootstrapException(e);
    } catch (IOException e) {
        throw new ServerBootstrapException(e);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) Properties(java.util.Properties) URI(java.net.URI) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ApplicationAdapter(com.sun.jersey.api.core.ApplicationAdapter)

Example 2 with ApplicationAdapter

use of com.sun.jersey.api.core.ApplicationAdapter 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 3 with ApplicationAdapter

use of com.sun.jersey.api.core.ApplicationAdapter 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)

Aggregations

ApplicationAdapter (com.sun.jersey.api.core.ApplicationAdapter)3 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)2 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)2 File (java.io.File)2 IOException (java.io.IOException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 DispatcherType (javax.servlet.DispatcherType)1 Servlet (javax.servlet.Servlet)1 Application (javax.ws.rs.core.Application)1 Context (org.apache.catalina.Context)1 Tomcat (org.apache.catalina.startup.Tomcat)1 ProtocolHandler (org.apache.coyote.ProtocolHandler)1 EnvironmentLoaderListener (org.apache.shiro.web.env.EnvironmentLoaderListener)1 AbstractEndpoint (org.apache.tomcat.util.net.AbstractEndpoint)1 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 NuxeoAuthenticationFilter (org.nuxeo.ecm.platform.ui.web.auth.NuxeoAuthenticationFilter)1 WebEngineFilter (org.nuxeo.ecm.webengine.app.WebEngineFilter)1