List of usage examples for java.lang Exception toString
public String toString()
From source file:gdt.jgui.entity.folder.JFolderFacetOpenItem.java
private static boolean isTextFile(File file) { try {/* w w w .j a v a 2 s. co m*/ String mime$ = Files.probeContentType(file.toPath()); //System.out.println("FileOpenItem: isTextFile:mime="+mime$); if (mime$.equals("text/plain")) return true; return false; } catch (Exception e) { Logger.getLogger(JFileOpenItem.class.getName()).info(e.toString()); return false; } }
From source file:com.gtwm.pb.servlets.ServletUtilMethods.java
/** * Log errors with as much information as possible: include user, URL, * recursive causes and a stack trace to the original occurence in the * application/*from w ww. jav a 2s . c om*/ * * NB Doesn't throw a servletException, that has to be done as well as * calling this */ public static void logException(Exception ex, HttpServletRequest request, String topLevelMessage) { String errorMessage = ""; if (topLevelMessage != null) { errorMessage += topLevelMessage + "\r\n" + " - "; } errorMessage += ex.toString() + "\r\n"; errorMessage += " - URL = " + getRequestQuery(request) + "\r\n"; errorMessage += " - Logged in user: " + request.getRemoteUser() + "\r\n"; errorMessage += getExceptionCauses(ex); logger.error(errorMessage); }
From source file:eionet.rod.countrysrv.Extractor.java
public static void execute(int mode, String userName) { try {/* w ww. ja va2 s . c o m*/ if (extractor == null) { extractor = new Extractor(); } extractor.harvest(mode, userName); } catch (Exception e) { LOGGER.error(e.getMessage(), e); RODServices.sendEmail("Error in extractor", e.toString()); } }
From source file:com.socrata.datasync.job.MetadataJob.java
public static JobStatus addLogEntry(String logDatasetID, SocrataConnectionInfo connectionInfo, MetadataJob job, JobStatus status) {/*from w w w . java2s. c om*/ final Soda2Producer producer = Soda2Producer.newProducer(connectionInfo.getUrl(), connectionInfo.getUser(), connectionInfo.getPassword(), connectionInfo.getToken()); List<Map<String, Object>> upsertObjects = new ArrayList<Map<String, Object>>(); Map<String, Object> newCols = new HashMap<String, Object>(); // add standard log data Date currentDateTime = new Date(); newCols.put("Date", (Object) currentDateTime); newCols.put("DatasetID", (Object) job.getDatasetID()); newCols.put("JobFile", (Object) job.getPathToSavedFile()); if (status.isError()) { newCols.put("Errors", (Object) status.getMessage()); } else { newCols.put("Success", (Object) true); } upsertObjects.add(ImmutableMap.copyOf(newCols)); JobStatus logStatus = JobStatus.SUCCESS; String errorMessage = ""; boolean noPublishExceptions = false; try { producer.upsert(logDatasetID, upsertObjects); noPublishExceptions = true; } catch (SodaError sodaError) { errorMessage = sodaError.getMessage(); } catch (InterruptedException intrruptException) { errorMessage = intrruptException.getMessage(); } catch (Exception other) { errorMessage = other.toString() + ": " + other.getMessage(); } finally { if (!noPublishExceptions) { logStatus = JobStatus.PUBLISH_ERROR; logStatus.setMessage(errorMessage); } } return logStatus; }
From source file:com.sachachua.quantified.client.NetworkUtilities.java
/** * Perform 2-way sync with the server-side contacts. We send a request that * includes all the locally-dirty contacts so that the server can process * those changes, and we receive (and return) a list of contacts that were * updated on the server-side that need to be updated locally. * * @param account The account being synced * @param authtoken The authtoken stored in the AccountManager for this * account/*from w ww . ja va2s.c om*/ * @param serverSyncState A token returned from the server on the last sync * @param dirtyContacts A list of the contacts to send to the server * @return A list of contacts that we need to update locally */ /*public static List<RawContact> syncContacts( Account account, String authtoken, long serverSyncState, List<RawContact> dirtyContacts) throws JSONException, ParseException, IOException, AuthenticationException { // Convert our list of User objects into a list of JSONObject List<JSONObject> jsonContacts = new ArrayList<JSONObject>(); for (RawContact rawContact : dirtyContacts) { jsonContacts.add(rawContact.toJSONObject()); } // Create a special JSONArray of our JSON contacts JSONArray buffer = new JSONArray(jsonContacts); // Create an array that will hold the server-side contacts // that have been changed (returned by the server). final ArrayList<RawContact> serverDirtyList = new ArrayList<RawContact>(); // Prepare our POST data final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(PARAM_USERNAME, account.name)); params.add(new BasicNameValuePair(PARAM_AUTH_TOKEN, authtoken)); params.add(new BasicNameValuePair(PARAM_CONTACTS_DATA, buffer.toString())); if (serverSyncState > 0) { params.add(new BasicNameValuePair(PARAM_SYNC_STATE, Long.toString(serverSyncState))); } Log.i(TAG, params.toString()); HttpEntity entity = new UrlEncodedFormEntity(params); // Send the updated friends data to the server Log.i(TAG, "Syncing to: " + SYNC_CONTACTS_URI); final HttpPost post = new HttpPost(SYNC_CONTACTS_URI); post.addHeader(entity.getContentType()); post.setEntity(entity); final HttpResponse resp = getHttpClient().execute(post); final String response = EntityUtils.toString(resp.getEntity()); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Our request to the server was successful - so we assume // that they accepted all the changes we sent up, and // that the response includes the contacts that we need // to update on our side... final JSONArray serverContacts = new JSONArray(response); Log.d(TAG, response); for (int i = 0; i < serverContacts.length(); i++) { RawContact rawContact = RawContact.valueOf(serverContacts.getJSONObject(i)); if (rawContact != null) { serverDirtyList.add(rawContact); } } } else { if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "Authentication exception in sending dirty contacts"); throw new AuthenticationException(); } else { Log.e(TAG, "Server error in sending dirty contacts: " + resp.getStatusLine()); throw new IOException(); } } return serverDirtyList; } /** * Download the avatar image from the server. * * @param avatarUrl the URL pointing to the avatar image * @return a byte array with the raw JPEG avatar image */ /*public static byte[] downloadAvatar(final String avatarUrl) { // If there is no avatar, we're done if (TextUtils.isEmpty(avatarUrl)) { return null; } try { Log.i(TAG, "Downloading avatar: " + avatarUrl); // Request the avatar image from the server, and create a bitmap // object from the stream we get back. URL url = new URL(avatarUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); try { final BitmapFactory.Options options = new BitmapFactory.Options(); final Bitmap avatar = BitmapFactory.decodeStream(connection.getInputStream(), null, options); // Take the image we received from the server, whatever format it // happens to be in, and convert it to a JPEG image. Note: we're // not resizing the avatar - we assume that the image we get from // the server is a reasonable size... Log.i(TAG, "Converting avatar to JPEG"); ByteArrayOutputStream convertStream = new ByteArrayOutputStream( avatar.getWidth() * avatar.getHeight() * 4); avatar.compress(Bitmap.CompressFormat.JPEG, 95, convertStream); convertStream.flush(); convertStream.close(); // On pre-Honeycomb systems, it's important to call recycle on bitmaps avatar.recycle(); return convertStream.toByteArray(); } finally { connection.disconnect(); } } catch (MalformedURLException muex) { // A bad URL - nothing we can really do about it here... Log.e(TAG, "Malformed avatar URL: " + avatarUrl); } catch (IOException ioex) { // If we're unable to download the avatar, it's a bummer but not the // end of the world. We'll try to get it next time we sync. Log.e(TAG, "Failed to download user avatar: " + avatarUrl); } return null; } /**/ public static String readStringFromURL(String url) { //initialize InputStream is = null; String result = ""; //http post try { HttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } //convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } return result; }
From source file:org.kegbot.app.setup.SetupFragment.java
protected static String toHumanError(Exception e) { StringBuilder builder = new StringBuilder(); if (e.getCause() instanceof HttpHostConnectException) { builder.append("Could not connect to remote host."); } else if (e instanceof NotAuthorizedException) { builder.append("Username or password was incorrect."); } else if (e instanceof KegbotApiServerError) { builder.append("Bad response from server ("); builder.append(e.toString()); builder.append(")"); } else if (e instanceof SocketException || e.getCause() instanceof SocketException) { builder.append("Server is down or unreachable."); } else {// w w w .ja v a 2 s .c om builder.append(e.getMessage()); } return builder.toString(); }
From source file:com.mapr.ocr.text.ImageToText.java
public static String processPDF(String fileName) { File imageFile = new File(fileName); StringBuilder resultText = new StringBuilder(); PDFDocument pdfDocument = new PDFDocument(); try {/*from w ww. j a v a2 s .c om*/ pdfDocument.load(imageFile); SimpleRenderer simpleRenderer = new SimpleRenderer(); simpleRenderer.setResolution(300); List<Image> images = simpleRenderer.render(pdfDocument); ITesseract tesseract = new Tesseract(); tesseract.setLanguage("eng"); for (Image x : images) { resultText.append(tesseract.doOCR((BufferedImage) x)); } } catch (Exception e) { e.printStackTrace(); LOGGER.log(Level.SEVERE, "Exception processing PDF file " + fileName + " " + e); String rowKey = FilenameUtils .removeExtension(fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length())); populateDataInMapRDB(config, errorTable, rowKey, cf, "error", e.toString()); populateDataInMapRDB(config, errorTable, rowKey, cf, "filepath", fileName); } finally { return resultText.toString(); } }
From source file:com.microsoft.azure.utility.compute.ComputeTestBase.java
protected static VirtualMachine createVM(ResourceContext context, String vmName, String userName, String password, boolean createWithPublicIpAddr, ConsumerWrapper<VirtualMachine> vmInputModifier) throws Exception { log.info(String.format("Create vm in %s: %s, rg: %s", context.getLocation(), vmName, context.getResourceGroupName())); if (context == null) { context = createTestResourceContext(createWithPublicIpAddr); }/*www . j a va 2s .c o m*/ VirtualMachineCreateOrUpdateResponse vmResponse; try { vmResponse = ComputeHelper.createVM(resourceManagementClient, computeManagementClient, networkResourceProviderClient, storageManagementClient, context, vmName, userName, password, vmInputModifier); } catch (Exception ex) { log.info(ex.toString()); throw ex; } log.info(vmResponse.getVirtualMachine().getName() + " creation is requested."); // String expectedVMRefId = ComputeTestHelper.getVMReferenceId(m_subId, m_rgName, vmName); Assert.assertEquals(HttpStatus.SC_CREATED, vmResponse.getStatusCode()); Assert.assertEquals(vmName, vmResponse.getVirtualMachine().getName()); Assert.assertEquals(context.getVMInput().getLocation().toLowerCase(), vmResponse.getVirtualMachine().getLocation().toLowerCase()); Assert.assertEquals(context.getAvailabilitySetId().toLowerCase(), vmResponse.getVirtualMachine().getAvailabilitySetReference().getReferenceUri().toLowerCase()); validateVM(context.getVMInput(), vmResponse.getVirtualMachine()); //wait for the vm creation ComputeLongRunningOperationResponse lroResponse = computeManagementClient .getLongRunningOperationStatus(vmResponse.getAzureAsyncOperation()); validateLROResponse(lroResponse, vmResponse.getAzureAsyncOperation()); //validate get vm log.info("get vm"); VirtualMachineGetResponse getVMResponse = computeManagementClient.getVirtualMachinesOperations() .get(context.getResourceGroupName(), vmName); Assert.assertEquals(HttpStatus.SC_OK, getVMResponse.getStatusCode()); validateVM(context.getVMInput(), getVMResponse.getVirtualMachine()); return getVMResponse.getVirtualMachine(); }
From source file:com.dv.Utils.Tools.java
/** * ?/*from ww w .j a v a 2 s . co m*/ * * @param e */ public static void error(Exception e) { if (showError) { ; Log.e(TAG + Thread.currentThread().getStackTrace()[1].getClass().getSimpleName(), e.toString()); } }