List of usage examples for java.lang Exception getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:co.cask.cdap.client.rest.TestUtils.java
public static void verifyException(Class<? extends RuntimeException> expectedException, Callable<Void> callable) { try {//from w w w. jav a 2s . c o m callable.call(); Assert.fail("Expected exception type: " + expectedException.getName()); } catch (Exception e) { Assert.assertEquals(expectedException, e.getClass()); } }
From source file:com.cognifide.cq.cqsm.core.utils.MessagingUtils.java
public static String createMessage(Exception e) { return StringUtils.isBlank(e.getMessage()) ? "Internal error: " + e.getClass() : e.getMessage(); }
From source file:de.thomasvolk.genexample.GenAlg.java
private static void printErrorAndExit(Exception e, Options options) { System.err.printf("Fehler: %s - %s\n", e.getClass().getSimpleName(), e.getMessage()); printUsage(options);/*from w ww.ja v a 2 s. co m*/ System.exit(1); }
From source file:info.papdt.blacklight.api.search.SearchApi.java
public static MessageListModel searchStatus(String q, int count, int page) { WeiboParameters params = new WeiboParameters(); params.put("q", q); params.put("count", count); params.put("page", page); try {//from ww w. ja va 2 s .c o m JSONObject json = request(Constants.SEARCH_STATUSES, params, HTTP_GET); return new Gson().fromJson(json.toString(), MessageListModel.class); } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Cannot search, " + e.getClass().getSimpleName()); } return null; } }
From source file:info.papdt.blacklight.api.search.SearchApi.java
public static UserListModel searchUser(String q, int count, int page) { WeiboParameters params = new WeiboParameters(); params.put("q", q); params.put("count", count); params.put("page", page); try {//from w w w .jav a2 s . co m JSONObject json = request(Constants.SEARCH_USERS, params, HTTP_GET); return new Gson().fromJson(json.toString(), UserListModel.class); } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Cannot search, " + e.getClass().getSimpleName()); } return null; } }
From source file:com.utest.domain.service.util.FileUploadUtil.java
public static void uploadFile(final File targetFile, final String targetURL, final String targerFormFieldName_) throws Exception { final PostMethod filePost = new PostMethod(targetURL); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); filePost.addRequestHeader("X-Atlassian-Token", "no-check"); try {/* w ww. jav a 2 s . c om*/ final FilePart fp = new FilePart(targerFormFieldName_, targetFile); fp.setTransferEncoding(null); final Part[] parts = { fp }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); final HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); final int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { Logger.getLogger(FileUploadUtil.class) .info("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { Logger.getLogger(FileUploadUtil.class) .info("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (final Exception ex) { Logger.getLogger(FileUploadUtil.class) .error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage(), ex); throw ex; } finally { Logger.getLogger(FileUploadUtil.class).debug(new String(filePost.getResponseBody())); filePost.releaseConnection(); } }
From source file:info.magnolia.cms.util.ExceptionUtil.java
/** * Translates an exception class name to an english-readable idiom. Example: an instance of AccessDeniedException will be returned as "Access denied". *///from w ww . j a v a 2 s . c om public static String classNameToWords(Exception e) { return StringUtils.capitalize(StringUtils.removeEnd(e.getClass().getSimpleName(), "Exception") .replaceAll("[A-Z]", " $0").toLowerCase().trim()); }
From source file:uk.org.todome.Util.java
public static String getFileFromServer(String request) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(request); Log.i("Util.getFileFromServer", "Request used: " + request); try {// ww w .j ava2 s .c o m HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } else { Log.e("", "Failed to download file"); } } catch (Exception ex) { Log.e("Util.getFileFromServer", ex.getClass().toString() + " " + ex.getMessage()); } return builder.toString(); }
From source file:hpcc.hut.edu.vn.ocr.ocrserviceconnector.HpccOcrServiceConnector.java
public static String postToOcrService(byte[] data, int size, int imgw, int imgh, String lang, int psm, boolean isPrePostProcess) { System.out.println("Sent data: w = " + imgw + ", h = " + imgh + ", psm = " + psm + ", process: " + isPrePostProcess + ", with lang: " + lang); String result = ""; try {/*w ww .jav a2 s . c o m*/ HttpParams httpParamenters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParamenters, 30000); DefaultHttpClient httpClient = new DefaultHttpClient(httpParamenters); HttpPost postRequest = new HttpPost(HOST); ByteArrayBody bab = new ByteArrayBody(data, "input.jpg"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("image", bab); reqEntity.addPart("size", new StringBody("" + size)); // size to // check if // decompress // fail reqEntity.addPart("width", new StringBody("" + imgw)); reqEntity.addPart("height", new StringBody("" + imgh)); reqEntity.addPart("lang", new StringBody(lang)); reqEntity.addPart("psm", new StringBody("" + psm)); reqEntity.addPart("process", new StringBody("" + isPrePostProcess)); postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } result = s.toString(); System.out.println("result in Json: " + result); } catch (Exception e) { // handle exception here Log.e(e.getClass().getName(), e.getMessage()); return null; } return result; }
From source file:info.papdt.blacklight.api.search.SearchApi.java
public static ArrayList<String> suggestAtUser(String q, int count) { WeiboParameters params = new WeiboParameters(); params.put("q", q); params.put("count", count); params.put("type", 0); params.put("range", 0); try {/*ww w . j ava 2s . c o m*/ JSONArray json = requestArray(Constants.SEARCH_SUGGESTIONS_AT_USERS, params, HTTP_GET); ArrayList<String> ret = new ArrayList<String>(); for (int i = 0; i < json.length(); i++) { ret.add(json.getJSONObject(i).optString("nickname")); } return ret; } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Cannot search, " + e.getClass().getSimpleName()); Log.e(TAG, Log.getStackTraceString(e)); } return null; } }