List of usage examples for java.lang Exception toString
public String toString()
From source file:com.trsst.client.AnonymSSLSocketFactory.java
/** * Create the SSL Context./*from ww w . ja v a 2 s .co m*/ * * @return The SSLContext */ private static SSLContext createEasySSLContext() { try { SSLContext context = SSLContext.getInstance("SSL"); //$NON-NLS-1$ context.init(null, new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authType) { } public void checkServerTrusted(X509Certificate[] chain, String authType) { } public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[] {}; } } }, null); return context; } catch (Exception e) { throw new HttpClientError(e.toString()); } }
From source file:com.sun.portal.os.portlets.PortletChartUtilities.java
public static void writeChartImageData(ResourceRequest request, ResourceResponse response, String defaultImagePath) throws IOException { response.setContentType(CONTENT_TYPE_IMG_PNG); OutputStream out = response.getPortletOutputStream(); try {/*from w w w . j a va2 s .co m*/ JFreeChart chart = createChart(request); if (chart != null) { ChartUtilities.writeChartAsPNG(out, chart, 400, 300); } else { // A problem occurred - Stream out the default image writeDefaultImage(out, defaultImagePath); } } catch (Exception e) { System.err.println(e.toString()); } finally { out.close(); } }
From source file:com.thoughtworks.go.agent.launcher.ServerCall.java
public static ServerResponseWrapper invoke(HttpMethod method) throws Exception { HashMap<String, String> headers = new HashMap<String, String>(); HttpClient httpClient = new HttpClient(); httpClient.setConnectionTimeout(HTTP_TIMEOUT_IN_MILLISECONDS); try {/*from w ww . j ava2 s.co m*/ final int status = httpClient.executeMethod(method); if (status == HttpStatus.SC_NOT_FOUND) { StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); out.println("Return Code: " + status); out.println("Few Possible Causes: "); out.println("1. Your Go Server is down or not accessible."); out.println( "2. This agent might be incompatible with your Go Server.Please fix the version mismatch between Go Server and Go Agent."); out.close(); throw new Exception(sw.toString()); } if (status != HttpStatus.SC_OK) { throw new Exception("Got status " + status + " " + method.getStatusText() + " from server"); } for (Header header : method.getResponseHeaders()) { headers.put(header.getName(), header.getValue()); } return new ServerResponseWrapper(headers, method.getResponseBodyAsStream()); } catch (Exception e) { String message = "Couldn't access Go Server with base url: " + method.getURI() + ": " + e.toString(); LOG.error(message); throw new Exception(message, e); } finally { method.releaseConnection(); } }
From source file:com.intuit.tank.harness.functions.DateFunctions.java
/** * @param format// www .j av a 2 s. c om * @return */ private static DateFormat getFormatter(String format) { DateFormat formatter = null; try { formatter = StringUtils.isEmpty(format) ? DateFormat.getDateInstance() : new SimpleDateFormat(format); } catch (Exception e) { // bad format LOG.warn("Error parsing date format string: " + e.toString() + ". Using default format."); formatter = DateFormat.getDateInstance(); } return formatter; }
From source file:de.pubflow.server.core.restConnection.WorkflowSender.java
/** * Sends a post request to the Workflow engine to use a certain Workflow * specified through the given path.//from w ww . j a va 2s . c o m * * @param wfCall * The message with all necessary informations to create a new * Workflow * @param workflowPath * The path for the specific Workflow to be used. * @throws WFRestException * if the connection responses with a HTTP response code other * than 2xx */ public static void initWorkflow(WorkflowRestCall wfCall, String workflowPath) throws WFRestException { Logger myLogger = LoggerFactory.getLogger(WorkflowSender.class); myLogger.info("Trying to use workflow on: " + workflowPath); Gson gson = new Gson(); HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(workflowPath); HttpResponse response = null; try { StringEntity postingString = new StringEntity(gson.toJson(wfCall), ContentType.APPLICATION_JSON); post.setEntity(postingString); post.setHeader("Content-type", "application/json;charset=utf-8"); response = httpClient.execute(post); System.out.println(post.getURI()); myLogger.info("Http response: " + response.toString()); } catch (Exception e) { myLogger.error("Could not deploy new Workflow with ID: " + wfCall.getID()); myLogger.error(e.toString()); throw new WFRestException("Workflow could not be started"); } if (response.getStatusLine().getStatusCode() >= 300) { throw new WFRestException( "The called WorkflowService send status code: " + response.getStatusLine().getStatusCode() + " and error: " + response.getStatusLine().getReasonPhrase()); } }
From source file:fm.krui.kruifm.JSONFunctions.java
public static JSONObject getJSONObjectFromURL(String url) { InputStream is = null;/* w w w .ja v a2 s .c o m*/ String result = ""; JSONObject jArray = null; //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(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(TAG, "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e(TAG, "Error parsing data " + e.toString()); } return jArray; }
From source file:fm.krui.kruifm.JSONFunctions.java
public static JSONArray getJSONArrayFromURL(String url) { InputStream is = null;/*from w w w.j ava2s .c o m*/ String result = ""; JSONArray jArray = null; //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(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(TAG, "Error converting result " + e.toString()); } try { jArray = new JSONArray(result); } catch (JSONException e) { Log.e(TAG, "Error parsing data " + e.toString()); } return jArray; }
From source file:com.dwdesign.tweetings.util.WebViewProxySettings.java
public static void resetProxy(WebView webView) { final Context context = webView.getContext(); try {/*from w w w . j a va 2s . co m*/ final Object requestQueueObject = getRequestQueue(context); if (requestQueueObject != null) { setDeclaredField(requestQueueObject, "mProxyHost", null); } } catch (final Exception e) { Log.e("ProxySettings", "Exception resetting WebKit proxy: " + e.toString()); } }
From source file:com.mindquarry.desktop.util.HttpUtilities.java
public static CheckResult checkServerExistence(String login, String pwd, String address) throws MalformedURLException { try {// ww w.j av a2 s. c o m if (!address.endsWith("/")) //$NON-NLS-1$ address += "/"; //$NON-NLS-1$ HttpClient client = createHttpClient(login, pwd, address); GetMethod get = createAndExecuteGetMethod(address, client); if (200 == get.getStatusCode()) { return CheckResult.OK; } else if (401 == get.getStatusCode()) { return CheckResult.AUTH_REFUSED; } else { return CheckResult.NOT_AVAILABLE; } } catch (UnknownHostException uhe) { return CheckResult.NOT_AVAILABLE; } catch (MalformedURLException murle) { throw murle; } catch (Exception e) { log.info(e.toString()); return CheckResult.NOT_AVAILABLE; } }
From source file:Classes.DBConnection.java
/** * Initialize the connections configuration *//*w w w . j ava 2 s . c o m*/ public static void init_BasicDataSourceFactory() { Properties propiedades = new Properties(); /* setMaxActive(): N mx de conexiones que se pueden abrir simultneamente. setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms. setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando. */ propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver"); propiedades.setProperty("url", "jdbc:mysql://localhost:3306/prog"); propiedades.setProperty("maxActive", "10"); propiedades.setProperty("maxIdle", "8"); propiedades.setProperty("minIdle", "0"); propiedades.setProperty("maxWait", "500"); propiedades.setProperty("initialSize", "5"); propiedades.setProperty("defaultAutoCommit", "true"); propiedades.setProperty("username", "root"); propiedades.setProperty("password", "12345"); propiedades.setProperty("validationQuery", "select 1"); propiedades.setProperty("validationQueryTimeout", "100"); propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2"); propiedades.setProperty("poolPreparedStatements", "true"); propiedades.setProperty("maxOpenPreparedStatements", "10"); try { dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.toString()); } }