Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.googlecode.osde.internal.ui.wizards.export.OpenSocialApplicationExportWizard.java

private void export() {
    final IProject project = page.getProject();
    final String url = page.getUrl();
    final String output = page.getOutput();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ZipOutputStream out = null;
            try {
                ResourceCounter resourceCounter = new ResourceCounter();
                project.accept(resourceCounter);
                int fileCount = resourceCounter.getFileCount();
                monitor.beginTask("Exporting application", fileCount);
                out = new ZipOutputStream(new FileOutputStream(new File(output)));
                project.accept(new ApplicationExporter(out, project, url, monitor));
                monitor.done();//from  w  ww .j  av  a  2s  .c  o  m
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    };
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(),
                    "Error occurred when exporting application.", cause));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    "Error occurred when exporting application.");
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(
                    StatusUtil.newStatus(IStatus.WARNING, "Error occurred when exporting application.", t));
            status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY,
                    "Error occurred when exporting application.");
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        }
    }
}

From source file:com.jaeksoft.searchlib.web.AbstractServlet.java

final private void doRequest(HttpServletRequest request, Method method, HttpServletResponse response) {

    ServletTransaction transaction = new ServletTransaction(this, request, method, response);

    StringWriter sw = null;//w  w  w.j  a  v a  2s. c  o m
    PrintWriter pw = null;
    try {
        ClientFactory.INSTANCE.properties.checkApi();
        buildUrls(request);
        doRequest(transaction);
    } catch (Exception e) {
        transaction.addXmlResponse(XML_CALL_KEY_STATUS, XML_CALL_KEY_STATUS_ERROR);
        transaction.addXmlResponse(XML_CALL_KEY_EXCEPTION, e.toString());
        sw = new StringWriter();
        pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        Throwable t = e;
        while ((t = t.getCause()) != null) {
            pw.println("Caused by...");
            t.printStackTrace(pw);
        }
        transaction.addXmlResponse(XML_CALL_KEY_TRACE, sw.toString());
        Logging.error(e);
    } finally {
        IOUtils.close(pw, sw);
        try {
            transaction.writeXmlResponse();
        } catch (Exception e) {
            try {
                Logging.error(e.getMessage(), e);
                response.sendError(500, e.getMessage());
            } catch (IOException e1) {
                Logging.warn(e1.getMessage(), e1);
            }
        }
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.BaseService.java

/**
 * Loads the service context.//from   w w  w  . j a va 2  s  . co  m
 * 
 * @throws ServiceException thrown if the configuration for this service could not be loaded
 */
protected void loadContext() throws ServiceException {
    log.info("Loading new configuration for service {}", getId());

    if (serviceConfigurations == null || serviceConfigurations.isEmpty()) {
        setInitialized(true);
        return;
    }

    GenericApplicationContext newServiceContext = new GenericApplicationContext(getApplicationContext());
    newServiceContext.setDisplayName("ApplicationContext:" + getId());
    Lock writeLock = getReadWriteLock().writeLock();
    writeLock.lock();
    try {
        SpringConfigurationUtils.populateRegistry(newServiceContext, getServiceConfigurations());
        newServiceContext.refresh();

        GenericApplicationContext replacedServiceContext = serviceContext;
        onNewContextCreated(newServiceContext);
        setServiceContext(newServiceContext);
        setInitialized(true);
        if (replacedServiceContext != null) {
            replacedServiceContext.close();
        }
        log.info("{} service loaded new configuration", getId());
    } catch (Throwable e) {
        // Here we catch all the other exceptions thrown by Spring when it starts up the context
        setInitialized(false);
        Throwable rootCause = e;
        while (rootCause.getCause() != null) {
            rootCause = rootCause.getCause();
        }
        log.error("Configuration was not loaded for " + getId()
                + " service, error creating components.  The root cause of this error was: "
                + rootCause.getClass().getCanonicalName() + ": " + rootCause.getMessage());
        log.trace("Full stacktrace is: ", e);
        throw new ServiceException(
                "Configuration was not loaded for " + getId() + " service, error creating components.",
                rootCause);
    } finally {
        writeLock.unlock();
    }
}

From source file:com.haulmont.cuba.desktop.exception.ConnectExceptionHandler.java

@Override
public boolean handle(Thread thread, Throwable exception) {
    @SuppressWarnings("unchecked")
    List<Throwable> list = ExceptionUtils.getThrowableList(exception);
    for (Throwable throwable : list) {
        if (throwable instanceof RemoteAccessException) {
            Messages messages = AppBeans.get(Messages.NAME);
            String msg = messages.getMessage(getClass(), "connectException.message");
            if (throwable.getCause() == null) {
                App.getInstance().getMainFrame().showNotification(msg, Frame.NotificationType.ERROR);
            } else {
                String description = messages.formatMessage(getClass(), "connectException.description",
                        throwable.getCause().toString());
                App.getInstance().getMainFrame().showNotification(msg, description,
                        Frame.NotificationType.ERROR);
            }//from w w  w. j  ava2s  . c om
            return true;
        }
    }
    return false;
}

From source file:lib.Global.java

@Override
public F.Promise<Result> onError(Http.RequestHeader request, Throwable t) {
    if (t.getCause() instanceof Graylog2MasterUnavailableException) {
        final ServerNodes serverNodes = injector.getInstance(ServerNodes.class);
        final List<Node> configuredNodes = serverNodes.getConfiguredNodes();
        final List<Node> nodesEverConnectedTo = serverNodes.all(true);

        return F.Promise.<Result>pure(internalServerError(views.html.disconnected.no_master
                .render(Http.Context.current(), configuredNodes, nodesEverConnectedTo, serverNodes)));
    }//from w ww . java 2s  .  co  m
    return super.onError(request, t);
}

From source file:com.mirth.connect.plugins.directoryresource.DirectoryResourcePropertiesPanel.java

@Override
public void setProperties(ResourceProperties properties) {
    final DirectoryResourceProperties props = (DirectoryResourceProperties) properties;
    directoryField.setText(props.getDirectory());
    includeSubdirectoriesCheckBox.setSelected(props.isDirectoryRecursion());
    descriptionTextPane.setText(props.getDescription());

    final String workingId = PlatformUI.MIRTH_FRAME.startWorking("Loading libraries...");

    SwingWorker<List<String>, Void> worker = new SwingWorker<List<String>, Void>() {

        @Override/*  ww  w.  ja  v a2  s .c  om*/
        public List<String> doInBackground() throws ClientException {
            return (List<String>) PlatformUI.MIRTH_FRAME.mirthClient
                    .getServlet(DirectoryResourceServletInterface.class).getLibraries(props.getId());
        }

        @Override
        public void done() {
            try {
                List<String> libraries = get();
                if (libraries == null) {
                    libraries = new ArrayList<String>();
                }

                Object[][] data = new Object[libraries.size()][1];
                int i = 0;

                for (String library : libraries) {
                    data[i++][0] = library;
                }

                ((RefreshTableModel) libraryTable.getModel()).refreshDataVector(data);
            } catch (Throwable t) {
                if (t instanceof ExecutionException) {
                    t = t.getCause();
                }
                PlatformUI.MIRTH_FRAME.alertThrowable(PlatformUI.MIRTH_FRAME, t,
                        "Error loading libraries: " + t.toString());
            } finally {
                PlatformUI.MIRTH_FRAME.stopWorking(workingId);
            }
        }
    };

    worker.execute();
}

From source file:jp.co.opentone.bsol.linkbinder.view.exception.LinkBinderExceptionHandler.java

FacesMessage createFatalMessage(Throwable e) {
    if (e.getCause() == null) {
        FacesMessage m = new FacesMessage();
        m.setSeverity(FacesMessage.SEVERITY_FATAL);
        m.setSummary(m.getSeverity().toString());
        m.setDetail(String.format("Unhandled exception : %s", e.getClass().getSimpleName()));
        return m;
    } else {/* w  ww.j  a  v a  2  s.  c o  m*/
        return createFatalMessage(e.getCause());
    }
}

From source file:com.conversantmedia.mapreduce.tool.AnnotatedTool.java

/**
 * Walks up the tree until we get a root cause that's not an InvocationTargetExcption
 * @param exception//  www .j a va 2 s.c  o m
 * @return
 */
private Throwable findRootException(Throwable exception) {
    if (exception instanceof InvocationTargetException && exception.getCause() != null) {
        return findRootException(exception.getCause());
    }
    return exception;
}

From source file:org.onehippo.forge.camel.demo.rest.services.AbstractRestUpdateResource.java

/**
 * Creates a generic JAX-RS Error Response from the given error.
 * @param th//from  w w  w.j  ava2  s.  c  om
 * @return
 */
protected Response buildServerErrorResponse(Throwable th) {
    return Response.serverError().entity(th.getCause() != null ? th.getCause().toString() : th.toString())
            .build();
}

From source file:fedora.server.security.servletfilters.Base.java

public final void showThrowable(Throwable th, Log log, String msg) {
    if (log.isErrorEnabled()) {
        if (msg != null) {
            log.error(msg);/*from  w w  w . j  av a 2  s. c  o  m*/
        }
        log.error(th);
        log.error(th.getMessage());
        if (th.getCause() != null) {
            log.error(th.getCause().getMessage());
        }
        th.printStackTrace();
    }
}