use of javax.naming.InvalidNameException in project wildfly by wildfly.
the class InMemoryNamingStoreTestCase method testBindEmptyName.
@Test
public void testBindEmptyName() throws Exception {
try {
nameStore.bind(new CompositeName(), new Object(), Object.class);
fail("Should have thrown and InvalidNameException");
} catch (InvalidNameException expected) {
}
try {
nameStore.bind(new CompositeName(""), new Object(), Object.class);
fail("Should have thrown and InvalidNameException");
} catch (InvalidNameException expected) {
}
}
use of javax.naming.InvalidNameException in project uPortal by Jasig.
the class ReferenceCompositeGroupService method getEntity.
/**
* Returns an <code>IEntity</code> representing a portal entity. This does not guarantee that
* the entity actually exists.
*/
@Override
public IEntity getEntity(String key, Class type, String svcName) throws GroupsException {
IIndividualGroupService svc = null;
if (svcName == null) {
svc = getDefaultService();
} else {
try {
Name n = GroupService.parseServiceName(svcName);
svc = getComponentService(n);
} catch (InvalidNameException ine) {
throw new GroupsException("Invalid service name.");
}
}
return (svc == null) ? null : svc.getEntity(key, type);
}
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());
}
}
use of javax.naming.InvalidNameException in project zookeeper by apache.
the class ZKHostnameVerifier method extractCN.
private static String extractCN(final String subjectPrincipal) throws SSLException {
if (subjectPrincipal == null) {
return null;
}
try {
final LdapName subjectDN = new LdapName(subjectPrincipal);
final List<Rdn> rdns = subjectDN.getRdns();
for (int i = rdns.size() - 1; i >= 0; i--) {
final Rdn rds = rdns.get(i);
final Attributes attributes = rds.toAttributes();
final Attribute cn = attributes.get("cn");
if (cn != null) {
try {
final Object value = cn.get();
if (value != null) {
return value.toString();
}
} catch (final NoSuchElementException ignore) {
// ignore exception
} catch (final NamingException ignore) {
// ignore exception
}
}
}
return null;
} catch (final InvalidNameException e) {
throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished name");
}
}
Aggregations