Example usage for javax.naming NameNotFoundException getMessage

List of usage examples for javax.naming NameNotFoundException getMessage

Introduction

In this page you can find the example usage for javax.naming NameNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:de.fiz.ddb.aas.auxiliaryoperations.ThreadOrganisationSetApprove.java

private void copyingToLicensedOrgs(Organisation pOrganisation)
        throws AASUnauthorizedException, ExecutionException {
    LOG.log(Level.INFO, "copyingToLicensedOrgs.Organisation.getOIDs(): "
            + (pOrganisation != null ? pOrganisation.getOIDs() : "NULL"));
    if ((pOrganisation == null) || !ConstEnumOrgStatus.approved.equals(pOrganisation.getStatus())) {
        LOG.log(Level.INFO,/* www.  j a va 2 s .  com*/
                "Return: not in Status: " + (pOrganisation != null ? pOrganisation.getStatus() : "NULL"));
        return;
    }

    ThreadOrganisationCreate threadOrganisationCreate;
    ThreadOrganisationRead threadOrgOnWorkDirRead;

    try {
        threadOrganisationCreate = new ThreadOrganisationCreate(pOrganisation, _performer);
        threadOrganisationCreate.setAddToLicensedOrgs(true);
        threadOrganisationCreate.call();
        // -- find all sub-organizations
        Set<OIDs> vAllSubOrgIdsOnWorkDir = this.getAllSubOrgIds(false, pOrganisation.getOIDs(),
                SearchControls.ONELEVEL_SCOPE, this._performer);
        // -- all sub-organizations must be deleted:
        for (OIDs vOIDs : vAllSubOrgIdsOnWorkDir) {
            try {
                threadOrgOnWorkDirRead = new ThreadOrganisationRead(vOIDs, this._performer);
                this.copyingToLicensedOrgs(threadOrgOnWorkDirRead.call());
            } catch (NameNotFoundException ex) {
                LOG.log(Level.WARNING,
                        "copyingToLicensedOrgs.NameNotFoundException: ex '" + ex.getMessage() + "'");
            } catch (AASUnauthorizedException ex) {
                LOG.log(Level.WARNING, "copyingToLicensedOrgs.AASUnauthorizedException: ex: '" + ex.getMessage()
                        + "', Performer" + _performer);
            } catch (ExecutionException ex) {
                LOG.log(Level.WARNING,
                        "copyingToLicensedOrgs.ExecutionException: oid = '" + pOrganisation.getOIDs() + "'");
            }
        }
    } catch (NameAlreadyBoundException ex) {
        LOG.log(Level.WARNING,
                "copyingToLicensedOrgs.NameAlreadyBoundException: oid = '" + pOrganisation.getOIDs() + "'");
    } catch (AASUnauthorizedException ex) {
        LOG.log(Level.WARNING, "copyingToLicensedOrgs.AASUnauthorizedException: oid = '"
                + pOrganisation.getOIDs() + "', Performer" + _performer);
    } catch (ExecutionException ex) {
        LOG.log(Level.WARNING,
                "copyingToLicensedOrgs.ExecutionException: oid = '" + pOrganisation.getOIDs() + "'");
    }
}

From source file:de.fiz.ddb.aas.auxiliaryoperations.ThreadOrganisationSetApprove.java

public ThreadOrganisationSetApprove(OIDs pOIDs, AasPrincipal performer)
        throws IllegalArgumentException, ExecutionException, AASUnauthorizedException {
    this(performer);
    //check mandatory fields
    if (pOIDs == null) {
        throw new IllegalArgumentException("Illegal argument: OIDs = " + pOIDs);
    }/*  ww  w  . j  ava 2  s.  c  o m*/
    ThreadOrganisationRead threadOrgOnWorkDirRead = new ThreadOrganisationRead(pOIDs, performer);
    try {
        this._organisation = threadOrgOnWorkDirRead.call();
        this._oldStatus = this._organisation.getStatus();
    } catch (NameNotFoundException ex) {
        throw new ExecutionException(new NameNotFoundException(
                "OriganOrganization with ID '" + pOIDs + "' was not found. Message: " + ex.getMessage()));
    }
}

From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java

/**
 * Creates the sub context dirs./*from   w w w  . j av a2  s .c  o m*/
 *
 * @param path the path
 */
protected void createSubContextDirs(String path) {
    int idx = path.lastIndexOf('/');
    if (idx == -1) {
        throw new RuntimeException("Cannot create JNDI Path, because no subcontext: " + path);
    }
    String spath = path.substring(0, idx);
    try {
        initialContext.createSubcontext(spath);
    } catch (NameNotFoundException ex) {
        createSubContextDirs(spath);
        try {
            initialContext.createSubcontext(spath);
        } catch (NamingException ex2) {
            throw new RuntimeException("Cannot create Subcontext: " + spath + "; " + ex2.getMessage(), ex2);
        }
    } catch (NamingException ex) {
        throw new RuntimeException("Cannot create subcontext: " + spath + "; " + ex.getMessage(), ex);
    }
}

From source file:org.apache.archiva.redback.common.ldap.role.DefaultLdapRoleMapper.java

public boolean hasRole(DirContext context, String roleName) throws MappingException {
    String groupName = findGroupName(roleName);

    if (groupName == null) {
        if (this.useDefaultRoleName) {
            groupName = roleName;/* w w  w. jav a 2  s  .  c  o  m*/
        } else {
            log.warn("skip group creation as no mapping for roleName:'{}'", roleName);
            return false;
        }
    }
    NamingEnumeration<SearchResult> namingEnumeration = null;
    try {

        SearchControls searchControls = new SearchControls();

        searchControls.setDerefLinkFlag(true);
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        String filter = "objectClass=" + getLdapGroupClass();

        namingEnumeration = context.search("cn=" + groupName + "," + getGroupsDn(), filter, searchControls);

        return namingEnumeration.hasMore();
    } catch (NameNotFoundException e) {
        log.debug("group {} for role {} not found", groupName, roleName);
        return false;
    } catch (LdapException e) {
        throw new MappingException(e.getMessage(), e);
    } catch (NamingException e) {
        throw new MappingException(e.getMessage(), e);
    }

    finally {
        close(namingEnumeration);
    }
}

From source file:org.eclipse.ecr.runtime.api.ServiceManager.java

@Override
@SuppressWarnings("unchecked")
public <T> T getService(Class<T> serviceClass) throws Exception {
    ServiceDescriptor sd = services.get(serviceClass.getName());
    if (sd != null) {
        try {/*w  w  w .jav a2 s.  co  m*/
            T svc = (T) sd.getGroup().getServer().lookup(sd);
            if (svc != null) {
                return svc;
            }
        } catch (NameNotFoundException e) {
            // When all facades are deployed (JBoss for now), then lookup
            // errors are legitimate. Otherwise it may be just a bad
            // packaging issue, so don't log. TODO fix packaging
            if (J2EEContainerDescriptor.getSelected() == J2EEContainerDescriptor.JBOSS) {
                log.warn("Existing binding but unreachable service for " + serviceClass.getName()
                        + " ! Fallback on local service...");
                log.debug(e.getMessage() + " Check binding declaration: " + sd.toString());
            }
        }
    }
    return Framework.getLocalService(serviceClass);
}

From source file:org.exoplatform.services.jcr.ext.repository.creation.RepositoryCreationServiceImpl.java

private Set<String> extractDataSourceNames(RepositoryEntry repositoryEntry, boolean checkDataSourceExistance)
        throws RepositoryConfigurationException, RepositoryCreationException {
    Set<String> dataSourceNames = new HashSet<String>();
    for (WorkspaceEntry wsEntry : repositoryEntry.getWorkspaceEntries()) {
        boolean isMultiDB = DatabaseStructureType.valueOf(wsEntry.getContainer()
                .getParameterValue(JDBCWorkspaceDataContainer.DB_STRUCTURE_TYPE).toUpperCase())
                .isMultiDatabase();//from   w  w w.  j a  v a  2s. co  m
        String dbSourceName = wsEntry.getContainer().getParameterValue(JDBCWorkspaceDataContainer.SOURCE_NAME);

        if (isMultiDB && dataSourceNames.contains(dbSourceName)) {
            throw new RepositoryCreationException("RepositoryEntry for new " + repositoryEntry.getName()
                    + " repository contains workspaces that marked as multiDB but have same datasource "
                    + dbSourceName + ".");
        }

        if (checkDataSourceExistance) {
            try {
                DataSource ds = (DataSource) initialContextInitializer.getInitialContext().lookup(dbSourceName);
                if (ds != null) {
                    throw new RepositoryConfigurationException(
                            "RepositoryEntry for new " + repositoryEntry.getName()
                                    + " repository contains already binded datasource " + dbSourceName + ".");
                }
            } catch (NameNotFoundException e) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("An exception occurred: " + e.getMessage());
                }
            } catch (NamingException e) {
                throw new RepositoryConfigurationException(e.getMessage(), e);
            }
        }

        dataSourceNames.add(dbSourceName);
    }
    return dataSourceNames;
}

From source file:org.nuxeo.ecm.directory.ldap.LDAPSession.java

protected SearchResult getLdapEntry(String id, boolean fetchAllAttributes) throws NamingException {
    if (StringUtils.isEmpty(id)) {
        log.warn(/*  w w  w.j av a  2 s . c o  m*/
                "The application should not " + "query for entries with an empty id " + "=> return no results");
        return null;
    }
    String filterExpr;
    String baseFilter = getDirectory().getBaseFilter();
    if (baseFilter.startsWith("(")) {
        filterExpr = String.format("(&(%s={0})%s)", idAttribute, baseFilter);
    } else {
        filterExpr = String.format("(&(%s={0})(%s))", idAttribute, baseFilter);
    }
    String[] filterArgs = { id };
    SearchControls scts = getDirectory().getSearchControls(fetchAllAttributes);

    if (log.isDebugEnabled()) {
        log.debug(String.format(
                "LDAPSession.getLdapEntry(%s, %s): LDAP search base='%s' filter='%s' "
                        + " args='%s' scope='%s' [%s]",
                id, fetchAllAttributes, searchBaseDn, filterExpr, id, scts.getSearchScope(), this));
    }
    NamingEnumeration<SearchResult> results;
    try {
        results = dirContext.search(searchBaseDn, filterExpr, filterArgs, scts);
    } catch (NameNotFoundException nnfe) {
        // sometimes ActiveDirectory have some query fail with: LDAP:
        // error code 32 - 0000208D: NameErr: DSID-031522C9, problem
        // 2001 (NO_OBJECT).
        // To keep the application usable return no results instead of
        // crashing but log the error so that the AD admin
        // can fix the issue.
        log.error("Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe);
        return null;
    }

    if (!results.hasMore()) {
        log.debug("Entry not found: " + id);
        return null;
    }
    SearchResult result = results.next();
    try {
        String dn = result.getNameInNamespace();
        if (results.hasMore()) {
            result = results.next();
            String dn2 = result.getNameInNamespace();
            String msg = String.format("Unable to fetch entry for '%s': found more than one match,"
                    + " for instance: '%s' and '%s'", id, dn, dn2);
            log.error(msg);
            // ignore entries that are ambiguous while giving enough info
            // in the logs to let the LDAP admin be able to fix the issue
            return null;
        }
        if (log.isDebugEnabled()) {
            log.debug(String.format(
                    "LDAPSession.getLdapEntry(%s, %s): LDAP search base='%s' filter='%s' "
                            + " args='%s' scope='%s' => found: %s [%s]",
                    id, fetchAllAttributes, searchBaseDn, filterExpr, id, scts.getSearchScope(), dn, this));
        }
    } catch (UnsupportedOperationException e) {
        // ignore unsupported operation thrown by the Apache DS server in
        // the tests in embedded mode
    }
    return result;
}

From source file:org.nuxeo.ecm.directory.ldap.LDAPSession.java

public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences,
        Map<String, String> orderBy) throws DirectoryException {
    if (!hasPermission(SecurityConstants.READ)) {
        return new DocumentModelListImpl();
    }/*from ww w .ja va  2 s.  c o m*/
    try {
        // building the query using filterExpr / filterArgs to
        // escape special characters and to fulltext search only on
        // the explicitly specified fields
        String[] filters = new String[filter.size()];
        String[] filterArgs = new String[filter.size()];

        if (fulltext == null) {
            fulltext = Collections.emptySet();
        }

        int index = 0;
        for (String fieldName : filter.keySet()) {
            if (getDirectory().isReference(fieldName)) {
                log.warn(fieldName + " is a reference and will be ignored as a query criterion");
                continue;
            }

            String backendFieldName = getDirectory().getFieldMapper().getBackendField(fieldName);
            Object fieldValue = filter.get(fieldName);

            StringBuilder currentFilter = new StringBuilder();
            currentFilter.append("(");
            if (fieldValue == null) {
                currentFilter.append("!(" + backendFieldName + "=*)");
            } else if ("".equals(fieldValue)) {
                if (fulltext.contains(fieldName)) {
                    currentFilter.append(backendFieldName + "=*");
                } else {
                    currentFilter.append("!(" + backendFieldName + "=*)");
                }
            } else {
                currentFilter.append(backendFieldName + "=");
                if (fulltext.contains(fieldName)) {
                    switch (substringMatchType) {
                    case subinitial:
                        currentFilter.append("{" + index + "}*");
                        break;
                    case subfinal:
                        currentFilter.append("*{" + index + "}");
                        break;
                    case subany:
                        currentFilter.append("*{" + index + "}*");
                        break;
                    }
                } else {
                    currentFilter.append("{" + index + "}");
                }
            }
            currentFilter.append(")");
            filters[index] = currentFilter.toString();
            if (fieldValue != null && !"".equals(fieldValue)) {
                if (fieldValue instanceof Blob) {
                    // filter arg could be a sequence of \xx where xx is the
                    // hexadecimal value of the byte
                    log.warn("Binary search is not supported");
                } else {
                    // XXX: what kind of Objects can we get here? Is
                    // toString() enough?
                    filterArgs[index] = fieldValue.toString();
                }
            }
            index++;
        }
        String filterExpr = "(&" + getDirectory().getBaseFilter() + StringUtils.join(filters) + ')';
        SearchControls scts = getDirectory().getSearchControls(true);

        if (log.isDebugEnabled()) {
            log.debug(String.format(
                    "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]",
                    searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this));
        }
        try {
            NamingEnumeration<SearchResult> results = dirContext.search(searchBaseDn, filterExpr, filterArgs,
                    scts);
            DocumentModelList entries = ldapResultsToDocumentModels(results, fetchReferences);

            if (orderBy != null && !orderBy.isEmpty()) {
                getDirectory().orderEntries(entries, orderBy);
            }
            return entries;
        } catch (NameNotFoundException nnfe) {
            // sometimes ActiveDirectory have some query fail with: LDAP:
            // error code 32 - 0000208D: NameErr: DSID-031522C9, problem
            // 2001 (NO_OBJECT).
            // To keep the application usable return no results instead of
            // crashing but log the error so that the AD admin
            // can fix the issue.
            log.error("Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe);
            return new DocumentModelListImpl();
        }
    } catch (LimitExceededException e) {
        throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e);
    } catch (NamingException e) {
        throw new DirectoryException("executeQuery failed", e);
    }
}

From source file:org.springframework.ldap.core.LdapTemplate.java

/**
 * Perform a search operation, such as a search(), list() or listBindings().
 * This method handles all the plumbing; getting a readonly context; looping
 * through the NamingEnumeration and closing the context and enumeration. It
 * also calls the supplied DirContextProcessor before and after the search,
 * respectively. This enables custom pre-processing and post-processing,
 * like for example when handling paged results or other search controls.
 * <p>/*from w ww. j a v  a 2s  .  co m*/
 * The actual list is delegated to the {@link SearchExecutor} and each
 * {@link NameClassPair} (this might be a NameClassPair or a subclass
 * thereof) is passed to the CallbackHandler. Any encountered
 * NamingException will be translated using the NamingExceptionTranslator.
 * 
 * @param se the SearchExecutor to use for performing the actual list.
 * @param handler the NameClassPairCallbackHandler to which each found entry
 * will be passed.
 * @param processor DirContextProcessor for custom pre- and post-processing.
 * Must not be <code>null</code>. If no custom processing should take place,
 * please use e.g.
 * {@link #search(SearchExecutor, NameClassPairCallbackHandler)}.
 * @throws NamingException if any error occurs. Note that a
 * NameNotFoundException will be ignored. Instead this is interpreted that
 * no entries were found.
 */
public void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) {
    DirContext ctx = contextSource.getReadOnlyContext();

    NamingEnumeration results = null;
    RuntimeException ex = null;
    try {
        processor.preProcess(ctx);
        results = se.executeSearch(ctx);

        while (results.hasMore()) {
            NameClassPair result = (NameClassPair) results.next();
            handler.handleNameClassPair(result);
        }
    } catch (NameNotFoundException e) {
        // It is possible to ignore errors caused by base not found
        if (ignoreNameNotFoundException) {
            log.warn("Base context not found, ignoring: " + e.getMessage());
        } else {
            ex = LdapUtils.convertLdapException(e);
        }
    } catch (PartialResultException e) {
        // Workaround for AD servers not handling referrals correctly.
        if (ignorePartialResultException) {
            log.debug("PartialResultException encountered and ignored", e);
        } else {
            ex = LdapUtils.convertLdapException(e);
        }
    } catch (javax.naming.NamingException e) {
        ex = LdapUtils.convertLdapException(e);
    } finally {
        try {
            processor.postProcess(ctx);
        } catch (javax.naming.NamingException e) {
            if (ex == null) {
                ex = LdapUtils.convertLdapException(e);
            } else {
                // We already had an exception from above and should ignore
                // this one.
                log.debug("Ignoring Exception from postProcess, " + "main exception thrown instead", e);
            }
        }
        closeContextAndNamingEnumeration(ctx, results);
        // If we got an exception it should be thrown.
        if (ex != null) {
            throw ex;
        }
    }
}

From source file:org.swordess.ldap.odm.core.SessionImpl.java

@SuppressWarnings("unchecked")
@Override/*www  .j a v  a 2s  . c  o m*/
public <T> T read(Class<T> clazz, String dn) {
    if (null == dn) {
        return null;
    }

    LogUtils.debug(LOG, "read " + clazz.getName() + " with dn=" + dn);

    if (sessionCache.containsKey(dn)) {
        LogUtils.info(LOG, "cache hit " + dn);
        return (T) sessionCache.get(dn);
    }

    try {
        Attributes allDefinedAttrs = ctx.getAttributes(dn, EntityMetaData.getDefinedAttrNames(clazz));
        T entity = fromAttributesToEntity(clazz, allDefinedAttrs);
        sessionCache.put(dn, entity);
        return entity;

    } catch (NameNotFoundException e) {
        return null;

    } catch (NamingException e) {
        throw new SessionException(e.getMessage(), e);
    }
}