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:no.ntnu.okse.protocol.wsn.WSNotificationServer.java

/**
 * This method stops the execution of the WSNotificationServer instance.
 *///from  w  ww.  j a  v  a  2 s . com
@Override
public void stopServer() {
    try {
        log.info("Stopping WSNServer...");
        // Removing all subscribers
        _commandProxy.getAllRecipients().forEach(s -> {
            _commandProxy.getProxySubscriptionManager().removeSubscriber(s);
        });
        // Removing all publishers
        _commandProxy.getProxyRegistrationManager().getAllPublishers().forEach(p -> {
            _commandProxy.getProxyRegistrationManager().removePublisher(p);
        });

        // Stop the HTTP Client
        this._client.stop();
        // Stop the ServerConnector
        this._server.stop();
        this._serverThread = null;
        // Reset flags
        this._singleton = null;
        this._invoked = false;
        log.info("WSNServer Client and ServerThread stopped");
    } catch (Exception e) {
        totalErrors.incrementAndGet();
        log.trace(e.getStackTrace());
    }
}

From source file:com.castis.xylophone.adsmadapter.convert.axistree.ConvertRegionAxisTreeDTO.java

@Transactional(rollbackFor = Exception.class)
public int convertRegionTree(Date date, ADSMSchedulerLogDTO schedulerLog, ADSMJobNameType srcJopType,
        String treeName, boolean isPartialUpdate, String publisher, Platform platformType) throws Exception {
    long start = System.currentTimeMillis();

    String schedulerLogParam = schedulerLog.getParam();
    log.info("Start Update Region Tree (" + schedulerLogParam + ")");
    this.srcJobType = srcJopType;
    int treeID = 0;
    try {//from  w w  w  . ja  va  2 s .c  o  m
        int dataLogID = Integer.parseInt((String) schedulerLog.getParamValue("dataLogId"));
        String licenseStartDateStr = (String) schedulerLog.getParamValue(FilePolling.PARAM_START_TIME_PREFIX);

        NodeDTO rootNodeDTO = getRootNode(treeName + "_root", dataLogID);

        if (rootNodeDTO == null) {
            throw new CiRuntimeException(
                    "Fail to update Region Tree (Cannot Check root Info. " + schedulerLog.getParam() + ")");
        }

        treeID = tambourineConnector.getAxisTreeId(TreeType.REGION_AXIS_TREE, treeName, publisher, platformType,
                false);
        //?
        if (treeID <= 0)
            treeID = tambourineConnector.registerRegionAxisTree(
                    getAxisTreeDTO(treeName, rootNodeDTO, publisher, platformType), date);

        //?
        if (licenseStartDateStr != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date licenseStartDate = sdf.parse(licenseStartDateStr);
            Date syncStartDate = licenseStartDate;
            Date nowDate = new Date();

            if (isPartialUpdate == false)
                syncStartDate = nowDate;

            makeTreeNode(treeID, licenseStartDate, rootNodeDTO.getExternalNodeId(), schedulerLogParam, treeName,
                    dataLogID, isPartialUpdate);

            String param = "treeId:" + treeID + "/treeType:" + TreeType.REGION_AXIS_TREE.toString()
                    + "/treeName:" + treeName;
            FeSyncNoticeboardDTO feSyncNoticeboardDTO = tambourineConnector.generateFeSyncNoticeboardData(
                    SyncDataType.TREEDATA, syncStartDate, param, publisher, FeSyncNoticeboardStatus.NEWDATA,
                    platformType, null, null);

            //? sync ,treetype,treeName? syncNoticeboard disable
            tambourineConnector.disableFeSyncNoticeboard(feSyncNoticeboardDTO);

            //  syncNoticeboard? ?
            if (isPartialUpdate == false)
                tambourineConnector.insertTreeLogNSyncNoticeboard(treeID, TreeType.REGION_AXIS_TREE, treeName,
                        feSyncNoticeboardDTO, publisher, platformType);

        } else {
            makeTreeNode(treeID, date, rootNodeDTO.getExternalNodeId(), schedulerLogParam, treeName, dataLogID,
                    isPartialUpdate);

            Date nowDate = new Date();
            publisher = ADDSAdapterSetting.defaultSiteName;
            String param = "treeId:" + treeID + "/treeType:" + TreeType.REGION_AXIS_TREE.toString()
                    + "/treeName:" + treeName;
            FeSyncNoticeboardDTO feSyncNoticeboardDTO = tambourineConnector.generateFeSyncNoticeboardData(
                    SyncDataType.TREEDATA, nowDate, param, publisher, FeSyncNoticeboardStatus.NEWDATA,
                    platformType, null, null);
            //  syncNoticeboard? ?
            tambourineConnector.insertTreeLogNSyncNoticeboard(treeID, TreeType.REGION_AXIS_TREE, treeName,
                    feSyncNoticeboardDTO, publisher, platformType);
        }

        // ? 
        schedulerLog.setSchedulerStatus(ADSMSchedulerStatus.SUCCESS);
        schedulerLog.setMessage(TREE_NAME_MESSAGE_PREFIX + treeName);
    } catch (Exception e) {
        TheLogger.getWriter().error("Fail to update Region Tree (" + schedulerLog.getParam() + ")");
        long end = System.currentTimeMillis();
        log.error("Fail to update Region Tree(" + schedulerLog.getParam() + ") - T(" + (end - start) + ")");

        // ? ?   
        schedulerLog.setSchedulerStatus(ADSMSchedulerStatus.FAIL);
        schedulerLog.setMessage(e.getMessage());
        StackTraceElement[] stackTraces = e.getStackTrace();
        if (stackTraces.length > 0) {
            schedulerLog.setFailProcess(stackTraces[0].getClassName() + " - " + stackTraces[0].getMethodName()
                    + "(" + stackTraces[0].getLineNumber() + ")");
        }
        throw e;
    }

    long end = System.currentTimeMillis();
    log.info("Complete to update Region Tree (" + schedulerLog.getParam() + ") - T(" + (end - start) + ")");
    TheLogger.getWriter().info("Update Region Tree Success(" + schedulerLog.getParam() + ")");

    return treeID;

}

From source file:seava.j4e.web.controller.AbstractBaseController.java

/**
 * Generic exception handler//from  www  . j  a va  2  s. c  om
 * 
 * @param e
 * @param response
 * @return
 * @throws IOException
 */
@ExceptionHandler(value = Exception.class)
@ResponseBody
protected String handleException(Exception e, HttpServletResponse response) throws IOException {

    e.printStackTrace();

    StringBuffer sb = new StringBuffer(" NOT MANAGED EXCEPTION HANDLER ");
    if (e.getLocalizedMessage() != null) {
        sb.append(e.getLocalizedMessage());
    } else if (e.getCause() != null) {
        if (sb.length() > 0) {
            sb.append(" Reason: ");
        }
        sb.append(e.getCause().getLocalizedMessage());
    }
    if (sb.length() == 0) {
        if (e.getStackTrace() != null) {
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            e.printStackTrace(response.getWriter());
            return null;
        }
    }
    response.setStatus(HttpStatus.EXPECTATION_FAILED.value());
    response.getOutputStream().print(sb.toString());
    response.getOutputStream().flush();
    return null;

}

From source file:es.bsc.servicess.ide.PackagingUtils.java

/** Instrument the Orchestration Element classes
 * @param project Java project/*from ww w. j a v a  2  s.co m*/
 * @param classes Orchestration Element classes
 * @param deps Orchestration Element dependencies
 * @param myProgressMonitor Eclipse progress monitor
 * @throws CoreException
 */
public static void instrumentOrchestrations(IJavaProject project, IFolder classes, List<Dependency> deps,
        IProgressMonitor myProgressMonitor) throws CoreException {
    IFile metadataFile = project.getProject().getFolder(ProjectMetadata.METADATA_FOLDER)
            .getFile(ProjectMetadata.METADATA_FILENAME);
    if (metadataFile != null && metadataFile.exists()) {
        try {
            ProjectMetadata pr_meta = new ProjectMetadata(new File(metadataFile.getRawLocation().toOSString()));
            //TODO Chak if should be all orchestration or only internal
            instrumentOrchestrations(pr_meta.getRuntimeLocation(), pr_meta.getAllOrchestrationClasses(),
                    classes, deps, myProgressMonitor);
            pr_meta.getRuntimeLocation();
        } catch (Exception e) {
            CoreException ce = new CoreException(
                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
            ce.setStackTrace(e.getStackTrace());
            throw (ce);
        }
    } else {
        throw (new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "metadata file not found")));
    }
}

From source file:org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider.java

public Source invoke(Source request) {
    Source response = null;/*from   ww w.  jav  a  2  s .c o m*/
    try {
        RequestSecurityTokenType rst = convertToJAXBObject(request);
        Object operationImpl = null;
        List<?> objectList = rst.getAny();
        for (int i = 0; i < objectList.size(); i++) {
            Object obj = objectList.get(i);
            if (obj instanceof JAXBElement) {
                QName qname = ((JAXBElement<?>) obj).getName();
                if (qname.equals(new QName(WSTRUST_13_NAMESPACE, WSTRUST_REQUESTTYPE_ELEMENTNAME))) {
                    operationImpl = operationMap.get(((JAXBElement<?>) obj).getValue().toString());
                    break;
                }

            }
        }

        if (operationImpl == null) {
            throw new Exception("Implementation for this operation not found.");
        }
        Method[] methods = operationImpl.getClass().getMethods();
        for (int x = 0; x < methods.length; x++) {
            Class<?>[] paramClass = methods[x].getParameterTypes();
            if (paramClass.length == 1 && paramClass[0].equals(rst.getClass())) {
                RequestSecurityTokenResponseCollectionType tokenResponse = (RequestSecurityTokenResponseCollectionType) methods[x]
                        .invoke(operationImpl, rst);
                if (tokenResponse == null) {
                    throw new Exception("Error in implementation class.");
                }

                response = new JAXBSource(jaxbContext,
                        new ObjectFactory().createRequestSecurityTokenResponseCollection(tokenResponse));
                return response;
            }
        }

    } catch (Exception e) {
        LOG.error(e);
        try {
            SOAPFault fault = soapFactory.createFault();
            if (e.getMessage() == null) {
                fault.setFaultString(e.getCause().getMessage());
            } else {
                fault.setFaultString(e.getMessage());
            }
            Detail detail = fault.addDetail();
            detail = fault.getDetail();
            QName qName = new QName(WSTRUST_13_NAMESPACE, "Fault", "ns");
            DetailEntry de = detail.addDetailEntry(qName);
            qName = new QName(WSTRUST_13_NAMESPACE, "ErrorCode", "ns");
            SOAPElement errorElement = de.addChildElement(qName);
            StackTraceElement[] ste = e.getStackTrace();
            errorElement.setTextContent(ste[0].toString());
            throw new SOAPFaultException(fault);
        } catch (SOAPException e1) {
            LOG.error(e1);
        }

    }

    return response;
}

From source file:edu.umn.cs.spatialHadoop.nasa.ShahedServer.java

private void reportError(HttpServletResponse response, String msg, Exception e) throws IOException {
    if (e != null)
        e.printStackTrace();/*from   w  w  w . j av  a  2s  .c  o m*/
    LOG.error(msg);
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.getWriter().println("{\"message\": '" + msg + "',");
    if (e != null) {
        response.getWriter().println("\"error\": '" + e.getMessage() + "',");
        response.getWriter().println("\"stacktrace\": [");
        for (StackTraceElement trc : e.getStackTrace()) {
            response.getWriter().println("'" + trc.toString() + "',");
        }
        response.getWriter().println("]");
    }
    response.getWriter().println("}");
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java

private void initializeJsonGenerator() throws IOException {
    try {/*w w  w.  ja va2 s.co m*/
        factory = new JsonFactory();
        jsonBuffer = new ByteArrayOutputStream(CAPACITY);
        generator = factory.createJsonGenerator(jsonBuffer);
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());
    }
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java

@Override
public void receive(ByteBuffer buf, String channelId) {
    try {/*from  w  w  w  .j a  va 2 s. co m*/
        buf.mark();
        int size = buf.remaining();
        if (size < 1)
            return;

        parseUsingStream(buf);
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());
    }
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java

private void startNewPolygon() throws IOException {
    try {/*from  ww w.  j a  v a2  s .  c  o m*/
        if (generator == null)
            initializeJsonGenerator();
        generator.writeStartObject();
        generator.writeArrayFieldStart("rings");
        generator.writeStartArray();
        firstVertex = true;
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());

    }
}

From source file:com.esri.geoevent.solutions.adapter.cot.CoTAdapterInbound.java

private NodeList unpackXML(String xml, String targetTag) throws Exception {
    try {// ww  w . j av  a  2 s . com
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource source = new InputSource();
        source.setCharacterStream(new StringReader(xml));
        Document doc = db.parse(source);
        NodeList nodeList = doc.getElementsByTagName(targetTag);
        return nodeList;
    } catch (Exception e) {
        log.error(e);
        log.error(e.getStackTrace());
        throw (e);
    }
}