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());
}
}
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
}
}
}
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
}
}
}
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();
}
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;
}
Aggregations