List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:com.jbsoft.musync.providers.ArtistImageProvider.java
public String getArtistPhotoUrl() { String string_url = "http://developer.echonest.com/api/v4/artist/images?api_key=" + API_KEY + "&name=" + query + "&license=cc-by-sa"; // First formate the url to accept any format/paramaters try {/* w w w .j av a2 s .c o m*/ url = new URL(string_url); uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); url = uri.toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } try { Log.d("GoogleImageProvider", "URL IS " + string_url); final JSONParser jsonParser = new JSONParser(); HttpUrlConnection mConnection = new HttpUrlConnection(); String response = mConnection.sslhttpgetdata(url.toString()); if (response != null) { JSONObject jObject = jsonParser.getJSONFromString(response); JSONObject object = jObject.getJSONObject("response"); JSONArray array = object.getJSONArray("images"); Log.d(TAG, "Response is " + object.toString()); JSONObject first = array.getJSONObject(0); Log.d(TAG, "Images[0] is " + first.toString()); link = first.getString("url"); mLinks.add(link); Log.d(TAG, "URL IS " + link); } else { Log.d(TAG, "Response returned NULL"); } } catch (JSONException e) { e.printStackTrace(); } Log.d(TAG, "Link is " + link); return link; }
From source file:com.vwuilbea.mymoviecatalog.util.RestClient.java
public void executeGet() { // If you want to use post method to hit server try {//from w w w . ja v a2 s. c o m URL url = new URL(URL_TEST); ExecuteGet executeGet = new ExecuteGet(); executeGet.execute(url); } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:dmsl.smartbill.GoogleShoppingAPIHelperClass.java
/** * Sends an HTTP request to Google API for Shopping and retrieves a JSON * String of a product, based on the barcode number given in the search * criteria./*from ww w . ja va 2 s. c o m*/ * * @param barcodeContents * The product's barcode which we use to find that product. * @return The JSON String that holds information about the product. */ private String getJsonStringFromGoogleShopping(String barcodeContents) { URL u; InputStream is = null; DataInputStream dis = null; String s; StringBuilder sb = new StringBuilder(); String jsonString = null; try { u = new URL("https://www.googleapis.com/shopping/search/v1/public/products?key=" + SHOPPING_API_KEY + "&country=US&restrictBy=gtin:" + barcodeContents + "&startIndex=1&maxResults=1"); is = u.openStream(); dis = new DataInputStream(new BufferedInputStream(is)); while ((s = dis.readLine()) != null) { sb = sb.append(s + "\n"); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } jsonString = sb.toString(); return jsonString; }
From source file:com.nanocrawler.robotstxt.RobotstxtServer.java
public boolean allows(WebURL webURL) { try {// ww w . ja va2s . co m URL url = new URL(webURL.getURL()); String host = getHost(url); 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(url); } return directives.allows(path); } catch (MalformedURLException e) { e.printStackTrace(); } return true; }
From source file:com.recomdata.transmart.data.export.util.ExportImageProcessor.java
public void run() { URL imageURL = null;// w w w. j av a 2 s. co m File imageFile = new File(imagesTempDir + File.separator + filename); ReadableByteChannel rbc = null; FileOutputStream fos = null; try { if (StringUtils.isEmpty(imageURI)) return; imageURL = new URL(imageURI); rbc = Channels.newChannel(imageURL.openStream()); fos = new FileOutputStream(imageFile); fos.getChannel().transferFrom(rbc, 0, 1 << 24); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != fos) try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:net.bashtech.geobot.BotManager.java
public static String postRemoteDataSongRequest(String urlString, String channel, String requester) { if (BotManager.getInstance().CoeBotTVAPIKey.length() > 4) { URL url;//w w w . ja v a2 s. com HttpURLConnection conn; try { url = new URL("http://coebot.tv/api/v1/reqsongs/add/" + channel.toLowerCase() + "$" + BotManager.getInstance().CoeBotTVAPIKey + "$" + BotManager.getInstance().nick); String postData = "url=" + URLEncoder.encode(urlString, "UTF-8") + "&requestedBy=" + URLEncoder.encode(requester, "UTF-8"); conn = (HttpURLConnection) url.openConnection(); System.out.println(postData); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "CoeBot"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 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 = ""; if (conn.getResponseCode() < 400) { Scanner inStream = new Scanner(conn.getInputStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); } inStream.close(); } else { Scanner inStream = new Scanner(conn.getErrorStream()); while (inStream.hasNextLine()) { response += (inStream.nextLine()); } inStream.close(); } System.out.println(response); return response; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return null; } else { return null; } }
From source file:cm.aptoide.pt.LatestLikesComments.java
public Cursor getComments() { endPointComments = String.format(endPointComments, repoName); MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "apkid", "name", "text", "username", "time" }); try {/* w ww. jav a2 s.c o m*/ NetworkUtils utils = new NetworkUtils(); JSONObject respJSON = utils.getJsonObject(endPointComments, context); JSONArray array = respJSON.getJSONArray("listing"); for (int i = 0; i != array.length(); i++) { String apkid = ((JSONObject) array.get(i)).getString("apkid"); String name = ((JSONObject) array.get(i)).getString("name"); String text = ((JSONObject) array.get(i)).getString("text"); String timestamp = ((JSONObject) array.get(i)).getString("timestamp"); Date date = Configs.TIME_STAMP_FORMAT.parse(timestamp); String time = DateTimeUtils.getInstance(context).getTimeDiffString(date.getTime()); String username = ((JSONObject) array.get(i)).getString("username"); if (username.equals("NOT_SIGNED_UP")) { username = ""; } cursor.newRow().add(i).add(apkid).add(name).add(text).add(username).add(time); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return cursor; }
From source file:io.selendroid.server.grid.SelfRegisteringRemote.java
/** * Extracts the configuration./* w w w . j a va2 s . c o m*/ * * @return The configuration * @throws JSONException On JSON errors. */ private JSONObject getConfiguration() throws JSONException { JSONObject configuration = new JSONObject(); configuration.put("port", config.getPort()); configuration.put("register", true); if (config.getProxy() != null) { configuration.put("proxy", config.getProxy()); } else { configuration.put("proxy", "org.openqa.grid.selenium.proxy.DefaultRemoteProxy"); } configuration.put("role", "node"); configuration.put("registerCycle", 5000); configuration.put("maxInstances", 5); // adding hub details URL registrationUrl; try { registrationUrl = new URL(config.getRegistrationUrl()); } catch (MalformedURLException e) { e.printStackTrace(); throw new SelendroidException("Grid hub url cannot be parsed: " + e.getMessage()); } configuration.put("hubHost", registrationUrl.getHost()); configuration.put("hubPort", registrationUrl.getPort()); // adding driver details configuration.put("remoteHost", "http://" + config.getServerHost() + ":" + config.getPort()); return configuration; }
From source file:com.codecarpet.fbconnect.FBLoginDialog.java
private void loadLoginPage() { Map<String, String> params = new HashMap<String, String>(); params.put("fbconnect", "1"); params.put("connect_display", "touch"); params.put("api_key", _session.getApiKey()); params.put("next", "fbconnect://success"); try {/* w ww .ja va 2 s . c o m*/ loadURL(kLoginURL, "GET", params, null); } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:de.comlineag.snc.webcrawler.robotstxt.RobotstxtServer.java
public boolean allows(WebURL webURL) { if (!config.isEnabled()) { return true; }// w ww .j a v a2 s .c o m try { URL url = new URL(webURL.getURL()); String host = getHost(url); 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(url); } return directives.allows(path); } catch (MalformedURLException e) { e.printStackTrace(); } return true; }