Search in sources :

Example 26 with InvalidNameException

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());
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) ServiceUnavailableException(javax.naming.ServiceUnavailableException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) ConnectException(java.net.ConnectException) NameNotFoundException(javax.naming.NameNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) InvalidNameException(javax.naming.InvalidNameException) InvalidNameException(javax.naming.InvalidNameException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException)

Example 27 with InvalidNameException

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());
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) NamingEnumeration(javax.naming.NamingEnumeration) ServiceUnavailableException(javax.naming.ServiceUnavailableException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) ConnectException(java.net.ConnectException) NameNotFoundException(javax.naming.NameNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) InvalidNameException(javax.naming.InvalidNameException) InvalidNameException(javax.naming.InvalidNameException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)27 CompositeName (javax.naming.CompositeName)10 LdapName (javax.naming.ldap.LdapName)8 Name (javax.naming.Name)6 NameNotFoundException (javax.naming.NameNotFoundException)5 Rdn (javax.naming.ldap.Rdn)5 ArrayList (java.util.ArrayList)4 NotContextException (javax.naming.NotContextException)4 URISyntaxException (java.net.URISyntaxException)3 Context (javax.naming.Context)3 NamingException (javax.naming.NamingException)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 LinkedList (java.util.LinkedList)2 AuthenticationException (javax.naming.AuthenticationException)2 ConfigurationException (javax.naming.ConfigurationException)2 ContextNotEmptyException (javax.naming.ContextNotEmptyException)2 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)2