List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:net.bashtech.geobot.BotManager.java
public static String postRemoteDataTwitch(String urlString, String postData, int krakenVersion) { URL url;//from w w w.j a v a2 s. co m HttpURLConnection conn; try { url = new URL(urlString); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setFixedLengthStreamingMode(postData.getBytes().length); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Accept", "application/vnd.twitchtv.v" + krakenVersion + "+json"); conn.setRequestProperty("Authorization", "OAuth " + BotManager.getInstance().krakenOAuthToken); conn.setRequestProperty("Client-ID", BotManager.getInstance().krakenClientID); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetSongStreamURLTask.java
@Override protected Boolean doInBackground(String... params) { if (mSongID.equals(mApp.getService().getCurrentSong().getId())) { try {/* w w w . j a v a 2 s . co m*/ mApp.getService().getCurrentSong() .setFilePath(GMusicClientCalls.getSongStream(mSongID).toURL().toString()); } catch (MalformedURLException e) { e.printStackTrace(); return false; } catch (JSONException e) { e.printStackTrace(); return false; } catch (URISyntaxException e) { e.printStackTrace(); return false; } catch (Exception e) { e.printStackTrace(); return false; } if (mApp.getService().getCurrentSong().getId() == null) { return false; } else { return true; } } else { this.cancel(true); return false; } }
From source file:com.WeatherProxy.java
private void getWeather(String lat, String lng) { weatherNow = ""; String apiUrl = "https://api.forecast.io/forecast/"; String apiKey = "fad007e59cd36e504fa337d946feb7d2"; String urlString = apiUrl + apiKey + "/" + lat + "," + lng; try {// w ww .j av a2s . c o m URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); conn.connect(); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } // The body of the response is available as an input stream. // Using BufferedReader is good practice for efficient I/O, because it // takes lots of little reads and does fewer larger actual I/O // operations. It doesn't make much difference in this case, // since we only do one I/O. But it's still good practice. BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); // api.forecast.io returns a single (very long) line of JSON. weatherNow += br.readLine(); } catch (MalformedURLException e) { e.printStackTrace(); this.weatherNow = "{ 'error': 'MalformedURLException' }"; } catch (IOException e) { e.printStackTrace(); this.weatherNow = "{ 'error': 'IOException' }"; } }
From source file:com.openingdesign.qna.model.impl.QueryAndResponseImpl.java
public String getEtherpadId() { URL url;//from w w w . ja v a 2 s .c om try { url = new URL(getUrl()); return url.getPath().replace("/", ""); } catch (MalformedURLException e) { e.printStackTrace(); return "???"; } }
From source file:de.anneundsebp.ondemand.parser.fm4.Step2.java
@Override public void process(Map<String, String> context, Category category) { try {//ww w. j av a2 s. c o m this.category = category; String page = Util.loadPage(category.url); parseCategories(page); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.example.jarida.http.AsyncConnection.java
@Override public String doInBackground(String... params) { final String method = params[0]; final String urlString = params[1]; final StringBuilder builder = new StringBuilder(); try {/*from w ww. ja v a 2 s.co m*/ final URL url = new URL(urlString); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(method); if (method.equals(METHOD_POST)) { final String urlParams = params[2]; conn.setRequestProperty(HTTP.CONTENT_LEN, "" + Integer.toString(urlParams.getBytes().length)); System.out.println(urlParams); // Send request final DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(urlParams); wr.flush(); wr.close(); } // Get Response final InputStream is = conn.getInputStream(); final BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; while ((line = rd.readLine()) != null) { builder.append(line); } rd.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:net.bashtech.geobot.BotManager.java
public static String postCoebotConfig(String postData, String channel) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;//from w w w. j a va2 s . co m HttpURLConnection conn; try { url = new URL("http://coebot.tv/api/v1/channel/update/config/" + channel.toLowerCase() + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; } else return ""; }
From source file:net.bashtech.geobot.BotManager.java
public static String postCoebotVars(String postData, String requestURL) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;//from w w w . j a va 2 s.c o m HttpURLConnection conn; try { url = new URL(requestURL + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length)); // conn.setConnectTimeout(5 * 1000); // conn.setReadTimeout(5 * 1000); PrintWriter out = new PrintWriter(conn.getOutputStream()); out.print(postData); out.close(); String response = ""; Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) response += (inStream.nextLine()); inStream.close(); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return ""; } else return ""; }
From source file:com.bai.android.data.arcamera.DownloadContent.java
/** * Takes the url of the file selected for download * @param downloadUrl - url of the file to download *//*from w w w . j a va 2 s .c o m*/ // constructor public DownloadContent(int fileWhich) { String dlFilename = null; try { this.file = fileWhich; if (file == Constant.DownloadFileCode.TESS) { // tesseract trained data unzipLocation = Constant.DATA_PATH + Constant.TESS_FOLDER; // dir to unzip localFileLocation = Constant.DATA_PATH + Constant.TESS_FOLDER + Constant.TESS_ZIP_FILENAME; // location of the zip file (after download) dlFilename = Constant.TESS_FOLDER + Constant.TESS_ZIP_FILENAME; // filename of archive on server with subdir (e.g. "tessdata/jpn.zip") } else if (file == Constant.DownloadFileCode.DICT) { // dictionary db unzipLocation = Constant.DATA_PATH + Constant.DICT_FOLDER; localFileLocation = Constant.DATA_PATH + Constant.DICT_FOLDER + Constant.DICT_ZIP_FILENAME; dlFilename = Constant.DICT_FOLDER + Constant.DICT_ZIP_FILENAME; } else { } this.downloadUrl = new URL(Constant.SERVER_LOC + dlFilename); } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:com.ewcms.plugin.crawler.generate.robotstxt.RobotstxtServer.java
public boolean allows(WebURL webURL) { if (!config.isEnabled()) { return true; }/*from ww w . j a v a 2 s.c o m*/ try { URL url = new URL(webURL.getURL()); String host = url.getHost().toLowerCase(); String path = url.getPath(); HostDirectives directives = host2directivesCache.get(host); if (directives != null && directives.needsRefetch()) { synchronized (host2directivesCache) { host2directivesCache.remove(host); directives = null; } } if (directives == null) { directives = fetchDirectives(host); } return directives.allows(path); } catch (MalformedURLException e) { e.printStackTrace(); } return true; }