org.glassfish.hk2.utilities.binding.AbstractBinder Java Examples

The following examples show how to use org.glassfish.hk2.utilities.binding.AbstractBinder. 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: TileMapServiceResourceIntegrationTest.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure()
{
  service = Mockito.mock(TmsService.class);
  request = Mockito.mock(HttpServletRequest.class);

  ResourceConfig config = new ResourceConfig();
  config.register(TileMapServiceResource.class);
  config.register(new AbstractBinder()
  {
    @Override
    protected void configure()
    {
      bind(service).to(TmsService.class);
    }
  });
  config.register(new AbstractBinder()
  {
    @Override
    protected void configure()
    {
      bind(request).to(HttpServletRequest.class);
    }
  });
  return config;
}
 
Example #2
Source File: WebApplicationResourceConfig.java    From game-of-life-modern-java with MIT License 6 votes vote down vote up
public WebApplicationResourceConfig() {
   	packages("com.giorgiosironi.gameoflife.web");
   	property(MvcFeature.TEMPLATE_BASE_PATH, "templates");
   	register(FreemarkerMvcFeature.class);
   	register(new AbstractBinder() {
		@Override
		protected void configure() {
			InMemoryGenerationRepository repository = new InMemoryGenerationRepository();
			Generation original = Generation.withAliveCells(
					Cell.onXAndY(1, 1),
					Cell.onXAndY(1, 2),
					Cell.onXAndY(2, 1),
					Cell.onXAndY(2, 2),
					Cell.onXAndY(7, 1),
					Cell.onXAndY(7, 2),
					Cell.onXAndY(7, 3),
					Cell.onXAndY(7, 8)
			);
			repository.add("a-block-and-a-bar", 0, original);
			bind(repository).to(GenerationRepository.class);
		}
   	});
}
 
Example #3
Source File: SingularityAuthFeature.java    From Singularity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
  context.register(
    new AbstractBinder() {

      @Override
      public void configure() {
        bind(SingularityMultiMethodAuthenticator.class)
          .to(
            new TypeLiteral<Authenticator<ContainerRequestContext, SingularityUser>>() {}
          )
          .in(Singleton.class);
        bind(SingularityAuthedUserFactory.class)
          .to(SingularityAuthedUserFactory.class)
          .in(Singleton.class);
        bind(SingularityAuthFactoryProvider.class)
          .to(ValueFactoryProvider.class)
          .in(Singleton.class);
        bind(SingularityAuthParamInjectionResolver.class)
          .to(new TypeLiteral<InjectionResolver<Auth>>() {})
          .in(Singleton.class);
      }
    }
  );
  return true;
}
 
Example #4
Source File: MockApplication.java    From soabase with Apache License 2.0 6 votes vote down vote up
@Override
public void run(MockConfiguration configuration, Environment environment) throws Exception
{
    AbstractBinder abstractBinder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            bind(new MockHK2Injected()).to(MockHK2Injected.class);
        }
    };
    environment.jersey().register(abstractBinder);
    environment.jersey().register(MockResource.class);
    LifeCycle.Listener listener = new AbstractLifeCycle.AbstractLifeCycleListener()
    {
        @Override
        public void lifeCycleStarted(LifeCycle event)
        {
            System.out.println("Starting...");
            startedLatch.countDown();
        }
    };
    environment.lifecycle().addLifeCycleListener(listener);
}
 
Example #5
Source File: MockApplication.java    From soabase with Apache License 2.0 6 votes vote down vote up
@Override
public void run(TestConfiguration configuration, Environment environment) throws Exception
{
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            bind(throwInternalError).to(AtomicBoolean.class);
            bind(counter).to(AtomicInteger.class);
        }
    };
    environment.jersey().register(binder);
    environment.jersey().register(MockResource.class);

    JerseyClientConfiguration clientConfiguration = new JerseyClientConfiguration();
    clientConfiguration.setMaxConnectionsPerRoute(Integer.MAX_VALUE);
    clientConfiguration.setMaxConnections(Integer.MAX_VALUE);
    client = new ClientBuilder(environment).buildJerseyClient(clientConfiguration, "test");

    startedLatch.countDown();
}
 
Example #6
Source File: TokenFeature.java    From robe with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean configure(FeatureContext context) {
    context.register(new AbstractBinder() {
        @Override
        public void configure() {
            bind(TokenAuthenticator.class)
                    .in(Singleton.class);
            bind(TokenFactory.class)
                    .in(Singleton.class);
            bind(TokenFactoryProvider.class)
                    .to(ValueFactoryProvider.class)
                    .in(Singleton.class);
            bind(TokenParamInjectionResolver.class)
                    .to(new TypeLiteral<InjectionResolver<RobeAuth>>() {
                    })
                    .in(Singleton.class);
        }
    });
    return true;
}
 
Example #7
Source File: RasterResourceTest.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure()
{
  service = Mockito.mock(MrsPyramidService.class);
  request = Mockito.mock(HttpServletRequest.class);

  ResourceConfig config = new ResourceConfig();
  config.register(RasterResource.class);
  config.register(new AbstractBinder()
  {
    @Override
    protected void configure()
    {
      bind(service).to(MrsPyramidService.class);
    }
  });
  return config;
}
 
Example #8
Source File: MetadataResourceTest.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure()
{
  service = Mockito.mock(MrsPyramidService.class);

  ResourceConfig config = new ResourceConfig();
  config.register(MetadataResource.class);
  config.register(new AbstractBinder()
  {
    @Override
    protected void configure()
    {
      bind(service).to(MrsPyramidService.class);
    }
  });
  return config;
}
 
Example #9
Source File: ColorScaleResourceTest.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure()
{
  service = Mockito.mock(MrsPyramidService.class);

  ResourceConfig config = new ResourceConfig();
  config.register(ColorScaleResource.class);
  config.register(new AbstractBinder()
  {
    @Override
    protected void configure()
    {
      bind(service).to(MrsPyramidService.class);
    }
  });
  return config;
}
 
Example #10
Source File: JerseyApplication.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
public JerseyApplication() {
    property(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, "io.katharsis.example.jersey.domain");
    property(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN, APPLICATION_URL);
    register(KatharsisDynamicFeature.class);
    register(new AbstractBinder() {
        @Override
        public void configure() {
            bindFactory(ObjectMapperFactory.class).to(ObjectMapper.class).in(Singleton.class);
            bindService(TaskRepository.class);
            bindService(ProjectRepository.class);
            bindService(TaskToProjectRepository.class);
        }

        private void bindService(Class<?> serviceType) {
            bind(serviceType).to(serviceType).proxy(true).in(RequestScoped.class);
        }
    });

}
 
Example #11
Source File: Jersey2BackstopperConfigHelperTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
public void backstopperOnlyExceptionMapperFactory_removes_all_exception_mappers_except_Jersey2ApiExceptionHandler()
    throws NoSuchFieldException, IllegalAccessException {
    // given
    AbstractBinder lotsOfExceptionMappersBinder = new AbstractBinder() {
        @Override
        protected void configure() {
            bind(JsonMappingExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(JsonParseExceptionMapper.class).to(ExceptionMapper.class).in(Singleton.class);
            bind(generateJerseyApiExceptionHandler(projectApiErrors, utils)).to(ExceptionMapper.class);
        }
    };

    ServiceLocator locator = ServiceLocatorUtilities.bind(lotsOfExceptionMappersBinder);

    // when
    BackstopperOnlyExceptionMapperFactory overrideExceptionMapper = new BackstopperOnlyExceptionMapperFactory(locator);

    // then
    Set<Object> emTypesLeft = overrideExceptionMapper.getFieldObj(
        ExceptionMapperFactory.class, overrideExceptionMapper, "exceptionMapperTypes"
    );
    assertThat(emTypesLeft).hasSize(1);
    ServiceHandle serviceHandle = overrideExceptionMapper.getFieldObj(emTypesLeft.iterator().next(), "mapper");
    assertThat(serviceHandle.getService()).isInstanceOf(Jersey2ApiExceptionHandler.class);
}
 
Example #12
Source File: WebDAVNoBaseUrlTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Override
public Application configure() {

    initMocks(this);

    final ResourceConfig config = new ResourceConfig();

    config.register(new DebugExceptionMapper());
    config.register(new TestAuthnFilter("testUser", ""));
    config.register(new TrellisWebDAVRequestFilter());
    config.register(new TrellisWebDAVResponseFilter());
    config.register(new TrellisWebDAV(mockBundler));
    config.register(new TrellisHttpResource(mockBundler));
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(mockBundler).to(ServiceBundler.class);
        }
    });
    return config;
}
 
Example #13
Source File: WebDAVTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Override
protected Application configure() {

    initMocks(this);

    final ResourceConfig config = new ResourceConfig();

    try {
        System.setProperty(CONFIG_HTTP_BASE_URL, getBaseUri().toString());
        config.register(new DebugExceptionMapper());
        config.register(new TrellisWebDAVRequestFilter());
        config.register(new TrellisWebDAVResponseFilter());
        config.register(new TrellisWebDAV(mockBundler));
        config.register(new TrellisHttpResource(mockBundler));
        config.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(mockBundler).to(ServiceBundler.class);
            }
        });
        return config;
    } finally {
        System.clearProperty(CONFIG_HTTP_BASE_URL);
    }
}
 
Example #14
Source File: AdminApiApplication.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public AdminApiApplication(ServerInstance instance, AccessControlFactory accessControlFactory) {
  this.serverInstance = instance;
  this.accessControlFactory = accessControlFactory;
  packages(RESOURCE_PACKAGE);
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bind(serverInstance).to(ServerInstance.class);
      bind(accessControlFactory).to(AccessControlFactory.class);
    }
  });

  register(JacksonFeature.class);

  registerClasses(io.swagger.jaxrs.listing.ApiListingResource.class);
  registerClasses(io.swagger.jaxrs.listing.SwaggerSerializers.class);
  register(new ContainerResponseFilter() {
    @Override
    public void filter(ContainerRequestContext containerRequestContext,
        ContainerResponseContext containerResponseContext)
        throws IOException {
      containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
    }
  });
}
 
Example #15
Source File: ExampleApplication.java    From okta-auth-java with Apache License 2.0 6 votes vote down vote up
private void configureJersey(JerseyEnvironment jersey) {

        // Load any resource in the resources package
        String baseResourcePackage = getClass().getPackage().getName() + ".resources";
        jersey.packages(baseResourcePackage);

        AuthenticationClient client = AuthenticationClients.builder()
                                                           .build();

        // use @Inject to bind the DAOs
        jersey.register(new AbstractBinder() {
            @Override
            protected void configure() {
                bind(new DefaultStormtrooperDao()).to(StormtrooperDao.class);
                bind(new DefaultTieCraftDao()).to(TieCraftDao.class);
                bind(client).to(AuthenticationClient.class);
            }
        });
    }
 
Example #16
Source File: JettyServerProvider.java    From browserup-proxy with Apache License 2.0 6 votes vote down vote up
private AbstractBinder proxyManagerToHkBinder(MitmProxyManager proxyManager) {
    Factory<MitmProxyManager> proxyManagerFactory = new Factory<MitmProxyManager>() {

        @Override
        public MitmProxyManager provide() {
            return proxyManager;
        }

        @Override
        public void dispose(MitmProxyManager instance) {}
    };

    return new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(proxyManagerFactory).to(MitmProxyManager.class);
        }
    };
}
 
Example #17
Source File: PinotServiceManagerAdminApiApplication.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public PinotServiceManagerAdminApiApplication(PinotServiceManager pinotServiceManager) {
  packages(RESOURCE_PACKAGE);
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bind(pinotServiceManager).to(PinotServiceManager.class);
    }
  });
  register(JacksonFeature.class);
  registerClasses(io.swagger.jaxrs.listing.ApiListingResource.class);
  registerClasses(io.swagger.jaxrs.listing.SwaggerSerializers.class);
}
 
Example #18
Source File: TestProcessorResource.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Application configure() {
    final ResourceConfig config = new ResourceConfig();
    config.register(ProcessorResource.class);
    config.register(JacksonFeature.class);
    config.register(new AbstractBinder(){
        @Override
        public void configure() {
            bindFactory(MockRequestContext.class).to(HttpServletRequest.class);
        }
    });
    config.register(new AbstractBinder(){
        @Override
        public void configure() {
            bindFactory(MockServletContext.class).to(ServletContext.class);
        }
    });
    return config;
}
 
Example #19
Source File: TFBApplication.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TFBApplication() {
	super(ServerHeaderFilter.class, JacksonFeature.class, Jackson2MapperProvider.class,
			MustacheMvcFeature.class, PlaintextResource.class, JsonResource.class,
			FortunesResource.class, WorldResource.class);
	property("jersey.config.server.mvc.caching.mustache", "true");
	register(new AbstractBinder() {
		@Override
		protected void configure() {
			bindFactory(EMFactory.class).to(EntityManagerFactory.class).in(Singleton.class);
		}
	});
}
 
Example #20
Source File: MigrationFeature.java    From ameba with MIT License 5 votes vote down vote up
private void bindFlyway(final String name, final Flyway flyway) {
    ServiceLocatorUtilities.bind(locator, new AbstractBinder() {
        @Override
        protected void configure() {
            bind(flyway).to(Flyway.class).named(name).proxy(false);
            if (name.equals(DataSourceManager.getDefaultDataSourceName())) {
                bind(flyway).to(Flyway.class).proxy(false);
            }
        }
    });
}
 
Example #21
Source File: BrokerAdminApiApplication.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public BrokerAdminApiApplication(RoutingManager routingManager, BrokerRequestHandler brokerRequestHandler,
    BrokerMetrics brokerMetrics) {
  packages(RESOURCE_PACKAGE);
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bind(routingManager).to(RoutingManager.class);
      bind(brokerRequestHandler).to(BrokerRequestHandler.class);
      bind(brokerMetrics).to(BrokerMetrics.class);
    }
  });
  register(JacksonFeature.class);
  registerClasses(io.swagger.jaxrs.listing.ApiListingResource.class);
  registerClasses(io.swagger.jaxrs.listing.SwaggerSerializers.class);
}
 
Example #22
Source File: TestSecretResource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
SecretResourceTestConfig() {
  register(new PaginationInfoInjectorBinder());
  register(MultiPartFeature.class);
  register(SecretResource.class);
  register(new ExceptionToHttpErrorProvider());
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bindFactory(TestUtil.CredentialStoreTaskTestInjector.class).to(CredentialStoresTask.class);
      bindFactory(ConfigurationTestInjector.class).to(Configuration.class);
    }
  });
  register(JacksonObjectMapperResolver.class);
}
 
Example #23
Source File: DisconnectedResourceConfig.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public DisconnectedResourceConfig() {
  register(new AbstractBinder() {
    @Override
    protected void configure() {
      bindFactory(DisconnectedSSOServiceInjector.class).to(DisconnectedSSOService.class);
      bindFactory(AuthenticationResourceHandlerInjector.class).to(AuthenticationResourceHandler.class);
    }
  });
}
 
Example #24
Source File: TestTransformJSONResource.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #25
Source File: AdminConsoleApp.java    From soabase with Apache License 2.0 5 votes vote down vote up
@Override
public final void run(T configuration, Environment environment) throws Exception
{
    environment.jersey().register(DiscoveryResource.class);
    environment.jersey().register(AttributesResource.class);
    environment.jersey().register(PreferencesResource.class);

    environment.jersey().register(AuthResource.class);
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            AuthSpecHolder holder = new AuthSpecHolder(builder.getAuthSpec());
            bind(holder).to(AuthSpecHolder.class);
        }
    };
    environment.jersey().register(binder);
    if ( builder.getAuthSpec() != null )
    {
        environment.servlets().setSessionHandler(new SessionHandler());
    }

    ComponentManager componentManager = SoaBundle.getFeatures(environment).getNamed(ComponentManager.class, SoaFeatures.DEFAULT_NAME);
    for ( TabComponent component : componentManager.getTabs() )
    {
        int index = 0;
        for ( AssetsPath assetsPath : component.getAssetsPaths() )
        {
            AssetServlet servlet = new AssetServlet(assetsPath.getResourcePath(), assetsPath.getUriPath(), null, Charsets.UTF_8);
            environment.servlets().addServlet(component.getName() + index++, servlet).addMapping(assetsPath.getUriPath() + '*');
        }
    }

}
 
Example #26
Source File: Jersey2BackstopperConfigHelperTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void exceptionMapperFactoryOverrideBinder_configures_ExceptionMappers_override() {
    // given
    AbstractBinder defaultJersey2ExceptionMapperBinder = new ExceptionMapperFactory.Binder();
    ExceptionMapperFactoryOverrideBinder overrideBinder =  new ExceptionMapperFactoryOverrideBinder();
    ServiceLocator locator = ServiceLocatorUtilities.bind(defaultJersey2ExceptionMapperBinder, overrideBinder);

    // when
    ExceptionMappers result = locator.getService(ExceptionMappers.class);

    // then
    assertThat(result).isInstanceOf(BackstopperOnlyExceptionMapperFactory.class);
}
 
Example #27
Source File: JerseyServletProvider.java    From vespa with Apache License 2.0 5 votes vote down vote up
private static Binder componentInjectorBinder(RestApiContext restApiContext) {
    final ComponentGraphProvider componentGraphProvider = new ComponentGraphProvider(restApiContext.getInjectableComponents());
    final TypeLiteral<InjectionResolver<Component>> componentAnnotationType = new TypeLiteral<InjectionResolver<Component>>() {
    };

    return new AbstractBinder() {
        @Override
        public void configure() {
            bind(componentGraphProvider).to(componentAnnotationType);
        }
    };
}
 
Example #28
Source File: LinkFactoryResourceConfig.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
public static void configureWithoutPlugins(ResourceConfig config) {
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(RestJsonSchemaGeneratorFactory.class, Singleton.class).to(JsonSchemaGenerator.class).in(
                    Singleton.class);
            bind(BaseUriCreatorDefault.class).to(BaseUriCreator.class).in(Singleton.class);
            bindFactory(LinkFactoryContextFactory.class).to(LinkFactoryContext.class).in(RequestScoped.class).proxy(
                    true);
            bindFactory(LinkMetaFactoryFactory.class).to(LinkMetaFactory.class);
        }
    });

}
 
Example #29
Source File: LinkFactoryResourceConfig.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
private static void bindDefaultPlugins(ResourceConfig config) {
    config.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(MethodCheckerForLinkFactory.class)
                    .to(MethodCheckerForLink.class)
                    .in(RequestScoped.class)
                    .proxy(true);
            bindFactory(FieldCheckerForSchemaFactory.class, Singleton.class).to(FieldCheckerForSchema.class).in(
                    Singleton.class);
        }
    });
}
 
Example #30
Source File: JerseySpringTest.java    From gravitee-management-rest-api with Apache License 2.0 5 votes vote down vote up
protected void decorate(ResourceConfig resourceConfig) {
    resourceConfig.register(AuthenticationFilter.class);

    final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    resourceConfig.register(new AbstractBinder() {
        @Override
        protected void configure() {
            bind(response).to(HttpServletResponse.class);
        }
    });
}