Search in sources :

Example 16 with ServiceUnavailableException

use of javax.naming.ServiceUnavailableException 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 17 with ServiceUnavailableException

use of javax.naming.ServiceUnavailableException 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

ServiceUnavailableException (javax.naming.ServiceUnavailableException)17 NamingException (javax.naming.NamingException)9 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)5 JMXConnector (javax.management.remote.JMXConnector)4 AuthenticationException (javax.naming.AuthenticationException)4 InvalidNameException (javax.naming.InvalidNameException)4 NameNotFoundException (javax.naming.NameNotFoundException)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ConnectException (java.net.ConnectException)3 Properties (java.util.Properties)3 CommunicationException (javax.naming.CommunicationException)3 InitialContext (javax.naming.InitialContext)3 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 CommandLine (org.apache.commons.cli.CommandLine)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3