List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:eu.cloudscale.showcase.servlets.helpers.PaymentService.java
@Async public Future<String> callPaymentService(String distribution, String attr1, String attr2, String attr3) { try {// www . ja v a 2s . c om ExecutorService executor = Executors.newFixedThreadPool(1); String url = this.getUrl(distribution, attr1, attr2, attr3); Future<Response> response = executor.submit(new Request(new URL(url))); InputStream input = response.get().getBody(); executor.shutdown(); String body = IOUtils.toString(input, "UTF-8"); return new AsyncResult<String>(body); } catch (MalformedURLException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:net.peterkuterna.appengine.apps.devoxxsched.util.Md5Calculator.java
private byte[] getResponse(final String requestUri) { try {/*from w w w. j a v a 2s . co m*/ URL url = new URL(requestUri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-agent", "Devoxx Schedule AppEngine Backend"); connection.setDoOutput(true); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(120 * 1000); connection.setRequestProperty("Cache-Control", "no-cache,max-age=0"); connection.setRequestProperty("Pragma", "no-cache"); InputStream response = connection.getInputStream(); log.info("response = " + connection.getResponseCode()); if (connection.getResponseCode() == 200) { return IOUtils.toByteArray(response); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:jhttpp2.Jhttpp2Launcher.java
public Jhttpp2Launcher() { server = new Jhttpp2Server(true); server.setServerProperties(loadServerProperties()); restoreSettings();/*from w ww . j av a 2s .co m*/ server.setSettingsSaver(this); SortedMap<String, URL> hostRedirects = new TreeMap<String, URL>(); try { hostRedirects.put("redirect.me.com", new URL("http://localhost:80/")); } catch (MalformedURLException e) { e.printStackTrace(); } server.setHostRedirects(hostRedirects); server.init(); if (Jhttpp2Server.error) { System.out.println("Error: " + Jhttpp2Server.error_msg); } else { new Thread(server).start(); log.info("Running on port " + server.port); } }
From source file:javaapplication1.Prog.java
public Long getAmountfromAcc(String accountName, String userName) throws JSONException { JSONObject jsonArray = null;/* w w w.j av a2 s .c om*/ try { URL u = new URL("http://localhost:8080/bankserver/users/" + userName + "/" + accountName); HttpURLConnection httpURLConnection = (HttpURLConnection) u.openConnection(); httpURLConnection.setRequestMethod("GET"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(httpURLConnection.getInputStream())); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line + '\n'); } String jsonString = stringBuilder.toString(); jsonArray = new JSONObject(jsonString); Long amountt = jsonArray.getLong("amount"); System.out.print("amount:" + amountt + "/n"); return amountt; } catch (MalformedURLException e) { e.printStackTrace(); } catch (ProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:edu.usf.cutr.HomeController.java
/** * Updates original gtfs-rt files //w w w . jav a2 s . c om */ @RequestMapping(value = "/update-files.do", method = RequestMethod.GET) public void updateFiles(HttpServletRequest request, HttpServletResponse response) { try { String savePath = UrlUtils.getResourcePath(request, URLConstants.TRIPS_NAME); ioManager.downloadFile(URLConstants.TRIPS, savePath); savePath = UrlUtils.getResourcePath(request, URLConstants.VEHICLES_NAME); ioManager.downloadFile(URLConstants.VEHICLES, savePath); } catch (MalformedURLException e) { e.printStackTrace(); createJSONResponse(response, "Status: ERROR \n" + e); } catch (IOException e) { e.printStackTrace(); createJSONResponse(response, "Status: ERROR \n" + e); } createJSONResponse(response, "Status: OK"); }
From source file:org.basket3.filesystem.S3ObjectDaoTest.java
@Test public void testStoreS3Object() throws S3Exception { S3ObjectDao dao = new GAES3ObjectDao(); S3Object s3Object = null; try {//w ww. ja v a2s .c o m s3Object = new GAES3Object("test", "test", new URL("file://test/test.txt")); dao.storeS3Object(s3Object); } catch (MalformedURLException e) { e.printStackTrace(); } S3Object result = dao.loadS3Object("test", "test"); assertNotNull(result); toJSONStringPrint("Result S3Object=", result); }
From source file:net.sasasin.sreader.batch.ContentHeaderDriver.java
@SuppressWarnings("unchecked") private void fetchByRome(FeedUrl f, Set<ContentHeader> c) { try {//from w ww . j a v a 2 s.c o m // ?RSS InputStream is = IOUtils.toInputStream(new WgetHttpComponentsImpl(new URL(f.getUrl())).read()); // Rome SyndFeed feed = new SyndFeedInput().build(new XmlReader(is)); for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) { logger.info(this.getClass().getSimpleName() + " processing " + entry.getLink()); ContentHeader ch = new ContentHeader(); // HTTP 30xmoved?URL?? // 30x???????new URL(entry.getLink())???? URL entryUrl = new WgetHttpComponentsImpl(new URL(entry.getLink())).getOriginalUrl(); ch.setUrl(entryUrl.toString()); ch.setId(Md5Util.crypt(ch.getUrl())); ch.setTitle(entry.getTitle()); ch.setFeedUrl(f); c.add(ch); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (FeedException e) { e.printStackTrace(); } }
From source file:WelcomeApplet.java
private ActionListener makeAction(final String urlString) { return new ActionListener() {/*from w w w.ja v a 2 s . c om*/ public void actionPerformed(ActionEvent event) { try { getAppletContext().showDocument(new URL(urlString)); } catch (MalformedURLException e) { e.printStackTrace(); } } }; }
From source file:com.sastix.cms.server.utils.FileService.java
public String downloadResource(String resourceExternalURI, String relativePath) { String path = null;/*from w w w. jav a2 s. com*/ try { URL url = new URL(resourceExternalURI); InputStream is = url.openStream(); path = volume + relativePath; OutputStream os = new FileOutputStream(path); byte[] b = new byte[2048]; int length; while ((length = is.read(b)) != -1) { os.write(b, 0, length); } is.close(); os.close(); return path; } catch (MalformedURLException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return path; }
From source file:com.mstiles92.plugins.stileslib.player.UUIDFetcher.java
public Map<String, UUID> execute() { Map<String, UUID> results = new HashMap<>(); try {//from w w w . j a v a 2 s .co m BasicHttpClient client = new BasicHttpClient(new URL("https://api.mojang.com/profiles/minecraft")); client.addHeader("Content-Type", "application/json"); int requests = (int) Math.ceil((double) usernames.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { int start = i * PROFILES_PER_REQUEST; int end = Math.min((i + 1) * PROFILES_PER_REQUEST, usernames.size()); client.setBody(JSONArray.toJSONString(usernames.subList(start, end))); String response = client.post(); JSONArray responseJson = (JSONArray) new JSONParser().parse(response); for (Object o : responseJson) { JSONObject profile = (JSONObject) o; String id = (String) profile.get("id"); String name = (String) profile.get("name"); results.put(name, getUUID(id)); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return results; }