List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.ggvaidya.TaxRef.Net.DownloadITIS.java
public static DarwinCSV getIt(JFrame mainFrame) { try {/*from w ww.j ava 2 s. co m*/ URL url = new URL(url_itisDwCtab); File tempFile = File.createTempFile("itis_dwctab", ".txt", null); FileUtils.copyURLToFile(url, tempFile, 10000, 100000); return new DarwinCSV(tempFile, DarwinCSV.FILE_CSV_DELIMITED); } catch (MalformedURLException ex) { MessageBox.messageBox(mainFrame, "Malformed URL", "Malformed URL (" + ex + "): " + url_itisDwCtab); } catch (IOException ex) { MessageBox.messageBox(mainFrame, "Unable to download ITIS-DwCA file", ex.getLocalizedMessage()); } return null; }
From source file:com.yoctopuce.YoctoAPI.YFirmwareUpdate.java
static byte[] _downloadfile(String url) throws YAPI_Exception { ByteArrayOutputStream result = new ByteArrayOutputStream(1024); URL u = null;/*from w ww . j a va2s . c om*/ try { u = new URL(url); } catch (MalformedURLException e) { throw new YAPI_Exception(YAPI.IO_ERROR, e.getLocalizedMessage()); } BufferedInputStream in = null; try { URLConnection connection = u.openConnection(); in = new BufferedInputStream(connection.getInputStream()); byte[] buffer = new byte[1024]; int readed = 0; while (readed >= 0) { readed = in.read(buffer, 0, buffer.length); if (readed < 0) { // end of connection break; } else { result.write(buffer, 0, readed); } } } catch (IOException e) { throw new YAPI_Exception(YAPI.IO_ERROR, "unable to contact www.yoctopuce.com :" + e.getLocalizedMessage()); } finally { if (in != null) { try { in.close(); } catch (IOException ignore) { } } } return result.toByteArray(); }
From source file:com.hybris.mobile.data.WebServiceDataProvider.java
/** * Synchronous call for logging in/* ww w . j av a 2 s. c o m*/ * * @param httpBody * @return The data from the server as a string, in almost all cases JSON * @throws MalformedURLException * @throws IOException * @throws JSONException */ public static String getLoginResponse(Bundle httpBody) throws MalformedURLException, IOException { String response = ""; URL url = new URL(WebServiceAuthProvider.tokenURL()); trustAllHosts(); HttpsURLConnection connection = createSecureConnection(url); connection.setHostnameVerifier(DO_NOT_VERIFY); String authString = "mobile_android:secret"; String authValue = "Basic " + Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", authValue); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); OutputStream os = new BufferedOutputStream(connection.getOutputStream()); os.write(encodePostBody(httpBody).getBytes()); os.flush(); try { LoggingUtils.d(LOG_TAG, connection.toString()); response = readFromStream(connection.getInputStream()); } catch (MalformedURLException e) { LoggingUtils.e(LOG_TAG, "Error reading stream \"" + connection.getInputStream() + "\". " + e.getLocalizedMessage(), null); } catch (IOException e) { response = readFromStream(connection.getErrorStream()); } finally { connection.disconnect(); } return response; }
From source file:org.ebayopensource.turmeric.eclipse.utils.wsdl.WSDLUtil.java
/** * Validate url.//from w ww .j ava 2 s. c o m * * @param url the url * @return the string */ public static String validateURL(final String url) { if (StringUtils.isBlank(url)) return "url is blank."; try { new URL(StringEscapeUtils.escapeHtml(url)); } catch (final MalformedURLException e) { return e.getLocalizedMessage(); } return ""; }
From source file:com.hybris.mobile.data.WebServiceDataProvider.java
/** * Synchronous call for logging out//from w ww . j a va 2 s .c o m * * @return The data from the server as a string, in almost all cases JSON * @throws MalformedURLException * @throws IOException * @throws JSONException */ public static String getLogoutResponse(Context context) throws MalformedURLException, IOException, JSONException { // Refresh if necessary if (WebServiceAuthProvider.tokenExpiredHint(context)) { WebServiceAuthProvider.refreshAccessToken(context); } boolean refreshLimitReached = false; int refreshed = 0; String response = ""; while (!refreshLimitReached) { // If we have refreshed max number of times, we will not do so again if (refreshed == 1) { refreshLimitReached = true; } URL url = new URL(urlForLogout(context)); HttpsURLConnection connection = createSecureConnection(url); trustAllHosts(); connection.setHostnameVerifier(DO_NOT_VERIFY); String authValue = "Bearer " + SDKSettings.getSharedPreferenceString(context, "access_token"); connection.setRequestMethod("POST"); connection.setRequestProperty("Authorization", authValue); connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); try { LoggingUtils.d(LOG_TAG, "LogoutResponse" + connection.toString()); response = readFromStream(connection.getInputStream()); } catch (MalformedURLException e) { LoggingUtils.e(LOG_TAG, "Error reading stream \"" + connection.getInputStream() + "\". " + e.getLocalizedMessage(), null); } catch (IOException e) { response = readFromStream(connection.getErrorStream()); } finally { connection.disconnect(); } // Allow for calls to return nothing if (response.length() == 0) { return ""; } // Check for JSON parsing errors (will throw JSONException is can't be parsed) JSONObject object = new JSONObject(response); // If no error, return response if (!object.has("error")) { return response; } // If there is a refresh token error, refresh the token else if (object.getString("error").equals("invalid_token")) { if (refreshLimitReached) { // Give up return response; } else { // Refresh the token WebServiceAuthProvider.refreshAccessToken(context); refreshed++; } } } // while(!refreshLimitReached) return response; }
From source file:org.pentaho.di.core.market.Market.java
/** * Uninstalls the passed MarketEntry.//ww w.java 2 s.c om * * @param marketEntry * @throws KettleException */ public static void uninstall(final MarketEntry marketEntry, final ProgressMonitorDialog monitorDialog, boolean refresh) throws KettleException { String parentFolderName = buildPluginsFolderPath(marketEntry); File pluginFolder = new File(parentFolderName + File.separator + marketEntry.getId()); LogChannel.GENERAL.logBasic("Uninstalling plugin in folder: " + pluginFolder.getAbsolutePath()); if (!pluginFolder.exists()) { throw new KettleException( "No plugin was found in the expected folder : " + pluginFolder.getAbsolutePath()); } try { for (PluginInterface plugin : PluginRegistry.getInstance() .findPluginsByFolder(pluginFolder.toURI().toURL())) { // unload plugin ClassLoader cl = PluginRegistry.getInstance().getClassLoader(plugin); if (cl instanceof KettleURLClassLoader) { ((KettleURLClassLoader) cl).closeClassLoader(); } // remove plugin from registry PluginRegistry.getInstance().removePlugin(plugin.getPluginType(), plugin); } } catch (MalformedURLException e1) { LogChannel.GENERAL.logError(e1.getLocalizedMessage(), e1); } // delete plugin folder deleteDirectory(pluginFolder); if (refresh) { if (!Display.getDefault().getThread().equals(Thread.currentThread())) { Spoon.getInstance().getDisplay().asyncExec(new Runnable() { public void run() { try { refreshSpoon(monitorDialog); } catch (KettleException e) { e.printStackTrace(); } } }); } else { refreshSpoon(monitorDialog); } } }
From source file:org.opennms.ng.services.capsdconfig.CapsdConfigManager.java
/** * The file URL is read and a 'specific IP' is added for each entry in this * file. Each line in the URL file can be one of -<IP><space># <comments> * or <IP>or #<comments>// ww w . ja v a 2 s.c om * <p/> * Lines starting with a '#' are ignored and so are characters after a ' * <space>#' in a line. * * @param url the URL file * @return List of addresses retrieved from the URL */ private static List<String> getAddressesFromURL(String url) { List<String> addrList = new ArrayList<String>(); try { // open the file indicated by the url URL fileURL = new URL(url); InputStream file = fileURL.openStream(); // check to see if the file exists if (file != null) { BufferedReader buffer = new BufferedReader(new InputStreamReader(file, "UTF-8")); String ipLine = null; String specIP = null; // get each line of the file and turn it into a specific address while ((ipLine = buffer.readLine()) != null) { ipLine = ipLine.trim(); if (ipLine.length() == 0 || ipLine.charAt(0) == COMMENT_CHAR) { // blank line or skip comment continue; } // check for comments after IP int comIndex = ipLine.indexOf(COMMENT_STR); if (comIndex == -1) { specIP = ipLine; } else { specIP = ipLine.substring(0, comIndex); ipLine = ipLine.trim(); } addrList.add(specIP); specIP = null; } buffer.close(); } else { LOG.warn("URL does not exist: {}", url); } } catch (MalformedURLException e) { LOG.error("Error reading URL: {}: {}", e.getLocalizedMessage(), url); } catch (FileNotFoundException e) { LOG.error("Error reading URL: {}: {}", e.getLocalizedMessage(), url); } catch (IOException e) { LOG.error("Error reading URL: {}: {}", e.getLocalizedMessage(), url); } return addrList; }
From source file:uk.ac.ox.oucs.vle.TestPopulatorInput.java
public InputStream getInput(PopulatorContext context) { InputStream input;/* w w w. j av a2 s . c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); try { URL xcri = new URL(context.getURI()); if ("file".equals(xcri.getProtocol())) { input = xcri.openStream(); } else { HttpHost targetHost = new HttpHost(xcri.getHost(), xcri.getPort(), xcri.getProtocol()); httpclient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(context.getUser(), context.getPassword())); HttpGet httpget = new HttpGet(xcri.toURI()); HttpResponse response = httpclient.execute(targetHost, httpget); HttpEntity entity = response.getEntity(); if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) { throw new IllegalStateException( "Invalid response [" + response.getStatusLine().getStatusCode() + "]"); } input = entity.getContent(); } } catch (MalformedURLException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (IllegalStateException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (IOException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (URISyntaxException e) { throw new PopulatorException(e.getLocalizedMessage()); } return input; }
From source file:net.straylightlabs.archivo.controller.UpdateCheckTask.java
private SoftwareUpdateDetails getCurrentRelease(JSONObject json) { logger.debug("Release JSON: {}", json); try {/*from w w w . ja v a 2s. c o m*/ if (json.getBoolean("update_available")) { URL location = new URL(json.getString("location")); List<String> changes = parseChangeList(json); LocalDate date = LocalDate.parse(json.getString("date")); return new SoftwareUpdateDetails( SoftwareUpdateDetails.versionToString(json.getInt("major_ver"), json.getInt("minor_ver"), json.getInt("release_ver"), json.getBoolean("is_beta"), json.getInt("beta_ver")), location, date, changes); } else { return SoftwareUpdateDetails.UNAVAILABLE; } } catch (MalformedURLException e) { logger.error("Error parsing update location: {}", e.getLocalizedMessage()); return SoftwareUpdateDetails.UNAVAILABLE; } }
From source file:uk.ac.ox.oucs.vle.XcriPopulatorInput.java
public InputStream getInput(PopulatorContext context) throws PopulatorException { InputStream input = null;/*from w w w . j a v a2 s. c o m*/ HttpEntity entity = null; try { URL xcri = new URL(context.getURI()); HttpHost targetHost = new HttpHost(xcri.getHost(), xcri.getPort(), xcri.getProtocol()); httpClient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(context.getUser(), context.getPassword())); HttpGet httpget = new HttpGet(xcri.toURI()); HttpResponse response = httpClient.execute(targetHost, httpget); entity = response.getEntity(); if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) { throw new PopulatorException("Invalid Response [" + response.getStatusLine().getStatusCode() + "]"); } input = entity.getContent(); } catch (MalformedURLException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (IllegalStateException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (IOException e) { throw new PopulatorException(e.getLocalizedMessage()); } catch (URISyntaxException e) { throw new PopulatorException(e.getLocalizedMessage()); } finally { if (null == input && null != entity) { try { entity.getContent().close(); } catch (IOException e) { log.error("IOException [" + e + "]"); } } } return input; }