List of usage examples for java.lang Throwable toString
public String toString()
From source file:com.liferay.portal.editor.fckeditor.receiver.impl.BaseCommandReceiver.java
public void fileUpload(CommandArgument commandArgument, HttpServletRequest request, HttpServletResponse response) {/*from www . j a va 2s . c o m*/ InputStream inputStream = null; String returnValue = null; try { ServletFileUpload servletFileUpload = new LiferayFileUpload( new LiferayFileItemFactory(UploadServletRequestImpl.getTempDir()), request); servletFileUpload .setFileSizeMax(PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE)); LiferayServletRequest liferayServletRequest = new LiferayServletRequest(request); List<FileItem> fileItems = servletFileUpload.parseRequest(liferayServletRequest); Map<String, Object> fields = new HashMap<String, Object>(); for (FileItem fileItem : fileItems) { if (fileItem.isFormField()) { fields.put(fileItem.getFieldName(), fileItem.getString()); } else { fields.put(fileItem.getFieldName(), fileItem); } } DiskFileItem diskFileItem = (DiskFileItem) fields.get("NewFile"); String fileName = StringUtil.replace(diskFileItem.getName(), CharPool.BACK_SLASH, CharPool.SLASH); String[] fileNameArray = StringUtil.split(fileName, '/'); fileName = fileNameArray[fileNameArray.length - 1]; String contentType = diskFileItem.getContentType(); if (Validator.isNull(contentType) || contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) { contentType = MimeTypesUtil.getContentType(diskFileItem.getStoreLocation()); } if (diskFileItem.isInMemory()) { inputStream = diskFileItem.getInputStream(); } else { inputStream = new ByteArrayFileInputStream(diskFileItem.getStoreLocation(), LiferayFileItem.THRESHOLD_SIZE); } long size = diskFileItem.getSize(); returnValue = fileUpload(commandArgument, fileName, inputStream, contentType, size); } catch (Exception e) { FCKException fcke = null; if (e instanceof FCKException) { fcke = (FCKException) e; } else { fcke = new FCKException(e); } Throwable cause = fcke.getCause(); returnValue = "203"; if (cause != null) { String causeString = GetterUtil.getString(cause.toString()); if (causeString.contains("NoSuchFolderException") || causeString.contains("NoSuchGroupException")) { returnValue = "204"; } else if (causeString.contains("ImageNameException")) { returnValue = "205"; } else if (causeString.contains("FileExtensionException") || causeString.contains("FileNameException")) { returnValue = "206"; } else if (causeString.contains("PrincipalException")) { returnValue = "207"; } else if (causeString.contains("ImageSizeException") || causeString.contains("FileSizeException")) { returnValue = "208"; } else if (causeString.contains("SystemException")) { returnValue = "209"; } else { throw fcke; } } _writeUploadResponse(returnValue, response); } finally { StreamUtil.cleanUp(inputStream); } _writeUploadResponse(returnValue, response); }
From source file:eionet.cr.api.xmlrpc.XmlRpcServices.java
@Override public List getResourcesSinceTimestamp(Date timestamp) throws CRException { if (logger.isInfoEnabled()) { logger.info("Entered " + Thread.currentThread().getStackTrace()[1].getMethodName()); }/*from w ww. j av a2 s . c o m*/ List<Map<String, String[]>> result = new ArrayList<Map<String, String[]>>(); if (timestamp != null) { // given timestamp must be less than current time (in seconds) long curTimeSeconds = Util.currentTimeSeconds(); long givenTimeSeconds = Util.getSeconds(timestamp.getTime()); if (givenTimeSeconds < curTimeSeconds) { try { Collection<SubjectDTO> subjects = DAOFactory.get().getDao(HelperDAO.class) .getSubjectsNewerThan(timestamp, MAX_RESULTS); for (Iterator<SubjectDTO> subjectsIter = subjects.iterator(); subjectsIter.hasNext();) { SubjectDTO subjectDTO = subjectsIter.next(); HashMap<String, String[]> map = new HashMap<String, String[]>(); for (Iterator<String> predicatesIter = subjectDTO.getPredicates().keySet() .iterator(); predicatesIter.hasNext();) { String predicate = predicatesIter.next(); map.put(predicate, toStringArray(subjectDTO.getObjects(predicate))); } // if map not empty and the subject has a URL (i.e. getUrl() is not blank) // then add the map to result if (!map.isEmpty()) { String url = subjectDTO.getUrl(); if (!StringUtils.isBlank(url)) { String[] arr = new String[1]; arr[0] = url; map.put(Predicates.CR_URL, arr); // QAW needs this special reserved predicate result.add(map); } } } } catch (Throwable t) { t.printStackTrace(); if (t instanceof CRException) { throw (CRException) t; } else { throw new CRException(t.toString(), t); } } } } return result; }
From source file:ch.rasc.wampspring.method.WampAnnotationMethodMessageHandler.java
private void handleCallMessage(CallMessage callMessage, WampHandlerMethod handlerMethod) { try {/*w ww .ja v a2 s.com*/ checkAuthentication(handlerMethod, callMessage); InvocableWampHandlerMethod invocable = new InvocableWampHandlerMethod( handlerMethod.createWithResolvedBean(), this.methodParameterConverter); invocable.setMessageMethodArgumentResolvers(this.argumentResolvers); Object[] arguments = null; if (callMessage.getArguments() != null) { arguments = callMessage.getArguments().toArray(); } Object returnValue = invocable.invoke(callMessage, arguments); CallResultMessage callResultMessage = new CallResultMessage(callMessage, returnValue); send(callResultMessage); } catch (Exception ex) { CallErrorMessage callErrorMessage = new CallErrorMessage(callMessage, "", ex.toString()); send(callErrorMessage); this.logger.error("Error while processing message " + callMessage, ex); } catch (Throwable t) { CallErrorMessage callErrorMessage = new CallErrorMessage(callMessage, "", t.toString()); send(callErrorMessage); this.logger.error("Error while processing message " + callErrorMessage, t); } }
From source file:dk.dbc.opensearch.datadock.DatadockPool.java
/** * Checks the jobs submitted for execution * /*from w w w . ja va 2 s. com*/ * if a Job throws an exception it is written to the log and the * datadock continues. * * @throws InterruptedException if the job.get() call is interrupted (by kill or otherwise). */ public void checkJobs() throws InterruptedException { log.debug("DatadockPool method checkJobs called"); log.debug(String.format("job size = %s", jobs.size())); Set<IIdentifier> finishedJobs = new HashSet<IIdentifier>(); for (IIdentifier id : jobs.keySet()) { FutureTask<Boolean> job = jobs.get(id); log.debug(String.format("job is done: %s", job.isDone())); if (job.isDone()) { Boolean success = Boolean.FALSE; try { log.debug("DatadockPool checking job"); success = job.get(); } catch (ExecutionException ee) { // getting exception from thread Throwable cause = ee.getCause(); log.error(String.format("Exception caught for identifier: %s, from thread: '%s'", id, cause), cause); log.info(String.format("Setting status to FAILURE for identifier: %s with message: '%s'", id, cause.getMessage())); try { String msg = cause.getMessage() == null ? cause.toString() : cause.getMessage(); // avoid giving null to setStatusFailure harvester.setStatusFailure(id, msg); } catch (HarvesterUnknownIdentifierException ex) { String error = String.format( "Failed to set failure status for identifier: %s . Message: %s", id, ex.getMessage()); log.error(error, ex); } catch (HarvesterInvalidStatusChangeException ex) { String error = String.format( "Failed to set failure status for identifier: %s . Message: %s", id, ex.getMessage()); log.error(error, ex); } catch (HarvesterIOException ex) { String error = String.format( "Failed to set failure status for identifier: %s . Message: %s", id, ex.getMessage()); log.error(error, ex); } } log.debug("DatadockPool adding to finished jobs"); finishedJobs.add(id); } } for (IIdentifier finishedJobId : finishedJobs) { log.debug(String.format("Removing Job with id: %s. Remaining jobs: %s", finishedJobId, jobs.size())); jobs.remove(finishedJobId); } }
From source file:io.bitsquare.gui.util.BSFormatter.java
public String formatCoin(Coin coin) { if (coin != null) { try {// w w w .j a v a 2s. co m return coinFormat.noCode().format(coin).toString(); } catch (Throwable t) { log.warn("Exception at formatBtc: " + t.toString()); return ""; } } else { return ""; } }
From source file:io.bitsquare.gui.util.BSFormatter.java
public Coin parseToCoin(String input) { if (input != null && input.length() > 0) { try {// w w w . ja v a 2s . c o m return coinFormat.parse(cleanInput(input)); } catch (Throwable t) { log.warn("Exception at parseToBtc: " + t.toString()); return Coin.ZERO; } } else { return Coin.ZERO; } }
From source file:io.bitsquare.gui.util.BSFormatter.java
public String formatFiat(Fiat fiat) { if (fiat != null) { try {//from w ww . j a v a 2 s.c o m return fiatFormat.noCode().format(fiat).toString(); } catch (Throwable t) { log.warn("Exception at formatFiat: " + t.toString()); return "N/A " + fiat.getCurrencyCode(); } } else { return "N/A"; } }
From source file:io.bitsquare.gui.util.BSFormatter.java
private String formatFiatWithCode(Fiat fiat) { if (fiat != null) { try {//from w ww . j ava 2 s. c om return fiatFormat.noCode().format(fiat).toString() + " " + fiat.getCurrencyCode(); } catch (Throwable t) { log.warn("Exception at formatFiatWithCode: " + t.toString()); return "N/A " + fiat.getCurrencyCode(); } } else { return "N/A"; } }
From source file:io.bitsquare.gui.util.BSFormatter.java
public String formatCoinWithCode(Coin coin) { if (coin != null) { try {// w w w . j av a 2s .com // we don't use the code feature from coinFormat as it does automatic switching between mBTC and BTC and // pre and post fixing return coinFormat.postfixCode().format(coin).toString(); } catch (Throwable t) { log.warn("Exception at formatBtcWithCode: " + t.toString()); return ""; } } else { return ""; } }
From source file:com.xinlan.otma.net.CustomHttpResponseHandler.java
@Override public final void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) { if (responseBytes != null) { Runnable parser = new Runnable() { @Override//from w w w. j a v a 2 s. co m public void run() { try { // final T jsonResponse = parseResponse(responseBytes); postRunnable(new Runnable() { @Override public void run() { onFailure(statusCode, headers, throwable, throwable.toString()); } }); } catch (final Exception ex) { postRunnable(new Runnable() { @Override public void run() { onFailure(statusCode, headers, ex, ex.toString()); } }); } } }; if (!getUseSynchronousMode()) { new Thread(parser).start(); } else { // In synchronous mode everything should be run on one thread parser.run(); } } else { Log.v(LOG_TAG, "response body is null, calling onFailure(Throwable, JSONObject)"); onFailure(statusCode, headers, throwable, throwable.toString()); } }