List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceTestIT.java
@Test(enabled = false) public void testPresenceHeartbeatSNAPSHOT() { String urlstring = "http://localhost:8080/optimizer-0.8.0-SNAPSHOT/optimizer/"; log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + urlstring + "==="); String outputLine;//from ww w .ja v a2 s .c o m String completeOutput = ""; try { URL url = new URL(urlstring + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + urlstring + " . Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER service heartbeatin " + urlstring + " FINISHED ==="); }
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceTestIT.java
@Test(enabled = false) public void testPresenceHeartbeatDIRECT() { String urlstring = "http://localhost:8080/optimizer/"; log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + "urlstring " + "==="); String outputLine;/*from w ww . j a v a 2s . c om*/ String completeOutput = ""; try { URL url = new URL(urlstring + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + urlstring + " . Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER service heartbeatin " + "urlstring " + " FINISHED ==="); }
From source file:fm.krui.kruifm.TrackUpdateHandler.java
/** * Downloads album art from passed URL using the last.fm api. * @param url Web safe location of image as URL. * @return Bitmap of the image requested *//* w w w . j a v a2 s .c o m*/ protected Bitmap downloadAlbumArt(String url) { Bitmap bitmap; // Check if an album art URL was returned. If there's no location, there's no point in wasting resources trying to download nothing. if (artUrl.equals("*NO_ART*") == false) { // Download the image from URL try { HttpURLConnection connection; connection = (HttpURLConnection) new URL(url).openConnection(); connection.connect(); InputStream input = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(input); return bitmap; } catch (MalformedURLException e) { Log.e(TAG, "Malformed URL detected when downloading album art: "); e.printStackTrace(); } catch (IOException e) { Log.e(TAG, "Failed to process album art: "); e.printStackTrace(); } } // If the download fails or image doesn't exist, display the default KRUI background image. bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.krui_background_logo); return bitmap; }
From source file:com.skcraft.launcher.launch.JavaRuntimeFetcher.java
private JsonNode getJRE() { Platform system = Environment.getInstance().getPlatform(); String os = system == Platform.WINDOWS ? "windows" : system == Platform.MAC_OS_X ? "osx" : "linux"; if (os.equals("linux")) { throw new UnsupportedOperationException("Mojang do not support a linux JRE :["); }/*w w w . j ava 2s . c om*/ InputStream inputStream = null; JsonNode jre = null; try { HttpURLConnection connection = (HttpURLConnection) new URL(LAUNCHER_DATA).openConnection(); inputStream = connection.getInputStream(); JsonNode root = new ObjectMapper().readTree(inputStream); JsonNode platform = root.get(os); JsonNode x64 = platform.get("64"); jre = x64.get("jre"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { Closer.close(inputStream); } if (jre == null) { throw new UnsupportedOperationException("Cannot retrieve JRE url for system " + os + ":x64"); } return jre; }
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceOpenShiftTest.java
@Test(enabled = TestConstants.EnabledTestOpenShift) public void testPresenceHeartbeat() { log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + BASE_URL + "==="); String outputLine;/* w ww . ja va2 s . c o m*/ String completeOutput = ""; try { URL url = new URL(BASE_URL + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + BASE_URL + ". Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + BASE_URL + " FINISHED ==="); }
From source file:org.forgerock.openam.examples.PwnedAuth.java
private String haveIBeenPwned() { String json = ""; try {/*from w w w. ja v a 2 s .c om*/ URL url = new URL("https://haveibeenpwned.com/api/v2/breachedaccount/" + userMail); debug.message("PwnedAuth.haveIBeenPwned(): url : " + url); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); if (conn.getResponseCode() == 404) { debug.message("PwnedAuth.haveIBeenPwned() : response 404 - no breaches found"); return json; } if (conn.getResponseCode() != 200) { debug.message("PwnedAuth.haveIBeenPwned(): HTTP failed, response code:" + conn.getResponseCode()); throw new RuntimeException("PwnedAuth : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; while ((output = br.readLine()) != null) { json = json + output; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return json; }
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceOpenShiftTest.java
@Test(enabled = false) public void testPresenceHeartbeatSNAPSHOT() { log.info("=== TEST for presence of OPTIMIZER service DEPLOYED IN OPENSHIFT heartbeat in " + BASE_URL + " ==="); String outputLine;// w w w. jav a2 s .c o m String completeOutput = ""; try { URL url = new URL(BASE_URL + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + BASE_URL + " . Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER service heartbeat IN OPENSHIFT " + BASE_URL + " FINISHED ==="); }
From source file:org.openbmap.soapclient.FileUploader.java
/** * Sends a head request to the server to check whether uploaded file actually exists on the server * @param file file//www .ja v a 2 s . c o m * @return true if file was available */ private boolean fileActuallyExists(final String file) { if (mValidationBaseUrl == null) { Log.i(TAG, "Validation url not set. Skipping server side validation"); return true; } try { // not very generic yet final String expectedUrl = mValidationBaseUrl + mUser + "_" + file.substring(file.lastIndexOf(File.separator) + 1, file.length()); final HttpURLConnection connection = (HttpURLConnection) new URL(expectedUrl).openConnection(); connection.setRequestMethod("HEAD"); final int responseCode = connection.getResponseCode(); if (responseCode != 200) { // Not OK. return false; } } catch (final MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return true; } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; }
From source file:eu.codeplumbers.cosi.api.tasks.DeleteFileTask.java
private String deleteFileRequest(File file) { String result = ""; URL urlO = null;/*from ww w. j ava 2 s . co m*/ try { urlO = new URL(url + file.getRemoteId() + "/"); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(false); conn.setDoInput(true); conn.setRequestMethod("DELETE"); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); result = writer.toString(); in.close(); conn.disconnect(); } catch (MalformedURLException e) { result = e.getLocalizedMessage(); } catch (ProtocolException e) { result = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { result = e.getLocalizedMessage(); } return result; }
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceOpenShiftTest.java
@Test(enabled = false) public void testPresenceHeartbeatDIRECT() { String urlstring = "http://localhost:8080/optimizer/"; log.info("=== TEST for presence of OPTIMIZER service heartbeat IN OPENSHIFT " + "urlstring " + "==="); String outputLine;/*from www. ja v a 2 s. co m*/ String completeOutput = ""; try { URL url = new URL(urlstring + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + urlstring + " . Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER SERVICE DEPLOYED IN OPENSHIFT service heartbeatin " + "urlstring " + " FINISHED ==="); }