List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.gtwm.pb.servlets.ServletUtilMethods.java
/** * Return a string for logging purposes, of an exception's 'cause stack', * i.e. the original exception(s) thrown and stack trace, i.e. the methods * that the exception was thrown through. * /*from w w w . j a v a 2 s. c o m*/ * Called by logException */ private static String getExceptionCauses(Exception ex) { String errorMessage = ex.toString() + "\r\n"; if (ex.getCause() != null) { // Recursively find causes of exception errorMessage += " - Error was due to..."; Exception exceptionCause = ex; String causeIndent = " - "; errorMessage += causeIndent + ex.toString() + "\r\n"; while (exceptionCause.getCause() != null) { if (exceptionCause.getCause() instanceof Exception) { exceptionCause = (Exception) exceptionCause.getCause(); causeIndent += " - "; errorMessage += causeIndent + getExceptionCauses(exceptionCause); } } } // Include out relevant parts of the stack trace StackTraceElement[] stackTrace = ex.getStackTrace(); if (stackTrace.length > 0) { errorMessage += " - Stack trace:\r\n"; int nonGtwmClassesLogged = 0; for (StackTraceElement stackTraceElement : stackTrace) { if (!stackTraceElement.getClassName().startsWith("com.gtwm.")) { nonGtwmClassesLogged++; } // Only trace our own classes + a few more, stop shortly after // we get to java language or 3rd party classes if (nonGtwmClassesLogged < 15) { errorMessage += " " + stackTraceElement.toString() + "\r\n"; } } } return errorMessage; }
From source file:com.baasbox.configuration.PropertiesConfigurationHelper.java
/*** * Set an Enumerator value.//from w w w . j a v a2s . c o m * The Enumerator class must implement the IProperties interface * @param en The Enumerator class * @param iKey * @param value * @throws ConfigurationException * @throws PushNotInitializedException * @throws PushSwitchException * @throws Exception */ public static void setByKey(Class en, String iKey, Object value) throws ConfigurationException { Object enumValue = findByKey(en, iKey); try { en.getMethod("setValue", Object.class).invoke(enumValue, value); } catch (Exception e) { if (e.getCause() instanceof IllegalStateException) throw new IllegalStateException(e.getCause()); if (e.getCause() instanceof PushSwitchException) throw (PushSwitchException) e.getCause(); if (e.getCause() instanceof PushNotInitializedException) throw (PushNotInitializedException) e.getCause(); if (e.getCause() instanceof PushInvalidApiKeyException) throw (PushInvalidApiKeyException) e.getCause(); throw new ConfigurationException("Invalid key (" + iKey + ") or value (" + value + ")", e); } }
From source file:com.opengamma.integration.tool.marketdata.MarketDataSnapshotTool.java
private static StructuredMarketDataSnapshot makeSnapshot(final MarketDataSnapshotter marketDataSnapshotter, final ViewProcessor viewProcessor, final ViewDefinition viewDefinition, final ViewExecutionOptions viewExecutionOptions) throws InterruptedException { final ViewClient vc = viewProcessor.createViewClient(UserPrincipal.getLocalUser()); vc.setResultListener(new ViewResultListener() { @Override/*w w w . ja v a 2s . c o m*/ public UserPrincipal getUser() { String ipAddress; try { ipAddress = InetAddress.getLocalHost().getHostAddress(); } catch (final UnknownHostException e) { ipAddress = "unknown"; } return new UserPrincipal("MarketDataSnapshotterTool", ipAddress); } @Override public void viewDefinitionCompiled(final CompiledViewDefinition compiledViewDefinition, final boolean hasMarketDataPermissions) { } @Override public void viewDefinitionCompilationFailed(final Instant valuationTime, final Exception exception) { s_logger.error(exception.getMessage() + "\n\n" + (exception.getCause() == null ? "" : exception.getCause().getMessage())); } @Override public void cycleStarted(final ViewCycleMetadata cycleMetadata) { } @Override public void cycleFragmentCompleted(final ViewComputationResultModel fullFragment, final ViewDeltaResultModel deltaFragment) { } @Override public void cycleCompleted(final ViewComputationResultModel fullResult, final ViewDeltaResultModel deltaResult) { s_logger.info("cycle completed"); } @Override public void cycleExecutionFailed(final ViewCycleExecutionOptions executionOptions, final Exception exception) { s_logger.error(exception.getMessage() + "\n\n" + (exception.getCause() == null ? "" : exception.getCause().getMessage())); } @Override public void processCompleted() { } @Override public void processTerminated(final boolean executionInterrupted) { } @Override public void clientShutdown(final Exception e) { } }); vc.setViewCycleAccessSupported(true); vc.attachToViewProcess(viewDefinition.getUniqueId(), viewExecutionOptions); vc.waitForCompletion(); vc.pause(); EngineResourceReference<? extends ViewCycle> cycleReference = null; try { cycleReference = vc.createLatestCycleReference(); return marketDataSnapshotter.createSnapshot(vc, cycleReference.get()); } finally { cycleReference.release(); vc.shutdown(); } }
From source file:org.duracloud.duradmin.util.SpaceUtil.java
public static void streamToResponse(InputStream is, HttpServletResponse response, String mimetype, String contentLength) throws ContentStoreException, IOException { OutputStream outStream = response.getOutputStream(); try {/*from ww w . j a v a 2 s .co m*/ response.setContentType(mimetype); if (contentLength != null) { response.setContentLengthLong(Long.parseLong(contentLength)); } byte[] buf = new byte[1024]; int read = -1; while ((read = is.read(buf)) > 0) { outStream.write(buf, 0, read); } response.flushBuffer(); } catch (Exception ex) { if (ex.getCause() instanceof ContentStateException) { response.reset(); response.setStatus(HttpStatus.SC_CONFLICT); String message = "The requested content item is currently in long-term storage" + " with limited retrieval capability. Please contact " + "DuraCloud support (https://wiki.duraspace.org/x/6gPNAQ) " + "for assistance in retrieving this content item."; //It is necessary to pad the message in order to force Internet Explorer to //display the server sent text rather than display the browser default error message. //If the message is less than 512 bytes, the browser will ignore the message. //c.f. http://support.microsoft.com/kb/294807 message += StringUtils.repeat(" ", 512); outStream.write(message.getBytes()); } else { throw ex; } } finally { try { outStream.close(); } catch (Exception e) { log.warn("failed to close outputstream ( " + outStream + "): message=" + e.getMessage(), e); } } }
From source file:gr.scify.newsum.Utils.java
/** * //from w w w .ja va2s .com * @param sCustomUrl the URL to access data * @return the data processed from that URL */ public static String getFromHttp(String sCustomUrl, boolean getHeader) { String sRes = null; BufferedReader in = null; // if getHead is True, bring url head, else bring url text // return "this is a new String from the custom tab"; try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); // set the url request.setURI(new URI(sCustomUrl)); HttpResponse response = client.execute(request); // init the reader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(); String line = ""; while ((line = in.readLine()) != null) { // sb.append(Html.fromHtml(line).toString()); sb.append(line); } System.out.println(sb.toString()); in.close(); if (getHeader) { // fetch only header return getTitle(sb.toString(), "<title>(.*|\\\n*)</title>"); } sRes = sb.toString(); // System.out.println(page); } catch (Exception ex) { System.err.println("ERROR" + ex.getCause()); } return sRes; }
From source file:org.openspaces.rest.utils.ControllerUtils.java
public static SpaceDocument[] createSpaceDocuments(String type, String body, GigaSpace gigaSpace) throws TypeNotFoundException { HashMap<String, Object>[] propertyMapArr; try {//from ww w . j a v a 2s . c o m //if single json object convert it to array String data = body; if (!body.startsWith("[")) { StringBuilder sb = new StringBuilder(body); sb.insert(0, "["); sb.append("]"); data = sb.toString(); } //convert to json propertyMapArr = mapper.readValue(data, typeRef); } catch (Exception e) { throw new HttpMessageNotReadableException(e.getMessage(), e.getCause()); } SpaceDocument[] documents = new SpaceDocument[propertyMapArr.length]; for (int i = 0; i < propertyMapArr.length; i++) { Map<String, Object> typeBasedProperties = getTypeBasedProperties(type, propertyMapArr[i], gigaSpace); documents[i] = new SpaceDocument(type, typeBasedProperties); } return documents; }
From source file:com.wineaccess.winerylicensedetail.WineryLicenseDetailAdapterHelper.java
/** * This method is used to update the WineryLicenseDetail in the database. * //from w w w . ja v a 2 s. c o m * @param wineryLicenseDetailUpdatePO * is used to take the input in this PO. * @return output map containing response */ public static Map<String, Object> updateWineryLicenseDetail( final WineryLicenseDetailUpdatePO wineryLicenseDetailUpdatePO) { logger.info("start updateWineryLicenseDetail method"); String errorMsg = StringUtils.EMPTY; final Map<String, Object> output = new ConcurrentHashMap<String, Object>(); Response response = null; try { MasterData caLicenseType = null; WineryModel winery = null; WineryLicenseDetailModel wineryLicenseDetailModel = null; if ((wineryLicenseDetailUpdatePO.getCaLicenseTypeId() != null) && !(wineryLicenseDetailUpdatePO.getCaLicenseTypeId().isEmpty())) { caLicenseType = MasterDataRepository .getMasterDataById(Long.parseLong(wineryLicenseDetailUpdatePO.getCaLicenseTypeId())); if (caLicenseType == null) { // caLicenseType not exist response = ApplicationUtils.errorMessageGenerate( SystemErrorCode.UPDATE_WINERY_LICENSE_INVALID_CA_LICENSE_TYPE, SystemErrorCode.UPDATE_WINERY_LICENSE_INVALID_CA_LICENSE_TYPE_TEXT, SUCCESS_CODE); logger.error("CA License Type not exist"); } } if (response == null && wineryLicenseDetailUpdatePO.getWineryId() != null) { winery = WineryRepository.getWineryById(Long.parseLong(wineryLicenseDetailUpdatePO.getWineryId())); if (winery == null) { // winery not exist response = ApplicationUtils.errorMessageGenerate( SystemErrorCode.UPDATE_WINERY_LICENSE_INVALID_WINERY, SystemErrorCode.UPDATE_WINERY_LICENSE_INVALID_WINERY_TEXT, SUCCESS_CODE); logger.error("winery not exist"); } } if (response == null) { wineryLicenseDetailModel = WineryLicenseDetailRepository.getWineryLicenseDetailByWinery(winery); if (wineryLicenseDetailModel == null) { wineryLicenseDetailModel = new WineryLicenseDetailModel(); wineryLicenseDetailModel.setCaLicenseType(caLicenseType); wineryLicenseDetailModel.setWinery(winery); if (wineryLicenseDetailUpdatePO.getContractExecuted() != null) { wineryLicenseDetailModel.setContractExecuted( Boolean.parseBoolean(wineryLicenseDetailUpdatePO.getContractExecuted())); } else { wineryLicenseDetailModel.setContractExecuted(false); } if (wineryLicenseDetailUpdatePO.getShipCompliant() != null) { wineryLicenseDetailModel.setShipCompliant( Boolean.parseBoolean(wineryLicenseDetailUpdatePO.getShipCompliant())); } else { wineryLicenseDetailModel.setShipCompliant(false); } if (wineryLicenseDetailUpdatePO.getShipEscrowNo() != null) { wineryLicenseDetailModel.setShipEscrowNo(wineryLicenseDetailUpdatePO.getShipEscrowNo()); } WineryLicenseDetailRepository.save(wineryLicenseDetailModel); WineryLicenseDetailVO wineryLicenseDetailVO = new WineryLicenseDetailVO( SystemErrorCode.UPDATE_WINERY_LICENSE_SUCCESS_TEXT); BeanUtils.copyProperties(wineryLicenseDetailVO, wineryLicenseDetailModel); wineryLicenseDetailVO.setWineryId(wineryLicenseDetailModel.getWinery().getId()); response = new com.wineaccess.response.SuccessResponse(wineryLicenseDetailVO, SUCCESS_CODE); } } if (response == null) { //if (caLicenseType != null) { wineryLicenseDetailModel.setCaLicenseType(caLicenseType); //} wineryLicenseDetailModel.setWinery(winery); if (wineryLicenseDetailUpdatePO.getContractExecuted() != null) { wineryLicenseDetailModel.setContractExecuted( Boolean.parseBoolean(wineryLicenseDetailUpdatePO.getContractExecuted())); } if (wineryLicenseDetailUpdatePO.getShipCompliant() != null) { wineryLicenseDetailModel .setShipCompliant(Boolean.parseBoolean(wineryLicenseDetailUpdatePO.getShipCompliant())); } if (wineryLicenseDetailUpdatePO.getShipEscrowNo() != null) { wineryLicenseDetailModel.setShipEscrowNo(wineryLicenseDetailUpdatePO.getShipEscrowNo()); } WineryLicenseDetailRepository.update(wineryLicenseDetailModel); WineryLicenseDetailVO wineryLicenseDetailVO = new WineryLicenseDetailVO( SystemErrorCode.UPDATE_WINERY_LICENSE_SUCCESS_TEXT); BeanUtils.copyProperties(wineryLicenseDetailVO, wineryLicenseDetailModel); wineryLicenseDetailVO.setWineryId(wineryLicenseDetailModel.getWinery().getId()); response = new com.wineaccess.response.SuccessResponse(wineryLicenseDetailVO, SUCCESS_CODE); } } catch (Exception e) { errorMsg = e.getCause().getMessage(); } if (errorMsg.contains("uk_winery_id")) { response = ApplicationUtils.errorMessageGenerate(SystemErrorCode.UPDATE_WINERY_LICENSE_ALREADY_EXISTS, SystemErrorCode.UPDATE_WINERY_LICENSE_ALREADY_EXISTS_TEXT, SUCCESS_CODE); logger.error("winery license detail already exists"); } output.put(OUPUT_PARAM_KEY, response); logger.info("exit updateWineryLicenseDetail method"); return output; }
From source file:org.hyperic.hq.plugin.appha.VSphereUtil.java
static String getUuid(ManagedEntity entity) { if (entity == null) { return null; }/*from ww w . j av a 2s .c om*/ String uuid = null; try { if (entity instanceof HostSystem) { HostSystem host = (HostSystem) entity; HostListSummary summary = host.getSummary(); if (summary == null) { return null; } HostHardwareSummary hardware = summary.getHardware(); if (hardware == null) { return null; } uuid = hardware.getUuid(); } else if (entity instanceof VirtualMachine) { VirtualMachine vm = (VirtualMachine) entity; VirtualMachineConfigInfo config = vm.getConfig(); if (config == null) { return null; } uuid = config.getUuid(); } } catch (Exception e) { Throwable causeBy = e.getCause(); if (e instanceof ManagedObjectNotFound || causeBy instanceof ManagedObjectNotFound) { if (_log.isDebugEnabled()) { _log.debug("getUuid: ManagedEntity[name=" + entity.getName() + "] not found."); } } else { _log.info("Could not get UUID for ManagedEntity[name=" + entity.getName() + "]: " + e.getMessage(), e); } return null; } return uuid; }
From source file:com.taobao.datax.plugins.common.DBSource.java
/** * A synchronized static method which create {@link DataSource}. NOTE: * Client must make sure all connections to the same database should share * the same value a suggestion: use genKey we provide below * //from w w w. j a v a 2s . c o m * @param key * key to query database source * * @param p * Properties file. * * @return true if create DataSource successfully, false if failed. * * @throws IllegalStateException * */ public static synchronized boolean register(String key, Properties p) { boolean succeed = false; if (!sourceInfoMap.containsKey(key)) { BasicDataSource dataSource = null; try { dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(p); } catch (Exception e) { logger.error(String.format("Key [%s] register database pool failed .", key)); throw new IllegalStateException(e.getCause()); } if (null != dataSource) { dataSource.setAccessToUnderlyingConnectionAllowed(true); sourceInfoMap.put(key, dataSource); logger.info(String.format("Key [%s] register database pool successfully .", key)); succeed = true; } else { logger.error(String.format("Key [%s] register database pool failed .", key)); } } else { logger.error(String.format("Key [%s] already in database pool .", key)); } return succeed; }
From source file:com.ecofactor.qa.automation.platform.util.SeleniumDriverUtil.java
/** * Check if appium error. Display if any appium error and throws DeviceException. * @param exception the ex/*w w w .j ava2s . c om*/ * @throws DeviceException the device exception */ private static void checkIfAppiumError(final Exception exception) throws DeviceException { setErrorMsg("\033[41;1mError in creating driver. " + exception.getMessage()); if (exception.getCause() instanceof HttpHostConnectException) { setErrorMsg("\033[41;1mAppium not started, Please start."); } setLogString(LogSection.END, errorMsg, true); hasErrors = true; throw new DeviceException(getErrorMsg()); }