Example usage for javax.naming NamingException printStackTrace

List of usage examples for javax.naming NamingException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.openiam.idm.srvc.synch.service.generic.LdapAdapterForGenericObject.java

private void closeConnection() {
    try {/*  ww  w .  j  av a2 s . co m*/
        if (ctx != null) {
            ctx.close();
        }

    } catch (NamingException ne) {
        log.error(ne.getMessage(), ne);
        ne.printStackTrace();
    }

}

From source file:edu.byu.wso2.apim.extensions.helpers.BYUEntityHelper.java

public BYUEntityHelper(String dSName) {
    try {// w  w w.ja  va 2s.c o  m
        if (ds == null) {
            if (log.isDebugEnabled())
                log.debug("BYUEntityHelper: looking up  datasource");

            ds = (DataSource) new InitialContext().lookup(dSName);

            if (log.isDebugEnabled())
                log.debug("acquired datasource");
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

From source file:org.beangle.security.ldap.connect.SimpleLdapUserStore.java

public Set<Attribute> getAttributes(String uid, String attrName) {
    Set<Attribute> values = CollectUtils.newHashSet();
    DirContext ctx = getContext();
    if (ctx == null)
        return values;
    try {/*from   ww w .ja v  a 2  s  . com*/
        String dn = getUserDN(uid);
        if (dn == null) {
            logger.debug("User {} not found", uid);
            return values;
        }
        javax.naming.Name userID = new CompositeName(dn);
        Attributes attrs = null;
        if (null != attrName) {
            attrs = ctx.getAttributes(userID, new String[] { attrName });
        } else {
            attrs = ctx.getAttributes(userID);
        }
        for (NamingEnumeration<? extends Attribute> ne = attrs.getAll(); ne.hasMoreElements();) {
            Attribute attr = ne.nextElement();
            values.add(attr);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return values;
}

From source file:eu.uqasar.util.UQasarUtil.java

/**
 * /*from  w w w.j  av a2 s .  co m*/
 * @param node Node whose value is studied
 * @return
 */
private static Multimap<SuggestionType, Object> getSuggestionForNode(TreeNode node) {

    // For storing the suggestion type and the payload
    Multimap<SuggestionType, Object> suggestionsMultimap = ArrayListMultimap.create();

    final String EMPTY = "";

    try {
        InitialContext ic = new InitialContext();
        ProjectSimilarityService projectSimilarityService = (ProjectSimilarityService) ic
                .lookup("java:module/ProjectSimilarityService");
        QualityObjectiveSimilarityService qoSimilarityService = (QualityObjectiveSimilarityService) ic
                .lookup("java:module/QualityObjectiveSimilarityService");
        //TODO: Finding similar metrics

        if (node instanceof QualityObjective) {
            QualityObjective qo = (QualityObjective) node;
            Float value = qo.getValue();

            // If the value of a quality objective cannot be computed, 
            // attempt to obtain a suggestion             
            if (value == null || value.isNaN()) {
                // Attempt to find a suitable project 
                Project proj = qo.getProject();
                Project similarProject = null;
                if (proj != null) {
                    // Get a list of similar projects
                    List<Project> similarProjects = projectSimilarityService.getSimilarProjects(proj);
                    if (similarProjects != null && similarProjects.size() > 0) {
                        // For now obtain the first suitable project
                        similarProject = similarProjects.get(0);
                    }
                }

                // If a suitable similar project was found, search for similar Quality Objective(s) to be suggested
                if (similarProject != null) {
                    // Get similar QOs from a similar project
                    List<QualityObjective> qos = qoSimilarityService.getSimilarQOs(qo, similarProject);
                    // If results were found, construct a suggestion (for now obtain the first one). 
                    if (qos != null && qos.size() > 0) {
                        suggestionsMultimap.put(SuggestionType.QO_REPLACE, qos.get(0));
                        return suggestionsMultimap;
                    }
                }

                // Otherwise suggest the QO to be removed
                suggestionsMultimap.put(SuggestionType.QO_REMOVE, null);
                return suggestionsMultimap;
            }
        }
        // if a metric has no value / the value is 0, return a suggestion to 
        // remove the metric 
        if (node instanceof Metric) {

            Metric metric = (Metric) node;
            Float value = metric.getValue();

            if (value == null || value.isNaN() || value.isInfinite()) {
                suggestionsMultimap.put(SuggestionType.METRIC_REMOVE, null);
                return suggestionsMultimap;
            }
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }

    // If no suggestion is to be provided, return an empty string 
    // (overwrite the possible existing suggestion). 
    suggestionsMultimap.put(SuggestionType.NO_SUGGESTION, "");
    return suggestionsMultimap;
}

From source file:com.web.server.XMLDeploymentScanner.java

@Override
protected void onDelete(File file) {
    System.out.println(file.getAbsolutePath());
    try {/*ww  w . j a v  a  2 s  .c  o m*/
        XMLDataSources xmlDataSources = xmlmap.get(xmlmap);
        for (XMLDataSource xmlDataSource : xmlDataSources.xmlDataSources) {
            if (xmlDataSource != null)
                ic.unbind("java:/" + xmlDataSource.getJndi());
        }
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(file.getAbsolutePath());
}

From source file:com.openkm.util.MailUtils.java

/**
 * /*from   w  ww  . j av a 2  s  .c om*/
 */
private static Session getMailSession() {
    Session mailSession = null;

    try {
        InitialContext initialContext = new InitialContext();
        Object obj = initialContext.lookup(Config.JNDI_BASE + "mail/OpenKM");
        mailSession = (Session) PortableRemoteObject.narrow(obj, Session.class);
    } catch (javax.naming.NamingException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return mailSession;
}

From source file:edu.byu.wso2.apim.extensions.CheckActorPermissions.java

public void init(SynapseEnvironment synapseEnvironment) {
    if (log.isInfoEnabled()) {
        log.info("Initializing CheckActorPermissions Mediator");
    }/*  www.j  a  va2 s . c o  m*/
    if (log.isDebugEnabled())
        log.debug("CheckActorPermissions: looking up Person/GRO datasource" + PRODsName);
    try {
        this.proDs = (DataSource) new InitialContext().lookup(PRODsName);
    } catch (NamingException e) {
        e.printStackTrace();
    }
    if (log.isDebugEnabled())
        log.debug("CheckActorPermissions: acquired datasource");

}

From source file:com.healthcit.cacure.businessdelegates.LdapUserManager.java

public List<UserCredentials> getAllUsers() {

    List<UserCredentials> userCredentials = new ArrayList<UserCredentials>();

    try {//from w  w w  .j  av  a 2s .  co m

        SearchControls searchCtls = new SearchControls();
        String returnedAtts[] = { "uid" };
        searchCtls.setReturningAttributes(returnedAtts);
        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String searchFilter = "(&(objectClass=person))";

        NamingEnumeration<SearchResult> elements = contextSource.getReadOnlyContext().search("", searchFilter,
                searchCtls);

        while (elements.hasMoreElements()) {
            DistinguishedName dn = new DistinguishedName(elements.nextElement().getName());
            String userName = dn.getValue("uid");
            userCredentials.add(getUserFromDatabase(userName));
        }

    } catch (org.springframework.ldap.NamingException e) {
        e.printStackTrace();
        return null;
    } catch (NamingException e) {
        e.printStackTrace();
        return null;
    }

    return userCredentials;

}

From source file:eu.uqasar.util.UQasarUtil.java

/**
 * Traverse the tree in postorder and update tree values
 * @param node//  w w w. ja va 2s  . c  o  m
 */
private static void postorder(TreeNode node) {

    if (node == null) {
        return;
    }

    logger.debug("------------postorder: " + node.getName() + "---------------");

    // Iterate the node children
    for (Object o : node.getChildren()) {
        TreeNode nodeChild = (TreeNode) o;
        UQasarUtil.postorder(nodeChild);
    }
    logger.debug("Traversing project tree in postorder..." + node.toString());
    // Update the value
    try {
        InitialContext ic = new InitialContext();
        AdapterDataService adapterDataService = new AdapterDataService();
        TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");

        if (node instanceof Metric) {
            Metric metric = (Metric) node;
            logger.debug("Recomputing the value of the Metric " + node);
            Float value = null;
            if (metric.getMetricSource() == MetricSource.Manual) {
                metric.updateQualityStatus();
            } else {
                value = adapterDataService.getMetricValue(metric.getMetricSource(), metric.getMetricType(),
                        metric.getProject());
                metric.setValue(value);
            }
            metric.setLastUpdated(getLatestTreeUpdateDate());
            metric.addHistoricValue();
            // End Metric node treatment 
        } else if (node instanceof QualityIndicator) {
            logger.info("Recomputing the value of the Quality Indicator " + node);
            QualityIndicator qi = (QualityIndicator) node;
            if (qi.getUseFormula()) {
                String formulaToEval = Formula.parseFormula(qi.getViewFormula());
                if (formulaToEval != null && !formulaToEval.isEmpty()) {

                    Float computedValue = Formula.evalFormula(formulaToEval);
                    if (computedValue != null && !computedValue.isNaN()) {
                        qi.setValue(computedValue);
                        qi.setLastUpdated(getLatestTreeUpdateDate());
                        treeNodeService.update(qi);
                    }

                }
            } else {
                float achieved = 0;
                float denominator = 0;
                for (final TreeNode me : qi.getChildren()) {
                    float weight = ((Metric) me).getWeight();
                    if (me.getQualityStatus() == QualityStatus.Green) {
                        achieved += weight;
                    }
                    denominator += weight;
                }
                if (denominator == 0)
                    qi.getChildren().size();
                qi.setValue(achieved * 100 / denominator);
            }
            qi.setLastUpdated(getLatestTreeUpdateDate());
            qi.addHistoricValue();
            // End Q.Indicator node treatment 
        } else if (node instanceof QualityObjective) {
            logger.info("Recomputing the value of the Quality Objective " + node);
            QualityObjective qo = (QualityObjective) node;
            if (qo.getUseFormula()) {
                String formulaToEval = Formula.parseFormula(qo.getViewFormula());
                if (formulaToEval != null && !formulaToEval.isEmpty()) {

                    Float computedValue = Formula.evalFormula(formulaToEval);
                    if (computedValue != null && !computedValue.isNaN()) {
                        qo.setValue(computedValue);
                        qo.setLastUpdated(getLatestTreeUpdateDate());
                    }

                }
            } else {
                float denominator = 0;
                float achieved = 0;
                for (final TreeNode qi : qo.getChildren()) {
                    float weight = ((QualityIndicator) qi).getWeight();
                    if (qi.getQualityStatus() == QualityStatus.Green) {
                        achieved += weight;
                    }
                    denominator += weight;
                }
                qo.setValue(achieved * 100 / denominator);
            }
            qo.setLastUpdated(getLatestTreeUpdateDate());
            qo.addHistoricValue();
            // End Quality Objective node treatment 
        } else if (node instanceof Project) {
            logger.info("Recomputing the value of the Project " + node);
            Project prj = (Project) node;
            double qoValueSum = 0;
            double denominator = 0;
            for (Object o : node.getChildren()) {
                QualityObjective qo = (QualityObjective) o;
                if (qo.getWeight() == 0) {
                    continue;
                }
                qoValueSum += qo.getValue() * (prj.isFormulaAverage() ? qo.getWeight() : 1);
                denominator += prj.isFormulaAverage() ? qo.getWeight() : 1;
            }

            // bad idea to divide something under 0
            if (denominator == 0) {
                denominator = 1;
            }

            Double computedValue = qoValueSum / denominator;

            if (computedValue != null && !computedValue.isNaN() && !computedValue.isInfinite()) {
                prj.setValue(computedValue);
            }

            prj.setLastUpdated(getLatestTreeUpdateDate());
            prj.addHistoricValue();
            logger.debug(" [" + qoValueSum + "] denominator [" + denominator + "] " + computedValue);
            // End Project node treatment 
        }

        // Get a (possible) suggestion for the tree node
        Multimap<?, ?> suggestions = getSuggestionForNode(node);
        //TODO: take all the suggestions into account
        Object[] types = suggestions.keys().toArray();
        Object[] suggestionsValues = suggestions.values().toArray();
        if (types.length > 0) {
            // for now use the first item as suggestion
            SuggestionType stype = (SuggestionType) types[0];
            node.setSuggestionType(stype);
            if (suggestionsValues[0] != null && !suggestionsValues[0].equals("")) {
                node.setSuggestionValue((String) suggestionsValues[0]);
            }
        }

        treeNodeService.update(node);

    } catch (NamingException e) {
        e.printStackTrace();
    }

    return;
}

From source file:eu.uqasar.util.UQasarUtil.java

/**
 * Traverse the tree in postorder and update tree values
 * @param node//from  w  w w . ja va 2  s .co  m
 */
private static void postorderWithParticularNode(TreeNode node, TreeNode projectTreeNode) {

    if (node == null) {
        return;
    }

    if (projectTreeNode == null) {
        return;
    }

    logger.debug("------------postorder: " + projectTreeNode.getName() + "---------------");

    logger.debug("Traversing project tree in postorder..." + projectTreeNode.toString());
    // Update the value
    try {
        InitialContext ic = new InitialContext();
        AdapterDataService adapterDataService = new AdapterDataService();
        TreeNodeService treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");

        if (projectTreeNode instanceof Metric) {
            Metric metric = (Metric) projectTreeNode;
            logger.debug("Recomputing the value of the Metric " + projectTreeNode);
            Float value = null;
            if (metric.getMetricSource() == MetricSource.Manual) {
                metric.updateQualityStatus();
            } else {
                value = adapterDataService.getMetricValue(metric.getMetricSource(), metric.getMetricType(),
                        metric.getProject());
                metric.setValue(value);
            }
            metric.setLastUpdated(getLatestTreeUpdateDate());
            metric.addHistoricValue();
            // End Metric node treatment 
        } else if (projectTreeNode instanceof QualityIndicator) {
            logger.info("Recomputing the value of the Quality Indicator " + projectTreeNode);
            QualityIndicator qi = (QualityIndicator) projectTreeNode;
            if (qi.getUseFormula()) {
                String formulaToEval = Formula.parseFormula(qi.getViewFormula());
                if (formulaToEval != null && !formulaToEval.isEmpty()) {

                    Float computedValue = Formula.evalFormula(formulaToEval);
                    if (computedValue != null && !computedValue.isNaN()) {
                        qi.setValue(computedValue);
                        qi.setLastUpdated(getLatestTreeUpdateDate());
                        treeNodeService.update(qi);
                    }

                }
            } else {
                float achieved = 0;
                float denominator = 0;
                for (final TreeNode me : qi.getChildren()) {
                    float weight = ((Metric) me).getWeight();
                    if (me.getQualityStatus() == QualityStatus.Green) {
                        achieved += weight;
                    }
                    denominator += weight;
                }
                if (denominator == 0)
                    qi.getChildren().size();
                qi.setValue(achieved * 100 / denominator);
            }
            qi.setLastUpdated(getLatestTreeUpdateDate());
            qi.addHistoricValue();
            // End Q.Indicator node treatment 
        } else if (projectTreeNode instanceof QualityObjective) {
            logger.info("Recomputing the value of the Quality Objective " + projectTreeNode);
            QualityObjective qo = (QualityObjective) projectTreeNode;
            if (qo.getUseFormula()) {
                String formulaToEval = Formula.parseFormula(qo.getViewFormula());
                if (formulaToEval != null && !formulaToEval.isEmpty()) {

                    Float computedValue = Formula.evalFormula(formulaToEval);
                    if (computedValue != null && !computedValue.isNaN()) {
                        qo.setValue(computedValue);
                        qo.setLastUpdated(getLatestTreeUpdateDate());
                    }

                }
            } else {
                float denominator = 0;
                float achieved = 0;
                for (final TreeNode qi : qo.getChildren()) {
                    float weight = ((QualityIndicator) qi).getWeight();
                    if (qi.getQualityStatus() == QualityStatus.Green) {
                        achieved += weight;
                    }
                    denominator += weight;
                }
                qo.setValue(achieved * 100 / denominator);
            }
            qo.setLastUpdated(getLatestTreeUpdateDate());
            qo.addHistoricValue();
            // End Quality Objective node treatment 
        } else if (projectTreeNode instanceof Project) {
            logger.info("Recomputing the value of the Project " + projectTreeNode);
            Project prj = (Project) projectTreeNode;
            double qoValueSum = 0;
            double denominator = 0;
            for (Object o : projectTreeNode.getChildren()) {
                QualityObjective qo = (QualityObjective) o;
                if (qo.getWeight() == 0) {
                    continue;
                }
                qoValueSum += qo.getValue() * (prj.isFormulaAverage() ? qo.getWeight() : 1);
                denominator += prj.isFormulaAverage() ? qo.getWeight() : 1;
            }

            // bad idea to divide something under 0
            if (denominator == 0) {
                denominator = 1;
            }

            Double computedValue = qoValueSum / denominator;

            if (computedValue != null && !computedValue.isNaN() && !computedValue.isInfinite()) {
                prj.setValue(computedValue);
            }

            prj.setLastUpdated(getLatestTreeUpdateDate());
            prj.addHistoricValue();
            logger.debug(" [" + qoValueSum + "] denominator [" + denominator + "] " + computedValue);
            // End Project node treatment 
        }

        // Get a (possible) suggestion for the tree node
        Multimap<?, ?> suggestions = getSuggestionForNode(projectTreeNode);
        //TODO: take all the suggestions into account
        Object[] types = suggestions.keys().toArray();
        Object[] suggestionsValues = suggestions.values().toArray();
        if (types.length > 0) {
            // for now use the first item as suggestion
            SuggestionType stype = (SuggestionType) types[0];
            projectTreeNode.setSuggestionType(stype);
            if (suggestionsValues[0] != null && !suggestionsValues[0].equals("")) {
                projectTreeNode.setSuggestionValue((String) suggestionsValues[0]);
            }
        }

        treeNodeService.update(projectTreeNode);

    } catch (NamingException e) {
        e.printStackTrace();
    }

    // Iterate the node children
    TreeNode nodeChild = projectTreeNode.getParent();
    UQasarUtil.postorderWithParticularNode(projectTreeNode, nodeChild);

    return;
}