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:org.kie.server.controller.websocket.management.KieServerMgmtCommandServiceImpl.java

@Override
public KieServerControllerServiceResponse executeCommand(final KieServerControllerDescriptorCommand command) {
    if (command == null) {
        return new KieServerControllerServiceResponse(ResponseType.FAILURE, "Command can not be null");
    }/*from   w  w  w  . ja v  a  2 s .  c  o  m*/

    try {
        Object result = null;
        Object handler = null;
        // find out the handler to call to process given command
        if (SpecManagementService.class.getName().equals(command.getService())) {
            handler = specManagementService;
        } else if (RuntimeManagementService.class.getName().equals(command.getService())) {
            handler = runtimeManagementService;
        } else if (RuleCapabilitiesService.class.getName().equals(command.getService())) {
            handler = ruleCapabilitiesService;
        } else {
            throw new IllegalStateException("Unable to find handler for " + command.getService() + " service");
        }

        LOGGER.debug("Service handler: {}", handler);
        LOGGER.debug("Command arguments size: {}", command.getArguments().size());

        List<Object> arguments = new ArrayList<>();
        // process and unwrap arguments
        for (Object arg : command.getArguments()) {
            LOGGER.debug("Before :: Argument with type {} and value {}", arg == null ? "null" : arg.getClass(),
                    arg);
            if (arg instanceof Wrapped) {
                arg = ((Wrapped) arg).unwrap();
            }
            LOGGER.debug("After :: Argument with type {} and value {}", arg == null ? "null" : arg.getClass(),
                    arg);
            arguments.add(arg);
        }

        LOGGER.debug("About to execute {} operation on {} with args {}", command.getMethod(), handler,
                arguments);

        // process command via reflection and handler
        result = MethodUtils.invokeMethod(handler, command.getMethod(), arguments.toArray());
        LOGGER.debug("Handler {} returned response {}", handler, result);
        // return successful result
        return new KieServerControllerServiceResponse(ResponseType.SUCCESS, "", result);
    } catch (InvocationTargetException e) {
        LOGGER.error("Failed to invoke service method", e);
        return new KieServerControllerServiceResponse(ResponseType.FAILURE,
                e.getTargetException().getMessage());
    } catch (Throwable e) {
        LOGGER.error("Error while processing {} command", command, e);
        // return failure result
        return new KieServerControllerServiceResponse(ResponseType.FAILURE, e.getMessage());
    }
}

From source file:gov.us.fhim.ui.actions.ImportSpreadsheet.java

/**
 * @see IActionDelegate#run(IAction)/* w w w.  j a  v a  2s.c  o m*/
 */
public void run(IAction action) {

    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);

    ObjectPluginAction opa = (ObjectPluginAction) action;

    final TreeSelection selection = (TreeSelection) opa.getSelection();

    final String ActionTitle = "Import Terminology";

    final FileDialog fdlg = new FileDialog(shell, SWT.SINGLE);

    fdlg.setText("Select Terminology Source File");

    fdlg.setFilterNames(FILTER_NAMES);
    fdlg.setFilterExtensions(FILTER_EXTS);

    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

            File f = (File) selection.getFirstElement();

            String umlPath = myWorkspaceRoot.getLocation().toOSString() + f.getFullPath().toOSString();

            try {
                importMapping(monitor, umlPath, fdlg);
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                myWorkspaceRoot.refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e) {
            }

            if (monitor.isCanceled()) {
                monitor.done();
                return;
            }

            monitor.done();

        }

    };

    try {
        if (fdlg.open() != null) {
            progressDialog.run(false, true, runnableWithProgress);
            MetricsDialog dlg = new MetricsDialog(shell);
            dlg.create();
            dlg.open();
        }

    } catch (InvocationTargetException invocationTargetException) {
        MessageDialog.openError(shell, ActionTitle,
                "Error Processing Export " + invocationTargetException.getMessage());

    } catch (InterruptedException interruptedException) {
        MessageDialog.openError(shell, ActionTitle,
                "Error Processing Export " + interruptedException.getMessage());

    } finally {
        progressDialog.close();

    }
}

From source file:org.castor.cache.distributed.OsCache.java

/**
 * {@inheritDoc}/* w w w .j av a2  s. c  om*/
 */
@SuppressWarnings("unchecked")
public V get(final Object key) {
    try {
        return (V) _getMethod.invoke(_cache, new Object[] { String.valueOf(key) });
    } catch (InvocationTargetException e) {
        String cause = e.getTargetException().getClass().getName();
        if (cause.equals(NEEDS_REFRESH_EXCEPTION)) {
            invokeCacheMethod(_cancelMethod, new Object[] { String.valueOf(key) });
            return null;
        }

        String msg = "Failed to call method on OSCache instance: " + e.getMessage();
        LOG.error(msg, e);
        throw new IllegalStateException(e.getMessage());
    } catch (Exception e) {
        String msg = "Failed to call method on OSCache instance: " + e.getMessage();
        LOG.error(msg, e);
        throw new IllegalStateException(e.getMessage());
    }
}

From source file:com.htmlhifive.tools.jslint.dialog.CreateEngineDialog.java

@Override
protected void okPressed() {
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
    DownloadEngineSupport support = createEngineDownload((Boolean) wvJslint.getValue());
    try {/*from w ww .  j  a  va  2s  .  com*/
        IFile file = ResourcesPlugin.getWorkspace().getRoot()
                .getFile(new Path(wvOutputDir.getValue() + "/" + support.getEngine().getFileName()));
        if (file.exists()) {
            MessageBox box = new MessageBox(getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
            box.setMessage(Messages.DM0004.getText());
            box.setText(Messages.DT0011.getText());
            if (box.open() == SWT.CANCEL) {
                return;
            }
        }
        DownloadRunnable progress = new DownloadRunnable(support);
        progressDialog.run(true, false, progress);
        EngineInfo info = progress.getResult();
        if (info == null) {
            ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(),
                    ValidationStatus.error(Messages.EM0015.getText()));
            return;
        }
        ConfirmLicenseDialog dialog = new ConfirmLicenseDialog(getShell(),
                StringUtils.trim(info.getLicenseStr()), Messages.DT0009.getText());

        if (dialog.open() == IDialogConstants.OK_ID) {
            if (file.exists()) {
                file.setContents(new ByteArrayInputStream(info.getMainSource().getBytes()), IResource.FORCE,
                        null);
            } else {
                file.create(new ByteArrayInputStream(info.getMainSource().getBytes()), true, null);
            }
            this.engineFilePath = file.getFullPath().toString();
        } else {
            return;
        }
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0015.getText(),
                new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, e.getMessage(), e));
        logger.put(Messages.EM0100, e);
    } catch (InterruptedException e) {
        // ????????.
        throw new AssertionError();
    } catch (CoreException e) {
        ErrorDialog.openError(getShell(), Messages.DT0003.getText(), Messages.EM0016.getText(), e.getStatus());
        logger.put(Messages.EM0100, e);
    }

    super.okPressed();
}

From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java

/** returns the field value in the base bean for the specified field.
 * @param fieldName fieldname whose value has to be got.
 * @param baseBean Bean containing the field.
 * @return value of the field.//ww  w .  j a v  a  2s .  c  o  m
 */
private Object getFieldValue(String fieldName, Object baseBean) {
    Field field = null;
    Method method = null;
    Class dataClass = baseBean.getClass();
    Object value = null;

    try {
        field = dataClass.getDeclaredField(fieldName);
        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        try {
            String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            method = dataClass.getMethod(methodName, null);
        } catch (NoSuchMethodException noSuchMethodException) {
            LOG.error(noSuchMethodException.getMessage(), noSuchMethodException);
        }
    }

    try {
        if (field != null && field.isAccessible()) {
            value = field.get(baseBean);
        } else {
            value = method.invoke(baseBean, null);
        }
    } catch (IllegalAccessException illegalAccessException) {
        LOG.error(illegalAccessException.getMessage(), illegalAccessException);
    } catch (InvocationTargetException invocationTargetException) {
        LOG.error(invocationTargetException.getMessage(), invocationTargetException);
    }
    return value;
}

From source file:velo.entity.EmailTemplate.java

@Deprecated
public Object executeGetMethod(Object obj, String methodName) throws MethodExecutionException {
    //System.out.println("Trying to execute Method name: '" + methodName + "', on Object: " + obj);
    try {//from w w w.j a  v a 2s  . c om
        Class[] parameterTypes = new Class[] {};
        Method name = obj.getClass().getMethod(methodName, parameterTypes);
        Object[] arguments = new Object[] {};
        Object result = name.invoke(obj, arguments);

        return result;

    } catch (InvocationTargetException ite) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + ite.getMessage());
    } catch (IllegalAccessException iae) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + iae.getMessage());
    } catch (NoSuchMethodException nsme) {
        throw new MethodExecutionException("Could not execute method named: '" + methodName + "' over object: '"
                + obj + "', failed message is: " + nsme.getMessage());
    }
}

From source file:com.dungnv.vfw5.base.service.BaseFWServiceImpl.java

@Override
public List prepareCondition(TDTO tForm) {
    List<ConditionBean> lstCondition = new ArrayList<ConditionBean>();
    if (tForm == null) {
        return lstCondition;
    }// w ww.ja va2  s. co m
    Method methods[] = tForm.toModel().getClass().getDeclaredMethods();
    Method methodForms[] = tForm.getClass().getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        if (ReflectUtils.isGetter(methods[i])) {
            try {
                Object value = methods[i].invoke(tForm.toModel());
                String returnType = methods[i].getReturnType().getSimpleName().toUpperCase();
                if (value == null || "".equals(value)) {
                    if (ParamUtils.TYPE_NUMBER.indexOf(returnType) >= 0) {
                        try {
                            Column column = methods[i].getAnnotation(Column.class);
                            if (StringUtils.validString(column.columnDefinition())) {
                                String colId = "";
                                String colName = "";
                                for (int j = 0; j < methodForms.length; j++) {
                                    if (methodForms[j].getName().equals(methods[i].getName() + "Name")) {
                                        value = methodForms[j].invoke(tForm);
                                        if (!StringUtils.validString(value)) {
                                            break;
                                        }
                                        Class cl = Class.forName("com.dungnv.ra.database.BO."
                                                + column.columnDefinition() + "BO");
                                        Constructor ct = cl.getConstructor();
                                        Object obj = ct.newInstance();
                                        Method mtd[] = cl.getMethods();
                                        for (int k = 0; k < mtd.length; k++) {
                                            if (mtd[k].getName().equals("getColId")) {
                                                colId = mtd[k].invoke(obj).toString();
                                            }
                                            if (mtd[k].getName().equals("getColName")) {
                                                colName = mtd[k].invoke(obj).toString();
                                            }
                                        }
                                        break;
                                    }
                                }
                                if (StringUtils.validString(value)) {
                                    lstCondition
                                            .add(new ConditionBean(ReflectUtils.getColumnBeanName(methods[i]),
                                                    ParamUtils.OP_IN,
                                                    BaseFWDAOImpl.genSubQuery(column.columnDefinition(), colId,
                                                            colName, value.toString()),
                                                    ParamUtils.TYPE_NUMBER));
                                }
                            }
                        } catch (Exception e) {
                            System.out.println("PrepareCondition Error: " + e.getMessage());
                        }
                    }
                } else if (ParamUtils.TYPE_STRING.indexOf(returnType) >= 0) {
                    if (!value.equals(String.valueOf(ParamUtils.DEFAULT_VALUE))) {
                        String stringValue = value.toString();
                        String opCompare = ParamUtils.OP_LIKE;
                        String valueCompare = StringUtils.formatLike(stringValue);
                        Column column = methods[i].getAnnotation(Column.class);
                        if (StringUtils.validString(column.columnDefinition())
                                && column.columnDefinition().equals("param")) {
                            opCompare = ParamUtils.OP_EQUAL;
                            valueCompare = stringValue.toLowerCase(Locale.ENGLISH);
                        }
                        if (!stringValue.trim().equals("")) {
                            lstCondition.add(new ConditionBean(
                                    StringUtils.formatFunction("lower",
                                            ReflectUtils.getColumnBeanName(methods[i])),
                                    opCompare, valueCompare, ParamUtils.TYPE_STRING));
                        }
                    }
                } else if (ParamUtils.TYPE_NUMBER.indexOf(returnType) >= 0) {
                    if (!value.toString().equals(String.valueOf(ParamUtils.DEFAULT_VALUE))) {
                        lstCondition.add(new ConditionBean(ReflectUtils.getColumnBeanName(methods[i]),
                                ParamUtils.OP_EQUAL, value.toString(), ParamUtils.TYPE_NUMBER));
                    }
                } else if (ParamUtils.TYPE_DATE.indexOf(returnType) >= 0) {
                    Date dateValue = (Date) value;
                    String methodName = methods[i].getName();
                    String operator = ParamUtils.OP_EQUAL;
                    if (methodName.indexOf("From") >= 0 || methodName.indexOf("Begin") >= 0
                            || methodName.indexOf("Sta") >= 0) {
                        operator = ParamUtils.OP_GREATER_EQUAL;
                    } else if (methodName.indexOf("To") >= 0 || methodName.indexOf("End") >= 0
                            || methodName.indexOf("Last") >= 0) {
                        operator = ParamUtils.OP_LESS_EQUAL;
                    }
                    lstCondition.add(new ConditionBean(
                            StringUtils.formatFunction("trunc", ReflectUtils.getColumnBeanName(methods[i])),
                            operator, StringUtils.formatDate(dateValue), ParamUtils.TYPE_DATE));
                }
            } catch (IllegalAccessException iae) {
                System.out.println("PrepareCondition Error: " + iae.getMessage());
            } catch (InvocationTargetException ite) {
                System.out.println("PrepareCondition Error: " + ite.getMessage());
            }
        }
    }
    return lstCondition;
}

From source file:org.stanwood.nwn2.gui.model.UIObject.java

public void applyStyle(UIObject styledObject) {
    if (styledObject.getClass() == this.getClass()) {
        for (Method m : styledObject.getClass().getMethods()) {
            if (m.getName().startsWith("get") && !m.getName().equalsIgnoreCase("getprototype")
                    && !m.getName().equalsIgnoreCase("getname") && !m.getName().equalsIgnoreCase("getclass")
                    && !m.getName().equalsIgnoreCase("getchildren")
                    && !m.getName().equalsIgnoreCase("getparent")) {
                try {
                    Object value = m.invoke(styledObject);
                    if (value != null) {
                        Method m2 = this.getClass().getMethod("set" + m.getName().substring(3),
                                value.getClass());

                        m2.invoke(this, value);
                    }//from ww w . ja v a 2  s.c o m
                } catch (InvocationTargetException e) {
                    log.error(e.getMessage(), e);
                } catch (SecurityException e) {
                    log.error(e.getMessage(), e);
                } catch (NoSuchMethodException e) {
                    log.error(e.getMessage(), e);
                } catch (IllegalArgumentException e) {
                    log.error(e.getMessage(), e);
                } catch (IllegalAccessException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
        for (NWN2GUIObject child : styledObject.getChildren()) {
            NWN2GUIObject newChild;
            try {
                newChild = (NWN2GUIObject) child.clone();
                newChild.setParent(this);
                addChildObject(newChild);
            } catch (CloneNotSupportedException e) {
                log.error(e.getMessage(), e);
            }

        }

        if (width != null) {
            width.setObject(this);
        }
        if (height != null) {
            height.setObject(this);
        }
        if (x != null) {
            x.setObject(this);
        }
        if (y != null) {
            y.setObject(this);
        }
    }
}

From source file:org.pentaho.di.ui.core.dialog.DisplayInvocationHandler.java

@Override
public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
    if (display.getThread() == Thread.currentThread()) {
        try {/* w  ww . j ava 2s.  co m*/
            return method.invoke(delegate, args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }
    if (asyncForVoid && method.getReturnType().equals(Void.TYPE)) {
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    method.invoke(delegate, args);
                } catch (Throwable e) {
                    if (e instanceof InvocationTargetException) {
                        e = e.getCause();
                    }
                    log.logError(e.getMessage(), e);
                }
            }
        });
        return null;
    }
    final ResultHolder resultHolder = new ResultHolder();
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            try {
                resultHolder.result = method.invoke(delegate, args);
            } catch (InvocationTargetException e) {
                resultHolder.throwable = e.getCause();
            } catch (Exception e) {
                resultHolder.throwable = e;
            }
        }
    });
    if (resultHolder.result != null) {
        return resultHolder.result;
    } else {
        throw resultHolder.throwable;
    }
}

From source file:org.kuali.coeus.common.budget.framework.query.QueryList.java

/** calculates the sum of the field in this QueryList.
 * @param fieldName field of bean whose sum has to be calculated.
 * @param arg argument for the getter method of field if it takes any argumnt,
 * else can be null.//  w ww.  j  a v a  2s.  c o  m
 * @param value value for the argument, else can be null.
 * @return returns sum.
 */
public double sum(String fieldName, Class arg, Object value) {
    if (size() == 0) {
        return 0;
    }

    Object current;
    Field field = null;
    Method method = null;
    Class dataClass = get(0).getClass();
    double sum = 0;

    try {
        field = dataClass.getDeclaredField(fieldName);

        Class fieldClass = field.getType();
        if (!(fieldClass.equals(Integer.class) || fieldClass.equals(Long.class)
                || fieldClass.equals(Double.class) || fieldClass.equals(Float.class)
                || fieldClass.equals(BigDecimal.class) || fieldClass.equals(BigInteger.class)
                || fieldClass.equals(ScaleTwoDecimal.class) || fieldClass.equals(ScaleTwoDecimal.class)
                || fieldClass.equals(int.class) || fieldClass.equals(long.class)
                || fieldClass.equals(float.class) || fieldClass.equals(double.class))) {
            throw new UnsupportedOperationException("Data Type not numeric");
        }

        if (!field.isAccessible()) {
            throw new NoSuchFieldException();
        }
    } catch (NoSuchFieldException noSuchFieldException) {
        try {
            String methodName = "get" + (fieldName.charAt(0) + "").toUpperCase() + fieldName.substring(1);
            if (arg != null) {
                Class args[] = { arg };
                method = dataClass.getMethod(methodName, args);
            } else {
                method = dataClass.getMethod(methodName, null);
            }
        } catch (NoSuchMethodException noSuchMethodException) {
            LOG.error(noSuchMethodException.getMessage(), noSuchMethodException);
        }
    }

    for (int index = 0; index < size(); index++) {
        current = get(index);

        try {
            if (field != null && field.isAccessible()) {
                sum = sum + Double.parseDouble(((Comparable) field.get(current)).toString());
            } else {
                Comparable dataValue;
                if (value != null) {
                    Object values[] = { value };
                    dataValue = (Comparable) method.invoke(current, values);
                } else {
                    dataValue = (Comparable) method.invoke(current, null);
                }
                if (dataValue != null) {
                    sum += Double.parseDouble(dataValue.toString());
                }

            }
        } catch (IllegalAccessException illegalAccessException) {
            LOG.error(illegalAccessException.getMessage(), illegalAccessException);
        } catch (InvocationTargetException invocationTargetException) {
            LOG.error(invocationTargetException.getMessage(), invocationTargetException);
        }
    }
    return sum;
}