Example usage for java.lang.reflect InvocationTargetException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Browser.java

/**
 * Attempts to locate the default web browser on the local system.  
 * Caches results so it only locates the browser once for each use of this 
 * class per JVM instance.//from   ww w .  j  a  v a 2 s.  co  m
 *
 * @return The browser for the system.  Note that this may not be what you 
 * would consider to be a standard web browser; instead, it's the 
 * application that gets called to open the default web browser.  In some 
 * cases, this will be a non-String object that provides the means of 
 * calling the default browser.
 */
private static Object locateBrowser() {
    if (browser != null) {
        return browser;
    }
    switch (jvm) {
    case MRJ_2_0:
        try {
            Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] { FINDER_CREATOR });
            Object aeTarget = aeTargetConstructor.newInstance(new Object[] { finderCreatorCode });
            Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] { GURL_EVENT });
            Object appleEvent = appleEventConstructor.newInstance(
                    new Object[] { gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID });

            // Don't set browser = appleEvent because then the next time we call
            // locateBrowser(), we'll get the same AppleEvent, to which we'll 
            // already have added the relevant parameter. Instead, regenerate 
            // the AppleEvent every time. There's probably a way to do this 
            // better; if any has any ideas, please let me know.

            return appleEvent;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InstantiationException ie) {
            browser = null;
            errorMessage = ie.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getMessage();
            return browser;
        }

    case MRJ_2_1:
        File systemFolder;
        try {
            systemFolder = (File) findFolder.invoke(null, new Object[] { kSystemFolderType });
        } catch (IllegalArgumentException iare) {
            browser = null;
            errorMessage = iare.getMessage();
            return browser;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
            return browser;
        }

        // Avoid a FilenameFilter because that can't be stopped mid-list
        String[] systemFolderFiles = systemFolder.list();

        for (int i = 0; i < systemFolderFiles.length; i++) {
            try {
                File file = new File(systemFolder, systemFolderFiles[i]);
                if (!file.isFile()) {
                    continue;
                }
                // We're looking for a file with a creator code of 'MACS' and
                // a type of 'FNDR'.  Only requiring the type results in non-Finder
                // applications being picked up on certain Mac OS 9 systems,
                // especially German ones, and sending a GURL event to those
                // applications results in a logout under Multiple Users.
                Object fileType = getFileType.invoke(null, new Object[] { file });
                if (FINDER_TYPE.equals(fileType.toString())) {
                    Object fileCreator = getFileCreator.invoke(null, new Object[] { file });
                    if (FINDER_CREATOR.equals(fileCreator.toString())) {
                        // Actually the Finder, but that's OK
                        browser = file.toString();
                        return browser;
                    }
                }
            } catch (IllegalArgumentException iare) {
                browser = browser;
                errorMessage = iare.getMessage();
                return null;
            } catch (IllegalAccessException iae) {
                browser = null;
                errorMessage = iae.getMessage();
                return browser;
            } catch (InvocationTargetException ite) {
                browser = null;
                errorMessage = ite.getTargetException().getClass() + ": "
                        + ite.getTargetException().getMessage();
                return browser;
            }
        }
        browser = null;
        break;

    case MRJ_3_0:
    case MRJ_3_1:
        browser = ""; // Return something non-null
        break;

    case WINDOWS_NT:
        browser = "cmd.exe";
        break;

    case WINDOWS_9x:
        browser = "command.com";
        break;

    case OTHER:
    default:
        browser = "netscape";
        break;
    }

    return browser;
}

From source file:fxts.stations.util.BrowserLauncher.java

/**
 * Attempts to locate the default web browser on the local system.  Caches results so it
 * only locates the browser once for each use of this class per JVM instance.
 *
 * @return The browser for the system.  Note that this may not be what you would consider
 *         to be a standard web browser; instead, it's the application that gets called to
 *         open the default web browser.  In some cases, this will be a non-String object
 *         that provides the means of calling the default browser.
 *//*from  w  ww . j a  v a 2  s.  c o  m*/
private static Object locateBrowser() {
    if (browser != null) {
        return browser;
    }
    switch (jvm) {
    case MRJ_2_0:
        try {
            Integer finderCreatorCode = (Integer) makeOSType.invoke(null, new Object[] { FINDER_CREATOR });
            Object aeTarget = aeTargetConstructor.newInstance(new Object[] { finderCreatorCode });
            Integer gurlType = (Integer) makeOSType.invoke(null, new Object[] { GURL_EVENT });
            Object appleEvent = appleEventConstructor.newInstance(
                    new Object[] { gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID });
            // Don't set browser = appleEvent because then the next time we call
            // locateBrowser(), we'll get the same AppleEvent, to which we'll already have
            // added the relevant parameter. Instead, regenerate the AppleEvent every time.
            // There's probably a way to do this better; if any has any ideas, please let
            // me know.
            return appleEvent;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InstantiationException ie) {
            browser = null;
            errorMessage = ie.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getMessage();
            return browser;
        }
    case MRJ_2_1:
        File systemFolder;
        try {
            systemFolder = (File) findFolder.invoke(null, new Object[] { kSystemFolderType });
        } catch (IllegalArgumentException iare) {
            browser = null;
            errorMessage = iare.getMessage();
            return browser;
        } catch (IllegalAccessException iae) {
            browser = null;
            errorMessage = iae.getMessage();
            return browser;
        } catch (InvocationTargetException ite) {
            browser = null;
            errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
            return browser;
        }
        String[] systemFolderFiles = systemFolder.list();
        // Avoid a FilenameFilter because that can't be stopped mid-list
        for (int i = 0; i < systemFolderFiles.length; i++) {
            try {
                File file = new File(systemFolder, systemFolderFiles[i]);
                if (!file.isFile()) {
                    continue;
                }
                // We're looking for a file with a creator code of 'MACS' and
                // a type of 'FNDR'.  Only requiring the type results in non-Finder
                // applications being picked up on certain Mac OS 9 systems,
                // especially German ones, and sending a GURL event to those
                // applications results in a logout under Multiple Users.
                Object fileType = getFileType.invoke(null, new Object[] { file });
                if (FINDER_TYPE.equals(fileType.toString())) {
                    Object fileCreator = getFileCreator.invoke(null, new Object[] { file });
                    if (FINDER_CREATOR.equals(fileCreator.toString())) {
                        browser = file.toString(); // Actually the Finder, but that's OK
                        return browser;
                    }
                }
            } catch (IllegalArgumentException iare) {
                browser = browser;
                errorMessage = iare.getMessage();
                return null;
            } catch (IllegalAccessException iae) {
                browser = null;
                errorMessage = iae.getMessage();
                return browser;
            } catch (InvocationTargetException ite) {
                browser = null;
                errorMessage = ite.getTargetException().getClass() + ": "
                        + ite.getTargetException().getMessage();
                return browser;
            }
        }
        browser = null;
        break;
    case MRJ_3_0:
    case MRJ_3_1:
        browser = ""; // Return something non-null
        break;
    case WINDOWS_NT:
        browser = "cmd.exe";
        break;
    case WINDOWS_9x:
        browser = "command.com";
        break;
    case OTHER:
    default:
        browser = "netscape";
        break;
    }
    return browser;
}

From source file:fxts.stations.util.BrowserLauncher.java

/**
 * Attempts to open the default web browser to the given URL.
 *
 * @param url The URL to open//from w  w w. j  a va  2 s . c  om
 *
 * @throws IOException If the web browser could not be located or does not run
 */
public static void openURL(String url) throws IOException {
    if (!loadedWithoutErrors) {
        throw new IOException("Exception in finding browser: " + errorMessage);
    }
    Object browser = locateBrowser();
    if (browser == null) {
        throw new IOException("Unable to locate browser: " + errorMessage);
    }
    switch (jvm) {
    case MRJ_2_0:
        Object aeDesc = null;
        try {
            aeDesc = aeDescConstructor.newInstance(new Object[] { url });
            putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
            sendNoReply.invoke(browser, new Object[] {});
        } catch (InvocationTargetException ite) {
            throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
        } catch (IllegalAccessException iae) {
            throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
        } catch (InstantiationException ie) {
            throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
        } finally {
            aeDesc = null; // Encourage it to get disposed if it was created
            browser = null; // Ditto
        }
        break;
    case MRJ_2_1:
        Runtime.getRuntime().exec(new String[] { (String) browser, url });
        break;
    case MRJ_3_0:
        int[] instance = new int[1];
        int result = ICStart(instance, 0);
        if (result == 0) {
            int[] selectionStart = new int[] { 0 };
            byte[] urlBytes = url.getBytes();
            int[] selectionEnd = new int[] { urlBytes.length };
            result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart,
                    selectionEnd);
            if (result == 0) {
                // Ignore the return value; the URL was launched successfully
                // regardless of what happens here.
                ICStop(instance);
            } else {
                throw new IOException("Unable to launch URL: " + result);
            }
        } else {
            throw new IOException("Unable to create an Internet Config instance: " + result);
        }
        break;
    case MRJ_3_1:
        try {
            openURL.invoke(null, new Object[] { url });
        } catch (InvocationTargetException ite) {
            throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
        } catch (IllegalAccessException iae) {
            throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
        }
        break;
    case WINDOWS_NT:
    case WINDOWS_9x:
        // cmd = 'rundll32 url.dll,FileProtocolHandler http://...'
        Process process = Runtime.getRuntime().exec(WIN_PATH + " " + WIN_FLAG + " " + url);
        // This avoids a memory leak on some versions of Java on Windows.
        // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
        try {
            process.waitFor();
            process.exitValue();
        } catch (InterruptedException ie) {
            throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
        }
        break;
    case OTHER:
        // Assume that we're on Unix and that Netscape is installed

        // First, attempt to open the URL in a currently running session of Netscape
        process = Runtime.getRuntime().exec(new String[] { (String) browser, NETSCAPE_REMOTE_PARAMETER,
                NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END });
        try {
            int exitCode = process.waitFor();
            if (exitCode != 0) { // if Netscape was not open
                Runtime.getRuntime().exec(new String[] { (String) browser, url });
            }
        } catch (InterruptedException ie) {
            throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
        }
        break;
    default:
        // This should never occur, but if it does, we'll try the simplest thing possible
        Runtime.getRuntime().exec(new String[] { (String) browser, url });
        break;
    }
}

From source file:Browser.java

/**
 * Open the specified URL in the client web browser.
 * /*  w  w w.  j  av  a  2s . c o  m*/
 * @param url  URL to open.
 * @throws     IOException If there is brwoser problem.   
 */
public static void openUrl(String url) throws IOException {
    if (!loadedWithoutErrors) {
        throw new IOException("Exception in finding browser: " + errorMessage);
    }
    Object browser = locateBrowser();
    if (browser == null) {
        throw new IOException("Unable to locate browser: " + errorMessage);
    }

    switch (jvm) {
    case MRJ_2_0:
        Object aeDesc = null;
        try {
            aeDesc = aeDescConstructor.newInstance(new Object[] { url });
            putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
            sendNoReply.invoke(browser, new Object[] {});
        } catch (InvocationTargetException ite) {
            throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
        } catch (IllegalAccessException iae) {
            throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
        } catch (InstantiationException ie) {
            throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
        } finally {
            aeDesc = null; // Encourage it to get disposed if it was created
            browser = null; // Ditto
        }
        break;

    case MRJ_2_1:
        Runtime.getRuntime().exec(new String[] { (String) browser, url });
        break;

    case MRJ_3_0:
        int[] instance = new int[1];
        int result = ICStart(instance, 0);
        if (result == 0) {
            int[] selectionStart = new int[] { 0 };
            byte[] urlBytes = url.getBytes();
            int[] selectionEnd = new int[] { urlBytes.length };
            result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart,
                    selectionEnd);
            if (result == 0) {
                // Ignore the return value; the URL was launched successfully
                // regardless of what happens here.
                ICStop(instance);
            } else {
                throw new IOException("Unable to launch URL: " + result);
            }
        } else {
            throw new IOException("Unable to create an Internet Config instance: " + result);
        }
        break;

    case MRJ_3_1:
        try {
            openURL.invoke(null, new Object[] { url });
        } catch (InvocationTargetException ite) {
            throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
        } catch (IllegalAccessException iae) {
            throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
        }
        break;

    case WINDOWS_NT:
    case WINDOWS_9x:
        // Add quotes around the URL to allow ampersands and other special
        // characters to work.
        Process process = Runtime.getRuntime().exec(new String[] { (String) browser, FIRST_WINDOWS_PARAMETER,
                SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' });

        // This avoids a memory leak on some versions of Java on Windows.
        // That's hinted at in <http://developer.java.sun.com/developer/qow/
        // archive/68/>.
        try {
            process.waitFor();
            process.exitValue();
        } catch (InterruptedException ie) {
            throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
        }
        break;

    case OTHER:
        // Assume that we're on Unix and that Netscape is installed
        // First, attempt to open the URL in a currently running session of 
        // Netscape
        String command = browser.toString() + " -raise " + NETSCAPE_REMOTE_PARAMETER + " "
                + NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END;

        process = Runtime.getRuntime().exec(command);

        try {
            int exitCode = process.waitFor();
            if (exitCode != 0) { // if Netscape was not open
                Runtime.getRuntime().exec(new String[] { (String) browser, url });
            }
        } catch (InterruptedException exception) {
            exception.printStackTrace();
            throw new IOException("InterruptedException while launching browser: " + exception.getMessage());
        }
        break;
    default:
        // This should never occur, but if it does, we'll try the simplest 
        // thing possible
        Runtime.getRuntime().exec(new String[] { (String) browser, url });
        break;
    }
}

From source file:org.cesecore.keys.token.p11.Pkcs11SlotLabel.java

/**
 * Creating dummy provider just to have C_Initialize executed with multiple
 * thread argument. {@link Pkcs11Wrapper#getInstance(File)} should call it
 * before making any PKCS#11 calls. If not then C_Initialize will be called
 * with null argument causing multi threading to be disabled for the token.
 * //from   w w w.  j  a  va 2  s  . c o  m
 * There is a boolean in the sun code ensuring that C_Initialize is only
 * called once.
 * To check this implementation the p11 spy utils could be used. Check that
 * it is only one C_Initialize call and that null is not passed.
 * @param a file with the path of the p11 module on which C_Finalize should
 * be called.
 */
static void doC_Initialize(final File libFile) {
    try {
        getSunP11ProviderNoExceptionHandeling(
                getSunP11ProviderInputStream(-1, libFile, Pkcs11SlotLabelType.SLOT_NUMBER, null, null));
    } catch (InvocationTargetException e) {
        // the p11 module don't like the bogus arguments and throws an exception but we don't bother about this since
        // C_Initialize has already been called with multithread arguments.
        log.debug("Get dummy sun provider throws an exception. This is OK.", e);
    } catch (Exception e) {
        final String msg = "Error constructing pkcs11 provider: " + e.getMessage();
        log.error(msg);
        throw new IllegalStateException(msg, e);
    }
}

From source file:net.iaeste.iws.core.transformers.CSVTransformer.java

/**
 * <p>Reflective invocation of the Object Setter methods. To enforce the
 * Setter Validation checks on the values. Required to avoid that illegal
 * values is being processed.</p>/* www . jav a  2 s .  com*/
 *
 * <p>The method will also catch any thrown IllegalArgument Exceptions and
 * add the result to the error map given.</p>
 *
 * @param errors   Validation Error Map
 * @param obj      The Object to invoke the Setter on
 * @param field    The Object field to be set
 * @param argument Argument to the Setter
 * @throws IWSException If a Reflection Error occurred.
 */
private static <O extends Verifiable> void invokeMethodOnObject(final Map<String, String> errors, final O obj,
        final OfferFields field, final Object argument) {
    if ((field.getMethod() != null) && field.useField(OfferFields.Type.DOMESTIC)) {
        try {
            final Method implementation = obj.getClass().getMethod(field.getMethod(), field.getArgumentClass());
            implementation.invoke(obj, argument);
        } catch (InvocationTargetException e) {
            // The Reflection Framework is wrapping all caught Exceptions
            // inside the Invocation Target Exception. Since our setters
            // is throwing an IllegalArgument Exception, we have to see if
            // this occurs.
            if (e.getTargetException() instanceof IllegalArgumentException) {
                LOG.debug("Setter {} Invocation Error: {}", field.getMethod(), e.getTargetException(),
                        e.getTargetException());
                errors.put(field.getField(), e.getTargetException().getMessage());
            } else {
                LOG.debug("Setter {} Invocation Error: {}", field.getMethod(), e.getMessage(), e);
                errors.put(field.getField(), e.getMessage());
            }
        } catch (SecurityException | NoSuchMethodException | IllegalArgumentException
                | IllegalAccessException e) {
            // The Reflection framework forces a check for the
            // NoSuchMethodException. Additionally, if the Java Security
            // Manager is used, we may also see a SecurityException.
            //   Invoking the method may also result in either an
            // IllegalArgumentException or IllegalAccessException.
            LOG.error(e.getMessage(), e);
            throw new IWSException(IWSErrors.FATAL, e.getMessage(), e);
        }
    } else {
        LOG.warn("Cannot set field {}, as there is no method associated with it.", field.getField());
    }
}

From source file:com.espertech.esper.dataflow.core.SignalHandlerDefaultWInvoke.java

@Override
public void handleSignal(EPDataFlowSignal signal) {
    try {//from  w  w  w .j  a va2 s  . c o m
        handleSignalInternal(signal);
    } catch (InvocationTargetException ex) {
        log.error("Failed to invoke signal handler: " + ex.getMessage(), ex);
    }
}

From source file:org.apache.tapestry.listener.ListenerMap.java

/**
 *  Invoked by the inner listener/adaptor classes to
 *  invoke the method./*from w  w  w. j  av  a2 s. c o  m*/
 *
 **/

private static void invokeTargetMethod(Object target, Method method, Object[] args) {
    if (LOG.isDebugEnabled())
        LOG.debug("Invoking listener method " + method + " on " + target);

    try {
        try {
            method.invoke(target, args);
        } catch (InvocationTargetException ex) {
            Throwable inner = ex.getTargetException();

            if (inner instanceof ApplicationRuntimeException)
                throw (ApplicationRuntimeException) inner;

            // Edit out the InvocationTargetException, if possible.

            if (inner instanceof RuntimeException)
                throw (RuntimeException) inner;

            throw ex;
        }
    } catch (ApplicationRuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        // Catch InvocationTargetException or, preferrably,
        // the inner exception here (if its a runtime exception).

        throw new ApplicationRuntimeException(Tapestry.format("ListenerMap.unable-to-invoke-method",
                method.getName(), target, ex.getMessage()), ex);
    }
}

From source file:MainClass.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));

    final Button indeterminate = new Button(composite, SWT.CHECK);
    indeterminate.setText("Indeterminate");
    Button showProgress = new Button(composite, SWT.NONE);
    showProgress.setText("Show Progress");

    final Shell shell = parent.getShell();

    showProgress.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            try {
                new ProgressMonitorDialog(shell).run(true, true,
                        new LongRunningOperation(indeterminate.getSelection()));
            } catch (InvocationTargetException e) {
                MessageDialog.openError(shell, "Error", e.getMessage());
            } catch (InterruptedException e) {
                MessageDialog.openInformation(shell, "Cancelled", e.getMessage());
            }//w ww .j a  va 2s .c  om
        }
    });

    parent.pack();
    return composite;
}

From source file:com.jaspersoft.jasperserver.remote.dbservices.impl.BeanConnectionServiceImpl.java

/**
  */*from   w  ww  .  j  a  v a  2 s. c o  m*/
  * @param resource
  * @return Connection object, guaranteed to be non-null (not found or not supported resource indicated by exception)
  * @throws ResourceNotFoundException if no resource found 
  * @throws RemoteException in case of unclassified error
  */
public Connection getConnection(Resource resource) {
    Connection result = null;
    long startTime = System.currentTimeMillis();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Enter getConnection .. Start Time" + System.currentTimeMillis());
        }
        if (resource instanceof BeanReportDataSource) {
            BeanReportDataSource beanDataSource = (BeanReportDataSource) resource;
            applicationContext = StaticApplicationContext.getApplicationContext();
            Object bean = this.applicationContext.getBean(beanDataSource.getBeanName());
            Method serviceMethod = bean.getClass().getMethod(beanDataSource.getBeanMethod(), null);
            JdbcDataSourceService service = (JdbcDataSourceService) serviceMethod.invoke(bean, null);
            result = service.getDataSource().getConnection();
        } else {
            throw new RemoteException("Invalid Resource: Please check datasource url");
        }
    } catch (InvocationTargetException ex) {
        logger.error(ex.getMessage(), ex);
        throw new RemoteException("Cannot get bean datasource connection:" + ex.toString());
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new RemoteException("Cannot get bean datasource connection:" + ex.getMessage());
    } finally {
        if (logger.isDebugEnabled()) {
            long elapsedTime = System.currentTimeMillis() - startTime;
            logger.debug("Exit getConnection .. Total Time Spent: " + elapsedTime);
        }
    }
    return result;

}