Search in sources :

Example 1 with ServiceLocatorImpl

use of org.jvnet.hk2.internal.ServiceLocatorImpl in project jersey by jersey.

the class JettyContainerTest method testParentServiceLocator.

/**
     * Test that defined ServiceLocator becomes a parent of the newly created service locator.
     */
@Test
public void testParentServiceLocator() {
    final ServiceLocator locator = new ServiceLocatorImpl("MyServiceLocator", null);
    final Server server = JettyHttpContainerFactory.createServer(URI.create("http://localhost:9876"), new ResourceConfig(Resource.class), false, locator);
    JettyHttpContainer container = (JettyHttpContainer) server.getHandler();
    InjectionManager injectionManager = container.getApplicationHandler().getInjectionManager();
    HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
    ServiceLocator serviceLocator = hk2InjectionManager.getServiceLocator();
    assertTrue("Application injection manager was expected to have defined parent locator", serviceLocator.getParent() == locator);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Server(org.eclipse.jetty.server.Server) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) JettyHttpContainer(org.glassfish.jersey.jetty.JettyHttpContainer) ServiceLocatorImpl(org.jvnet.hk2.internal.ServiceLocatorImpl) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with ServiceLocatorImpl

use of org.jvnet.hk2.internal.ServiceLocatorImpl in project jersey by jersey.

the class ServiceLocatorGenerator method create.

@Override
public ServiceLocator create(final String name, final ServiceLocator parent) {
    if (parent != null && !(parent instanceof ServiceLocatorImpl)) {
        throw new AssertionError("parent must be a " + ServiceLocatorImpl.class.getName() + " instead it is a " + parent.getClass().getName());
    }
    final ServiceLocatorImpl sli = new CustomServiceLocator(name, (ServiceLocatorImpl) parent);
    final DynamicConfigurationImpl dci = new DynamicConfigurationImpl(sli);
    // The service locator itself
    dci.bind(Utilities.getLocatorDescriptor(sli));
    // The injection resolver for three thirty
    dci.addActiveDescriptor(Utilities.getThreeThirtyDescriptor(sli));
    // The dynamic configuration utility
    dci.bind(BuilderHelper.link(DynamicConfigurationServiceImpl.class, false).to(DynamicConfigurationService.class).in(Singleton.class.getName()).localOnly().build());
    dci.bind(BuilderHelper.createConstantDescriptor(new DefaultClassAnalyzer(sli)));
    dci.commit();
    return sli;
}
Also used : DynamicConfigurationImpl(org.jvnet.hk2.internal.DynamicConfigurationImpl) DefaultClassAnalyzer(org.jvnet.hk2.internal.DefaultClassAnalyzer) DynamicConfigurationServiceImpl(org.jvnet.hk2.internal.DynamicConfigurationServiceImpl) ServiceLocatorImpl(org.jvnet.hk2.internal.ServiceLocatorImpl)

Aggregations

ServiceLocatorImpl (org.jvnet.hk2.internal.ServiceLocatorImpl)2 Server (org.eclipse.jetty.server.Server)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 HK2InjectionManager (org.glassfish.jersey.hk2.HK2InjectionManager)1 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)1 JettyHttpContainer (org.glassfish.jersey.jetty.JettyHttpContainer)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1 DefaultClassAnalyzer (org.jvnet.hk2.internal.DefaultClassAnalyzer)1 DynamicConfigurationImpl (org.jvnet.hk2.internal.DynamicConfigurationImpl)1 DynamicConfigurationServiceImpl (org.jvnet.hk2.internal.DynamicConfigurationServiceImpl)1