Search in sources :

Example 61 with NameNotFoundException

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

the class CustomDescriptorTestCase method testAnnotated.

// @EJB
// private DescriptorGreeterBean bean;
@Test
public void testAnnotated() throws NamingException {
    final InitialContext ctx = new InitialContext();
    try {
        final AnnotatedGreeterBean bean = (AnnotatedGreeterBean) ctx.lookup("java:global/ejb-descriptor-test/AnnotatedGreeter!org.jboss.as.test.integration.ejb.descriptor.AnnotatedGreeterBean");
        final String name = "testAnnotated";
        final String result = bean.greet(name);
        assertEquals("Hi testAnnotated", result);
    } catch (NameNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 62 with NameNotFoundException

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

the class EEConcurrentManagementTestCase method testManagedScheduledExecutorServiceManagement.

@Test
public void testManagedScheduledExecutorServiceManagement() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/scheduledexecutor/" + RESOURCE_NAME;
    addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    addOperation.get(ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    try {
        // lookup
        Assert.assertNotNull(new InitialContext().lookup(jndiName));
    } finally {
        // remove
        final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
        removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
        Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
        try {
            new InitialContext().lookup(jndiName);
            Assert.fail();
        } catch (NameNotFoundException e) {
        // expected
        }
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 63 with NameNotFoundException

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

the class EEConcurrentManagementTestCase method testManagedExecutorServiceManagement.

@Test
public void testManagedExecutorServiceManagement() throws Exception {
    final PathAddress pathAddress = EE_SUBSYSTEM_PATH_ADDRESS.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, RESOURCE_NAME);
    // add
    final ModelNode addOperation = Util.createAddOperation(pathAddress);
    final String jndiName = "java:jboss/ee/concurrency/executor/" + RESOURCE_NAME;
    addOperation.get(ManagedExecutorServiceResourceDefinition.JNDI_NAME).set(jndiName);
    addOperation.get(ManagedExecutorServiceResourceDefinition.CORE_THREADS).set(2);
    final ModelNode addResult = managementClient.getControllerClient().execute(addOperation);
    Assert.assertFalse(addResult.get(FAILURE_DESCRIPTION).toString(), addResult.get(FAILURE_DESCRIPTION).isDefined());
    try {
        // lookup
        Assert.assertNotNull(new InitialContext().lookup(jndiName));
    } finally {
        // remove
        final ModelNode removeOperation = Util.createRemoveOperation(pathAddress);
        removeOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        final ModelNode removeResult = managementClient.getControllerClient().execute(removeOperation);
        Assert.assertFalse(removeResult.get(FAILURE_DESCRIPTION).toString(), removeResult.get(FAILURE_DESCRIPTION).isDefined());
        try {
            new InitialContext().lookup(jndiName);
            Assert.fail();
        } catch (NameNotFoundException e) {
        // expected
        }
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 64 with NameNotFoundException

use of javax.naming.NameNotFoundException in project tomee by apache.

the class LazyEjbReference method getObject.

public Object getObject() throws NamingException {
    if (reference != null) {
        return reference.getObject();
    }
    final SystemInstance systemInstance = SystemInstance.get();
    final EjbResolver resolver = systemInstance.getComponent(EjbResolver.class);
    final String deploymentId = resolver.resolve(info, moduleUri);
    if (deploymentId == null) {
        String key = "lazyEjbRefNotResolved";
        if (info.getHome() != null) {
            key += ".home";
        }
        final String message = messages.format(key, info.getName(), info.getEjbLink(), info.getHome(), info.getInterface());
        throw new NameNotFoundException(message);
    }
    final ContainerSystem containerSystem = systemInstance.getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
    if (beanContext == null) {
        final String message = messages.format("deploymentNotFound", info.getName(), deploymentId);
        throw new NameNotFoundException(message);
    }
    InterfaceType type = null;
    switch(info.getRefType()) {
        case LOCAL:
            type = InterfaceType.BUSINESS_LOCAL;
            break;
        case REMOTE:
            type = InterfaceType.BUSINESS_REMOTE;
            break;
    }
    final String jndiName = "openejb/Deployment/" + JndiBuilder.format(deploymentId, info.getInterface(), type);
    if (useCrossClassLoaderRef && isRemote(beanContext)) {
        reference = new CrossClassLoaderJndiReference(jndiName);
    } else {
        reference = new IntraVmJndiReference(jndiName);
    }
    return reference.getObject();
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) IntraVmJndiReference(org.apache.openejb.core.ivm.naming.IntraVmJndiReference) InterfaceType(org.apache.openejb.InterfaceType) NameNotFoundException(javax.naming.NameNotFoundException) SystemInstance(org.apache.openejb.loader.SystemInstance) CrossClassLoaderJndiReference(org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference)

Example 65 with NameNotFoundException

use of javax.naming.NameNotFoundException in project tomee by apache.

the class IvmContext method lookup.

public Object lookup(final String compositName) throws NamingException {
    if (compositName.isEmpty()) {
        return this;
    }
    final String compoundName;
    final int index = compositName.indexOf(':');
    if (index > -1) {
        final String prefix = compositName.substring(0, index);
        String path = compositName.substring(index + 1);
        final ParsedName name = new ParsedName(path);
        if (prefix.equals("openejb")) {
            path = name.path();
            return openejbURLContextFactory.getContext().lookup(path);
        } else if (prefix.equals("java")) {
            if (name.getComponent().equals("openejb")) {
                path = name.remaining().path();
                return openejbURLContextFactory.getContext().lookup(path);
            } else {
                path = name.path();
                return javaURLContextFactory.getContext().lookup(path);
            }
        } else {
            // we don't know what the prefix means, throw an exception
            throw new NamingException("Unknown JNDI name prefix '" + prefix + ":'");
        }
    } else {
        /*
              the resolve method always starts with the comparison assuming that the first
              component of the name is a context of a peer node or the same node, so we have
              to prepend the current context name to the relative lookup path.
            */
        compoundName = mynode.getAtomicName() + '/' + compositName;
    }
    /*
           If the object has been resolved in the past from this context and the specified path (name)
           it will be in the fastCache which is significantly faster then peruse the Node graph.
           80 ms compared to 300 ms for a full node path search.
        */
    Object obj = fastCache.get(compoundName);
    if (obj == null) {
        try {
            obj = mynode.resolve(new ParsedName(compoundName), readOnly);
        } catch (final NameNotFoundException nnfe) {
            obj = federate(compositName);
        }
        // don't cache proxies
        if (!(obj instanceof IntraVmProxy) && !(obj instanceof ContextualJndiReference)) {
            fastCache.put(compoundName, obj);
        }
    }
    if (obj == null) {
        throw new NameNotFoundException("Name \"" + compositName + "\" not found.");
    }
    if (obj.getClass() == IvmContext.class) {
        ((IvmContext) obj).myEnv = myEnv;
    } else if (obj instanceof Reference) {
        // TODO: JRG - this needs a test
        while (obj instanceof Reference) {
            obj = ((Reference) obj).getObject();
        }
    } else if (obj instanceof LinkRef) {
        obj = lookup(((LinkRef) obj).getLinkName());
    }
    return obj;
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) IntraVmProxy(org.apache.openejb.core.ivm.IntraVmProxy) LinkRef(javax.naming.LinkRef)

Aggregations

NameNotFoundException (javax.naming.NameNotFoundException)168 NamingException (javax.naming.NamingException)81 InitialContext (javax.naming.InitialContext)75 Context (javax.naming.Context)71 Reference (javax.naming.Reference)40 Test (org.junit.Test)39 NotContextException (javax.naming.NotContextException)35 Name (javax.naming.Name)34 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)33 OperationNotSupportedException (javax.naming.OperationNotSupportedException)29 CompositeName (javax.naming.CompositeName)27 Binding (javax.naming.Binding)22 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)16 IOException (java.io.IOException)12 NamingContext (org.eclipse.jetty.jndi.NamingContext)12 ArrayList (java.util.ArrayList)10 InvalidNameException (javax.naming.InvalidNameException)10 Attributes (javax.naming.directory.Attributes)10 HashMap (java.util.HashMap)7