List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:es.tekniker.framework.ktek.questionnaire.mng.server.OrionContextBrokerClient.java
private HttpURLConnection getOrionContextBrokerGEConnection(String method, String service, String contentType) { HttpURLConnection conn = null; URL url = null;//from ww w .ja va2 s . c o m String urlStr = this.protocol + "://" + service + method; log.debug(urlStr); try { url = new URL(urlStr); conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod(this.methodPOST); conn.setRequestProperty(this.headerContentType, contentType); conn.setConnectTimeout(this.timeout); log.debug(this.headerContentType + " " + contentType); } catch (MalformedURLException e) { log.error("MalformedURLException " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { log.error("IOException " + e.getMessage()); e.printStackTrace(); } return conn; }
From source file:com.sciamlab.ckan4j.CKANApiClient.java
private Object actionPOST(String action, JSONObject body) throws CKANException { String result_string = ""; try {//from ww w. j a v a 2s . co m result_string = this.http.doPOST(new URL(ckan_api_endpoint + "/action/" + action), body.toString(), MediaType.APPLICATION_JSON_TYPE, null, new MultivaluedHashMap<String, String>() { { put("Authorization", new ArrayList<String>() { { if (ckan_api_key != null) add(ckan_api_key); } }); } }).readEntity(String.class); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } JSONObject result; try { result = new JSONObject(result_string); } catch (JSONException e) { throw new CKANException(e); } if (!result.getBoolean("success")) throw new CKANException(result.getJSONObject("error")); return result.get("result"); }
From source file:com.sciamlab.ckan4j.CKANApiClient.java
private Object actionGET(String action, MultivaluedHashMap<String, String> params) throws CKANException { String result_string = ""; try {/*from w w w . j ava2 s . com*/ result_string = this.http.doGET(new URL(ckan_api_endpoint + "/action/" + action), params, new MultivaluedHashMap<String, String>() { { put("Authorization", new ArrayList<String>() { { if (ckan_api_key != null) add(ckan_api_key); } }); } }).readEntity(String.class); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } JSONObject result; try { result = new JSONObject(result_string); } catch (JSONException e) { throw new CKANException(e); } if (!result.getBoolean("success")) throw new CKANException(result.getJSONObject("error")); return result.get("result"); }
From source file:io.selendroid.standalone.server.grid.SelfRegisteringRemote.java
/** * Extracts the configuration.// w ww . j ava 2 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("maxSession", config.getMaxSession()); // adding hub details URL registrationUrl; try { registrationUrl = new URL(config.getRegistrationUrl()); } catch (MalformedURLException e) { log.log(Level.SEVERE, "Grid hub url cannot be parsed", e); 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("seleniumProtocol", "WebDriver"); configuration.put("host", config.getServerHost()); configuration.put("remoteHost", "http://" + config.getServerHost() + ":" + config.getPort()); return configuration; }
From source file:com.owly.srv.RemoteBasicStatItfImpl.java
public RemoteBasicStat getRemoteStatistic(String nameSrv, String ipSrv, String typeSrv, String typeStat, int clientPort) { URL url = null;/*w w w . j a v a 2 s . c o m*/ BufferedReader reader = null; StringBuilder stringBuilder; JSONObject objJSON = new JSONObject(); JSONParser objParser = new JSONParser(); RemoteBasicStat remoteBasicStat = new RemoteBasicStat(); HttpURLConnection connection; // URL ot execute and get a Basic Stadistic. // Url to send to remote server // for example : // http://135.1.128.127:5000/OwlyClnt/Stats_TopCPU String urlToSend = "http://" + ipSrv + ":" + clientPort + "/OwlyClnt/" + typeStat; logger.debug("URL for HTTP request : " + urlToSend); try { url = new URL(urlToSend); connection = (HttpURLConnection) url.openConnection(); // just want to do an HTTP GET here connection.setRequestMethod("GET"); // uncomment this if you want to write output to this url // connection.setDoOutput(true); // give it 15 seconds to respond connection.setReadTimeout(3 * 1000); connection.connect(); // read the output from the server reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); stringBuilder = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { stringBuilder.append(line + "\n"); } logger.debug("Response received : " + stringBuilder.toString()); // Get the response and save into a JSON object, and parse the // JSON object objJSON = (JSONObject) objParser.parse(stringBuilder.toString()); logger.debug("JSON received : " + objJSON.toString()); // Add all info received in a new object of satistics remoteBasicStat.setRmtSeverfromJSONObject(objJSON); // Add more details for the stadistics. remoteBasicStat.setIpServer(ipSrv); logger.debug("IP of server : " + remoteBasicStat.getIpServer()); remoteBasicStat.setNameServer(nameSrv); logger.debug("Name of Server : " + remoteBasicStat.getNameServer()); remoteBasicStat.setTypeServer(typeSrv); logger.debug("Type of Server : " + remoteBasicStat.getTypeServer()); } catch (MalformedURLException e) { logger.error("MalformedURLException : " + e.getMessage()); logger.error("Exception ::", e); } catch (IOException e) { logger.error("IOException : " + e.toString()); logger.error("Exception ::", e); } catch (ParseException e) { logger.error("ParseException : " + e.toString()); logger.error("Exception ::", e); } return remoteBasicStat; }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void download(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String media = request.getParameter("media"); String type = request.getParameter("type"); try {/*ww w . j a v a2 s.c o m*/ URL url = new URL(request.getParameter("url")); File typeDir = getTypeDir(media, type, true); String name = url.getPath().replaceAll("^([^/]*/)*", ""); InputStream iS = url.openStream(); OutputStream oS = new FileOutputStream(new File(typeDir, name)); IOUtils.copyLarge(iS, oS); IOUtils.closeQuietly(iS); IOUtils.closeQuietly(oS); setTextResponse(response, response.SC_OK, "Successfully downloaded 1 remote file"); } catch (MalformedURLException muE) { setTextResponse(response, response.SC_BAD_REQUEST, muE.getMessage()); } catch (IllegalArgumentException iaE) { setTextResponse(response, response.SC_BAD_REQUEST, iaE.getMessage()); } catch (FileNotFoundException fnfE) { setTextResponse(response, response.SC_BAD_REQUEST, fnfE.getMessage()); } }
From source file:org.openintents.lib.DeliciousApiHelper.java
public String[] getTags() throws java.io.IOException { String[] result = null;//from w w w . ja va 2s . c om String rpc = mAPI + "tags/get"; Element tag; java.net.URL u = null; try { u = new URL(rpc); } catch (java.net.MalformedURLException mu) { System.out.println("Malformed URL>>" + mu.getMessage()); } Document doc = null; try { javax.net.ssl.HttpsURLConnection connection = (javax.net.ssl.HttpsURLConnection) u.openConnection(); //that's actualy pretty ugly to do, but a neede workaround for m5.rc15 javax.net.ssl.HostnameVerifier v = new org.apache.http.conn.ssl.AllowAllHostnameVerifier(); connection.setHostnameVerifier(v); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(connection.getInputStream()); } catch (java.io.IOException ioe) { System.out.println("Error >>" + ioe.getMessage()); Log.e(_TAG, "Error >>" + ioe.getMessage()); } catch (ParserConfigurationException pce) { System.out.println("ERror >>" + pce.getMessage()); Log.e(_TAG, "ERror >>" + pce.getMessage()); } catch (SAXException se) { System.out.println("ERRROR>>" + se.getMessage()); Log.e(_TAG, "ERRROR>>" + se.getMessage()); } catch (Exception e) { Log.e(_TAG, "Error while excecuting HTTP method. URL is: " + u); System.out.println("Error while excecuting HTTP method. URL is: " + u); e.printStackTrace(); } if (doc == null) { Log.e(_TAG, "document was null, check internet connection?"); throw new java.io.IOException("Error reading stream >>" + rpc + "<<"); } int tagsLen = doc.getElementsByTagName("tag").getLength(); result = new String[tagsLen]; for (int i = 0; i < tagsLen; i++) { tag = (Element) doc.getElementsByTagName("tag").item(i); result[i] = new String(tag.getAttribute("tag").trim()); } //System.out.println( new Scanner( u.openStream() ).useDelimiter( "\\Z" ).next() ); return result; }
From source file:com.github.pemapmodder.pocketminegui.gui.startup.installer.FetchVersionsThread.java
private void fetchJenkinsBuilds(String urlPath, String buildPrefix, ReleaseType releaseType) { try {//w ww . j av a 2 s. c o m URL url = new URL(urlPath); String jsonString = IOUtils.toString(url); JSONObject object = new JSONObject(jsonString); JSONArray array = object.getJSONArray("builds"); for (Object arrayObject : array) { JSONObject build = (JSONObject) arrayObject; if (!build.getString("result").equals("SUCCESS")) { continue; } String artifactName = null; for (Object artifactObject : build.getJSONArray("artifacts")) { JSONObject artifact = (JSONObject) artifactObject; if (artifact.getString("fileName").endsWith(".phar")) { artifactName = artifact.getString("relativePath"); } } if (artifactName == null) { continue; } Release release = new Release(buildPrefix + "-" + build.getInt("number"), releaseType, build.getLong("timestamp"), build.getString("url") + "artifact/" + artifactName); synchronized (releases) { releases.add(release); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException | JSONException | NullPointerException | ClassCastException e) { if (e.getMessage().startsWith("Server returned HTTP response code: 521")) { System.err.println("Jenkins server is down!"); return; } System.err.println("Jenkins API returned invalid value, resulting in this error: "); e.printStackTrace(); } }
From source file:be.fedict.hsm.client.HSMProxyClient.java
/** * Sets the HTTP proxy that should be used to communicate with the HSP Proxy * web service.// w w w.ja va 2s.c om * * @param proxyHost * the HTTP proxy host. * @param proxyPort * the HTTP proxy port number. */ public void setProxy(String proxyHost, int proxyPort) { try { clientProxySelector.setProxy(this.endpointAddress, proxyHost, proxyPort); } catch (MalformedURLException e) { LOG.error("URL error: " + e.getMessage(), e); } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.router.StatelessTrafficRouterPerformanceTest.java
public URL routeTest(final HTTPRequest request, String[] rstrs) throws TrafficRouterException, GeolocationException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Attempting to route HTTPRequest: " + request.getRequestedUrl()); }/*from ww w . j a v a 2 s .c om*/ final String ip = request.getClientIP(); final DeliveryService ds = selectDeliveryService(request, true); if (ds == null) { return null; } final StatTracker.Track track = StatTracker.getTrack(); List<Cache> caches = selectCache(request, ds, track); Dispersion dispersion = ds.getDispersion(); Cache cache = dispersion.getCache(consistentHash(caches, request.getPath())); try { if (cache != null) { return new URL(ds.createURIString(request, cache)); } } catch (final MalformedURLException e) { LOGGER.error(e.getMessage(), e); throw new TrafficRouterException(URL_ERR_STR, e); } LOGGER.warn("No Cache found in CoverageZoneMap for HTTPRequest.getClientIP: " + ip); final String zoneId = null; Geolocation clientLocation = getGeolocationService().location(request.getClientIP()); final List<CacheLocation> cacheLocations = orderCacheLocations(getCacheRegister().getCacheLocations(zoneId), ds, clientLocation); for (final CacheLocation location : cacheLocations) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Trying location: " + location.getId()); } caches = getSupportingCaches(location.getCaches(), ds); if (caches.isEmpty()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("No online, supporting caches were found at location: " + location.getId()); } return null; } cache = dispersion.getCache(consistentHash(caches, request.getPath())); LOGGER.warn("cache selected: " + cache.getId()); Map<String, AtomicInteger> m = new HashMap<String, AtomicInteger>(); long time = System.currentTimeMillis(); for (String str : rstrs) { cache = dispersion.getCache(consistentHash(caches, str)); AtomicInteger i = m.get(cache.getId()); if (i == null) { i = new AtomicInteger(0); m.put(cache.getId(), i); } i.incrementAndGet(); } time = System.currentTimeMillis() - time; LOGGER.warn(String.format("time: %d", time)); for (String id : m.keySet()) { LOGGER.warn(String.format("cache(%s): %d", id, m.get(id).get())); } m = new HashMap<String, AtomicInteger>(); time = System.currentTimeMillis(); for (String str : rstrs) { cache = consistentHashOld(caches, str); AtomicInteger i = m.get(cache.getId()); if (i == null) { i = new AtomicInteger(0); m.put(cache.getId(), i); } i.incrementAndGet(); } time = System.currentTimeMillis() - time; LOGGER.warn(String.format("time: %d", time)); for (String id : m.keySet()) { LOGGER.warn(String.format("cache(%s): %d", id, m.get(id).get())); } if (cache != null) { try { return new URL(ds.createURIString(request, cache)); } catch (final MalformedURLException e) { LOGGER.error(e.getMessage(), e); throw new TrafficRouterException(URL_ERR_STR, e); } } } LOGGER.info(UNABLE_TO_ROUTE_REQUEST); throw new TrafficRouterException(UNABLE_TO_ROUTE_REQUEST); }