List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:gov.nasa.jpl.analytics.util.CommonUtil.java
public static String reverseUrl(String url) { String reversedURLPath = ""; try {/*w ww . j a v a 2 s . c o m*/ String[] reversedURL = TableUtil.reverseUrl(url).split(":"); reversedURL[0] = reversedURL[0].replace('.', '/'); reversedURLPath = reversedURL[0] + "/" + hashString(url); } catch (MalformedURLException e) { LOG.error("Error occurred while reversing the URL " + url); e.printStackTrace(); } return reversedURLPath; }
From source file:ZipURLStreamHandler.java
/** * Creates a <code>URL</code> that points to the specified entry within the * specified zip file and has the specified protocol name. To use the * resulting <code>URL</code>, an application must set a * <code>URLStreamHandlerFactory</code> (via the <code>URL</code> class) * which will return a <code>ZipURLStreamHandler</code> for the protocol name * given to this method. Returns <code>null</code> if the specified protocol * is unrecognized./*w w w .jav a2 s . c om*/ */ public static URL createURL(String protocol, String fileName, String entryName) { try { return new URL(protocol, "", -1, fileName + "|" + entryName); } catch (MalformedURLException e) { e.printStackTrace(); return null; } }
From source file:uk.ac.cam.cl.dtg.picky.client.analytics.Analytics.java
private static void upload(Properties properties, String datasetURL) { if (datasetURL == null) return;/*ww w . jav a2 s . c o m*/ URL url; try { url = new URL(new URL(datasetURL), URL); } catch (MalformedURLException e1) { e1.printStackTrace(); return; } try { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost post = new HttpPost(url.toURI()); post.setHeader("Content-Type", "text/plain; charset=utf-8"); StringWriter stringWriter = new StringWriter(); properties.store(stringWriter, ""); HttpEntity entity = new StringEntity(stringWriter.toString()); post.setEntity(entity); HttpResponse response = client.execute(post); LOG.info("Uploading analytics: " + response.getStatusLine()); } catch (IOException | URISyntaxException e) { LOG.error(e.getMessage()); } }
From source file:com.firegnom.valkyrie.util.PacksHelper.java
/** * Download packs.//from w w w . j a v a 2s.co m * * @param path the path * @param o the o */ public static void downloadPacks(String path, Observer o) { Download packsDownload; try { packsDownload = new Download(new URL("http://valkyrie.firegnom.com/data/packs.json"), path, true); } catch (MalformedURLException e1) { e1.printStackTrace(); return; } if (!packsDownload.download()) { return; } File packs = new File(path + "packs.json"); JSONObject packsjson; try { packsjson = new JSONObject(Util.convertStreamToString(new FileInputStream(packs))); JSONArray packsArray = packsjson.getJSONArray("install"); for (int i = 0; i < packsArray.length(); i++) { String pack = packsArray.getString(i); if (!new File(path + pack + ".json").exists()) { URL u = new URL("http://valkyrie.firegnom.com/data/" + pack + ".zip"); Download d; if (o != null) { d = new Download(u, path, true, o); } else { d = new Download(u, path, true); } System.out.println(d.download()); System.out.println(path + pack + ".zip"); NativeUnzip un = new NativeUnzip(); String c = new String(path + pack + ".zip"); String dj = new String(path); long time = System.currentTimeMillis(); // un.dounzip(c,dj); ZipUtil.unzip(new File(path + pack + ".zip"), new File(path)); System.out.println("time :" + ((System.currentTimeMillis() - time) / 1000)); } } } catch (JSONException e) { e.printStackTrace(); return; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } }
From source file:com.tweetlanes.android.core.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { public void run() { URL url;//from w w w .jav a 2s . co m Bitmap bitmap = null; try { url = new URL(urlAsString); // Log.d("tweetlanes url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:com.photon.phresco.nativeapp.eshop.net.NetworkManager.java
public static boolean checkHttpsURLStatus(final String url) { boolean https_StatusFlag = false; System.out.println("Entered in checkHttpsURLStatus >>>>>>>>>>>>>>>"); URL httpsurl;/*from ww w . jav a 2 s. c o m*/ try { // Create a context that doesn't check certificates. SSLContext ssl_ctx = SSLContext.getInstance("TLS"); TrustManager[] trust_mgr = get_trust_mgr(); ssl_ctx.init(null, // key manager trust_mgr, // trust manager new SecureRandom()); // random number generator HttpsURLConnection.setDefaultSSLSocketFactory(ssl_ctx.getSocketFactory()); System.out.println("Url =========" + url); httpsurl = new URL(url); HttpsURLConnection con = (HttpsURLConnection) httpsurl.openConnection(); con.setHostnameVerifier(DO_NOT_VERIFY); int statusCode = con.getResponseCode(); System.out.println("statusCode =========" + statusCode); if (statusCode == HttpURLConnection.HTTP_OK) { https_StatusFlag = true; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } return https_StatusFlag; }
From source file:com.shafiq.mytwittle.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { @Override// www . j av a 2 s . c o m public void run() { URL url; Bitmap bitmap = null; try { url = new URL(urlAsString); // Log.d("mytwittle url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:com.tweetlanes.android.URLFetch.java
public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) { Thread t = new Thread() { public void run() { URL url;/*from w ww . j a v a2s . c o m*/ Bitmap bitmap = null; try { url = new URL(urlAsString); //Log.d("tweetlanes url fetch", urlAsString); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { bitmap = (Bitmap) response; } else { InputStream inputStream = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (callback != null) { callback.finished(bitmap != null ? true : false, bitmap); } } }; t.start(); }
From source file:cloudworker.RemoteWorker.java
private static void cleanUpInstance() { /*try {/*from w ww .j a v a 2s . co m*/ CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotInstanceRequestsRequest(spotInstanceRequestIds); ec2.cancelSpotInstanceRequests(cancelRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error cancelling instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); }*/ List<String> instanceId = new ArrayList<String>(); String inputLine; URL EC2MetaData; try { EC2MetaData = new URL("http://169.254.169.254/latest/meta-data/instance-id"); URLConnection EC2MD = EC2MetaData.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(EC2MD.getInputStream())); while ((inputLine = in.readLine()) != null) { instanceId.add(inputLine); } in.close(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { // Terminate instances. TerminateInstancesRequest terminateRequest = new TerminateInstancesRequest(instanceId); ec2.terminateInstances(terminateRequest); } catch (AmazonServiceException e) { // Write out any exceptions that may have occurred. System.out.println("Error terminating instances"); System.out.println("Caught Exception: " + e.getMessage()); System.out.println("Reponse Status Code: " + e.getStatusCode()); System.out.println("Error Code: " + e.getErrorCode()); System.out.println("Request ID: " + e.getRequestId()); } }
From source file:com.mingsoft.weixin.http.HttpClientConnectionManager.java
/** * ?GET??/*ww w. j a va2 s .c o m*/ * * @param url * @return */ public static HttpGet getGetMethod(String url) { URI uri = null; try { URL _url = new URL(url); uri = new URI(_url.getProtocol(), _url.getHost(), _url.getPath(), _url.getQuery(), null); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpGet pmethod = new HttpGet(uri); // ?? pmethod.addHeader("Connection", "keep-alive"); pmethod.addHeader("Cache-Control", "max-age=0"); pmethod.addHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); pmethod.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/;q=0.8"); return pmethod; }