use of javax.naming.InvalidNameException in project tomee by apache.
the class JNDIContext method lookup.
@Override
public Object lookup(String name) throws NamingException {
if (name == null) {
throw new InvalidNameException("The name cannot be null");
} else if (name.equals("")) {
return new JNDIContext(this);
} else if (name.startsWith("java:")) {
name = name.replaceFirst("^java:", "");
} else if (!name.startsWith("/")) {
name = tail + name;
}
final String prop = name.replaceFirst("comp/env/", "");
String value = System.getProperty(prop);
if (value != null) {
return parseEntry(prop, value);
}
if (name.equals("comp/ORB")) {
return getDefaultOrb();
}
final JNDIRequest req = new JNDIRequest();
req.setRequestMethod(RequestMethodCode.JNDI_LOOKUP);
req.setRequestString(name);
req.setModuleId(moduleId);
final JNDIResponse res;
try {
res = request(req);
} catch (Exception e) {
if (e instanceof RemoteException) {
if (e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
} else if (AuthenticationException.class.isInstance(e.getCause())) {
throw AuthenticationException.class.cast(e.getCause());
}
}
throw (NamingException) new NamingException("Cannot lookup '" + name + "'.").initCause(e);
}
switch(res.getResponseCode()) {
case ResponseCodes.JNDI_EJBHOME:
return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
case ResponseCodes.JNDI_BUSINESS_OBJECT:
return createBusinessObject(res.getResult());
case ResponseCodes.JNDI_OK:
return res.getResult();
case ResponseCodes.JNDI_INJECTIONS:
return res.getResult();
case ResponseCodes.JNDI_CONTEXT:
final JNDIContext subCtx = new JNDIContext(this);
if (!name.endsWith("/")) {
name += '/';
}
subCtx.tail = name;
return subCtx;
case ResponseCodes.JNDI_DATA_SOURCE:
return createDataSource((DataSourceMetaData) res.getResult());
case ResponseCodes.JNDI_WEBSERVICE:
return createWebservice((WsMetaData) res.getResult());
case ResponseCodes.JNDI_RESOURCE:
final String type = (String) res.getResult();
value = System.getProperty("Resource/" + type);
if (value == null) {
return null;
}
return parseEntry(prop, value);
case ResponseCodes.JNDI_REFERENCE:
final Reference ref = (Reference) res.getResult();
try {
return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
} catch (Exception e) {
throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
}
case ResponseCodes.JNDI_NOT_FOUND:
throw new NameNotFoundException(name + " does not exist in the system. Check that the app was successfully deployed.");
case ResponseCodes.JNDI_NAMING_EXCEPTION:
final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
if (throwable instanceof NamingException) {
throw (NamingException) throwable;
}
throw (NamingException) new NamingException().initCause(throwable);
case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
throw (RuntimeException) res.getResult();
case ResponseCodes.JNDI_ERROR:
{
Object result = res.getResult();
if (Error.class.isInstance(result)) {
throw Error.class.cast(result);
}
if (RuntimeException.class.isInstance(result)) {
throw RuntimeException.class.cast(result);
}
final Throwable th = Throwable.class.cast(result);
throw new ClientRuntimeException(th.getMessage(), th);
}
default:
throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
}
}
use of javax.naming.InvalidNameException in project tomee by apache.
the class JNDIContext method list.
@SuppressWarnings("unchecked")
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
if (name == null) {
throw new InvalidNameException("The name cannot be null");
} else if (name.startsWith("java:")) {
name = name.replaceFirst("^java:", "");
} else if (!name.startsWith("/")) {
name = tail + name;
}
final JNDIRequest req = new JNDIRequest(RequestMethodCode.JNDI_LIST, name);
req.setModuleId(moduleId);
final JNDIResponse res;
try {
res = request(req);
} catch (Exception e) {
if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.").initCause(e);
}
throw (NamingException) new NamingException("Cannot list '" + name + "'.").initCause(e);
}
switch(res.getResponseCode()) {
case ResponseCodes.JNDI_OK:
return null;
case ResponseCodes.JNDI_ENUMERATION:
return (NamingEnumeration) res.getResult();
case ResponseCodes.JNDI_NOT_FOUND:
throw new NameNotFoundException(name);
case ResponseCodes.JNDI_NAMING_EXCEPTION:
final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
if (throwable instanceof NamingException) {
throw (NamingException) throwable;
}
throw (NamingException) new NamingException().initCause(throwable);
case ResponseCodes.JNDI_ERROR:
throw (Error) res.getResult();
default:
throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
}
}
Aggregations