List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:com.beesham.popularmovies.sync.MoviesSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient, SyncResult syncResult) {//w w w . ja v a 2 s. c o m HttpURLConnection urlConnection = null; BufferedReader reader = null; String moviesJsonStr = null; try { final String MOVIES_BASE_URL = getContext().getString(R.string.movies_base_url); final String API_KEY_PARAM = "api_key"; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String sort_by = prefs.getString(getContext().getString(R.string.pref_sort_key), getContext().getString(R.string.pref_sort_default)); Uri builtUri = Uri.parse(MOVIES_BASE_URL).buildUpon().appendPath(sort_by) .appendQueryParameter(API_KEY_PARAM, API_KEY).build(); URL url = new URL(builtUri.toString()); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setConnectTimeout(10000); urlConnection.setReadTimeout(15000); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) return; reader = new BufferedReader((new InputStreamReader(inputStream))); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } if (buffer.length() == 0) return; moviesJsonStr = buffer.toString(); getMovieDataFromJson(moviesJsonStr); } catch (MalformedURLException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } finally { if (urlConnection != null) urlConnection.disconnect(); if (reader != null) { try { reader.close(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } } } }
From source file:com.beesham.popularmovies.sync.MoviesSyncAdapter.java
/** * Gets and stores the movie trailer and reviews JSON data * @param movieId/*w ww. j a v a 2s . c o m*/ * @param flag * @return */ private String getTrailersOrReviews(String movieId, int flag) { HttpURLConnection urlConnection = null; BufferedReader reader = null; String movieJsonStr = null; String MOVIE_QUERY_URL = null; try { switch (flag) { case 0: MOVIE_QUERY_URL = getContext().getString(R.string.movies_base_trailers_url, movieId); break; case 1: MOVIE_QUERY_URL = getContext().getString(R.string.movies_base_reviews_url, movieId); break; } final String API_KEY_PARAM = "api_key"; Uri builtUri = Uri.parse(MOVIE_QUERY_URL).buildUpon().appendQueryParameter(API_KEY_PARAM, API_KEY) .build(); URL url = new URL(builtUri.toString()); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setConnectTimeout(10000); urlConnection.setReadTimeout(15000); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) return null; reader = new BufferedReader((new InputStreamReader(inputStream))); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } if (buffer.length() == 0) return null; movieJsonStr = buffer.toString(); } catch (MalformedURLException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } finally { if (urlConnection != null) urlConnection.disconnect(); if (reader != null) { try { reader.close(); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } } } return movieJsonStr; }
From source file:com.sap.dirigible.runtime.agent.WsApplyHandler.java
public void applyConfiguration(HttpServletRequest request) throws IOException { logger.debug("entering: " + this.getClass().getCanonicalName() + " -> " //$NON-NLS-1$ //$NON-NLS-2$ + APPLY_CONFIGURATION);/*ww w . j ava 2 s. c om*/ try { // boolean noLoadErrors = true; // String errorMessage = ""; List<String> remoteFiles = new ArrayList<String>(); // if ("*".equals(remote)) { // // for initial load or force reload // populateRemoteFiles(remoteFiles); // } else { remoteFiles.add(getRemote()); // } // TODO check and remove running services w/o corresponding // repository content (deleted meanwhile) for (Iterator<String> iterator = remoteFiles.iterator(); iterator.hasNext();) { String remoteFile = iterator.next(); addWebService(remoteFile, request); } } catch (MalformedURLException e) { logger.error(APPLY_CONFIGURATION, e); throw new IOException(String.format(APPLY_CONFIGURATION_FOR_WEB_SERVICE, e.getMessage()), e); } catch (Exception e) { logger.error(APPLY_CONFIGURATION, e); throw new IOException(String.format(APPLY_CONFIGURATION_FOR_WEB_SERVICE, e.getMessage()), e); } logger.debug("exiting: " + this.getClass().getCanonicalName() + " -> " //$NON-NLS-1$ //$NON-NLS-2$ + APPLY_CONFIGURATION); }
From source file:de.micromata.genome.jpa.impl.JpaWithExtLibrariesScanner.java
URL fixUrlToOpen(URL url) { String surl = url.toString(); String orgurl = surl;/*from w ww . j a va2s . c o m*/ if (surl.endsWith("!/") == true) { surl = surl.substring(0, surl.length() - 2); } if (StringUtils.startsWith(surl, "jar:jar:file:") == true) { surl = surl.substring("jar:jar:".length()); } if (StringUtils.startsWith(surl, "jar:file:") == true) { surl = surl.substring("jar:".length()); } try { URL ret = new URL(surl); log.info("Patches url from " + orgurl + " to " + surl); return ret; } catch (MalformedURLException ex) { log.warn("Cannot parse patched url: " + surl + "; " + ex.getMessage()); return url; } }
From source file:it.imtech.configuration.ChooseServer.java
/** * Setta il percorso del file di configurazione se la prima volta che * viene avviata l'applicazione/*from ww w . jav a2s. c o m*/ * * @param change Definisce se l'avvio dell'applicazione o se si vuole * modificare il percorso * @throws MalformedURLException * @throws ConfigurationException */ private XMLConfiguration setConfigurationPaths(boolean change, XMLConfiguration internalConf, ResourceBundle bundle) { URL urlConfig = null; XMLConfiguration configuration = null; try { String text = Utility.getBundleString("setconf", bundle); String title = Utility.getBundleString("setconf2", bundle); internalConf.setAutoSave(true); String n = internalConf.getString("configurl[@path]"); if (n.isEmpty()) { String s = (String) JOptionPane.showInputDialog(new Frame(), text, title, JOptionPane.PLAIN_MESSAGE, null, null, "http://phaidrastatic.cab.unipd.it/xml/config.xml"); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { internalConf.setProperty("configurl[@path]", s); urlConfig = new URL(s); } else { logger.info("File di configurazione non settato"); } } else { urlConfig = new URL(n); } if (urlConfig != null) { if (Globals.DEBUG) configuration = new XMLConfiguration(new File(Globals.JRPATH + Globals.DEBUG_XML)); else configuration = new XMLConfiguration(urlConfig); } } catch (final MalformedURLException ex) { logger.error(ex.getMessage()); JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_1", bundle)); } catch (final ConfigurationException ex) { logger.error(ex.getMessage()); JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_2", bundle)); } return configuration; }
From source file:org.ala.repository.Validator.java
/** * Validate a file//from ww w. j a v a 2 s.c om * * @param file the file to validate */ protected void validateFile(File file) { String fileName = file.getName(); try { if (fileName.matches(FileType.DC.getFilename())) { validateDcFile(file); } else if (fileName.matches(FileType.RDF.getFilename())) { validateRdfFile(file); } } catch (MalformedURLException ex) { // URI logger.error("Invalid URI: " + ex.getMessage() + " - " + file.getAbsolutePath()); } catch (IOException ex) { // File access errors logger.error("Failed to open file (" + file.getAbsolutePath() + "): " + ex.getMessage()); } catch (NoSuchFieldError ex) { // Missing fields logger.error("Missing field: " + ex.getMessage() + " - " + file.getAbsolutePath()); } catch (IllegalArgumentException ex) { // thrown by Assert class logger.error("Invalid data: " + ex.getMessage() + " - " + file.getAbsolutePath()); } catch (Exception ex) { // Anything else logger.error("General Exception: " + ex.getMessage() + " - " + file.getAbsolutePath()); } }
From source file:com.threewks.thundr.http.service.gae.HttpServiceImpl.java
private URL buildPostRequestUrl(HttpRequestImpl request) { String requestUrlString = request.getUrl(); try {/*from w ww .j a va2 s . co m*/ return new URL(requestUrlString); } catch (MalformedURLException e) { throw new HttpRequestException(e, "Failed to create destination url - generated '%s': %s", requestUrlString, e.getMessage()); } }
From source file:org.commonjava.aprox.model.core.RemoteRepository.java
public void calculateFields() { URL url = null;/*from w w w . j a va 2s . c o m*/ try { url = new URL(this.url); } catch (final MalformedURLException e) { LOGGER.error("Failed to parse repository URL: '{}'. Reason: {}", e, this.url, e.getMessage()); } if (url == null) { return; } final String userInfo = url.getUserInfo(); if (userInfo != null && user == null && password == null) { user = userInfo; password = null; int idx = userInfo.indexOf(':'); if (idx > 0) { user = userInfo.substring(0, idx); password = userInfo.substring(idx + 1); final StringBuilder sb = new StringBuilder(); idx = this.url.indexOf("://"); sb.append(this.url.substring(0, idx + 3)); idx = this.url.indexOf("@"); if (idx > 0) { sb.append(this.url.substring(idx + 1)); } this.url = sb.toString(); } } host = url.getHost(); if (url.getPort() < 0) { port = url.getProtocol().equals("https") ? 443 : 80; } else { port = url.getPort(); } }
From source file:com.threewks.thundr.http.service.gae.HttpServiceImpl.java
private URL buildGetRequestUrl(HttpRequestImpl request) { String requestUrlString = request.getUrl(); try {//w w w . j a v a2 s.c om String queryString = createQueryString(request); if (StringUtil.isNotBlank(queryString)) { requestUrlString = String.format("%s%s%s", requestUrlString, requestUrlString.contains("?") ? "&" : "?", queryString); } return new URL(requestUrlString); } catch (MalformedURLException e) { throw new HttpRequestException(e, "Failed to create destination url - generated '%s': %s", requestUrlString, e.getMessage()); } }