List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:io.kamax.mxisd.config.ServerConfig.java
@PostConstruct public void build() { log.info("--- Server config ---"); if (StringUtils.isBlank(getName())) { setName(mxCfg.getDomain());//from ww w . j a v a 2s .c om log.debug("server.name is empty, using matrix.domain"); } if (StringUtils.isBlank(getPublicUrl())) { setPublicUrl("https://" + getName()); log.debug("Public URL is empty, generating from name"); } else { setPublicUrl(StringUtils.replace(getPublicUrl(), "%SERVER_NAME%", getName())); } try { new URL(getPublicUrl()); } catch (MalformedURLException e) { log.warn("Public URL is not valid: {}", StringUtils.defaultIfBlank(e.getMessage(), "<no reason provided>")); } log.info("Name: {}", getName()); log.info("Port: {}", getPort()); log.info("Public URL: {}", getPublicUrl()); }
From source file:com.tune.reporting.helpers.ReportReaderJson.java
/** * Using provided report download URL, extract contents appropriate * to the content's format./*from w ww .j a va2s . c o m*/ * * @return Boolean If successful in reading remote report returns true. * @throws TuneSdkException Error within SDK If fails to read report. */ public Boolean read() throws TuneSdkException { try { URL jsonReportUrl = new URL(this.getReportUrl()); BufferedReader jsonBufferReader = new BufferedReader(new InputStreamReader(jsonReportUrl.openStream())); String cvsSplitBy = ","; List<String> jsonListLines = new ArrayList<String>(); String jsonBufferReaderLine; while ((jsonBufferReaderLine = jsonBufferReader.readLine()) != null) { jsonListLines.add(jsonBufferReaderLine); } // end while if (jsonListLines.size() == 0) { return false; } String jsonStr = jsonListLines.get(0); JSONArray jsonArray = new JSONArray(jsonStr); if (jsonArray.length() == 0) { return false; } for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonItem = jsonArray.getJSONObject(i); Iterator<?> keys = jsonItem.keys(); Map<String, String> jsonItemMap = new HashMap<String, String>(); while (keys.hasNext()) { String key = (String) keys.next(); Object value = jsonItem.get(key); jsonItemMap.put(key, value.toString()); } this.reportMapList.add(jsonItemMap); } } catch (MalformedURLException ex) { throw new TuneSdkException(ex.getMessage(), ex); } catch (IOException ex) { throw new TuneSdkException(ex.getMessage(), ex); } catch (Exception ex) { throw new TuneSdkException(ex.getMessage(), ex); } return true; }
From source file:de.nrw.hbz.regal.sync.ingest.DippDownloader.java
private void downloadStreams(File dir, String pid) { try {/*from w w w . j a v a 2 s .c om*/ URL url = new URL(getServer() + "listDatastreams/" + pid + "?xml=true"); String data = null; StringWriter writer = new StringWriter(); IOUtils.copy(url.openStream(), writer); data = writer.toString(); Element root = XmlUtils.getDocument(data); NodeList dss = root.getElementsByTagName("datastream"); for (int i = 0; i < dss.getLength(); i++) { Element dsel = (Element) dss.item(i); String datastreamName = dsel.getAttribute("dsid"); String fileName = dsel.getAttribute("label"); String mimeType = dsel.getAttribute("mimeType"); if (mimeType.contains("xml")) { fileName = datastreamName + ".xml"; } if (mimeType.contains("html")) { fileName = fileName + ".html"; } File dataStreamFile = new File(dir.getAbsolutePath() + File.separator + "" + fileName); download(dataStreamFile, getServer() + "get/" + pid + "/" + datastreamName); } } catch (MalformedURLException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:de.xirp.plugin.PluginManager.java
/** * Gets the URLs for the given plugins information. * /* w w w .j a va 2s . c o m*/ * @param info * the information about the plugin to get the URLs for * @return the URLs for the jars of the plugin */ private static List<URL> getJarURLs(PluginInfo info) { String path = getPluginLibPath(info); List<URL> urls = getJarURLsForOS(path); try { urls.add(new File(path).toURI().toURL()); } catch (MalformedURLException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } return urls; }
From source file:com.snaplogic.snaps.lunex.RequestProcessor.java
public String execute(RequestBuilder rBuilder) throws MalformedURLException, IOException { try {/*from w w w. j a v a2 s .co m*/ URL api_url = new URL(rBuilder.getURL()); HttpURLConnection httpUrlConnection = (HttpURLConnection) api_url.openConnection(); httpUrlConnection.setRequestMethod(rBuilder.getMethod().toString()); httpUrlConnection.setDoInput(true); httpUrlConnection.setDoOutput(true); if (rBuilder.getSnapType() != LunexSnaps.Read) { rBuilder.getHeaders().add(Pair.of(CONTENT_LENGTH, rBuilder.getRequestBodyLenght())); } for (Pair<String, String> header : rBuilder.getHeaders()) { if (!StringUtils.isEmpty(header.getKey()) && !StringUtils.isEmpty(header.getValue())) { httpUrlConnection.setRequestProperty(header.getKey(), header.getValue()); } } log.debug(String.format(LUNEX_HTTP_INFO, rBuilder.getSnapType(), rBuilder.getURL(), httpUrlConnection.getRequestProperties().toString())); if (rBuilder.getSnapType() != LunexSnaps.Read) { String paramsJson = null; if (!StringUtils.isEmpty(paramsJson = rBuilder.getRequestBody())) { DataOutputStream cgiInput = new DataOutputStream(httpUrlConnection.getOutputStream()); log.debug(String.format(LUNEX_HTTP_REQ_INFO, paramsJson)); cgiInput.writeBytes(paramsJson); cgiInput.flush(); IOUtils.closeQuietly(cgiInput); } } List<String> input = null; StringBuilder response = new StringBuilder(); try (InputStream iStream = httpUrlConnection.getInputStream()) { input = IOUtils.readLines(iStream); } catch (IOException ioe) { log.warn(String.format(INPUT_STREAM_ERROR, ioe.getMessage())); try (InputStream eStream = httpUrlConnection.getErrorStream()) { if (eStream != null) { input = IOUtils.readLines(eStream); } else { response.append(String.format(INPUT_STREAM_ERROR, ioe.getMessage())); } } catch (IOException ioe1) { log.warn(String.format(INPUT_STREAM_ERROR, ioe1.getMessage())); } } statusCode = httpUrlConnection.getResponseCode(); log.debug(String.format(HTTP_STATUS, statusCode)); if (input != null && !input.isEmpty()) { for (String line : input) { response.append(line); } } return formatResponse(response, rBuilder); } catch (MalformedURLException me) { log.error(me.getMessage(), me); throw me; } catch (IOException ioe) { log.error(ioe.getMessage(), ioe); throw ioe; } catch (Exception ex) { log.error(ex.getMessage(), ex); throw ex; } }
From source file:de.xirp.plugin.PluginManager.java
/** * Constructs a class loader for the given plugin information. The * loader has information about the jars of this plugin. * /*from ww w. j a v a2s . c o m*/ * @param info * information about the plugin * @return a class loader which may be used for loading the plugin */ public static URLClassLoader getClassLoader(PluginInfo info) { File file = new File(info.getAbsoluteJarPath()); List<URL> urls = getJarURLs(info); try { urls.add(file.toURI().toURL()); } catch (MalformedURLException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } URLClassLoader classLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()])); return classLoader; }
From source file:com.cellbots.communication.AppEngineCommChannel.java
@Override public void listenForMessages(long waitTimeBetweenPolling, boolean returnStream) { stopReading = false;// w w w. ja v a 2 s .co m new Thread(new Runnable() { @Override public void run() { Looper.prepare(); while (!stopReading) { try { resetConnection(); PostMethod post = new PostMethod(mHttpCmdUrl); post.setParameter("msg", "{}"); int result = post.execute(mHttpState, mConnection); String response = post.getResponseBodyAsString(); int cmdStart = response.indexOf(startCmdStr); if (cmdStart != -1) { String command = response.substring(cmdStart + startCmdStr.length()); command = command.substring(0, command.indexOf("\"")); Log.e("command", command); mMessageListener.onMessage(new CommMessage(command, null, "text/text", null, null, mChannelName, CommunicationManager.CHANNEL_GAE)); } // Thread.sleep(200); } catch (MalformedURLException e) { Log.e(TAG, "Error processing URL: " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "Error reading command from URL: " + mHttpCmdUrl + " : " + e.getMessage()); } } } }).start(); }
From source file:com.twosigma.beaker.sql.JDBCClient.java
public void loadDrivers(List<String> pathList) { synchronized (this) { dsMap = new HashMap<>(); drivers = new HashSet<>(); Set<URL> urlSet = new HashSet<>(); String dbDriverString = System.getenv("BEAKER_JDBC_DRIVER_LIST"); if (dbDriverString != null && !dbDriverString.isEmpty()) { String[] dbDriverList = dbDriverString.split(File.pathSeparator); for (String s : dbDriverList) { try { urlSet.add(toURL(s)); } catch (MalformedURLException e) { logger.error(e.getMessage()); }/*from w ww. jav a 2 s . c o m*/ } } if (pathList != null) { for (String path : pathList) { path = path.trim(); if (path.startsWith("--") || path.startsWith("#")) { continue; } try { urlSet.add(toURL(path)); } catch (MalformedURLException e) { logger.error(e.getMessage()); } } } URLClassLoader loader = new URLClassLoader(urlSet.toArray(new URL[urlSet.size()])); ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class, loader); Iterator<Driver> driversIterator = loadedDrivers.iterator(); try { while (driversIterator.hasNext()) { Driver d = driversIterator.next(); drivers.add(d); } } catch (Throwable t) { logger.error(t.getMessage()); } } }
From source file:bixo.fetcher.simulation.FakeRobotsFetcher.java
@Override public FetchedDatum get(ScoredUrlDatum scoredUrl) throws BaseFetchException { String url = scoredUrl.getUrl(); LOGGER.trace("Fake fetching " + url); URL theUrl;/*from w w w .j a v a 2 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); } // 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(scoredUrl.getPayload()); return result; }
From source file:com.denimgroup.threadfix.service.defects.RestUtils.java
public static InputStream postUrl(String urlString, String data, String username, String password) { URL url = null;/*from w w w . j av a 2 s . c o m*/ try { url = new URL(urlString); } catch (MalformedURLException e) { log.warn("URL used for POST was bad: '" + urlString + "'"); return null; } HttpURLConnection httpConnection = null; OutputStreamWriter outputWriter = null; try { httpConnection = (HttpURLConnection) url.openConnection(); setupAuthorization(httpConnection, username, password); httpConnection.addRequestProperty("Content-Type", "application/json"); httpConnection.addRequestProperty("Accept", "application/json"); httpConnection.setDoOutput(true); outputWriter = new OutputStreamWriter(httpConnection.getOutputStream()); outputWriter.write(data); outputWriter.flush(); InputStream is = httpConnection.getInputStream(); return is; } catch (IOException e) { log.warn("IOException encountered trying to post to URL with message: " + e.getMessage()); if (httpConnection == null) { log.warn( "HTTP connection was null so we cannot do further debugging of why the HTTP request failed"); } else { try { InputStream errorStream = httpConnection.getErrorStream(); if (errorStream == null) { log.warn("Error stream from HTTP connection was null"); } else { log.warn( "Error stream from HTTP connection was not null. Attempting to get response text."); String postErrorResponse = IOUtils.toString(errorStream); log.warn("Error text in response was '" + postErrorResponse + "'"); } } catch (IOException e2) { log.warn("IOException encountered trying to read the reason for the previous IOException: " + e2.getMessage(), e2); } } } finally { if (outputWriter != null) { try { outputWriter.close(); } catch (IOException e) { log.warn("Failed to close output stream in postUrl.", e); } } } return null; }