Example usage for java.lang Exception getStackTrace

List of usage examples for java.lang Exception getStackTrace

Introduction

In this page you can find the example usage for java.lang Exception getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#storeAccount(org.apache.lucene.gdata.data.GDataAccount)
 *//*from w w w.jav a 2  s .  c o m*/
public void storeAccount(GDataAccount Account) throws StorageException {
    if (Account == null)
        throw new StorageException("Can not save null Account");
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        if (query.get().getUser(Account.getName()) != null)
            throw new StorageException("Account already exists");
        StorageModifier modifier = this.controller.getStorageModifier();
        StorageAccountWrapper wrapper = new StorageAccountWrapper(Account);
        modifier.createAccount(wrapper);
    } catch (Exception e) {
        LOG.error("Can't save Account -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't save Account -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }
}

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#storeFeed(org.apache.lucene.gdata.data.ServerBaseFeed,
 *      java.lang.String)//from w ww. j ava 2 s  .  c  o m
 */
public void storeFeed(ServerBaseFeed feed, String accountName) throws StorageException {
    if (feed == null)
        throw new StorageException("can not insert null feed");
    if (accountName == null)
        throw new StorageException("accountName must not be null");
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        if (query.get().isFeedStored(feed.getId()))
            throw new StorageException("feed with feedID " + feed.getId() + " is already stored");
        StorageModifier modifier = this.controller.getStorageModifier();
        StorageFeedWrapper wrapper = new StorageFeedWrapper(feed, accountName);
        modifier.createFeed(wrapper);

    } catch (Exception e) {
        LOG.error("Can't create feed -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't create feed -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }

}

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#updateFeed(org.apache.lucene.gdata.data.ServerBaseFeed,
 *      java.lang.String)/* w w w  . j ava2s . c  o  m*/
 */
public void updateFeed(ServerBaseFeed feed, String accountName) throws StorageException {
    if (feed == null)
        throw new StorageException("can not update null feed");
    if (accountName == null)
        throw new StorageException("accountName must not be null");
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        if (!query.get().isFeedStored(feed.getId()))
            throw new StorageException("Account does not exist");
        StorageModifier modifier = this.controller.getStorageModifier();
        StorageFeedWrapper wrapper = new StorageFeedWrapper(feed, accountName);
        modifier.updateFeed(wrapper);

    } catch (Exception e) {
        LOG.error("Can't create feed -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't create feed -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }

}

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#deleteAccount(java.lang.String)
 *//* w  ww. j ava2  s  . c om*/
public void deleteAccount(String Accountname) throws StorageException {
    if (Accountname == null)
        throw new StorageException("can not delete null Account");
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        if (query.get().getUser(Accountname) == null)
            throw new StorageException("Account does not exist");
        StorageModifier modifier = this.controller.getStorageModifier();
        modifier.deleteAccount(Accountname);
    } catch (Exception e) {
        LOG.error("Can't update Account -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't update Account -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }
}

From source file:eu.impact_project.resultsrepository.ServiceImpl.java

/**
 * Formats the given exception so that it can be returned to the service
 * user instead of or along with the status message.
 * //from   w w w .j  ava  2  s.c  o  m
 */
private String formatException(Exception e) {
    String s = "\n" + e.toString() + "\n        ";

    for (StackTraceElement elem : e.getStackTrace()) {
        s += elem + "\n        ";
    }
    return s;
}

From source file:org.apache.lucene.gdata.storage.lucenestorage.StorageImplementation.java

/**
 * @see org.apache.lucene.gdata.storage.Storage#updateAccount(org.apache.lucene.gdata.data.GDataAccount)
 *//*from w  w  w  .java2  s .  co m*/
public void updateAccount(GDataAccount Account) throws StorageException {
    if (Account == null)
        throw new StorageException("Can not update null Account");
    ReferenceCounter<StorageQuery> query = null;
    try {
        query = this.controller.getStorageQuery();
        if (query.get().getUser(Account.getName()) == null)
            throw new StorageException("Account does not exist");
        StorageModifier modifier = this.controller.getStorageModifier();
        StorageAccountWrapper wrapper = new StorageAccountWrapper(Account);
        modifier.updateAccount(wrapper);
    } catch (Exception e) {
        LOG.error("Can't update Account -- " + e.getMessage(), e);
        StorageException ex = new StorageException("Can't update Account -- " + e.getMessage(), e);
        ex.setStackTrace(e.getStackTrace());
        throw ex;

    } finally {
        if (query != null)
            query.decrementRef();
    }

}

From source file:annis.visualizers.iframe.partitur.PartiturVisualizer.java

@Override
public void writeOutput(VisualizerInput input, Writer writer) {
    try {//from  w  w w. ja v  a 2s .  c o  m

        nodes = input.getResult().getGraph().getNodes();
        token = input.getResult().getGraph().getTokens();

        // get partitur
        PartiturParser partitur = new PartiturParser(input.getResult().getGraph(), input.getNamespace());

        // check right to left
        boolean isRTL = checkRTL(input.getResult().getTokenList());

        List<String> tierNames = new LinkedList<String>(partitur.getKnownTiers());
        Collections.sort(tierNames);

        // get keys that are allowed to select
        LinkedHashSet<String> keys = new LinkedHashSet<String>();
        String mapping = input.getMappings().getProperty("annos");
        if (mapping == null) {
            // default to the alphabetical order
            keys.addAll(partitur.getNameslist());
        } else {
            String[] splitted = mapping.split(",");
            for (int k = 0; k < splitted.length; k++) {
                String s = splitted[k].trim();
                if (partitur.getNameslist().contains(s)) {
                    keys.add(s);
                }
            }
        }

        writer.append(
                "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
        writer.append("<link href=\"" + input.getResourcePath("jbar.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("jquery.tooltip.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("jquery.noty.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<link href=\"" + input.getResourcePath("partitur.css")
                + "\" rel=\"stylesheet\" type=\"text/css\" >");
        writer.append("<script src=\"" + input.getResourcePath("jquery-1.7.1.min.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.jbar.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.tooltip.min.js") + "\"></script>");
        writer.append("<script src=\"" + input.getResourcePath("jquery.noty.js") + "\"></script>");
        writer.append("<script>");
        writer.append(convertToJavacSriptArray(new LinkedList<String>()));
        writer.append("\nvar levelNames = [");
        int i = 0;
        for (String levelName : tierNames) {
            if (keys.contains(levelName)) {
                writer.append((i++ > 0 ? ", " : "") + "\"" + levelName + "\"");
            }
        }
        writer.append("];\n</script>");
        writer.append("<script type=\"text/javascript\" src=\"" + input.getResourcePath("PartiturVisualizer.js")
                + "\"></script>");

        writer.append("</head>");
        writer.append("<body>\n");

        writer.append("<ul id=\"toolbar\"></ul>");
        writer.append("<div id=\"partiture\">");

        if (isRTL) {
            writer.append("<table class=\"partitur_table\" dir=\"rtl\">\n");
        } else {
            writer.append("<table class=\"partitur_table\")\">\n");
        }

        for (String tier : keys) {
            List<String> indexlist = new ArrayList<String>();

            for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) {
                for (PartiturParser.ResultElement strr : span) {
                    if (strr.getName().equals(tier) && !indexlist.contains(strr.getId())) {
                        indexlist.add(strr.getId());
                    }
                }
            }

            String[] currentarray; //Saves annotation-ids of the current row

            while (!indexlist.isEmpty()) { //Create Rows until all Annotations fit in
                List<String> currentdontuselist = new LinkedList<String>(); //Lists all Annotations that should not be added to the current row
                writer.append("<tr class=\"level_" + tier + "\"><th>" + tier + "</th>"); //new row

                currentarray = new String[partitur.getResultlist().size()];
                for (int iterator3 = 0; iterator3 < partitur.getResultlist().size(); iterator3++) {
                    currentarray[iterator3] = null;
                }

                int spanCounter = 0;
                for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) { //for each Token
                    for (PartiturParser.ResultElement annotationelement : span) { // for each Annotation annotationelement of that Token
                        if (indexlist.contains(annotationelement.getId())
                                && !currentdontuselist.contains(annotationelement.getId())) {
                            boolean neu = false; //Should the Annotation be added?
                            if (currentarray[spanCounter] == null) {
                                indexlist.remove(annotationelement.getId());
                                currentarray[spanCounter] = annotationelement.getId();
                                neu = true;
                            }
                            //get all other annotationelement.id (earlier Ids => dontuselist)
                            int span2Counter = 0;
                            for (List<PartiturParser.ResultElement> span2 : partitur.getResultlist()) {
                                for (PartiturParser.ResultElement strr2 : span2) {
                                    if (strr2.getId().equals(annotationelement.getId()) && neu) //{
                                    {
                                        if (currentarray[span2Counter] == null) {
                                            currentarray[span2Counter] = annotationelement.getId();
                                        }
                                    }
                                    if (span2Counter <= spanCounter
                                            && !currentdontuselist.contains(strr2.getId())) {
                                        currentdontuselist.add(strr2.getId());
                                    }
                                }
                                span2Counter++;
                            }
                            //break; //Not needed?
                        }
                    }
                    spanCounter++;
                }

                //Write Row
                int length = 1;
                for (int iterator5 = 0; iterator5 < currentarray.length; iterator5 += length) {
                    StringBuffer tokenIdsArray = new StringBuffer();
                    StringBuffer eventIdsArray = new StringBuffer();
                    boolean unused = true;
                    length = 1;
                    if (currentarray[iterator5] == null) { //empty entry
                        writer.append("<td></td>");
                    } else {
                        PartiturParser.ResultElement element = null;
                        HashSet<Integer> common = new HashSet<Integer>();
                        boolean found = false;
                        int outputSpanCounter = 0;
                        for (List<PartiturParser.ResultElement> outputSpan : partitur.getResultlist()) {
                            for (PartiturParser.ResultElement strr : outputSpan) {
                                if (strr.getId().equals(currentarray[iterator5])) {
                                    if (!found) {
                                        element = strr;
                                    }
                                    if (!common.contains(outputSpanCounter)) {
                                        common.add(outputSpanCounter);
                                    }
                                    found = true;
                                    if (unused) {
                                        tokenIdsArray.append("" + strr.getId() + "_" + outputSpanCounter);
                                        eventIdsArray
                                                .append(tier + "_" + strr.getId() + "_" + outputSpanCounter);
                                        unused = false;
                                    } else {
                                        tokenIdsArray.append("," + strr.getId() + "_" + outputSpanCounter);
                                        eventIdsArray.append(
                                                "," + tier + "_" + strr.getId() + "_" + outputSpanCounter);
                                    }
                                }
                            }
                            outputSpanCounter++;
                        }
                        for (int iterator7 = iterator5 + 1; iterator7 < currentarray.length; iterator7++) {
                            if (common.contains(iterator7)) {
                                length++;
                            } else {
                                break;
                            }
                        }

                        for (int iterator8 = 0; iterator8 < currentarray.length; iterator8++) {
                            if (common.contains(iterator8)) {
                                Long id = ((PartiturParser.Token) partitur.getToken().toArray()[iterator8])
                                        .getId();
                                if (unused) {
                                    tokenIdsArray.append("" + id);
                                    eventIdsArray.append(tier + "_" + id);
                                    unused = false;
                                } else {
                                    tokenIdsArray.append("," + id);
                                    eventIdsArray.append("," + tier + "_" + id);
                                }
                            }
                        }

                        String color = "black";
                        if (input.getMarkableExactMap().containsKey("" + element.getNodeId())) {
                            color = input.getMarkableExactMap().get("" + element.getNodeId());
                        }
                        if (found) {
                            writer.append("<td class=\"single_event\" " + "id=\"event_" + tier + "_"
                                    + element.getId() + "_" + iterator5 + "\" " + "style=\"color:" + color
                                    + ";\" " + "colspan=" + length + " " + "annis:tokenIds=\"" + tokenIdsArray
                                    + "\" " + "annis:eventIds=\"" + eventIdsArray + "\" " + "title=\""
                                    + partitur.namespaceForTier(tier) + ":" + tier + " = "
                                    + StringEscapeUtils.escapeXml(element.getValue()) + "\"  " //tier =tier, event.getValue()= element.name
                                    + "onMouseOver=\"toggleAnnotation(this, true);\" "
                                    + "onMouseOut=\"toggleAnnotation(this, false);\" "
                                    + addTimeAttribute(element.getNodeId()) + ">" + element.getValue()
                                    + "</td>");
                        } else {
                            writer.append("<td class=\"single_event\" >error</td>");
                        }
                    }
                }
                writer.append("</tr>"); //finish row
            }
        }

        // add token itself
        writer.append("<tr><th>tok</th>");

        for (PartiturParser.Token token : partitur.getToken()) {
            String color = "black";

            if (input.getMarkableExactMap().containsKey("" + token.getId())) {
                color = input.getMarkableExactMap().get("" + token.getId());
            }
            writer.append("<td class=\"tok\" style=\"color:" + color + ";\" " + "id=\"token_" + token.getId()
                    + "\" " + ">" + token.getValue() + "</td>");
        }
        writer.append("</tr>");

        writer.append("</table>\n");
        writer.append("</div>\n");
        writer.append("</body></html>");

    } catch (Exception ex) {
        log.error(null, ex);
        try {
            String annisLine = "";
            for (int i = 0; i < ex.getStackTrace().length; i++) {
                if (ex.getStackTrace()[i].getClassName().startsWith("annis.")) {
                    annisLine = ex.getStackTrace()[i].toString();
                }
            }

            writer.append("<html><body>Error occured (" + ex.getClass().getName() + "): "
                    + ex.getLocalizedMessage() + "<br/>" + annisLine + "</body></html>");
        } catch (IOException ex1) {
            log.error(null, ex1);
        }
    }
}

From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.InferMLNetworkFromSequences.java

private String network2String(final DirectedGraphToGraphAdapter<String, PhyloEdge<String>> speciesNetwork) {
    Func1<String, String> _getNetworkNodeLabel = new Func1<String, String>() {
        public String execute(String node) {
            return node;
        }/* ww  w  . j a va 2s. c o m*/
    };

    Func1<String, Iterable<String>> _getDestinationNodes = new Func1<String, Iterable<String>>() {
        public Iterable<String> execute(String node) {
            return new GetDirectSuccessors<String, PhyloEdge<String>>().execute(speciesNetwork, node);
        }
    };

    Func2<String, String, String> _getNetworkDistanceForPrint = new Func2<String, String, String>() {
        public String execute(String parent, String child) {
            PhyloEdge<String> edge = speciesNetwork.getEdge(parent, child);
            if (edge.getBranchLength() == null) {
                return null;
            }
            return edge.getBranchLength() + "";
        }
    };

    Func2<String, String, String> _getProbabilityForPrint = new Func2<String, String, String>() {
        public String execute(String parent, String child) {
            PhyloEdge<String> edge = speciesNetwork.getEdge(parent, child);
            if (edge.getProbability() == null) {
                return null;
            }
            return edge.getProbability() + "";
        }
    };

    Func2<String, String, String> _getSupportForPrint = new Func2<String, String, String>() {
        public String execute(String parent, String child) {
            PhyloEdge<String> edge = speciesNetwork.getEdge(parent, child);
            if (edge.getSupport() == null) {
                return null;
            }
            return edge.getSupport() + "";
        }
    };

    Func1<String, HybridNodeType> _getHybridTypeForPrint = new Func1<String, HybridNodeType>() {
        public HybridNodeType execute(String node) {
            int inDegree = new GetInDegree<String, PhyloEdge<String>>().execute(speciesNetwork, node);
            return inDegree == 2 ? HybridNodeType.Hybridization : null;
        }
    };

    Func1<String, String> _getHybridNodeIndexForPrint = new Func1<String, String>() {
        List<String> hybridNodes = new ArrayList<String>();

        public String execute(String node) {
            int inDegree = new GetInDegree<String, PhyloEdge<String>>().execute(speciesNetwork, node);
            if (inDegree == 2) {
                int index = hybridNodes.indexOf(node) + 1;
                if (index == 0) {
                    hybridNodes.add(node);
                    return hybridNodes.size() + "";
                } else {
                    return index + "";
                }
            } else {
                return null;
            }
        }
    };

    try {
        StringWriter sw = new StringWriter();
        //   new RichNewickPrinterCompact<String>().print(true, "R", _getNetworkNodeLabel, _getDestinationNodes, _getNetworkDistanceForPrint, _getSupportForPrint, _getProbabilityForPrint, _getHybridNodeIndexForPrint, _getHybridTypeForPrint, sw);
        RichNewickPrinterCompact<String> printer = new RichNewickPrinterCompact<String>();
        printer.setGetBranchLength(_getNetworkDistanceForPrint);
        printer.setGetProbability(_getProbabilityForPrint);
        printer.setGetSupport(_getSupportForPrint);

        printer.print(true, new FindRoot<String>().execute(speciesNetwork), _getNetworkNodeLabel,
                _getDestinationNodes, _getHybridNodeIndexForPrint, _getHybridTypeForPrint, sw);
        sw.flush();
        sw.close();
        return sw.toString();
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.getStackTrace();
    }
    return null;
}

From source file:com.liferay.document.library.webdav.test.BaseWebDAVTestCase.java

public Tuple service(String method, String path, Map<String, String> headers, byte[] data) {

    WebDAVServlet webDAVServlet = new WebDAVServlet();

    String requestURI = _CONTEXT_PATH + _SERVLET_PATH + _PATH_INFO_PREFACE + path;

    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(method, requestURI);

    mockHttpServletRequest.setContextPath(_CONTEXT_PATH);
    mockHttpServletRequest.setServletPath(_SERVLET_PATH);
    mockHttpServletRequest.setPathInfo(_PATH_INFO_PREFACE + path);

    try {//from w ww.jav a  2 s . c  om
        mockHttpServletRequest.setRemoteUser(String.valueOf(TestPropsValues.getUserId()));
    } catch (Exception e) {
        Assert.fail("User ID cannot be initialized");
    }

    if (headers == null) {
        headers = new HashMap<>();
    }

    headers.put(HttpHeaders.USER_AGENT, getUserAgent());

    try {
        throw new Exception();
    } catch (Exception e) {
        StackTraceElement[] stackTraceElements = e.getStackTrace();

        for (StackTraceElement stackTraceElement : stackTraceElements) {
            String methodName = stackTraceElement.getMethodName();

            if (methodName.equals("setUp") || methodName.equals("tearDown") || methodName.startsWith("test")) {

                String testName = StringUtil.extractLast(stackTraceElement.getClassName(), CharPool.PERIOD);

                testName = StringUtil.removeSubstrings(testName, "WebDAV", "Test");

                headers.put("X-Litmus", testName + ": (" + stackTraceElement.getMethodName() + ":"
                        + stackTraceElement.getLineNumber() + ")");

                break;
            }
        }
    }

    if (data != null) {
        mockHttpServletRequest.setContent(data);

        String contentType = headers.remove(HttpHeaders.CONTENT_TYPE);

        if (contentType != null) {
            mockHttpServletRequest.setContentType(contentType);
        } else {
            mockHttpServletRequest.setContentType(ContentTypes.TEXT_PLAIN);
        }
    }

    for (Map.Entry<String, String> entry : headers.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        mockHttpServletRequest.addHeader(key, value);
    }

    try {
        MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();

        webDAVServlet.service(mockHttpServletRequest, mockHttpServletResponse);

        int statusCode = mockHttpServletResponse.getStatus();
        byte[] responseBody = mockHttpServletResponse.getContentAsByteArray();

        Map<String, String> responseHeaders = new HashMap<>();

        for (String name : mockHttpServletResponse.getHeaderNames()) {
            responseHeaders.put(name, mockHttpServletResponse.getHeader(name));
        }

        return new Tuple(statusCode, responseBody, responseHeaders);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.appeligo.ccdataindexer.Indexer.java

public int indexChannel(File channel) throws IOException {
    log.info("indexing channel " + channel.getName());
    boolean needToClose = openIndex();
    int count = 0;
    try {//from  w  w  w  .  j  a va 2s.  c om
        String channelNumber = channel.getName();
        String callSign = channelNumberToCallSign.get(channelNumber);
        if (callSign == null) {
            callSign = channelNumber;
            //log.error("Unable to indentify callsign for channel " +  channelNumber);
            //return 0;
        }

        Network network = networks.get(callSign);
        if (network == null) {
            log.error("Unable to indentify network for callsign " + callSign);
            return 0;
        }

        File[] programFiles = channel.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                if (name.endsWith(".gz") || name.endsWith(".zip")) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        if (programFiles != null) {
            for (File program : programFiles) {
                try {
                    if (afterDate == null || program.lastModified() > afterDate.getTime()) {
                        if (indexProgram(program, network)) {
                            count++;
                        }
                    }
                } catch (Exception e) {
                    log.error("Exception on Program File " + program.getAbsolutePath() + "\n" + e.getMessage()
                            + "\n" + e.getStackTrace().toString(), e);
                }
            }
        }
        log.info("processed " + count + " programs for channel :" + channelNumber);
    } finally {
        if (needToClose) {
            closeIndex();
        }
    }
    return count;
}