List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:com.basetechnology.s0.agentserver.webaccessmanager.WebAccessManager.java
public WebSite getWebSite(String url) { String webSiteUrl = null;/*from w ww .ja v a 2s . com*/ try { URL tempUrl = new URL(url); String protocol = tempUrl.getProtocol(); String host = tempUrl.getHost(); int port = tempUrl.getPort(); webSiteUrl = protocol + "://" + host + (port > 0 ? ":" + port : "") + "/"; } catch (MalformedURLException e) { throw new InvalidUrlException(e.getMessage()); } // Check if we already know about this site if (!webSites.containsKey(webSiteUrl)) { // No, create a new WebSite entry WebSite webSite = new WebSite(this, webSiteUrl); webSites.put(webSiteUrl, webSite); } // Return the WebSite for this URL return webSites.get(webSiteUrl); }
From source file:io.kamax.mxisd.config.rest.RestBackendConfig.java
private String buildEndpointUrl(String endpoint) { if (StringUtils.startsWith(endpoint, "/")) { if (StringUtils.isBlank(getHost())) { throw new ConfigurationException("rest.host"); }//from w w w . j a va2 s .co m try { new URL(getHost()); } catch (MalformedURLException e) { throw new ConfigurationException("rest.host", e.getMessage()); } return getHost() + endpoint; } else { return endpoint; } }
From source file:bixo.fetcher.simulation.FakeHttpFetcher.java
private FetchedDatum doGet(String url, Payload payload, boolean returnContent) throws BaseFetchException { LOGGER.trace("Fake fetching " + url); URL theUrl;//from ww w .jav a2 s. c o m try { theUrl = new URL(url); } catch (MalformedURLException e) { throw new UrlFetchException(url, e.getMessage()); } int statusCode = HttpStatus.SC_OK; int contentSize = 10000; int bytesPerSecond = 100000; if (_randomFetching) { contentSize = Math.max(0, (int) (_rand.nextGaussian() * 5000.0) + 10000) + 100; bytesPerSecond = Math.max(0, (int) (_rand.nextGaussian() * 25000.0) + 50000) + 1000; } else { String query = theUrl.getQuery(); if (query != null) { String[] params = query.split("&"); for (String param : params) { String[] keyValue = param.split("="); if (keyValue[0].equals("status")) { statusCode = Integer.parseInt(keyValue[1]); } else if (keyValue[0].equals("size")) { contentSize = Integer.parseInt(keyValue[1]); } else if (keyValue[0].equals("speed")) { bytesPerSecond = Integer.parseInt(keyValue[1]); } else { LOGGER.warn("Unknown fake URL parameter: " + keyValue[0]); } } } } if (statusCode != HttpStatus.SC_OK) { throw new HttpFetchException(url, "Exception requested from FakeHttpFetcher", statusCode, null); } if (!returnContent) { contentSize = 0; } // Now we want to delay for as long as it would take to fill in the data. float duration = (float) contentSize / (float) bytesPerSecond; LOGGER.trace(String.format("Fake fetching %d bytes at %d bps (%fs) from %s", contentSize, bytesPerSecond, duration, url)); try { Thread.sleep((long) (duration * 1000.0)); } catch (InterruptedException e) { // Break out of our delay, but preserve interrupt state. Thread.currentThread().interrupt(); } HttpHeaders headers = new HttpHeaders(); headers.add("x-responserate", "" + bytesPerSecond); FetchedDatum result = new FetchedDatum(url, url, System.currentTimeMillis(), headers, new ContentBytes(new byte[contentSize]), "text/html", bytesPerSecond); result.setPayload(payload); return result; }
From source file:com.gisgraphy.importer.ImporterHelper.java
/** * check if an url doesn't return 200 or 3XX code * @param urlAsString the url to check/*w w w .j a v a 2 s.co m*/ * @return true if the url exists and is valid */ public static boolean checkUrl(String urlAsString) { if (urlAsString == null) { logger.error("can not check null URL"); return false; } URL url; try { url = new URL(urlAsString); } catch (MalformedURLException e) { logger.error(urlAsString + " is not a valid url, can not check."); return false; } int responseCode; String responseMessage = "NO RESPONSE MESSAGE"; Object content = "NO CONTENT"; HttpURLConnection huc; try { huc = (HttpURLConnection) url.openConnection(); huc.setRequestMethod("HEAD"); responseCode = huc.getResponseCode(); content = huc.getContent(); responseMessage = huc.getResponseMessage(); } catch (ProtocolException e) { logger.error("can not check url " + e.getMessage(), e); return false; } catch (IOException e) { logger.error("can not check url " + e.getMessage(), e); return false; } if (responseCode == 200 || (responseCode > 300 && responseCode < 400)) { logger.info("URL " + urlAsString + " exists"); return true; } else { logger.error(urlAsString + " return a " + responseCode + " : " + content + "/" + responseMessage); return false; } }
From source file:nl.tue.gale.ae.GaleConfig.java
public void setRootGaleUrl(String rootGaleUrl) { try {/* ww w . j a v a 2 s . c o m*/ new URL(rootGaleUrl); } catch (MalformedURLException e) { throw new IllegalArgumentException("unable to set rootGaleUrl: " + e.getMessage(), e); } this.rootGaleUrl = rootGaleUrl; GaleUtil.setProperty("rootGaleUrl", rootGaleUrl); }
From source file:com.revo.deployr.client.core.impl.RProjectExecutionImpl.java
public URL downloadResults() throws RClientException, RSecurityException { String urlPath = this.liveContext.serverurl + REndpoints.RPROJECTEXECUTERESULTDOWNLOAD; String urlQuery = urlPath + "/" + this.project.id + "/" + this.about.id + ";jsessionid=" + this.liveContext.httpcookie; log.debug("downloadResults: url=" + urlQuery); URL downloadURL = null;/*from ww w. j a va 2s . c o m*/ try { downloadURL = new URL(urlQuery); } catch (MalformedURLException mex) { throw new RClientException("Download project execution results url malformed, ex=" + mex.getMessage()); } return downloadURL; }
From source file:io.kamax.mxisd.dns.ClientDnsOverwrite.java
public URIBuilder transform(URI initial) { URIBuilder builder = new URIBuilder(initial); Entry mapping = mappings.get(initial.getHost()); if (mapping == null) { throw new InternalServerError("No DNS client override for " + initial.getHost()); }//from www . j a va 2s. com try { URL target = new URL(mapping.getValue()); builder.setScheme(target.getProtocol()); builder.setHost(target.getHost()); if (target.getPort() != -1) { builder.setPort(target.getPort()); } return builder; } catch (MalformedURLException e) { log.warn("Skipping DNS overwrite entry {} due to invalid value [{}]: {}", mapping.getName(), mapping.getValue(), e.getMessage()); throw new ConfigurationException( "Invalid DNS overwrite entry in homeserver client: " + mapping.getName(), e.getMessage()); } }
From source file:de.xirp.plugin.PluginManager.java
/** * Gets the URLs of all jars which are located exactly at the * given directory path/*from www . j a v a 2s. c o m*/ * * @param path * the path to get the jar URLs from * @return a list of URLs of the jars */ private static List<URL> getJarURLsFromPath(String path) { File libs = new File(path); File[] jars = libs.listFiles(new FilenameFilter() { public boolean accept(@SuppressWarnings("unused") File dir, String name) { return name.endsWith(".jar"); //$NON-NLS-1$ } }); if (jars != null) { ArrayList<URL> urls = new ArrayList<URL>(jars.length); for (File jar : jars) { try { urls.add(jar.toURI().toURL()); } catch (MalformedURLException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } } return urls; } return new ArrayList<URL>(); }
From source file:Viewer3D.java
public void init() { if (filename == null) { // the path to the file for an applet try {/*from w w w . j a va 2 s .c om*/ java.net.URL path = getCodeBase(); filename = new java.net.URL(path.toString() + "./ballcone.lws"); } catch (java.net.MalformedURLException ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); System.exit(1); } } // Construct the Lw3d loader and load the file Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL); Scene loaderScene = null; try { loaderScene = lw3dLoader.load(filename); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Construct the applet canvas setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create a basic universe setup and the root of our scene u = new SimpleUniverse(c); BranchGroup sceneRoot = new BranchGroup(); // Change the back clip distance; the default is small for // some lw3d worlds View theView = u.getViewer().getView(); theView.setBackClipDistance(50000f); // Now add the scene graph defined in the lw3d file if (loaderScene.getSceneGroup() != null) { // Instead of using the default view location (which may be // completely bogus for the particular file you're loading), // let's use the initial view from the file. We can get // this by getting the view groups from the scene (there's // only one for Lightwave 3D), then using the inverse of the // transform on that view as the transform for the entire scene. // First, get the view groups (shouldn't be null unless there // was something wrong in the load TransformGroup viewGroups[] = loaderScene.getViewGroups(); // Get the Transform3D from the view and invert it Transform3D t = new Transform3D(); viewGroups[0].getTransform(t); Matrix4d m = new Matrix4d(); t.get(m); m.invert(); t.set(m); // Now we've got the transform we want. Create an // appropriate TransformGroup and parent the scene to it. // Then insert the new group into the main BranchGroup. TransformGroup sceneTransform = new TransformGroup(t); sceneTransform.addChild(loaderScene.getSceneGroup()); sceneRoot.addChild(sceneTransform); } // Make the scene graph live by inserting the root into the universe u.addBranchGraph(sceneRoot); }
From source file:org.manalith.ircbot.plugin.google.GooglePlugin.java
private int getGoogleCount(String keyword) { try {//w ww. j av a 2 s. com // http://code.google.com/apis/websearch/docs/#fonje URL url = new URL("https://ajax.googleapis.com/ajax/services/search/web?v=1.0&" + "q=" + URLEncoder.encode(keyword, "UTF-8") + "&key=" + apiKey + "&userip=" + InetAddress.getLocalHost().getHostAddress()); URLConnection connection = url.openConnection(); connection.addRequestProperty("Referer", apiReferer); String line; StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); while ((line = reader.readLine()) != null) { builder.append(line); } return Integer.parseInt(new JSONObject(builder.toString()).getJSONObject("responseData") .getJSONObject("cursor").getString("estimatedResultCount")); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } catch (JSONException e) { logger.error(e.getMessage(), e); } return -1; }