Example usage for javax.naming NamingException getExplanation

List of usage examples for javax.naming NamingException getExplanation

Introduction

In this page you can find the example usage for javax.naming NamingException getExplanation.

Prototype

public String getExplanation() 

Source Link

Document

Retrieves the explanation associated with this exception.

Usage

From source file:ar.com.zauber.commons.spring.configurers.JndiInitialContextHelper.java

/** dado paths jndi retorna archivos de propiedades */
public static Resource[] getJndiLocations(final String[] filePathJndiNames) {

    final ResourceLoader resourceLoader = new DefaultResourceLoader();

    try {//from w ww . j  ava 2  s  .c o m
        final InitialContext initCtx = new InitialContext();
        final Resource[] locations = new Resource[filePathJndiNames.length];
        boolean found = false;

        try {
            final Context envCtx = (Context) initCtx.lookup("java:comp/env");
            for (int i = 0; i < filePathJndiNames.length; i++) {
                locations[i] = resourceLoader.getResource((String) envCtx.lookup(filePathJndiNames[i]));
            }
            found = true;
        } catch (final NamingException e) {
            LOGGER.warn("Error JNDI looking up 'java:comp/env':" + e.getExplanation());
            // void
        }

        if (!found) {
            // Para Jetty 7 Server
            try {
                for (int i = 0; i < filePathJndiNames.length; i++) {
                    locations[i] = resourceLoader.getResource((String) initCtx.lookup(filePathJndiNames[i]));
                }
            } catch (final NamingException e) {
                LOGGER.warn("Hubo un error en el lookup de JNDI. Se usaran " + "properties del classpath: "
                        + e.getExplanation());
                return null;
            }
        }

        return locations;
    } catch (final NamingException e) {
        LOGGER.warn("Hubo un error en el lookup de JNDI. Se usaran " + "properties del classpath: "
                + e.getExplanation());
        return null;
    }
}

From source file:com.sapito.db.config.PersistenceConfig.java

@Bean
public DataSource dataSource() {
    try {//  w  w w.j  av  a  2s.  co m
        InitialContext context = new InitialContext();
        return (DataSource) context.lookup("jdbc/sapito");
    } catch (NamingException ex) {
        System.err.println("Exception getting jdbc/sapito from jndi");
        ex.getExplanation();
        return null;
    }
}

From source file:org.liveSense.auth.ldap.LdapAuthenticationHandler.java

boolean isLdapValid(final Credentials credentials) throws RepositoryException {
    LdapUser ldapUser = getLdapAuthData(credentials);
    if (ldapUser != null) {
        Hashtable<String, String> authEnv = new Hashtable<String, String>(11);
        //String dn = "uid=" + ldapUser.getUserName() + "," + ldapBase;
        String dn = StringUtils.replace(ldapBase, "${userName}", ldapUser.getUserName());
        authEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        authEnv.put(Context.PROVIDER_URL, ldapUrl);
        authEnv.put(Context.SECURITY_AUTHENTICATION, ldapAuthenticationType);
        authEnv.put(Context.SECURITY_PRINCIPAL, dn);
        authEnv.put(Context.SECURITY_CREDENTIALS, ldapUser.getPassword());
        try {//from w w w  . j  a v  a  2s  . c  o m
            DirContext ctx = new InitialDirContext(authEnv);
            Attributes attributes = ctx.getAttributes(dn);
            ldapUser.setAttributes(attributes);
            return true;
        } catch (AuthenticationException authEx) {
            return false;

        } catch (NamingException namEx) {
            throw new RepositoryException("Ldap Error:" + namEx.getExplanation());
        }
    }
    // no authdata, not valid
    return false;
}

From source file:org.lsc.jndi.JndiServices.java

private boolean doApply(final JndiModifications jm) throws CommunicationException {
    if (jm == null) {
        return true;
    }//from w w w . ja va  2 s  .c o  m

    try {
        switch (jm.getOperation()) {

        case ADD_ENTRY:
            ctx.createSubcontext(new LdapName(rewriteBase(jm.getDistinguishName())),
                    getAttributes(jm.getModificationItems(), true));
            break;

        case DELETE_ENTRY:
            if (recursiveDelete) {
                deleteChildrenRecursively(rewriteBase(jm.getDistinguishName()));
            } else {
                ctx.destroySubcontext(new LdapName(rewriteBase(jm.getDistinguishName())));
            }
            break;

        case MODIFY_ENTRY:
            Object[] table = jm.getModificationItems().toArray();
            ModificationItem[] mis = new ModificationItem[table.length];
            System.arraycopy(table, 0, mis, 0, table.length);
            ctx.modifyAttributes(new LdapName(rewriteBase(jm.getDistinguishName())), mis);
            break;

        case MODRDN_ENTRY:
            //We do not display this warning if we do not apply the modification with the option modrdn = false
            LOGGER.warn(
                    "WARNING: updating the RDN of the entry will cancel other modifications! Relaunch synchronization to complete update.");
            ctx.rename(new LdapName(rewriteBase(jm.getDistinguishName())),
                    new LdapName(rewriteBase(jm.getNewDistinguishName())));
            break;

        default:
            LOGGER.error("Unable to identify the right modification type: {}", jm.getOperation());
            return false;
        }
        return true;

    } catch (ContextNotEmptyException e) {
        LOGGER.error(
                "Object {} not deleted because it has children (LDAP error code 66 received). To delete this entry and it's subtree, set the dst.java.naming.recursivedelete property to true",
                jm.getDistinguishName());
        return false;

    } catch (NamingException ne) {
        if (LOGGER.isErrorEnabled()) {
            StringBuilder errorMessage = new StringBuilder("Error while ");
            switch (jm.getOperation()) {
            case ADD_ENTRY:
                errorMessage.append("adding");
                break;
            case MODIFY_ENTRY:
                errorMessage.append("modifying");
                break;
            case MODRDN_ENTRY:
                errorMessage.append("renaming");
                break;
            case DELETE_ENTRY:
                if (recursiveDelete) {
                    errorMessage.append("recursively ");
                }
                errorMessage.append("deleting");
                break;
            }
            errorMessage.append(" entry ").append(jm.getDistinguishName());
            errorMessage.append(" in directory :").append(ne.toString());

            LOGGER.error(errorMessage.toString());
        }

        if (ne instanceof CommunicationException) {
            // we lost the connection to the source or destination, stop everything!
            throw (CommunicationException) ne;
        }
        if (ne instanceof ServiceUnavailableException) {
            // we lost the connection to the source or destination, stop everything!
            CommunicationException ce = new CommunicationException(ne.getExplanation());
            ce.setRootCause(ne);
            throw ce;
        }

        return false;
    }
}

From source file:org.teiid.rhq.admin.DQPManagementView.java

public static String getVDBStatus(ProfileServiceConnection connection, String vdbName) {

    ManagedComponent mcVdb = null;/*from  w  w w  .  j  av a  2s .c  om*/
    try {
        mcVdb = ProfileServiceUtil.getManagedComponent(connection, new org.jboss.managed.api.ComponentType(
                PluginConstants.ComponentType.VDB.TYPE, PluginConstants.ComponentType.VDB.SUBTYPE), vdbName);
    } catch (NamingException e) {
        final String msg = "NamingException in getVDBStatus(): " + e.getExplanation(); //$NON-NLS-1$
        LOG.error(msg, e);
    } catch (Exception e) {
        final String msg = "Exception in getVDBStatus(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    if (mcVdb == null) {
        return Status.INACTIVE.toString();
    }

    return ProfileServiceUtil.getSimpleValue(mcVdb, "status", String.class); //$NON-NLS-1$
}

From source file:org.teiid.rhq.admin.DQPManagementView.java

/**
 * @param mcVdb/*from  w  ww . ja  v a2  s.c o m*/
 * @return count
 * @throws Exception
 */
private int getErrorCount(ProfileServiceConnection connection, String vdbName) {

    ManagedComponent mcVdb = null;
    try {
        mcVdb = ProfileServiceUtil.getManagedComponent(connection, new org.jboss.managed.api.ComponentType(
                PluginConstants.ComponentType.VDB.TYPE, PluginConstants.ComponentType.VDB.SUBTYPE), vdbName);
    } catch (NamingException e) {
        final String msg = "NamingException in getVDBStatus(): " + e.getExplanation(); //$NON-NLS-1$
        LOG.error(msg, e);
    } catch (Exception e) {
        final String msg = "Exception in getVDBStatus(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    // Get models from VDB
    int count = 0;
    ManagedProperty property = mcVdb.getProperty("models"); //$NON-NLS-1$
    CollectionValueSupport valueSupport = (CollectionValueSupport) property.getValue();
    MetaValue[] metaValues = valueSupport.getElements();

    for (MetaValue value : metaValues) {
        GenericValueSupport genValueSupport = (GenericValueSupport) value;
        ManagedObjectImpl managedObject = (ManagedObjectImpl) genValueSupport.getValue();

        // Get any model errors/warnings
        MetaValue errors = managedObject.getProperty("errors").getValue(); //$NON-NLS-1$
        if (errors != null) {
            CollectionValueSupport errorValueSupport = (CollectionValueSupport) errors;
            MetaValue[] errorArray = errorValueSupport.getElements();
            count += errorArray.length;
        }
    }
    return count;
}

From source file:org.teiid.rhq.plugin.TranslatorComponent.java

@Override
public Configuration loadResourceConfiguration() {

    ManagedComponent translator = null;/*w  w w .ja va  2  s  .  com*/
    try {
        translator = ProfileServiceUtil.getManagedComponent(getConnection(),
                new ComponentType(PluginConstants.ComponentType.Translator.TYPE,
                        PluginConstants.ComponentType.Translator.SUBTYPE),
                this.name);
    } catch (NamingException e) {
        final String msg = "NamingException in loadResourceConfiguration(): " + e.getExplanation(); //$NON-NLS-1$
        LOG.error(msg, e);
    } catch (Exception e) {
        final String msg = "Exception in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    String translatorName = ProfileServiceUtil.getSimpleValue(translator, "name", String.class);
    String description = ProfileServiceUtil.getSimpleValue(translator, "description", String.class);

    Configuration c = resourceConfiguration;
    PropertyList list = new PropertyList("translatorList");
    PropertyMap propMap = null;
    c.put(list);

    // First get translator specific properties
    ManagedProperty translatorProps = translator.getProperty("property");
    try {
        getTranslatorValues(translatorProps.getValue(), propMap, list);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }

    // Now get common properties
    c.put(new PropertySimple("name", translatorName));
    c.put(new PropertySimple("description", description));

    return c;

}

From source file:org.teiid.rhq.plugin.VDBComponent.java

@Override
public Configuration loadResourceConfiguration() {

    ManagedComponent mcVdb = null;/*ww  w.  ja  v  a2  s  .com*/
    try {
        mcVdb = ProfileServiceUtil.getManagedComponent(getConnection(), new org.jboss.managed.api.ComponentType(
                PluginConstants.ComponentType.VDB.TYPE, PluginConstants.ComponentType.VDB.SUBTYPE), this.name);
    } catch (NamingException e) {
        final String msg = "NamingException in loadResourceConfiguration(): " + e.getExplanation(); //$NON-NLS-1$
        LOG.error(msg, e);
    } catch (Exception e) {
        final String msg = "Exception in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    String vdbName = ProfileServiceUtil.getSimpleValue(mcVdb, "name", String.class);
    Integer vdbVersion = ProfileServiceUtil.getSimpleValue(mcVdb, "version", Integer.class);
    String vdbDescription = ProfileServiceUtil.getSimpleValue(mcVdb, "description", String.class);
    String vdbStatus = ProfileServiceUtil.getSimpleValue(mcVdb, "status", String.class);
    String connectionType = ProfileServiceUtil.getSimpleValue(mcVdb, "connectionType", String.class);
    String vdbURL = ProfileServiceUtil.getSimpleValue(mcVdb, "url", String.class);

    // Get plugin config map for models
    Configuration configuration = resourceContext.getPluginConfiguration();

    configuration.put(new PropertySimple("name", vdbName));
    configuration.put(new PropertySimple("version", vdbVersion));
    configuration.put(new PropertySimple("description", vdbDescription));
    configuration.put(new PropertySimple("status", vdbStatus));
    configuration.put(new PropertySimple("url", vdbURL));
    configuration.put(new PropertySimple("connectionType", connectionType));

    try {
        getTranslators(mcVdb, configuration);
    } catch (Exception e) {
        final String msg = "Exception in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    getModels(mcVdb, configuration);

    return configuration;

}