Search in sources :

Example 1 with AbstractBinder

use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.

the class DeclarativeLinkingFeature method configure.

@Override
public boolean configure(FeatureContext context) {
    Configuration config = context.getConfiguration();
    if (!config.isRegistered(ResponseLinkFilter.class)) {
        context.register(new AbstractBinder() {

            @Override
            protected void configure() {
                bindAsContract(NaiveResourceMappingContext.class).to(ResourceMappingContext.class).in(Singleton.class);
            }
        });
        context.register(ResponseLinkFilter.class);
        // context.register(RequestLinkFilter.class);
        return true;
    }
    return false;
}
Also used : Configuration(javax.ws.rs.core.Configuration) Singleton(javax.inject.Singleton) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) NaiveResourceMappingContext(org.glassfish.jersey.linking.mapping.NaiveResourceMappingContext)

Example 2 with AbstractBinder

use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.

the class CdiComponentProvider method bindHk2ClassAnalyzer.

private void bindHk2ClassAnalyzer() {
    ClassAnalyzer defaultClassAnalyzer = injectionManager.getInstance(ClassAnalyzer.class, ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME);
    int skippedElements = methodsToSkip.size() + fieldsToSkip.size();
    ClassAnalyzer customizedClassAnalyzer = skippedElements > 0 ? new InjecteeSkippingAnalyzer(defaultClassAnalyzer, methodsToSkip, fieldsToSkip) : defaultClassAnalyzer;
    Binder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(customizedClassAnalyzer).analyzeWith(ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME).to(ClassAnalyzer.class).named(CDI_CLASS_ANALYZER);
        }
    };
    injectionManager.register(binder);
}
Also used : AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) Binder(org.glassfish.jersey.internal.inject.Binder) ClassAnalyzer(org.glassfish.hk2.api.ClassAnalyzer) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 3 with AbstractBinder

use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.

the class InjectionManagerServerProviderTest method configure.

@Override
protected Application configure() {
    final ResourceConfig resourceConfig = new ResourceConfig(TestResource.class);
    resourceConfig.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(new MyInjectedService("hello")).to(MyInjectedService.class);
        }
    });
    resourceConfig.register(new MyFeature());
    resourceConfig.register(new MyReaderInterceptor());
    resourceConfig.register(new MyWriterInterceptor());
    return resourceConfig;
}
Also used : AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 4 with AbstractBinder

use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.

the class ValidatorTest method createInjectionManager.

private InjectionManager createInjectionManager() {
    InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
    injectionManager.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(new CommonConfig(RuntimeType.SERVER, ComponentBag.EXCLUDE_EMPTY)).to(Configuration.class);
        }
    });
    return injectionManager;
}
Also used : Configuration(javax.ws.rs.core.Configuration) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager)

Example 5 with AbstractBinder

use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.

the class InjectionManagerProviderTest method testFeatureClass.

@Test
public void testFeatureClass() {
    final Response response = target().path("resource").register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(new MyInjectedService("feature")).to(MyInjectedService.class);
        }
    }).register(MyFeature.class).request().post(Entity.entity("will-be-extended-by", MediaType.TEXT_PLAIN_TYPE));
    assertEquals(200, response.getStatus());
    assertEquals("will-be-extended-by-interceptor-feature", response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)19 Test (org.junit.Test)7 Singleton (javax.inject.Singleton)5 Binder (org.glassfish.jersey.internal.inject.Binder)4 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 Configuration (javax.ws.rs.core.Configuration)3 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 Binding (org.glassfish.jersey.internal.inject.Binding)2 ClassBinding (org.glassfish.jersey.internal.inject.ClassBinding)2 RequestScope (org.glassfish.jersey.process.internal.RequestScope)2 HeaderDelegateProvider (org.glassfish.jersey.spi.HeaderDelegateProvider)2 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1 ServletContext (javax.servlet.ServletContext)1 RuntimeType (javax.ws.rs.RuntimeType)1 ClassAnalyzer (org.glassfish.hk2.api.ClassAnalyzer)1 HK2InjectionManager (org.glassfish.jersey.hk2.HK2InjectionManager)1 ServiceFinderBinder (org.glassfish.jersey.internal.ServiceFinderBinder)1 PerThread (org.glassfish.jersey.internal.inject.PerThread)1