List of usage examples for java.lang.reflect InvocationTargetException getMessage
public String getMessage()
From source file:org.sonatype.nexus.extdirect.internal.ExtDirectServlet.java
@Override protected Dispatcher createDispatcher(final Class<? extends Dispatcher> cls) { return new SsmDispatcher() { @Override// ww w. ja v a2s . c o m protected Object createInvokeInstanceForMethodWithDefaultConstructor(final RegisteredMethod method) throws Exception { if (log.isDebugEnabled()) { log.debug("Creating instance of action class '{}' mapped to '{}", method.getActionClass().getName(), method.getActionName()); } @SuppressWarnings("unchecked") Iterable<BeanEntry<Annotation, Object>> actionInstance = beanLocator .locate(Key.get((Class) method.getActionClass())); return actionInstance.iterator().next().getValue(); } @Override protected Object invokeMethod(final RegisteredMethod method, final Object actionInstance, final Object[] parameters) throws Exception { if (log.isDebugEnabled()) { log.debug("Invoking action method: {}, java-method: {}", method.getFullName(), method.getFullJavaMethodName()); } Response response = null; EventDataBuilder builder = null; EventRecorder recorder = recorderProvider.get(); // Maybe record analytics events if (recorder != null && recorder.isEnabled()) { builder = new EventDataBuilder("Ext.Direct").set("type", method.getType().name()) .set("name", method.getName()).set("action", method.getActionName()); } MDC.put(getClass().getName(), method.getFullName()); try { response = asResponse(super.invokeMethod(method, actionInstance, parameters)); } catch (InvocationTargetException e) { response = handleException(method, e.getTargetException()); } catch (Throwable e) { response = handleException(method, e); } finally { // Record analytics event if (recorder != null && builder != null) { if (response != null) { builder.set("success", response.isSuccess()); } recorder.record(builder.build()); } MDC.remove(getClass().getName()); } return response; } private Response handleException(final RegisteredMethod method, final Throwable e) { // debug logging for sanity (without stacktrace for suppressed exception) log.debug("Failed to invoke action method: {}, java-method: {}, exception message: {}", method.getFullName(), method.getFullJavaMethodName(), e.getMessage(), isSuppressedException(e) ? null : e); // handle validation message responses which have contents if (e instanceof ConstraintViolationException) { ConstraintViolationException cause = (ConstraintViolationException) e; Set<ConstraintViolation<?>> violations = cause.getConstraintViolations(); if (violations != null && !violations.isEmpty()) { return asResponse(invalid(cause)); } } // exception logging for all non-suppressed exceptions if (!isSuppressedException(e)) { log.error("Failed to invoke action method: {}, java-method: {}", method.getFullName(), method.getFullJavaMethodName(), e); } return asResponse(error(e)); } private boolean isSuppressedException(final Throwable e) { return SUPPRESSED_EXCEPTIONS.stream().anyMatch(ex -> ex.isInstance(e)); } private Response asResponse(final Object result) { Response response; if (result == null) { response = success(); } else { if (result instanceof Response) { response = (Response) result; } else { response = success(result); } } return response; } }; }
From source file:com.ibm.team.build.internal.hjplugin.RTCScm.java
@Override protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher, FilePath workspacePath, TaskListener listener, SCMRevisionState revisionState) throws IOException, InterruptedException { // if #requiresWorkspaceForPolling is false, expect that launcher and workspacePath are null listener.getLogger().println(Messages.RTCScm_checking_for_changes()); // check to see if there are incoming changes try {/* w ww . j a v a2 s . co m*/ RTCFacadeWrapper facade = RTCFacadeFactory .getFacade(getDescriptor().getMasterBuildToolkit(getBuildTool(), listener), null); Boolean changesIncoming = (Boolean) facade.invoke("incomingChanges", //$NON-NLS-1$ new Class[] { String.class, // serverURI String.class, // userId String.class, // password File.class, // passwordFile int.class, // timeout String.class, // buildWorkspace Object.class, }, // listener getServerURI(), getUserId(), getPassword(), getPasswordFileFile(), getTimeout(), getBuildWorkspace(), listener); if (changesIncoming.equals(Boolean.TRUE)) { listener.getLogger().println(Messages.RTCScm_changes_found()); return PollingResult.SIGNIFICANT; } else { listener.getLogger().println(Messages.RTCScm_no_changes_found()); return PollingResult.NO_CHANGES; } } catch (InvocationTargetException e) { Throwable eToReport = e.getCause(); if (eToReport == null) { eToReport = e; } PrintWriter writer = listener .fatalError(Messages.RTCScm_checking_for_changes_failure(eToReport.getMessage())); eToReport.printStackTrace(writer); // if we can't check for changes then we can't build it throw new AbortException(Messages.RTCScm_checking_for_changes_failure2(eToReport.getMessage())); } catch (Exception e) { PrintWriter writer = listener.error(Messages.RTCScm_checking_for_changes_failure3(e.getMessage())); e.printStackTrace(writer); // if we can't check for changes then we can't build it throw new AbortException(Messages.RTCScm_checking_for_changes_failure3(e.getMessage())); } }
From source file:com.ibm.team.build.internal.hjplugin.RTCScm.java
@Override public boolean checkout(AbstractBuild<?, ?> build, Launcher arg1, FilePath workspacePath, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { listener.getLogger().println(Messages.RTCScm_checkout_started()); File passwordFileFile = getPasswordFileFile(); String baselineSetName = getBaselineSetName(build); String localBuildToolKit;/*from w ww .ja v a 2s. com*/ String nodeBuildToolKit; String passwordToUse = null; try { localBuildToolKit = getDescriptor().getMasterBuildToolkit(getBuildTool(), listener); nodeBuildToolKit = getDescriptor().getBuildToolkit(getBuildTool(), build.getBuiltOn(), listener); if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("checkout : " + build.getProject().getName() + " " + build.getDisplayName() + " " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + build.getBuiltOnStr() + " Load directory=\"" + workspacePath.getRemote() + "\"" + //$NON-NLS-2$ " Build tool=\"" + getBuildTool() + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " Local Build toolkit=\"" + localBuildToolKit + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " Node Build toolkit=\"" + nodeBuildToolKit + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " Server URI=\"" + getServerURI() + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " Userid=\"" + getUserId() + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " Authenticating with " //$NON-NLS-1$ + (passwordFileFile == null ? " configured password " : passwordFileFile.getAbsolutePath()) //$NON-NLS-1$ + " Build workspace=\"" + getBuildWorkspace() + "\"" + //$NON-NLS-2$ " Baseline Set name=\"" + baselineSetName + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } RTCFacadeWrapper facade = RTCFacadeFactory.getFacade(localBuildToolKit, null); passwordToUse = (String) facade.invoke("determinePassword", new Class[] { //$NON-NLS-1$ String.class, // password, File.class, // passwordFile, }, getPassword(), getPasswordFileFile()); } catch (InvocationTargetException e) { Throwable eToReport = e.getCause(); if (eToReport == null) { eToReport = e; } PrintWriter writer = listener.fatalError(Messages.RTCScm_checkout_failure(eToReport.getMessage())); eToReport.printStackTrace(writer); LOGGER.log(Level.FINER, "determinePassword had invocation failure " + eToReport.getMessage(), //$NON-NLS-1$ eToReport); // if we can't check out then we can't build it throw new AbortException(Messages.RTCScm_checkout_failure2(eToReport.getMessage())); } catch (Exception e) { PrintWriter writer = listener.fatalError(Messages.RTCScm_checkout_failure3(e.getMessage())); e.printStackTrace(writer); LOGGER.log(Level.FINER, "determinePassword failure " + e.getMessage(), e); //$NON-NLS-1$ // if we can't check out then we can't build it throw new AbortException(Messages.RTCScm_checkout_failure4(e.getMessage())); } OutputStream changeLogStream = new FileOutputStream(changeLogFile); RemoteOutputStream changeLog = new RemoteOutputStream(changeLogStream); if (workspacePath.isRemote()) { sendJarsToSlave(workspacePath); } boolean debug = Boolean.parseBoolean(build.getEnvironment(listener).get(DEBUG_PROPERTY)); RTCCheckoutTask checkout = new RTCCheckoutTask( build.getProject().getName() + " " + build.getDisplayName() + " " + build.getBuiltOnStr(), //$NON-NLS-1$ //$NON-NLS-2$ nodeBuildToolKit, getServerURI(), getUserId(), passwordToUse, getTimeout(), getBuildWorkspace(), baselineSetName, listener, changeLog, workspacePath.isRemote(), debug); workspacePath.act(checkout); return true; }
From source file:org.wso2.developerstudio.appfactory.ui.views.AppfactoryApplicationListView.java
private Action checkOutAndImportAction(final AppVersionInfo info) { Action reposettings = new Action() { public void run() { try { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog( Display.getDefault().getActiveShell()); progressMonitorDialog.create(); progressMonitorDialog.open(); progressMonitorDialog.run(true, true, new AppCheckoutAndImportJobJob(info)); } catch (InvocationTargetException e) { log.error("project open", e); //$NON-NLS-1$ } catch (InterruptedException e) { log.error("project open", e); //$NON-NLS-1$ printErrorLog(e.getMessage()); }//from w ww. jav a2s .c o m }; public String getText() { return Messages.AppfactoryApplicationListView_checkOutAndImportAction_menu_name; } @Override public ImageDescriptor getImageDescriptor() { ImageDescriptor imageDescriptorFromPlugin = Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "/icons/checkout.gif"); //$NON-NLS-1$ return imageDescriptorFromPlugin; } }; return reposettings; }
From source file:org.sigmah.server.servlet.base.AbstractServlet.java
/** * Secures the given {@code servletMethod} execution. * //from w ww. ja v a 2s .co m * @param request * The HTTP request. * @param response * The HTTP response. * @param servletMethod * Java servlet method to execute once user session has been secured. * @throws ServletException * If the servlet execution fails. */ private void secureServlet(final HttpServletRequest request, final HttpServletResponse response, final Method servletMethod) throws ServletException { if (servletMethod == null) { if (LOG.isErrorEnabled()) { LOG.error("The given servlet method {} is null.", servletMethod); } throw new IllegalArgumentException("Servlet method is required."); } User user = null; try { // Validates the user session and user access. final String authenticationToken = request.getParameter(ServletConstants.AUTHENTICATION_TOKEN); final String originPageToken = request.getParameter(ServletConstants.ORIGIN_PAGE_TOKEN); final String servletPath = request.getRequestURI().replaceFirst(ServletModule.ENDPOINT, ""); final Servlet servletEnum = Servlet.fromPathName(servletPath); final ServletMethod servletMethodEnum = ServletMethod.fromMethodName(servletMethod.getName()); final Access access = secureSessionValidator.validate(authenticationToken, servletEnum, servletMethodEnum, originPageToken); user = access.getUser(); switch (access.getAccessType()) { case INVALID_SESSION: if (LOG.isDebugEnabled()) { LOG.debug( "SERVLET METHOD EXECUTION FAILED - Servlet method: '{}' ; User: '{}' ; Error: Invalid auth token '{}'.", servletMethod, Servlets.logUser(user), authenticationToken); } throw new InvalidSessionException("Your session is no longer valid."); case UNAUTHORIZED_ACCESS: if (LOG.isDebugEnabled()) { LOG.debug( "SERVLET METHOD EXECUTION FAILED - Servlet method: '{}' ; User: '{}' ; Error: Unauthorized process.", servletMethod, Servlets.logUser(user)); } throw new UnauthorizedAccessException("You are not authorized to execute this process."); default: // Access granted, executes servlet method. if (LOG.isDebugEnabled()) { LOG.debug("SERVLET METHOD EXECUTION GRANTED - Servlet method: '{}' ; User: '{}'.", servletMethod, Servlets.logUser(user)); } // Activate filters into hibernate session. DomainFilters.applyUserFilter(user, entityManagerProvider.get()); final StopWatch chrono = new StopWatch(); chrono.start(); servletMethod.setAccessible(true); servletMethod.invoke(this, request, response, new ServletExecutionContext(access.getUser(), request, originPageToken)); if (LOG.isDebugEnabled()) { LOG.debug("SERVLET METHOD '{}' EXECUTED IN {} MS.", servletMethod, chrono.getTime()); } } } catch (final InvocationTargetException e) { // NO NEED TO LOG EXCEPTION HERE. if (e.getTargetException() instanceof ServletException) { // Servlet exception. throw (ServletException) e.getTargetException(); } else if (e.getTargetException() instanceof ConstraintViolationException) { // Bean validation failed. final ConstraintViolationException cve = (ConstraintViolationException) e.getTargetException(); if (LOG.isErrorEnabled()) { LOG.error("SERVLET METHOD EXECUTION FAILED - Servlet method: '" + servletMethod + "' ; User: '" + Servlets.logUser(user) + "' ; Error: A bean validation failed during servlet method execution. Consider performing the validation on client-side.\n" + Servlets.logConstraints(cve.getConstraintViolations())); } throw new ServletException(e.getCause().getMessage(), cve); } else { throw new ServletException(e.getCause().getMessage(), e.getTargetException()); } } catch (final Throwable e) { // Server unknown error. throw new ServletException(e.getMessage(), e); } }
From source file:reflex.node.KernelExecutor.java
public static ReflexValue executeFunction(int lineNumber, Object outerApi, String areaName, String fnName, List<ReflexValue> params) { String apiName;/*from www. ja va 2 s . com*/ if (!StringUtils.isEmpty(areaName) && areaName.length() > 1) { apiName = areaName.substring(0, 1).toUpperCase() + areaName.substring(1); } else { apiName = "<api name missing>"; } int numPassedParams = params.size(); try { // Find the method get[AreaName], which will return the area Method[] methods = outerApi.getClass().getMethods(); String getApiMethodName = "get" + apiName; for (Method m : methods) { if (m.getName().equals(getApiMethodName)) { // Call that method to get the api requested Object api = m.invoke(outerApi); // Now find the method with the fnName Method[] innerMethods = api.getClass().getMethods(); for (Method im : innerMethods) { if (im.getName().equals(fnName)) { // the api should just have one entry Type[] types = im.getGenericParameterTypes(); int numExpectedParams = types.length; if (numExpectedParams == numPassedParams) { List<Object> callParams = new ArrayList<Object>(types.length); // Now coerce the types... for (int i = 0; i < types.length; i++) { ReflexValue v = params.get(i); Object x = convertValueToType(v, types[i]); callParams.add(x); } // Now invoke Object ret; try { ret = im.invoke(api, callParams.toArray()); } catch (InvocationTargetException e) { // TODO Auto-generated catch block throw new ReflexException(lineNumber, String.format( "Error in Reflex script at line %d. Call to %s.%s failed: %s", lineNumber, apiName, fnName, e.getTargetException().getMessage()), e); } ReflexValue retVal = new ReflexNullValue(lineNumber); if (ret != null) { retVal = new ReflexValue(convertObject(ret)); } return retVal; } } } throw new ReflexException(lineNumber, String.format( "API call not found: %s.%s (taking %s parameters)", apiName, fnName, numPassedParams)); } } throw new ReflexException(lineNumber, "API '" + apiName + "' not found!"); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof OutOfMemoryError) { log.error(ExceptionToString.format(e)); throw (OutOfMemoryError) cause; } else if (cause instanceof RaptureException) { log.warn(ExceptionToString.format(e)); String message = ((RaptureException) cause).getFormattedMessage(); throw new ReflexException(lineNumber, message, e); } else { String details = null; if (cause.getMessage() != null) { details = ": " + cause.getMessage(); } RaptureException re = RaptureExceptionFactory .create(String.format("Error executing api call: %s.%s (takes %s parameters)%s", apiName, fnName, numPassedParams, details), e); String message = re.getFormattedMessage(); throw new ReflexException(lineNumber, message, re); } } throw new ReflexException(lineNumber, e.getTargetException().getMessage(), e); } catch (ReflexException e) { throw e; } catch (Exception e) { log.error(ExceptionToString.format(e)); throw new ReflexException(lineNumber, e.getMessage(), e); } }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Delete selected files//from w ww . j a v a 2s. c om * @param files */ private void deleteObjects(FileObject[] files) { // run a delete operation try { FileOperation delOperation = new FileOperation(fsManager, FileOperation.DELETE, true); delOperation.setDeleteArgs(files); new ProgressMonitorDialog(shell).run(true, true, delOperation); } catch (InvocationTargetException e) { VFSUtil.MessageBoxError(e.getMessage()); } catch (InterruptedException e) { VFSUtil.MessageBoxInfo(e.getMessage()); } // Refresh doRefresh(); }
From source file:org.egov.pims.service.EmployeeServiceImpl.java
/** * Returns Map for a given list/* w w w.j a v a2s .co m*/ * * @param list * @return */ public Map getMapForList(List list, String fieldName1, String fieldName2) { Map<Integer, String> retMap = new LinkedHashMap<Integer, String>(); try { String id = null; String name = null; Long longObj = null; for (Iterator iter = list.iterator(); iter.hasNext();) { Object object = (Object) iter.next(); id = (String) BeanUtils.getProperty(object, fieldName1); name = (String) BeanUtils.getProperty(object, fieldName2); if (id != null) { retMap.put(Integer.valueOf(id), (String) name); } } } catch (IllegalAccessException iac) { throw new ApplicationRuntimeException("Exception:" + iac.getMessage(), iac); } catch (InvocationTargetException e) { LOGGER.error(e); throw new ApplicationRuntimeException("Exception:" + e.getMessage(), e); } catch (NoSuchMethodException e) { LOGGER.error(e); throw new ApplicationRuntimeException("Exception:" + e.getMessage(), e); } return retMap; }
From source file:com.netspective.commons.xdm.XmlDataModelSchema.java
/** * Adds PCDATA areas./* w ww. j a va2s. c o m*/ */ public void addText(XdmParseContext pc, Object element, String text) throws DataModelException, UnsupportedTextException { if (options.ignorePcData) return; if (addText == null) { UnsupportedTextException e = new UnsupportedTextException(pc, element, text); pc.addError(e); if (pc.isThrowErrorException()) throw e; else return; } try { addText.invoke(element, new String[] { text }); } catch (InvocationTargetException ite) { pc.addError("Unable to add text '" + text + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": " + ite.getMessage()); log.error(ite); if (pc.isThrowErrorException()) { Throwable t = ite.getTargetException(); if (t instanceof DataModelException) { throw (DataModelException) t; } throw new DataModelException(pc, t); } } catch (Exception e) { pc.addError("Unable to add text '" + text + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": " + e.getMessage()); log.error(e); if (pc.isThrowErrorException()) throw new DataModelException(pc, e); } }
From source file:com.netspective.commons.xdm.XmlDataModelSchema.java
/** * Creates a named nested element./*from w ww. j av a2 s . c o m*/ */ public Object createElement(XdmParseContext pc, String alternateClassName, Object element, String elementName, boolean withinCustom) throws DataModelException, UnsupportedElementException { //System.out.println("Creating: " + element.getClass().getName() + " " + elementName + " " + alternateClassName + " " + withinCustom); try { if (element instanceof CustomElementCreator && !withinCustom) return ((CustomElementCreator) element).createCustomDataModelElement(pc, this, element, elementName, alternateClassName); else return createElement(pc, alternateClassName, element, elementName); } catch (InvocationTargetException ite) { pc.addError( "Could not create class for element '" + elementName + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": " + ite.getMessage()); log.error(ite); if (pc.isThrowErrorException()) { Throwable t = ite.getTargetException(); if (t instanceof DataModelException) { throw (DataModelException) t; } throw new DataModelException(pc, t); } else return null; } catch (Exception e) { pc.addError( "Could not create class for element '" + elementName + "' at " + pc.getLocator().getSystemId() + " line " + pc.getLocator().getLineNumber() + ": " + e.getMessage()); log.error(e); if (pc.isThrowErrorException()) throw new DataModelException(pc, e); return null; } }