Search in sources :

Example 1 with GuiceComponentProviderFactory

use of com.sun.jersey.guice.spi.container.GuiceComponentProviderFactory in project druid by druid-io.

the class WebserverTestUtils method createServer.

public static HttpServer createServer(String SERVICE_NAME, URI baseUri, String resourceClassName, Consumer<Binder> extender) throws IOException {
    Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of(binder -> {
        binder.bindConstant().annotatedWith(Names.named("serviceName")).to(SERVICE_NAME);
        binder.bindConstant().annotatedWith(Names.named("servicePort")).to(baseUri.getPort());
        binder.bindConstant().annotatedWith(Names.named("tlsServicePort")).to(baseUri.getPort() + 1);
        binder.bind(Key.get(ServiceEmitter.class)).toInstance(new NoopServiceEmitter());
        binder.bind(Key.get(AuthConfig.class)).toInstance(new AuthConfig());
        binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
        binder.bind(AuthenticatorMapper.class).toInstance(AuthTestUtils.TEST_AUTHENTICATOR_MAPPER);
        binder.bind(Key.get(HttpClient.class, Client.class)).toInstance(EasyMock.createMock(HttpClient.class));
        extender.accept(binder);
    }));
    ResourceConfig resourceConfig = new ClassNamesResourceConfig(resourceClassName + ';' + MockHttpServletRequest.class.getName());
    IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(resourceConfig, injector);
    HttpServer server = GrizzlyServerFactory.createHttpServer(baseUri, resourceConfig, ioc);
    return server;
}
Also used : HttpClient(org.apache.druid.java.util.http.client.HttpClient) Provider(javax.ws.rs.ext.Provider) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) Key(com.google.inject.Key) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) HttpServletRequest(javax.servlet.http.HttpServletRequest) ImmutableList(com.google.common.collect.ImmutableList) Binder(com.google.inject.Binder) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AuthTestUtils(org.apache.druid.server.security.AuthTestUtils) HttpServer(org.glassfish.grizzly.http.server.HttpServer) UriBuilder(javax.ws.rs.core.UriBuilder) AuthConfig(org.apache.druid.server.security.AuthConfig) URI(java.net.URI) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Context(javax.ws.rs.core.Context) GuiceComponentProviderFactory(com.sun.jersey.guice.spi.container.GuiceComponentProviderFactory) AuthenticatorMapper(org.apache.druid.server.security.AuthenticatorMapper) ClassNamesResourceConfig(com.sun.jersey.api.core.ClassNamesResourceConfig) SingletonTypeInjectableProvider(com.sun.jersey.spi.inject.SingletonTypeInjectableProvider) IOException(java.io.IOException) Names(com.google.inject.name.Names) EasyMock(org.easymock.EasyMock) GrizzlyServerFactory(com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) Injector(com.google.inject.Injector) Consumer(java.util.function.Consumer) IoCComponentProviderFactory(com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory) Initialization(org.apache.druid.initialization.Initialization) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Client(org.apache.druid.guice.annotations.Client) Collections(java.util.Collections) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Injector(com.google.inject.Injector) ClassNamesResourceConfig(com.sun.jersey.api.core.ClassNamesResourceConfig) HttpClient(org.apache.druid.java.util.http.client.HttpClient) HttpServer(org.glassfish.grizzly.http.server.HttpServer) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) AuthConfig(org.apache.druid.server.security.AuthConfig) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) ClassNamesResourceConfig(com.sun.jersey.api.core.ClassNamesResourceConfig) HttpClient(org.apache.druid.java.util.http.client.HttpClient) Client(org.apache.druid.guice.annotations.Client) GuiceComponentProviderFactory(com.sun.jersey.guice.spi.container.GuiceComponentProviderFactory) IoCComponentProviderFactory(com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Binder (com.google.inject.Binder)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 Names (com.google.inject.name.Names)1 GrizzlyServerFactory (com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory)1 ClassNamesResourceConfig (com.sun.jersey.api.core.ClassNamesResourceConfig)1 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)1 IoCComponentProviderFactory (com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory)1 GuiceComponentProviderFactory (com.sun.jersey.guice.spi.container.GuiceComponentProviderFactory)1 SingletonTypeInjectableProvider (com.sun.jersey.spi.inject.SingletonTypeInjectableProvider)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Collections (java.util.Collections)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Consumer (java.util.function.Consumer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Context (javax.ws.rs.core.Context)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Provider (javax.ws.rs.ext.Provider)1