Search in sources :

Example 86 with Reference

use of javax.naming.Reference in project redisson by redisson.

the class JndiRedissonFactory method getObjectInstance.

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Reference ref = (Reference) obj;
    RefAddr addr = ref.get("configPath");
    return buildClient(addr.getContent().toString());
}
Also used : RefAddr(javax.naming.RefAddr) Reference(javax.naming.Reference)

Example 87 with Reference

use of javax.naming.Reference in project wildfly by wildfly.

the class ServiceReferenceObjectFactory method getObjectInstance.

@SuppressWarnings("unchecked")
@Override
public final Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    final Reference reference = (Reference) obj;
    final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
    if (nameAdr == null) {
        throw NamingLogger.ROOT_LOGGER.invalidContextReference("srof");
    }
    final ServiceName serviceName = (ServiceName) nameAdr.getContent();
    try {
        final ServiceController<?> controller = serviceRegistry.getRequiredService(serviceName);
        return getObjectInstance(controller.awaitValue(), obj, name, nameCtx, environment);
    } catch (ServiceNotFoundException e) {
        throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName);
    } catch (InterruptedException e) {
        throw NamingLogger.ROOT_LOGGER.threadInterrupt(serviceName);
    } catch (Throwable t) {
        throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "START_FAILED");
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ModularReference(org.jboss.as.naming.context.ModularReference) Reference(javax.naming.Reference) ServiceNotFoundException(org.jboss.msc.service.ServiceNotFoundException)

Example 88 with Reference

use of javax.naming.Reference in project wildfly by wildfly.

the class ObjectFactoryTestCase method testBindAndRetrieveObjectFactoryFromInitialContext.

@Test
public void testBindAndRetrieveObjectFactoryFromInitialContext() throws Exception {
    final Reference reference = new Reference("java.util.String", TestObjectFactory.class.getName(), null);
    namingStore.bind(new CompositeName("test"), reference);
    final InitialContext initialContext = new InitialContext();
    final Object result = initialContext.lookup("test");
    assertTrue(result instanceof String);
    assertEquals("Test ParsedResult", result);
}
Also used : Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 89 with Reference

use of javax.naming.Reference in project wildfly by wildfly.

the class NamingContextTestCase method bindListWithContinuations.

private void bindListWithContinuations() throws NamingException {
    final Name name = new CompositeName("test/test");
    final Object object = new Object();
    namingStore.bind(name, object);
    final Name nameTwo = new CompositeName("test/testTwo");
    final Object objectTwo = new Object();
    namingStore.bind(nameTwo, objectTwo);
    final Name nameThree = new CompositeName("test/testThree");
    final Object objectThree = new Object();
    namingStore.bind(nameThree, objectThree);
    final Reference reference = new Reference(String.class.getName(), new StringRefAddr("nns", "test"), TestObjectFactoryWithNameResolution.class.getName(), null);
    namingStore.bind(new CompositeName("comp"), reference);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 90 with Reference

use of javax.naming.Reference in project wildfly by wildfly.

the class NamingContextTestCase method testLookupWithContinuation.

@Test
public void testLookupWithContinuation() throws Exception {
    namingStore.bind(new CompositeName("comp/nested"), "test");
    final Reference reference = new Reference(String.class.getName(), new StringRefAddr("nns", "comp"), TestObjectFactoryWithNameResolution.class.getName(), null);
    namingStore.bind(new CompositeName("test"), reference);
    Object result = namingContext.lookup(new CompositeName("test/nested"));
    assertEquals("test", result);
    // the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, Arrays.asList(new JndiPermission("comp/nested", "lookup")), namingContext, "test/nested");
    assertEquals("test", result);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) Test(org.junit.Test)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12