List of usage examples for java.lang Exception toString
public String toString()
From source file:azureml_besapp.AzureML_BESApp.java
/** * Read the API key and API URL of Azure ML request response REST API * //from w w w . j av a2 s . co m * @param filename fully qualified file name that contains API key and API URL */ public static void readApiInfo(String filename) { try { File apiFile = new File(filename); Scanner sc = new Scanner(apiFile); apiurl = sc.nextLine(); apikey = sc.nextLine(); startJobUrl = sc.nextLine(); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:com.kylinolap.jdbc.util.DefaultSslProtocolSocketFactory.java
private static SSLContext createEasySSLContext() { try {/*from w ww . ja va 2 s. com*/ SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null); return context; } catch (Exception e) { LOG.error(e.getMessage(), e); throw new HttpClientError(e.toString()); } }
From source file:Main.java
/** * Converts a TimeML 1.2 file into a non-tagged TE3 TimeML input * get TE3-input, TE3input from tml//from ww w . j a v a 2s .co m * * @param tmlfile * @return */ public static String TML2TE3(String tmlfile) { String outputfile = null; try { String line; boolean textfound = false; String header = ""; String footer = ""; String text = ""; //process header (and dct)/text/footer outputfile = tmlfile + ".TE3input"; BufferedWriter te3writer = new BufferedWriter(new FileWriter(new File(outputfile))); BufferedReader TE3inputReader = new BufferedReader(new FileReader(new File(tmlfile))); try { // read out header while ((line = TE3inputReader.readLine()) != null) { if (line.length() > 0) { // break on TEXT if (line.matches(".*<TEXT>.*")) { textfound = true; break; } } header += line + "\n"; } if (!textfound) { throw new Exception("Premature end of file (" + tmlfile + ")"); } // read out text while ((line = TE3inputReader.readLine()) != null) { if (line.length() > 0) { // break on TEXT if (line.matches(".*</TEXT>.*")) { textfound = false; break; } } text += line.replaceAll("<[^>]*>", "") + "\n"; } if (textfound) { throw new Exception("Premature end of file (" + tmlfile + ")"); } // read out footer while ((line = TE3inputReader.readLine()) != null) { line = line.replaceAll("<(!--|[TSA]LINK|MAKEINSTANCE)[^>]*>", "").trim(); if (line.length() > 0) { footer += line + "\n"; } } te3writer.write(header + "\n"); te3writer.write("\n<TEXT>\n" + text + "</TEXT>\n"); te3writer.write(footer + "\n"); System.err.println("Processing file: " + tmlfile); } finally { if (TE3inputReader != null) { TE3inputReader.close(); } if (te3writer != null) { te3writer.close(); } } } catch (Exception e) { System.err.println("Errors found (TML_file_utils):\n\t" + e.toString() + "\n"); if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { e.printStackTrace(System.err); } return null; } return outputfile; }
From source file:Main.java
public static void applyProperties(Object paramObject, Element paramElement) { Map<String, Object> localMap = getProperties(paramElement); Iterator<String> iterator = localMap.keySet().iterator(); Field[] arrayOfField = paramObject.getClass().getFields(); Method[] arrayOfMethod = paramObject.getClass().getMethods(); while (iterator.hasNext()) { String str = iterator.next(); Object localObject = localMap.get(str); try {/*ww w.j a va 2 s.c o m*/ for (int i = 0; i < arrayOfField.length; ++i) { if ((!arrayOfField[i].getName().equalsIgnoreCase(str)) || (!isTypeMatch(arrayOfField[i].getType(), localObject.getClass()))) continue; arrayOfField[i].set(paramObject, localObject); System.err.println("Set field " + arrayOfField[i].getName() + "=" + localObject); break; } for (int i = 0; i < arrayOfMethod.length; ++i) { if ((!arrayOfMethod[i].getName().equalsIgnoreCase("set" + str)) || (arrayOfMethod[i].getParameterTypes().length != 1) || (!isTypeMatch(arrayOfMethod[i].getParameterTypes()[0], localObject.getClass()))) continue; arrayOfMethod[i].invoke(paramObject, new Object[] { localObject }); System.err.println("Set method " + arrayOfMethod[i].getName() + "=" + localObject); break; } } catch (Exception localException) { System.err.println("Unable to apply property '" + str + "': " + localException.toString()); } } }
From source file:com.quietlycoding.android.reader.util.api.Authentication.java
/** * This method generates a quick token to send with API requests that * require editing content. This method is called as the API request is * being built so that it doesn't expire prior to the actual execution. * /*w w w .j a va 2s.com*/ * @param sid * - the user's authentication token from ClientLogin * @return token - the edit token generated by the server. * */ public static String generateFastToken(String sid) { try { final BasicClientCookie cookie = Authentication.buildCookie(sid); final DefaultHttpClient client = new DefaultHttpClient(); client.getCookieStore().addCookie(cookie); final HttpGet get = new HttpGet(TOKEN_URL); final HttpResponse response = client.execute(get); final HttpEntity entity = response.getEntity(); Log.d(TAG, "Server Response: " + response.getStatusLine()); final InputStream in = entity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; while ((line = reader.readLine()) != null) { Log.d(TAG, "Response Content: " + line); } reader.close(); client.getConnectionManager().shutdown(); return line; } catch (final Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:org.androidnerds.reader.util.api.Authentication.java
/** * This method returns back to the caller a proper authentication token to use with * the other API calls to Google Reader. * * @param user - the Google username//from www .java 2 s . c o m * @param pass - the Google password * @return sid - the returned authentication token for use with the API. * */ public static String getAuthToken(String user, String pass) { NameValuePair username = new BasicNameValuePair("Email", user); NameValuePair password = new BasicNameValuePair("Passwd", pass); NameValuePair service = new BasicNameValuePair("service", "reader"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(username); pairs.add(password); pairs.add(service); try { DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(AUTH_URL); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs); post.setEntity(entity); HttpResponse response = client.execute(post); HttpEntity respEntity = response.getEntity(); Log.d(TAG, "Server Response: " + response.getStatusLine()); InputStream in = respEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; String result = null; while ((line = reader.readLine()) != null) { if (line.startsWith("SID")) { result = line.substring(line.indexOf("=") + 1); } } reader.close(); client.getConnectionManager().shutdown(); return result; } catch (Exception e) { Log.d(TAG, "Exception caught:: " + e.toString()); return null; } }
From source file:azureml_besapp.AzureML_BESApp.java
/** * Call REST API for starting prediction job previously submitted * //ww w. j a v a2s.c om * @param job job to be started * @return response from the REST API */ public static String besStartJob(String job) { HttpPost post; HttpClient client; StringEntity entity; try { // create HttpPost and HttpClient object post = new HttpPost(startJobUrl + "/" + job + "/start?api-version=2.0"); client = HttpClientBuilder.create().build(); // add HTTP headers post.setHeader("Accept", "text/json"); post.setHeader("Accept-Charset", "UTF-8"); // set Authorization header based on the API key post.setHeader("Authorization", ("Bearer " + apikey)); // Call REST API and retrieve response content HttpResponse authResponse = client.execute(post); if (authResponse.getEntity() == null) { return authResponse.getStatusLine().toString(); } return EntityUtils.toString(authResponse.getEntity()); } catch (Exception e) { return e.toString(); } }
From source file:azureml_besapp.AzureML_BESApp.java
/** * Call REST API for canceling the batch job * //from w w w. j a v a2 s.c om * @param job job to be started * @return response from the REST API */ public static String besCancelJob(String job) { //job_id/start?api-version=2.0 HttpDelete post; HttpClient client; StringEntity entity; try { // create HttpPost and HttpClient object post = new HttpDelete(startJobUrl + job); client = HttpClientBuilder.create().build(); // add HTTP headers post.setHeader("Accept", "text/json"); post.setHeader("Accept-Charset", "UTF-8"); // set Authorization header based on the API key post.setHeader("Authorization", ("Bearer " + apikey)); // Call REST API and retrieve response content HttpResponse authResponse = client.execute(post); if (authResponse.getEntity() == null) { return authResponse.getStatusLine().toString(); } return EntityUtils.toString(authResponse.getEntity()); } catch (Exception e) { return e.toString(); } }
From source file:com.cloudera.sqoop.Sqoop.java
/** * Given a Sqoop object and a set of arguments to deliver to * its embedded SqoopTool, run the tool, wrapping the call to * ToolRunner.//from w ww . j a va 2s .c o m * This entry-point is preferred to ToolRunner.run() because * it has a chance to stash child program arguments before * GenericOptionsParser would remove them. */ public static int runSqoop(Sqoop sqoop, String[] args) { try { String[] toolArgs = sqoop.stashChildPrgmArgs(args); return ToolRunner.run(sqoop, toolArgs); } catch (Exception e) { LOG.error("Got exception running Sqoop: " + e.toString()); e.printStackTrace(); if (System.getProperty(SQOOP_RETHROW_PROPERTY) != null) { throw new RuntimeException(e); } return 1; } }
From source file:controllers.api.v2.Dataset.java
public static Promise<Result> getDataPlatforms() { try {/*ww w .j av a2s.com*/ return Promise.promise( () -> ok(Json.newObject().set("platforms", Json.toJson(DATA_TYPES_DAO.getAllPlatforms())))); } catch (Exception e) { Logger.error("Fail to get data platforms", e); return Promise.promise(() -> notFound("Fetch data Error: " + e.toString())); } }