Search in sources :

Example 16 with AbstractBinder

use of org.glassfish.hk2.utilities.binding.AbstractBinder in project nifi by apache.

the class TestTransformJSONResource method configure.

@Override
protected Application configure() {
    final ResourceConfig config = new ResourceConfig();
    config.register(TransformJSONResource.class);
    config.register(JacksonFeature.class);
    config.register(new AbstractBinder() {

        @Override
        public void configure() {
            bindFactory(MockServletContext.class).to(ServletContext.class);
        }
    });
    return config;
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServletContext(javax.servlet.ServletContext) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 17 with AbstractBinder

use of org.glassfish.hk2.utilities.binding.AbstractBinder in project Payara by payara.

the class AbstractRestResourceProvider method getResourceConfig.

@Override
public ResourceConfig getResourceConfig(Set<Class<?>> classes, final ServerContext sc, final ServiceLocator habitat, final Set<? extends Binder> additionalBinders) throws EndpointRegistrationException {
    final Reloader r = new Reloader();
    ResourceConfig rc = new ResourceConfig(classes);
    rc.property(ServerProperties.MEDIA_TYPE_MAPPINGS, getMimeMappings());
    rc.register(CsrfProtectionFilter.class);
    // TODO - JERSEY2
    // RestConfig restConf = ResourceUtil.getRestConfig(habitat);
    // if (restConf != null) {
    // if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
    // rc.getContainerResponseFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
    // rc.getContainerRequestFilters().add(LoggingFilter.class);
    // }
    // if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // }
    // else {
    // rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
    // }
    // 
    rc.register(r);
    rc.register(ReloadResource.class);
    rc.register(new MultiPartFeature());
    // rc.register(getJsonFeature());
    rc.register(new AbstractBinder() {

        @Override
        protected void configure() {
            AbstractActiveDescriptor<Reloader> descriptor = BuilderHelper.createConstantDescriptor(r);
            descriptor.addContractType(Reloader.class);
            bind(descriptor);
            AbstractActiveDescriptor<ServerContext> scDescriptor = BuilderHelper.createConstantDescriptor(sc);
            scDescriptor.addContractType(ServerContext.class);
            bind(scDescriptor);
            LocatorBridge locatorBridge = new LocatorBridge(habitat);
            AbstractActiveDescriptor<LocatorBridge> hDescriptor = BuilderHelper.createConstantDescriptor(locatorBridge);
            bind(hDescriptor);
            RestSessionManager rsm = habitat.getService(RestSessionManager.class);
            AbstractActiveDescriptor<RestSessionManager> rmDescriptor = BuilderHelper.createConstantDescriptor(rsm);
            bind(rmDescriptor);
        }
    });
    for (Binder b : additionalBinders) {
        rc.register(b);
    }
    rc.property(MessageProperties.LEGACY_WORKERS_ORDERING, true);
    return rc;
}
Also used : Binder(org.glassfish.hk2.utilities.Binder) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ServerContext(org.glassfish.internal.api.ServerContext) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) RestSessionManager(org.glassfish.common.util.admin.RestSessionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) AbstractActiveDescriptor(org.glassfish.hk2.utilities.AbstractActiveDescriptor)

Example 18 with AbstractBinder

use of org.glassfish.hk2.utilities.binding.AbstractBinder in project kylo by Teradata.

the class SchemaDiscoveryRestControllerTest method configure.

@Override
protected Application configure() {
    set(TestProperties.CONTAINER_PORT, PORT);
    enable(TestProperties.LOG_TRAFFIC);
    enable(TestProperties.DUMP_ENTITY);
    ResourceConfig config = new ResourceConfig(SchemaDiscoveryRestController.class);
    config.register(MultiPartFeature.class);
    config.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(Mockito.mock(CatalogFileManager.class)).to(CatalogFileManager.class);
        }
    });
    return config;
}
Also used : AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) CatalogFileManager(com.thinkbiganalytics.kylo.catalog.file.CatalogFileManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 19 with AbstractBinder

use of org.glassfish.hk2.utilities.binding.AbstractBinder in project storm by apache.

the class UIServer method main.

/**
 * main.
 * @param args args
 */
public static void main(String[] args) {
    Map<String, Object> conf = ConfigUtils.readStormConfig();
    int headerBufferSize = (int) conf.get(DaemonConfig.UI_HEADER_BUFFER_BYTES);
    final Integer httpsPort = ObjectReader.getInt(conf.get(DaemonConfig.UI_HTTPS_PORT), 0);
    final String httpsKsPath = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_PATH));
    final String httpsKsPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_PASSWORD));
    final String httpsKsType = (String) (conf.get(DaemonConfig.UI_HTTPS_KEYSTORE_TYPE));
    final String httpsKeyPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_KEY_PASSWORD));
    final String httpsTsPath = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_PATH));
    final String httpsTsPassword = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_PASSWORD));
    final String httpsTsType = (String) (conf.get(DaemonConfig.UI_HTTPS_TRUSTSTORE_TYPE));
    final Boolean httpsWantClientAuth = (Boolean) (conf.get(DaemonConfig.UI_HTTPS_WANT_CLIENT_AUTH));
    final Boolean httpsNeedClientAuth = (Boolean) (conf.get(DaemonConfig.UI_HTTPS_NEED_CLIENT_AUTH));
    final Boolean disableHttpBinding = (Boolean) (conf.get(DaemonConfig.UI_DISABLE_HTTP_BINDING));
    final boolean enableSslReload = ObjectReader.getBoolean(conf.get(DaemonConfig.UI_HTTPS_ENABLE_SSL_RELOAD), false);
    Server jettyServer = UIHelpers.jettyCreateServer((int) conf.get(DaemonConfig.UI_PORT), null, httpsPort, headerBufferSize, disableHttpBinding);
    UIHelpers.configSsl(jettyServer, httpsPort, httpsKsPath, httpsKsPassword, httpsKsType, httpsKeyPassword, httpsTsPath, httpsTsPassword, httpsTsType, httpsNeedClientAuth, httpsWantClientAuth, enableSslReload);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    jettyServer.setHandler(context);
    FilterConfiguration filterConfiguration = new FilterConfiguration((String) conf.get(DaemonConfig.UI_FILTER), (Map<String, String>) conf.get(DaemonConfig.UI_FILTER_PARAMS));
    final List<FilterConfiguration> filterConfigurationList = Arrays.asList(filterConfiguration);
    UIHelpers.configFilters(context, filterConfigurationList);
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    ResourceConfig resourceConfig = new ResourceConfig().packages("org.apache.storm.daemon.ui.resources").registerInstances(new AbstractBinder() {

        @Override
        protected void configure() {
            super.bind(metricsRegistry).to(StormMetricsRegistry.class);
        }
    }).register(AuthorizedUserFilter.class).register(HeaderResponseFilter.class).register(AuthorizationExceptionMapper.class).register(NotAliveExceptionMapper.class).register(DefaultExceptionMapper.class);
    ServletHolder jerseyServlet = new ServletHolder(new ServletContainer(resourceConfig));
    jerseyServlet.setInitOrder(0);
    context.addServlet(jerseyServlet, STORM_API_URL_PREFIX + "*");
    addRequestContextFilter(context, DaemonConfig.UI_HTTP_CREDS_PLUGIN, conf);
    // add special pathspec of static content mapped to the homePath
    ServletHolder holderHome = new ServletHolder("static-home", DefaultServlet.class);
    String packagedStaticFileLocation = System.getProperty(STORM_HOME) + FILE_SEPARATOR + "public/";
    if (Files.exists(Paths.get(packagedStaticFileLocation))) {
        holderHome.setInitParameter("resourceBase", packagedStaticFileLocation);
    } else {
        LOG.warn("Cannot find static file directory in " + packagedStaticFileLocation + " - assuming that UIServer is being launched" + "in a development environment and not from a packaged release");
        String developmentStaticFileLocation = UIServer.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "WEB-INF";
        if (Files.exists(Paths.get(developmentStaticFileLocation))) {
            holderHome.setInitParameter("resourceBase", developmentStaticFileLocation);
        } else {
            throw new RuntimeException("Cannot find static file directory in development " + "location " + developmentStaticFileLocation);
        }
    }
    holderHome.setInitParameter("dirAllowed", "true");
    holderHome.setInitParameter("pathInfoOnly", "true");
    context.addFilter(new FilterHolder(new HeaderResponseServletFilter(metricsRegistry)), "/*", EnumSet.allOf(DispatcherType.class));
    context.addServlet(holderHome, "/*");
    // Lastly, the default servlet for root content (always needed, to satisfy servlet spec)
    ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
    holderPwd.setInitParameter("dirAllowed", "true");
    context.addServlet(holderPwd, "/");
    metricsRegistry.startMetricsReporters(conf);
    Utils.addShutdownHookWithForceKillIn1Sec(metricsRegistry::stopMetricsReporters);
    try {
        jettyServer.start();
        jettyServer.join();
    } catch (Throwable t) {
        LOG.error("Exception in UIServer: ", t);
        throw new RuntimeException(t);
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) NotAliveExceptionMapper(org.apache.storm.daemon.ui.exceptionmappers.NotAliveExceptionMapper) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) HeaderResponseFilter(org.apache.storm.daemon.ui.filters.HeaderResponseFilter) HeaderResponseServletFilter(org.apache.storm.daemon.ui.filters.HeaderResponseServletFilter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType)

Aggregations

AbstractBinder (org.glassfish.hk2.utilities.binding.AbstractBinder)17 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 Test (org.junit.Test)4 Singleton (javax.inject.Singleton)3 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)3 SparkLocatorService (com.thinkbiganalytics.spark.service.SparkLocatorService)2 TransformService (com.thinkbiganalytics.spark.service.TransformService)2 ServletContext (javax.servlet.ServletContext)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)2 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)2 ServiceLocatorFactory (org.glassfish.hk2.api.ServiceLocatorFactory)2 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 RealtimeFeed (com.graphhopper.gtfs.RealtimeFeed)1 GraphHopperHealthCheck (com.graphhopper.http.health.GraphHopperHealthCheck)1 JTSTriangulator (com.graphhopper.isochrone.algorithm.JTSTriangulator)1 Triangulator (com.graphhopper.isochrone.algorithm.Triangulator)1 ProfileResolver (com.graphhopper.routing.ProfileResolver)1