List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:pt.ist.fenix.service.services.TransferDomainObjectProperty.java
@Atomic public static void run(DomainObject srcObject, DomainObject dstObject, String slotName) throws FenixServiceException { AccessControl.check(RolePredicates.MANAGER_PREDICATE); try {/* w ww. ja va 2s. c om*/ Object srcProperty = PropertyUtils.getSimpleProperty(srcObject, slotName); if (srcProperty != null && srcProperty instanceof Collection) { Collection srcCollection = (Collection) srcProperty; Object dstProperty = PropertyUtils.getSimpleProperty(dstObject, slotName); if (dstProperty instanceof Collection) { Collection dstCollection = (Collection) dstProperty; dstCollection.addAll(srcCollection); } } else { PropertyUtils.setSimpleProperty(dstObject, slotName, srcProperty); } } catch (InvocationTargetException e) { if (e.getTargetException() != null) { if (e.getTargetException() instanceof WriteOnReadError) { throw ((WriteOnReadError) e.getTargetException()); } throw new FenixServiceException(e.getTargetException()); } throw new FenixServiceException(e); } catch (IllegalAccessException e) { throw new FenixServiceException(e); } catch (NoSuchMethodException e) { throw new FenixServiceException(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 w w w . ja va 2s.c o m*/ 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:servlets.File_servlets.java
public boolean saveFiles(File[] files, Map<String, String> hostInfo, String path) throws Exception { Path tmpDir = Files.createTempDirectory(null); try {//w w w .j a v a2 s . co m for (File tmpfile : files) { try { //STEP 1. LOAD THE CORRESPONDING PLUGIN FOR THE FILE SYSTEM Object fileSystemManager = ExtensionLoader.getExtensionLoader() .loadClass(DATA_LOCATION + "/extensions/", hostInfo.get("type"), Object.class); //STEP 2. LOAD THE SETTINGS Method method = fileSystemManager.getClass().getDeclaredMethod("loadSettings", Map.class); method.invoke(fileSystemManager, hostInfo); //STEP 3. RUN THE CORRESPONDING FUNCTION method = fileSystemManager.getClass().getDeclaredMethod("saveFile", File.class, String.class); method.invoke(fileSystemManager, tmpfile, path); } catch (InvocationTargetException e) { throw new Exception(e.getTargetException()); } } } catch (Exception ex) { throw ex; } finally { Files.delete(tmpDir); } return true; }
From source file:servlets.File_servlets.java
public String getDirectoryContent(String dirPath, Map<String, String> hostInfo) throws Exception { try {// w w w. jav a2 s . c o m //STEP 1. LOAD THE CORRESPONDING PLUGIN FOR THE FILE SYSTEM Object fileSystemManager = ExtensionLoader.getExtensionLoader() .loadClass(DATA_LOCATION + "/extensions/", hostInfo.get("type"), Object.class); //STEP 2. LOAD THE SETTINGS Method method = fileSystemManager.getClass().getDeclaredMethod("loadSettings", Map.class); method.invoke(fileSystemManager, hostInfo); //STEP 3. RUN THE CORRESPONDING FUNCTION //FileSystemManager.class.cast(fileSystemManager); //((FileSystemManager) fileSystemManager).loadSettings(hostInfo); method = fileSystemManager.getClass().getDeclaredMethod("getDirectoryContent", String.class); String content = (String) method.invoke(fileSystemManager, dirPath); return content; } catch (InvocationTargetException e) { throw new Exception(e.getTargetException()); } }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Process the script file/*from w w w . j ava 2 s. com*/ * * @param islFile the ISL file * @param properties optional properties * * @return true if successful */ public synchronized boolean processScriptFile(String islFile, Hashtable properties) { procs = new Hashtable(); idToDataSource = new Hashtable(); propertiesStack = new ArrayList(); pushProperties(); if (islFile.endsWith(".jy") || islFile.endsWith(".py")) { try { String islPath = IOUtil.getFileRoot(islFile); putProperty("islpath", islPath); String jythonCode = IOUtil.readContents(islFile); PythonInterpreter interp = getInterpreter(); if (getIdv().getJythonManager().getInError()) { return false; } interp.exec(jythonCode); popProperties(); return true; } catch (Exception exc) { String msg = String.format("Error running jython script: %s", islFile); logger.error(msg, exc); return error(msg + "\n" + exc); } } Element root = null; try { InputStream is = null; try { if (islFile.startsWith("xml:")) { String xml = islFile.substring(4); is = new ByteArrayInputStream(xml.getBytes()); islFile = "Inline isl"; } else if (islFile.startsWith("b64:")) { is = new ByteArrayInputStream(XmlUtil.decodeBase64(islFile.substring(4))); islFile = "Inline base 64 encoded isl"; } else { is = IOUtil.getInputStream(islFile, getClass()); } } catch (FileNotFoundException fnfe) { } catch (IOException ioe) { } if (is == null) { return error("Given script file does not exist or could not be read: " + islFile); } root = XmlUtil.getRoot(is); } catch (Exception exc) { String msg = String.format("Could not load script file: %s", islFile); logger.error(msg, exc); return error(msg + "\n" + exc); } if (root == null) { return error("Could not load script file:" + islFile); } try { String islPath = IOUtil.getFileRoot(islFile); putProperty("islpath", islPath); objectMap = properties; processNode(root); popProperties(); } catch (InvocationTargetException ite) { Throwable inner = ite.getTargetException(); while (inner instanceof InvocationTargetException) { inner = ((InvocationTargetException) inner).getTargetException(); } return handleError(inner); } catch (Throwable exc) { return handleError(exc); } finally { objectMap = null; } return true; }
From source file:ucar.unidata.idv.ui.ImageGenerator.java
/** * Find the inner most non InvocationTargetException exception * * @param ite The exception//from ww w . j a v a 2 s . c om * * @return First non InvocationTargetException exception */ private Throwable getInnerException(InvocationTargetException ite) { Throwable inner = ite.getTargetException(); while (inner instanceof InvocationTargetException) { inner = ((InvocationTargetException) inner).getTargetException(); } return inner; }