List of usage examples for java.net MalformedURLException toString
public String toString()
From source file:org.sakaiproject.nakamura.grouper.changelog.HttpNakamuraManagerImpl.java
protected void setUrl(String urlString) { try {/*from ww w. j a v a 2 s .co m*/ url = new URL(urlString); } catch (MalformedURLException mfe) { log.error("Could not parse " + urlString + "into a URL."); throw new RuntimeException(mfe.toString()); } }
From source file:org.openhab.binding.unifi.internal.UnifiBinding.java
private void logout() { URL url = null;/*ww w . j a v a 2 s .c o m*/ if (cookies.size() == 0) return; try { url = new URL(getControllerUrl("api/logout")); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Cookie", cookies.get(0) + "; " + cookies.get(1)); connection.getInputStream(); } catch (MalformedURLException e) { logger.error("The URL '" + url + "' is malformed: " + e.toString()); } catch (Exception e) { logger.error("Cannot do logout. Exception: " + e.toString()); } }
From source file:org.powertac.server.CompetitionSetupService.java
@Override public String simSession(String bootData, String config, String jmsUrl, String logfileSuffix, List<String> brokerUsernames, String seedData, String weatherData, String inputQueueName) { String error = null;// w w w .j av a2s . co m try { log.info("simSession: bootData=" + bootData + ", config=" + config + ", jmsUrl=" + jmsUrl + ", seedData=" + seedData + ", weatherData=" + weatherData + ", inputQueue=" + inputQueueName); // process serverConfig now, because other options may override // parts of it serverProps.recycle(); setConfigMaybe(config); // Use weather file instead of webservice useWeatherDataMaybe(weatherData, false); // load random seeds if requested seedSource = seedData; // set the logfile suffix setLogSuffix(logfileSuffix, "sim-" + gameId); // jms setup if (jmsUrl != null) { serverProps.setProperty("server.jmsManagementService.jmsBrokerUrl", jmsUrl); } // boot data access URL bootUrl = null; if (controllerURL != null) { bootUrl = tss.getBootUrl(); } else if (bootData != null) { if (!bootData.contains(":")) bootData = "file:" + bootData; bootUrl = new URL(bootData); } if (null == bootUrl) { error = "bootstrap data source not given"; System.out.println(error); } else { log.info("bootUrl=" + bootUrl.toExternalForm()); startSimSession(brokerUsernames, inputQueueName, bootUrl); } } catch (MalformedURLException e) { // Note that this should not happen from the web interface error = "Malformed URL: " + e.toString(); System.out.println(error); } catch (IOException e) { error = "Error reading configuration " + config; } catch (ConfigurationException e) { error = "Error setting configuration " + config; } return error; }
From source file:org.kuali.mobility.bus.dao.BusDaoUMImpl.java
public void loadRoutes() { XStream xstream = new XStream(); xstream.processAnnotations(UMBusRouteReader.class); xstream.processAnnotations(UMBusRoute.class); xstream.processAnnotations(UMBusStop.class); xstream.processAnnotations(UMBusRoutePathReader.class); xstream.processAnnotations(UMBusRoutePathLatLong.class); xstream.processAnnotations(UMBusRoutePathInfo.class); xstream.addImplicitCollection(UMBusRouteReader.class, "routes"); xstream.addImplicitCollection(UMBusRoute.class, "stops"); xstream.addImplicitCollection(UMBusRoutePathReader.class, "paths"); UMBusRouteReader routeReader = null; try {/*from w w w . j a va 2 s . c om*/ routeReader = (UMBusRouteReader) xstream.fromXML(new URL(getBusRouteUrl())); } catch (MalformedURLException ex) { LOG.error(ex.toString()); } List<BusRoute> routes = new ArrayList<BusRoute>(); List<BusStop> stops = new ArrayList<BusStop>(); boolean hasRoutes = routeReader != null && CollectionUtils.isNotEmpty(routeReader.getRoutes()); if (hasRoutes) { for (UMBusRoute r : routeReader.getRoutes()) { BusRoute route = (BusRoute) getApplicationContext().getBean("busRoute"); route.setId(Long.parseLong(r.getId())); UMBusRoutePathReader pathReader = null; try { String fullUrl = getBusRoutePathUrl() + route.getId() + ".xml"; pathReader = (UMBusRoutePathReader) xstream.fromXML(new URL(fullUrl)); } catch (MalformedURLException ex) { LOG.error(ex.toString()); } catch (StreamException ex) { LOG.error(ex.toString()); } boolean hasPathReader = pathReader != null && (pathReader.getPaths() != null || pathReader.getInfo() != null); if (hasPathReader) { BusRoutePath routePath = (BusRoutePath) getApplicationContext().getBean("busRoutePath"); routePath.setId(pathReader.getInfo().getId()); routePath.setColor(pathReader.getInfo().getColor()); routePath.setTransparency(pathReader.getInfo().getTransparency()); routePath.setLineWidth(pathReader.getInfo().getLineWidth()); List<Double> points = new ArrayList<Double>(); for (UMBusRoutePathLatLong point : pathReader.getPaths()) { points.add(Double.parseDouble(point.getLatitude())); points.add(Double.parseDouble(point.getLongitude())); } routePath.setLatLongs(points); route.setPath(routePath); } route.setName(r.getName()); route.setColor(r.getColor()); LOG.debug("route color:" + route.getColor()); if (null == getBusStops()) { setBusStops(new ArrayList<BusStop>()); } if (r != null && r.getStops() != null) { for (UMBusStop s : r.getStops()) { BusStop stop = (BusStop) getApplicationContext().getBean("busStop"); //stop.setName(s.getName()); //LOG.debug("bus stop ROUTE name: " + r.getName() + ", stopname -" + s.getName() + ", stopname2 -" + s.getName2() + ", stopname3 - " + s.getName3()); //set busstopname loaded from xml stop.setName(getBusStopNameMapper().updateBusStopName(s.getName())); stop.setId(s.getName().hashCode()); stop.setLatitude(s.getLatitude()); stop.setLongitude(s.getLongitude()); List<ScheduledStop> schedule = new ArrayList<ScheduledStop>(); // TODO: Fix this to dynamically utilize the toacount // variable. // This is functional but potentially will break. if (s.getId1() != null) { LOG.debug("Looking up bus " + s.getId1()); Bus tBus = getBus(Long.parseLong(s.getId1())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); // scheduledStop.setTimeToArrival( (new Float( s.getToa1() ) ).intValue() ); // fix time as not rounding properly for float, changed to double scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa1()) / 60)); schedule.add(scheduledStop); } if (s.getId2() != null) { LOG.debug("Looking up bus " + s.getId2()); Bus tBus = getBus(Long.parseLong(s.getId2())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa2()) / 60)); schedule.add(scheduledStop); } if (s.getId3() != null) { LOG.debug("Looking up bus " + s.getId3()); Bus tBus = getBus(Long.parseLong(s.getId3())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa3()) / 60)); schedule.add(scheduledStop); } if (s.getId4() != null) { LOG.debug("Looking up bus " + s.getId4()); Bus tBus = getBus(Long.parseLong(s.getId4())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa4()) / 60)); schedule.add(scheduledStop); } if (s.getId5() != null) { LOG.debug("Looking up bus " + s.getId5()); Bus tBus = getBus(Long.parseLong(s.getId5())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa5()) / 60)); schedule.add(scheduledStop); } if (s.getId6() != null) { LOG.debug("Looking up bus " + s.getId6()); Bus tBus = getBus(Long.parseLong(s.getId6())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa6()) / 60)); schedule.add(scheduledStop); } if (s.getId7() != null) { LOG.debug("Looking up bus " + s.getId7()); Bus tBus = getBus(Long.parseLong(s.getId7())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa7()) / 60)); schedule.add(scheduledStop); } if (s.getId8() != null) { LOG.debug("Looking up bus " + s.getId8()); Bus tBus = getBus(Long.parseLong(s.getId8())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa8()) / 60)); schedule.add(scheduledStop); } if (s.getId9() != null) { LOG.debug("Looking up bus " + s.getId9()); Bus tBus = getBus(Long.parseLong(s.getId9())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa9()) / 60)); schedule.add(scheduledStop); } if (s.getId10() != null) { LOG.debug("Looking up bus " + s.getId10()); Bus tBus = getBus(Long.parseLong(s.getId10())); LOG.debug("Bus was " + (tBus == null ? "not " : "") + "found."); ScheduledStop scheduledStop = (ScheduledStop) getApplicationContext() .getBean("scheduledStop"); scheduledStop.setBus(tBus); scheduledStop.setBusStopRouteName(r.getName()); scheduledStop.setTimeToArrival(Math.round(new Double(s.getToa10()) / 60)); schedule.add(scheduledStop); } if (stops.contains(stop)) { LOG.debug("Bus stop already exists in the list for: " + stop.getName()); int i = stops.indexOf(stop); BusStop oldStop = stops.get(i); if (oldStop.getScheduledStop() == null) { oldStop.setScheduledStop(schedule); } else { oldStop.getScheduledStop().addAll(schedule); } stop = oldStop; } else { LOG.debug("Bus Stop is not found in master list for: " + stop.getName()); stop.setScheduledStop(schedule); stops.add(stop); } route.addStop(stop); } } if (route.getStops() == null || route.getStops().isEmpty()) { LOG.info("Route " + route.getName() + " has NO stops, so do NOT show it!!!"); } else { routes.add(route); } } } setBusRoutes(routes); setBusStops(stops); LOG.info((null == getBusRoutes() ? "Failed to load" : "Loaded " + getBusRoutes().size()) + " routes."); }
From source file:org.openhab.binding.unifi.internal.UnifiBinding.java
private String sendToController(String url, String urlParameters, String method) { try {/*from w ww . j a v a2 s .c om*/ synchronized (cookies) { byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); URL cookieUrl = new URL(url); HttpsURLConnection connection = (HttpsURLConnection) cookieUrl.openConnection(); connection.setInstanceFollowRedirects(true); connection.setRequestMethod(method); //for(String cookie : cookies) { connection.setRequestProperty("Cookie", cookies.get(0) + "; " + cookies.get(1)); //} if (urlParameters.length() > 0) { connection.setDoOutput(true); connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); connection.setUseCaches(false); try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { wr.write(postData); } } InputStream response = connection.getInputStream(); String line = readResponse(response); if (!checkResponse(line)) { logger.error("Unifi response: " + line); } return line; } } catch (MalformedURLException e) { logger.error("The URL '" + url + "' is malformed: " + e.toString()); } catch (Exception e) { logger.error("Cannot send data " + urlParameters + " to url " + url + ". Exception: " + e.toString()); } return ""; }
From source file:org.openhab.binding.unifi.internal.UnifiBinding.java
private boolean login() { String url = null;/*from ww w .j a va2 s . c o m*/ try { url = getControllerUrl("api/login"); String urlParameters = "{'username':'" + username + "','password':'" + password + "'}"; byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); URL cookieUrl = new URL(url); HttpsURLConnection connection = (HttpsURLConnection) cookieUrl.openConnection(); connection.setDoOutput(true); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Referer", getControllerUrl("login")); connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); connection.setUseCaches(false); try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { wr.write(postData); } //get cookie cookies.clear(); String headerName; for (int i = 1; (headerName = connection.getHeaderFieldKey(i)) != null; i++) { if (headerName.equals("Set-Cookie")) { cookies.add(connection.getHeaderField(i)); } } InputStream response = connection.getInputStream(); String line = readResponse(response); logger.debug("Unifi response: " + line); return checkResponse(line); } catch (MalformedURLException e) { logger.error("The URL '" + url + "' is malformed: " + e.toString()); } catch (Exception e) { logger.error("Cannot get Ubiquiti Unifi login cookie: " + e.toString()); } return false; }
From source file:com.esri.gpt.catalog.arcgis.metadata.AGSInterrogator.java
/** * Makes a guess at the reverse proxy endpoint assoctated with an internal SOAP endpoint. * <br/>Sometimes the ArcGIS server REST API references internal SOAP endpoints that are * inaccessible outside the local area network. * <br/>this method simple replaces the host:port for a SOAP endpoint with the host:port * of the pre-determined REST endpoint//from w w w . j a v a 2 s.c o m * @param soapEndpoint the SOAP endpoint that failed * @return the modified endpoint */ private String guessReverseProxyUrl(String soapEndpoint) { try { URL urlRest = new URL(this.target.getRestUrl()); URL urlSoap = new URL(soapEndpoint); String reversed = urlRest.getProtocol() + "://" + urlRest.getHost(); if ((urlRest.getPort() != -1) && (urlRest.getPort() != 80)) { reversed += ":" + urlRest.getPort(); } if ((urlSoap.getPath() != null) && (urlSoap.getPath().length() > 0)) { reversed += urlSoap.getPath(); return reversed; } } catch (MalformedURLException e) { String msg = "Unable to guess ArcGIS services catalog soap url (try reverse proxy):"; msg += "\n restUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(this.target.getRestUrl())) + "\n soapUrl=" + StringEscapeUtils.escapeHtml4(Val.stripControls(soapEndpoint)); LOGGER.finer(msg + "\n" + e.toString()); } return null; }
From source file:at.spardat.xma.boot.transport.HTTPTransport.java
@Override public XMA_URI getRedirection(XMA_URI resource) { String resourceHostApp = resource.getHostApp(); String translated = redirectCache.get(resourceHostApp); if (translated != null) { String newUrl = resource.toString().replace(resourceHostApp, translated); try {/*from www .j a va2 s. co m*/ return new XMA_URI(newUrl); } catch (MalformedURLException e) { log_.info("Can't translate URL: " + newUrl + ": " + e.toString()); } } return null; }
From source file:org.openhab.binding.jablotron.internal.JablotronBinding.java
private void login() { String url = null;/*w w w . ja v a 2s. co m*/ try { //login stavA = 0; stavB = 0; stavABC = 0; stavPGX = 0; stavPGY = 0; url = JABLOTRON_URL + "ajax/login.php"; String urlParameters = "login=" + email + "&heslo=" + password + "&aStatus=200&loginType=Login"; byte[] postData = urlParameters.getBytes(StandardCharsets.UTF_8); URL cookieUrl = new URL(url); HttpsURLConnection connection = (HttpsURLConnection) cookieUrl.openConnection(); synchronized (session) { connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Referer", JABLOTRON_URL); connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); setConnectionDefaults(connection); try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) { wr.write(postData); } JablotronResponse response = new JablotronResponse(connection); if (response.getException() != null) { logger.error("JablotronResponse login exception: {}", response.getException()); return; } if (!response.isOKStatus()) return; //get cookie session = response.getCookie(); //cloud request url = JABLOTRON_URL + "ajax/widget-new.php?" + getBrowserTimestamp(); ; cookieUrl = new URL(url); connection = (HttpsURLConnection) cookieUrl.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Referer", JABLOTRON_URL + "cloud"); connection.setRequestProperty("Cookie", session); connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); setConnectionDefaults(connection); //line = readResponse(connection); response = new JablotronResponse(connection); if (response.getException() != null) { logger.error("JablotronResponse widget exception: {}", response.getException().toString()); return; } if (response.getResponseCode() != 200 || !response.isOKStatus()) { return; } if (response.getWidgetsCount() == 0) { logger.error("Cannot found any jablotron device"); return; } service = response.getServiceId(0); //service request url = response.getServiceUrl(0); if (!services.contains(service)) { services.add(service); logger.info("Found Jablotron service: {} id: {}", response.getServiceName(0), service); } cookieUrl = new URL(url); connection = (HttpsURLConnection) cookieUrl.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Referer", JABLOTRON_URL); connection.setRequestProperty("Cookie", session); connection.setRequestProperty("Upgrade-Insecure-Requests", "1"); setConnectionDefaults(connection); if (connection.getResponseCode() == 200) { logger.debug("Successfully logged to Jablotron cloud!"); } else { logger.error("Cannot log in to Jablotron cloud!"); } } } catch (MalformedURLException e) { logger.error("The URL '{}' is malformed: {}", url, e.toString()); } catch (Exception e) { logger.error("Cannot get Jablotron login cookie: {}", e.toString()); } }
From source file:com.alvermont.javascript.tools.shell.ShellMain.java
/** * Read file or url specified by <tt>path</tt>. * @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if * <tt>convertToString</tt> is true. *///from ww w .j a v a 2 s.co m private static Object readFileOrUrl(String path, boolean convertToString) { URL url = null; // Assume path is URL if it contains dot and there are at least // 2 characters in the protocol part. The later allows under Windows // to interpret paths with driver letter as file, not URL. if (path.indexOf(':') >= 2) { try { url = new URL(path); } catch (MalformedURLException ex) { log.debug("MalformedURLException in readFileOrUrl", ex); } } InputStream is = null; int capacityHint = 0; if (url == null) { final File file = new File(path); capacityHint = (int) file.length(); try { is = new FileInputStream(file); } catch (IOException ex) { Context.reportError(ToolErrorReporter.getMessage("msg.couldnt.open", path)); return null; } } else { try { final URLConnection uc = url.openConnection(); is = uc.getInputStream(); capacityHint = uc.getContentLength(); // Ignore insane values for Content-Length if (capacityHint > (1 << 20)) { capacityHint = -1; } } catch (IOException ex) { Context.reportError( ToolErrorReporter.getMessage("msg.couldnt.open.url", url.toString(), ex.toString())); return null; } } if (capacityHint <= 0) { capacityHint = 4096; } byte[] data; try { try { data = Kit.readStream(is, capacityHint); } finally { is.close(); } } catch (IOException ex) { Context.reportError(ex.toString()); return null; } Object result; if (!convertToString) { result = data; } else { // Convert to String using the default encoding // XXX: Use 'charset=' argument of Content-Type if URL? result = new String(data); } return result; }