List of usage examples for java.lang.reflect InvocationTargetException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.tlabs.eve.api.parser.BaseRule.java
private static final boolean invokeMethod(final Object bean, final Method method, final Object value) { try {/* w ww .jav a 2 s . c o m*/ method.invoke(bean, value); return true; } catch (InvocationTargetException e) { LOG.warn("InvocationTargetException: " + e.getLocalizedMessage(), e); return false; } catch (IllegalAccessException e) { LOG.warn("IllegalAccessException: " + e.getLocalizedMessage(), e); return false; } }
From source file:org.opentaps.common.reporting.ChartViewHandler.java
public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { /*/*from w w w .j ava 2 s. c o m*/ * Looks for parameter "chart" first. Send this temporary image files * to client if it exists and return. */ String chartFileName = UtilCommon.getParameter(request, "chart"); if (UtilValidate.isNotEmpty(chartFileName)) { try { ServletUtilities.sendTempFile(chartFileName, response); if (chartFileName.indexOf(ServletUtilities.getTempOneTimeFilePrefix()) != -1) { // delete temporary file File file = new File(System.getProperty("java.io.tmpdir"), chartFileName); file.delete(); } } catch (IOException ioe) { Debug.logError(ioe.getLocalizedMessage(), module); } return; } /* * Next option eliminate need to store chart in file system. Some event handler * included in request chain prior to this view handler can prepare ready to use * instance of JFreeChart and place it to request attribute chartContext. * Currently chartContext should be Map<String, Object> and we expect to see in it: * "charObject" : JFreeChart * "width" : positive Integer * "height" : positive Integer * "encodeAlpha" : Boolean (optional) * "compressRatio" : Integer in range 0-9 (optional) */ Map<String, Object> chartContext = (Map<String, Object>) request.getAttribute("chartContext"); if (UtilValidate.isNotEmpty(chartContext)) { try { sendChart(chartContext, response); } catch (IOException ioe) { Debug.logError(ioe.getLocalizedMessage(), module); } return; } /* * Prepare context for next options */ Map<String, Object> callContext = FastMap.newInstance(); callContext.put("parameters", UtilHttp.getParameterMap(request)); callContext.put("delegator", request.getAttribute("delegator")); callContext.put("dispatcher", request.getAttribute("dispatcher")); callContext.put("userLogin", request.getSession().getAttribute("userLogin")); callContext.put("locale", UtilHttp.getLocale(request)); /* * view-map attribute "page" may contain BeanShell script in component * URL format that should return chartContext map. */ if (UtilValidate.isNotEmpty(page) && UtilValidate.isUrl(page) && page.endsWith(".bsh")) { try { chartContext = (Map<String, Object>) BshUtil.runBshAtLocation(page, callContext); if (UtilValidate.isNotEmpty(chartContext)) { sendChart(chartContext, response); } } catch (GeneralException ge) { Debug.logError(ge.getLocalizedMessage(), module); } catch (IOException ioe) { Debug.logError(ioe.getLocalizedMessage(), module); } return; } /* * As last resort we can decide that "page" attribute contains class name and "info" * contains method Map<String, Object> getSomeChart(Map<String, Object> context). * There are parameters, delegator, dispatcher, userLogin and locale in the context. * Should return chartContext. */ if (UtilValidate.isNotEmpty(page) && UtilValidate.isNotEmpty(info)) { Class handler = null; synchronized (this) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { handler = loader.loadClass(page); if (handler != null) { Method runMethod = handler.getMethod(info, new Class[] { Map.class }); chartContext = (Map<String, Object>) runMethod.invoke(null, callContext); if (UtilValidate.isNotEmpty(chartContext)) { sendChart(chartContext, response); } } } catch (ClassNotFoundException cnfe) { Debug.logError(cnfe.getLocalizedMessage(), module); } catch (SecurityException se) { Debug.logError(se.getLocalizedMessage(), module); } catch (NoSuchMethodException nsme) { Debug.logError(nsme.getLocalizedMessage(), module); } catch (IllegalArgumentException iae) { Debug.logError(iae.getLocalizedMessage(), module); } catch (IllegalAccessException iace) { Debug.logError(iace.getLocalizedMessage(), module); } catch (InvocationTargetException ite) { Debug.logError(ite.getLocalizedMessage(), module); } catch (IOException ioe) { Debug.logError(ioe.getLocalizedMessage(), module); } } } // Why you disturb me? throw new ViewHandlerException( "In order to generate chart you have to provide chart object or file name. There are no such data in request. Please read comments to ChartViewHandler class."); }
From source file:com.nabla.wapp.server.xml.Importer.java
public <T> T read(final Class<T> clazz, final Integer dataId, final String userSessionId) throws DispatchException, SQLException { final PreparedStatement stmt = StatementFormat.prepare(conn, sql, dataId); try {//from ww w. jav a2 s . co m final ResultSet rs = stmt.executeQuery(); try { if (!rs.next()) { errors.add(CommonServerErrors.NO_DATA); return null; } if (!userSessionId.equals(rs.getString("userSessionId"))) { if (log.isTraceEnabled()) log.trace("invalid user session ID"); errors.add(CommonServerErrors.ACCESS_DENIED); return null; } try { return impl.read(clazz, rs.getBinaryStream("content")); } catch (final InvocationTargetException e) { if (log.isDebugEnabled()) log.debug("exception thrown from a validate(). assume error was added to list", e); } catch (final ValueRequiredException e) { if (log.isDebugEnabled()) log.debug("required value", e); errors.add(Util.extractLine(e), Util.extractFieldName(e), CommonServerErrors.REQUIRED_VALUE); } catch (final ElementException e) { errors.add(Util.extractFieldName(e), e.getLocalizedMessage()); } catch (final PersistenceException e) { if (log.isDebugEnabled()) log.debug("deserialization error", e); errors.add(Util.extractLine(e), Util.extractFieldName(e), CommonServerErrors.INVALID_VALUE); } catch (final XMLStreamException e) { if (log.isDebugEnabled()) log.debug("XML error", e); errors.add(Util.extractLine(e), e.getLocalizedMessage()); } catch (final Exception e) { if (log.isDebugEnabled()) log.debug("error", e); errors.add(Util.extractLine(e), e.getLocalizedMessage()); } return null; } finally { Database.close(rs); } } finally { Database.close(stmt); } }
From source file:net.refractions.udig.catalog.ui.wizard.DataBaseRegistryWizardPage.java
/** * This method will run the provided activity using the * wizard page progress bar; and wait for the result to * complete.//from w ww .j a v a 2 s . co m * <p> * If anything goes wrong the message will be shown to the user * * @param activity */ protected void runInPage(final IRunnableWithProgress activity) { // on a technical level I am not sure which one of these we should use // boolean guess = true; try { if (guess) { // This is what I think PostGIS wizard page does getContainer().run(false, true, activity); } else { // This is what the origional wizard pages did // note the use of an internal blocking call to run the activity // and wait for it to complete? // getContainer().run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { PlatformGIS.runBlockingOperation(activity, monitor); } }); } } catch (InvocationTargetException e2) { // log the error CatalogUIPlugin.log(e2.getLocalizedMessage(), e2); // tell the user setErrorMessage(e2.getCause().getLocalizedMessage()); // preferences.performDefaults(); } catch (InterruptedException e2) { // user got tired of waiting ... } }
From source file:org.eclipse.jubula.client.ui.rcp.handlers.project.SaveProjectAsHandler.java
/** * {@inheritDoc}//from w ww . ja v a2s . c o m */ public Object executeImpl(ExecutionEvent event) { VersionDialog dialog = openInputDialog(); if (dialog.getReturnCode() == Window.OK) { final String newProjectName = dialog.getProjectName(); IRunnableWithProgress op = createOperation(newProjectName, dialog.getProjectVersion()); try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(op); fireReady(); } catch (InvocationTargetException ite) { // Exception occurred during operation log.error(ite.getLocalizedMessage(), ite.getCause()); } catch (InterruptedException e) { // Operation was canceled. // We have to clear the GUI because all of // the save work was done in the Master Session, which has been // rolled back. Utils.clearClient(); } } return null; }
From source file:org.opencms.jlan.CmsJlanRepository.java
/** * Creates a dynamic proxy for a disk interface which logs the method calls and their results.<p> * * @param impl the disk interface for which a logging proxy should be created * * @return the dynamic proxy which logs methods calls *///from w w w.j a v a2s . co m public static DiskInterface createLoggingProxy(final DiskInterface impl) { return (DiskInterface) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class[] { DiskInterface.class }, new InvocationHandler() { @SuppressWarnings("synthetic-access") public Object invoke(Object target, Method method, Object[] params) throws Throwable { // Just to be on the safe side performance-wise, we only log the parameters/result // if the info channel is enabled if (LOG.isInfoEnabled()) { List<String> paramStrings = new ArrayList<String>(); for (Object param : params) { paramStrings.add("" + param); } String paramsAsString = CmsStringUtil.listAsString(paramStrings, ", "); LOG.info("Call: " + method.getName() + " " + paramsAsString); } try { Object result = method.invoke(impl, params); if (LOG.isInfoEnabled()) { LOG.info("Returned from " + method.getName() + ": " + result); } return result; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if ((cause != null) && (cause instanceof CmsSilentWrapperException)) { // not really an error LOG.info(cause.getCause().getLocalizedMessage(), cause.getCause()); } else { LOG.error(e.getLocalizedMessage(), e); } throw e.getCause(); } } }); }
From source file:org.opencms.workplace.CmsWorkplace.java
/** * Fills all class parameter values from the data provided in the current request.<p> * // w w w.jav a 2 s. co m * All methods that start with "setParam" are possible candidates to be * automatically filled. The remaining part of the method name is converted * to lower case. Then a parameter of this name is searched in the request parameters. * If the parameter is found, the "setParam" method is automatically invoked * by reflection with the value of the parameter.<p> * * @param request the current JSP request */ @SuppressWarnings("unchecked") public void fillParamValues(HttpServletRequest request) { m_parameterMap = null; // ensure a multipart request is parsed only once (for "forward" scenarios with reports) if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) { // check if this is a multipart request m_multiPartFileItems = CmsRequestUtil.readMultipartFileItems(request); if (m_multiPartFileItems != null) { // this was indeed a multipart form request m_parameterMap = CmsRequestUtil.readParameterMapFromMultiPart( getCms().getRequestContext().getEncoding(), m_multiPartFileItems); request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART, Boolean.TRUE); } } if (m_parameterMap == null) { // the request was a "normal" request m_parameterMap = request.getParameterMap(); } List<Method> methods = paramSetMethods(); Iterator<Method> i = methods.iterator(); while (i.hasNext()) { Method m = i.next(); String name = m.getName().substring(8).toLowerCase(); String[] values = m_parameterMap.get(name); String value = null; if (values != null) { // get the parameter value from the map value = values[0]; } if (CmsStringUtil.isEmpty(value)) { value = null; } // TODO: this is very dangerous since most of the dialogs does not send encoded data // and by decoding not encoded data the data will get corrupted, for instance '1+2' will become '1 2'. // we should ensure that we decode the data only if the data has been encoded value = decodeParamValue(name, value); try { if (LOG.isDebugEnabled() && (value != null)) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_SET_PARAM_2, m.getName(), value)); } m.invoke(this, new Object[] { value }); } catch (InvocationTargetException ite) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(ite.getLocalizedMessage()); } } catch (IllegalAccessException eae) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(eae.getLocalizedMessage()); } } } }
From source file:org.opencms.workplace.CmsWorkplace.java
/** * Returns the values of all parameter methods of this workplace class instance.<p> * /*ww w . ja v a 2 s .c om*/ * @return the values of all parameter methods of this workplace class instance */ protected Map<String, Object> paramValues() { List<Method> methods = paramGetMethods(); Map<String, Object> map = new HashMap<String, Object>(methods.size()); Iterator<Method> i = methods.iterator(); while (i.hasNext()) { Method m = i.next(); Object o = null; try { o = m.invoke(this, new Object[0]); } catch (InvocationTargetException ite) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(ite.getLocalizedMessage()); } } catch (IllegalAccessException eae) { // can usually be ignored if (LOG.isInfoEnabled()) { LOG.info(eae.getLocalizedMessage()); } } if (o != null) { map.put(m.getName().substring(8).toLowerCase(), o); } } return map; }
From source file:org.wso2.carbon.protobuf.listener.ProtobufServletContainerInitializer.java
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { if (classes == null || classes.size() == 0) { return;/*from w w w . j a va 2 s .c o m*/ } // adding a listener to remove services when wars are undeployed servletContext.addListener(new ProtobufServletContextListener()); // keeps track of PB services in a PB war // Please note that, a PB war can contain many PB services List<ProtobufServiceData> serviceList = new ArrayList<ProtobufServiceData>(); // servlet to display proto files (like WSDL files) ServletRegistration.Dynamic dynamic = servletContext.addServlet("ProtoBufServlet", ProtobufServlet.class); for (Class<?> clazz : classes) { // Getting binary service registry ProtobufRegistry binaryServiceRegistry = (ProtobufRegistry) PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(ProtobufRegistry.class); // Is it a blocking service or not boolean blocking = clazz.getAnnotation(ProtobufService.class).blocking(); Method reflectiveMethod = null; Object serviceObj = null; String serviceName; String serviceType; try { if (blocking) { // getting newReflectiveBlocking method which will return a // blocking service reflectiveMethod = clazz.getInterfaces()[0].getDeclaringClass() .getMethod("newReflectiveBlockingService", clazz.getInterfaces()[0]); // Since it is a static method, we pass null serviceObj = reflectiveMethod.invoke(null, clazz.newInstance()); BlockingService blockingService = (BlockingService) serviceObj; // register service into Binary Service Registry serviceName = binaryServiceRegistry.registerBlockingService(blockingService); serviceType = "BlockingService"; // keeps PB service information in a bean // we need these when removing the services from Binary // Service Registry // we are using these beans instances inside our destroyer serviceList.add(new ProtobufServiceData(serviceName, serviceType)); servletContext.setAttribute("services", serviceList); dynamic.addMapping("/"); } else { // getting newReflectiveService which will return a non // blocking service reflectiveMethod = clazz.getInterfaces()[0].getDeclaringClass() .getMethod("newReflectiveService", clazz.getInterfaces()[0]); // Since it is a static method, we pass null serviceObj = reflectiveMethod.invoke(null, clazz.newInstance()); Service service = (Service) serviceObj; // register service into Binary Service Registry serviceName = binaryServiceRegistry.registerService(service); serviceType = "NonBlockingService"; // keeps PB service information in a bean // we need these information to remove the service from // Binary Service Registry later // we are using these bean instances in our destroyer serviceList.add(new ProtobufServiceData(serviceName, serviceType)); servletContext.setAttribute("services", serviceList); dynamic.addMapping("/"); } } catch (InvocationTargetException e) { String msg = "InvocationTargetException" + e.getLocalizedMessage(); log.error(msg, e); } catch (NoSuchMethodException e) { String msg = "NoSuchMethodException" + e.getLocalizedMessage(); log.error(msg, e); } catch (InstantiationException e) { String msg = "InstantiationException" + e.getLocalizedMessage(); log.error(msg, e); } catch (IllegalAccessException e) { String msg = "IllegalAccessException" + e.getLocalizedMessage(); log.error(msg, e); } } }