Example usage for java.lang.reflect InvocationTargetException InvocationTargetException

List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException InvocationTargetException.

Prototype

public InvocationTargetException(Throwable target) 

Source Link

Document

Constructs a InvocationTargetException with a target exception.

Usage

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.CloudUiUtil.java

public static IStatus runForked(final ICoreRunnable coreRunner, IWizard wizard) {
    try {//from  w  ww .  j av  a2  s.co  m
        IRunnableWithProgress runner = new IRunnableWithProgress() {
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                try {
                    coreRunner.run(monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        wizard.getContainer().run(true, false, runner);
    } catch (InvocationTargetException e) {
        IStatus status;
        if (e.getCause() instanceof CoreException) {
            status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID,
                    NLS.bind(Messages.CloudUiUtil_ERROR_FORK_OP_FAILED, e.getCause().getMessage()), e);
        } else {
            status = new Status(IStatus.ERROR, DockerFoundryServerUiPlugin.PLUGIN_ID,
                    NLS.bind(Messages.CloudUiUtil_ERROR_FORK_UNEXPECTED, e.getMessage()), e);
        }
        DockerFoundryServerUiPlugin.getDefault().getLog().log(status);
        IWizardPage page = wizard.getContainer().getCurrentPage();
        if (page instanceof DialogPage) {
            ((DialogPage) page).setErrorMessage(status.getMessage());
        }
        return status;
    } catch (InterruptedException e) {
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:hudson.plugins.debt.parser.DebtParser.java

/** {@inheritDoc} */
@Override/*from www  . j  ava2s. c om*/
public Collection<FileAnnotation> parse(final InputStream file, final String moduleName)
        throws InvocationTargetException {

    System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>entered DebtParser.parse()");

    try {
        Digester digester = new Digester();
        digester.setValidating(false);
        digester.setClassLoader(DebtParser.class.getClassLoader());

        String rootXPath = "debt";
        digester.addObjectCreate(rootXPath, Debt.class);
        digester.addSetProperties(rootXPath);

        String fileXPath = "debt/file";
        digester.addObjectCreate(fileXPath, hudson.plugins.debt.parser.File.class);
        digester.addSetProperties(fileXPath);
        digester.addSetNext(fileXPath, "addFile", hudson.plugins.debt.parser.File.class.getName());

        String bugXPath = "debt/file/violation";
        digester.addObjectCreate(bugXPath, Violation.class);
        digester.addSetProperties(bugXPath);
        digester.addCallMethod(bugXPath, "setMessage", 0);
        digester.addSetNext(bugXPath, "addViolation", Violation.class.getName());

        Debt module = (Debt) digester.parse(file);
        if (module == null) {
            throw new SAXException("Input stream is not a valid Debt file.");
        }

        return convert(module, moduleName);
    } catch (IOException exception) {
        throw new InvocationTargetException(exception);
    } catch (SAXException exception) {
        throw new InvocationTargetException(exception);
    }
}

From source file:info.magnolia.ui.admincentral.AdmincentralErrorHandlerTest.java

@Test
public void testPreciseErrorMessage() {
    // GIVEN/*w  ww .ja v  a  2 s .  c  om*/
    final String lessPreciseDetails = "An unsupported exception happened.";
    final String mostPreciseDetails = "Consciously throwing some unsupported exception for this test.";
    Exception e = new InvocationTargetException(
            new RuntimeException(lessPreciseDetails, new UnsupportedOperationException(mostPreciseDetails)));

    // WHEN
    errorHandler.error(new ErrorEvent(e));

    // THEN
    assertEquals(1, messages.size());
    Message message = messages.get(0);

    assertTrue(StringUtils.isNotBlank(message.getSubject()));
    assertTrue(StringUtils.isNotBlank(message.getMessage()));
    assertEquals(mostPreciseDetails, message.getSubject());
    assertEquals(USER_NAME, message.getSender());
}

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();//www  .ja  va  2  s.  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.legstar.eclipse.plugin.schemagen.wizards.AbstractToXsdWizardRunnable.java

/**
 * Make sure the project is refreshed as the files were created outside the
 * Eclipse API. Request the workbench to open an editor on the newly created
 * Xsd file.//from   w w  w . j a va2 s .  c o m
 * 
 * @param monitor the current monitor
 * @param scale the scale of progress
 * @throws InvocationTargetException execution fails
 */
protected void editXsdFile(final IProgressMonitor monitor, final int scale) throws InvocationTargetException {
    monitor.setTaskName(Messages.editor_opening_task_label);
    try {
        ((IContainer) getProject(mTargetContainer)).refreshLocal(IResource.DEPTH_INFINITE,
                new SubProgressMonitor(monitor, 1 * scale));
        if (getXsdFile() == null) {
            Throwable th = new AntLaunchException(
                    NLS.bind(Messages.ant_failure_console_msg, getTargetXsdFileName()));
            throw new InvocationTargetException(th);
        }
        Shell shell = mWizard.getContainer().getShell();
        shell.getDisplay().asyncExec(new Runnable() {
            public void run() {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                try {
                    IDE.openEditor(page, getXsdFile(), true);
                } catch (PartInitException e) {
                    AbstractWizard.logCoreException(e, Activator.PLUGIN_ID);
                }
            }
        });
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:gov.loc.www.zing.srw.srw_bindings.SRWSoapBindingImpl.java

public Stream searchRetrieveOperation(de.escidoc.core.domain.sru.SearchRetrieveRequestType request,
        MessageContext msgContext, String handle) throws RemoteException {
    log.debug("Enter: searchRetrieveOperation");
    if (log.isInfoEnabled()) {
        log.info("request: maximumRecords:" + request.getMaximumRecords() + " query:" + request.getQuery()
                + " recordPacking:" + request.getRecordPacking() + " recordSchema:" + request.getRecordSchema()
                + " recordXpath:" + request.getRecordXPath() + " sortKeys:" + request.getSortKeys()
                + " startRecord:" + request.getStartRecord() + " stylesheet:" + request.getStylesheet()
                + " version:" + request.getVersion());
    }/*from w  ww  . j ava  2 s  .c o  m*/
    long startTime = System.currentTimeMillis();
    try {
        UserContext.setUserContext(handle);
        try {
            UserContext.getSecurityContext();
        } catch (SystemException e1) {
            throw new InvocationTargetException(e1);
        }
    } catch (Exception ex) {
    }
    RestSearchRetrieveResponseType response = null;
    int resultSetIdleTime = ((Integer) msgContext.getProperty("resultSetIdleTime")).intValue();
    NonNegativeInteger nni = request.getResultSetTTL();
    if (log.isDebugEnabled())
        log.debug("resultSetTTL()=" + nni);
    if (nni != null) {
        int ttl = nni.intValue();
        log.debug("ttl=" + ttl);
        if (ttl < resultSetIdleTime)
            resultSetIdleTime = ttl;
    }
    String dbname = (String) msgContext.getProperty("dbname");
    SRWDatabase db = (SRWDatabase) msgContext.getProperty("db");
    if (log.isDebugEnabled())
        log.debug("db=" + db);

    String sortKeys = request.getSortKeys();
    if (sortKeys != null)
        request.setSortKeys(sortKeys);

    String query = request.getQuery();
    if (query.indexOf('%') >= 0) {
        try {
            request.setQuery(java.net.URLDecoder.decode(query, "utf-8"));
        } catch (java.io.UnsupportedEncodingException e) {
        }
    }

    try {
        if (query == null) {
            response = new RestSearchRetrieveResponseType();
            response.setSearchRetrieveResponse(new de.escidoc.core.domain.sru.SearchRetrieveResponseType());
            db.diagnostic(SRWDiagnostic.MandatoryParameterNotSupplied, "query",
                    response.getSearchRetrieveResponse());
        } else if (request.getStartRecord() != null
                && request.getStartRecord().intValue() == Integer.MAX_VALUE) {
            response = new RestSearchRetrieveResponseType();
            response.setSearchRetrieveResponse(new de.escidoc.core.domain.sru.SearchRetrieveResponseType());
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue, "startRecord",
                    response.getSearchRetrieveResponse());
        } else if (request.getMaximumRecords() != null
                && request.getMaximumRecords().intValue() == Integer.MAX_VALUE) {
            response = new RestSearchRetrieveResponseType();
            response.setSearchRetrieveResponse(new de.escidoc.core.domain.sru.SearchRetrieveResponseType());
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue, "maximumRecords",
                    response.getSearchRetrieveResponse());
        } else if (request.getResultSetTTL() != null
                && request.getResultSetTTL().intValue() == Integer.MAX_VALUE) {
            response = new RestSearchRetrieveResponseType();
            response.setSearchRetrieveResponse(new de.escidoc.core.domain.sru.SearchRetrieveResponseType());
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue, "resultSetTTL",
                    response.getSearchRetrieveResponse());
        } else {
            try {
                response = db.doRequest(request);
                if (response == null) {
                    response = new RestSearchRetrieveResponseType();
                    response.setSearchRetrieveResponse(
                            new de.escidoc.core.domain.sru.SearchRetrieveResponseType());
                    response.getSearchRetrieveResponse().setVersion("1.1");
                    setEchoedSearchRetrieveRequestType(request, response.getSearchRetrieveResponse());
                    db.diagnostic(SRWDiagnostic.GeneralSystemError, null, response.getSearchRetrieveResponse());
                    return response.toStream(db, true);
                }
                if (msgContext.getProperty("sru") != null && request.getStylesheet() != null) // you can't ask for
                    // a stylesheet in
                    // srw!
                    db.diagnostic(SRWDiagnostic.StylesheetsNotSupported, null,
                            response.getSearchRetrieveResponse());

                setEchoedSearchRetrieveRequestType(request, response.getSearchRetrieveResponse());
                if (request.getRecordXPath() != null)
                    db.diagnostic(72, null, response.getSearchRetrieveResponse());
                if (request.getSortKeys() != null && !request.getSortKeys().equals("") && !db.supportsSort())
                    db.diagnostic(SRWDiagnostic.SortNotSupported, null, response.getSearchRetrieveResponse());

                // set extraResponseData
                ExtraDataTO extraDataTo = new ExtraDataTO();

                // we're going to stick the database name in extraResponseData
                // every time
                if (db.databaseTitle != null)
                    extraDataTo.setDatabaseTitle(db.databaseTitle);
                else
                    extraDataTo.setDatabaseTitle(dbname);

                // did they ask for the targetURL to be returned?
                Hashtable extraRequestDataElements = SRWDatabase.parseElements(request.getExtraRequestData());
                String s = (String) extraRequestDataElements.get("returnTargetURL");
                log.info("returnTargetURL=" + s);
                if (s != null && !s.equals("false")) {
                    String targetStr = (String) msgContext.getProperty("targetURL");
                    log.info("targetStr=" + targetStr);
                    if (targetStr != null && targetStr.length() > 0) {
                        URL target = new URL(targetStr);
                        TargetUrlTO targetUrlTo = new TargetUrlTO();
                        targetUrlTo.setHost(target.getHost());
                        targetUrlTo.setPort(Integer.toString(target.getPort()));
                        targetUrlTo.setPath(target.getPath());
                        targetUrlTo.setQuery(Utilities.xmlEncode(target.getQuery()));
                        extraDataTo.setTargetURL(targetUrlTo);
                    }
                }

                // set extraResponseData
                SRWDatabase.setExtraResponseData(response.getSearchRetrieveResponse(), extraDataTo);
            } catch (Exception e) {
                log.error(e, e);
                throw new RemoteException(e.getMessage(), e);
            } finally {
                SRWDatabase.putDb(dbname, db);
            }
            response.getSearchRetrieveResponse().setVersion("1.1");
            log.info("\"" + query + "\"==>" + response.getSearchRetrieveResponse().getNumberOfRecords() + " ("
                    + (System.currentTimeMillis() - startTime) + "ms)");
            log.debug("Exit: searchRetrieveOperation");
            return response.toStream(db, true);
        }
    } catch (Exception e) {
        throw new RemoteException(e.getMessage(), e);
    }
    response.getSearchRetrieveResponse().setVersion("1.1");
    log.info("\"" + query + "\"==>" + response.getSearchRetrieveResponse().getNumberOfRecords() + " ("
            + (System.currentTimeMillis() - startTime) + "ms)");
    log.debug("Exit: searchRetrieveOperation");
    return response.toStream(db, true);
}

From source file:com.google.gdt.eclipse.designer.actions.deploy.DeployModuleAction.java

@Override
protected void runWithSelectedModule() throws Exception {
    final DeployDialog deployDialog = new DeployDialog(DesignerPlugin.getShell(), Activator.getDefault(),
            m_selectedModule);//from   w  ww.  j a  v a2 s  .  c  o m
    if (deployDialog.open() != Window.OK) {
        return;
    }
    //
    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                monitor.beginTask("Deployment of module '" + m_selectedModule.getId() + "'", 1);
                // create script
                {
                    monitor.worked(1);
                    createBuildScript(deployDialog);
                }
                // execute script
                {
                    IProject project = m_selectedModule.getProject();
                    IFolder targetFolder = m_selectedModule.getModuleFolder();
                    File buildFile = targetFolder.getFile("build.xml").getLocation().toFile();
                    AntHelper antHelper = new AntHelper(buildFile, project.getLocation().toFile());
                    antHelper.execute(monitor);
                }
            } catch (Throwable e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(DesignerPlugin.getShell());
    progressMonitorDialog.run(true, false, runnableWithProgress);
}

From source file:com.jaspersoft.studio.server.editor.ReportRunControler.java

public void setReportUnit(String key) {
    if (!key.equals(reportUnit)) {
        repExec = new ReportExecution();
        repExec.setStatus("queued"); //$NON-NLS-1$
        repExec.setReportURIFull(key);//from  w  w  w  .j a v  a  2 s.  c  om
        repExec.setReportURI(WSClientHelper.getReportUnitUri(key));
    }
    this.reportUnit = key;
    if (viewmap != null && prmInput == null) {
        try {
            icm = new InputControlsManager();
            ProgressMonitorDialog pm = new ProgressMonitorDialog(UIUtils.getShell());

            pm.run(true, true, new IRunnableWithProgress() {
                public void run(final IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(com.jaspersoft.studio.messages.Messages.ReportRunControler_1,
                            IProgressMonitor.UNKNOWN);
                    try {
                        cli = WSClientHelper.getClient(monitor, reportUnit);
                        icm.setWsclient(cli);
                        icm.initInputControls(
                                cli.initInputControls(reportUnit, ResourceDescriptor.TYPE_REPORTUNIT, monitor));

                        // TODO search all the repository
                        icm.getDefaults();
                        UIUtils.getDisplay().syncExec(new Runnable() {
                            public void run() {
                                if (viewmap != null)
                                    fillForms(monitor);
                                runReport();
                            }
                        });
                    } catch (Throwable e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        monitor.done();
                    }
                }

            });
        } catch (InvocationTargetException e) {
            UIUtils.showError(e.getCause());
        } catch (InterruptedException e) {
            UIUtils.showError(e);
        } catch (Exception e1) {
            UIUtils.showError(e1);
        }
    } else {
        runReport();
    }
}

From source file:com.jaspersoft.studio.server.dnd.RepositoryDNDHelper.java

public static void performDropOperation(final MResource targetParentResource, final String fullFilename) {
    final File file = new File(fullFilename);
    final String suggestedId = FilenameUtils.removeExtension(file.getName());
    final String suggestedName = FilenameUtils.removeExtension(file.getName());
    final String fileExt = Misc.nvl(FilenameUtils.getExtension(fullFilename)).toLowerCase();

    try {/*from ww  w .j  ava  2s  .c  o m*/
        ProgressMonitorDialog pm = new ProgressMonitorDialog(UIUtils.getShell());
        pm.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask(NLS.bind(Messages.RepositoryDNDHelper_SavingResourceTask, fullFilename),
                            IProgressMonitor.UNKNOWN);
                    // Gets a list of all siblings of the future resource
                    // This will allow to compute correct ID and NAME information for
                    // the
                    // ResourceDescriptor
                    List<ResourceDescriptor> childrenDescriptors = WSClientHelper.listFolder(
                            targetParentResource, WSClientHelper.getClient(monitor, targetParentResource),
                            targetParentResource.getValue().getUriString(), new NullProgressMonitor(), 0);
                    // Create the ResourceDescriptor depending on this kind (use file
                    // extension)
                    ResourceDescriptor newRD = getResourceDescriptor(targetParentResource, fileExt);
                    // Update the NAME and ID for the ResourceDescriptor
                    ResourceDescriptorUtil.setProposedResourceDescriptorIDAndName(childrenDescriptors, newRD,
                            suggestedId, suggestedName);
                    // Create and save the resource
                    final AFileResource fileResource = createNewFileResource(targetParentResource, newRD,
                            fileExt);
                    fileResource.setFile(file);

                    monitor.setTaskName(
                            NLS.bind(Messages.RepositoryDNDHelper_SavingResourceTask, fullFilename));
                    WSClientHelper.saveResource(fileResource, monitor);
                } catch (Throwable e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }

        });
    } catch (Exception e) {
        UIUtils.showError(e);
    }
}

From source file:es.bsc.servicess.ide.editors.deployers.LocalhostDeployer.java

@Override
public void deploy() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {//  www .j  av a  2 s  .  c o  m
        dialog.run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    executeDeployment(monitor);
                } catch (Exception e) {
                    throw (new InvocationTargetException(e));
                }
            }
        });
    } catch (InterruptedException e) {
        ErrorDialog.openError(super.getShell(), "Error", "Deploying the service",
                new StatusInfo(IStatus.ERROR, e.getMessage()));
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(super.getShell(), "Error", "Deploying the service",
                new StatusInfo(IStatus.ERROR, e.getMessage()));
        e.printStackTrace();
    }
}