List of usage examples for java.net URL getHost
public String getHost()
From source file:com.bleum.canton.loadpage.LoadPage.java
private void logIp(String urlStr, PrintWriter writer) { URL url; InetAddress address = null;/*from w w w . j a va 2s .co m*/ try { url = new URL(urlStr); String host = url.getHost(); address = InetAddress.getByName(host); String ip = address.getHostAddress(); LOGGER.info("Ip address of " + urlStr + " is: " + ip); writer.print(urlStr + CSV_SEPERATOR); writer.print(ip + CSV_SEPERATOR); } catch (UnknownHostException e) { // TODO Auto-generated catch block } catch (MalformedURLException e1) { // TODO Auto-generated catch block } }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.request.HTTPRequest.java
public void applyUrl(final URL url) { setPath(url.getPath());//from ww w . j av a 2 s . co m setQueryString(url.getQuery()); setHostname(url.getHost()); setRequestedUrl(url.toString()); }
From source file:com.jaeksoft.searchlib.web.controller.crawler.web.UrlFilterController.java
@Command @NotifyChange("testResult") public void onTest() throws SearchLibException, MalformedURLException { Client client = getClient();//from w ww. j a v a2 s . c om if (client == null) return; if (StringUtils.isEmpty(testUrl)) throw new SearchLibException("Please enter an URL."); testResult = null; URL u = new URL(testUrl); testResult = UrlFilterList.doReplace(u.getHost(), u.toString(), client.getUrlFilterList().getArray()); }
From source file:it.pronetics.madstore.crawler.publisher.impl.AtomPublisherImpl.java
private String getOrGenerateCollectionKey(Page page, Element feed) throws Exception { String key = feed.getAttribute(AtomConstants.ATOM_KEY); if (key == null || key.equals("")) { LOG.warn("No feed key found, generating surrogate key ..."); URL url = new URL(page.getLink().getLink()); String path = url.getHost(); if (path.startsWith("/")) { path = path.substring(1);/* w w w .j a v a 2 s.c o m*/ } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } key = path.replaceAll("\\.", "_").replaceAll("/", "-").replaceAll("\\:", "-").replaceAll("\\,", "-"); LOG.warn("Surrogated feed key: {}", key); } return key; }
From source file:org.hawkular.rx.commands.hawkular.CreateUrlCommand.java
protected String getDomainSorterUrl(String url) { //http://git.io/vRIHB try {/* w ww. j a v a 2s .co m*/ URL urlInstance = new URL(url); String[] levels = urlInstance.getHost().split("."); if (levels != null && levels.length > 1) { String[] levelsSorted = new String[levels.length]; //"a.b.redhat.com" will produce "redhat.com.a.b" Arrays.setAll(levelsSorted, i -> { switch (i) { case 0: case 1: String level = levels[levels.length - 1 - i]; //replace all the www's with a space so that they sort before any other name return "www".equals(level) ? " " : level; default: level = levels[i]; return "www".equals(level) ? " " : level; } }); return StringUtils.join(levelsSorted, "."); } return url; } catch (MalformedURLException e) { return url; } }
From source file:com.basetechnology.s0.agentserver.webaccessmanager.WebAccessManager.java
public WebSite getWebSite(String url) { String webSiteUrl = null;/*w w w . j a va 2s .c o m*/ 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:org.balloon_project.overflight.service.EndpointService.java
public Endpoint findOrigin(String url) { // TODO reimplement Endpoint result = null;/* w ww. j ava 2 s . com*/ try { URL concept = new URL(url); String urlString = concept.getHost() + concept.getPath(); // to find a suitable endpoint by the namespace, strip a "slash-fragment" e.g. http://dbpedia.org/resource/Indonesia --> http://dbpedia.org/resource // some endpoints have the same url prefix e.g. http://www4.wiwiss.fu-berlin.de/factbook/resource/ and http://www4.wiwiss.fu-berlin.de/dailymed/resource/ // endpoint namespaces can even be more abstract like http://enipedia.tudelft.nl and a concept is http://enipedia.tudelft.nl/wiki/Indonesia. // Hence, the stripping should be looped. // difficult e.g. http://openei.org/resources/Indonesia --> http://en.openei.org/ do { int lastIndexofSlash = urlString.lastIndexOf("/"); if (lastIndexofSlash != -1) { urlString = urlString.substring(0, lastIndexofSlash); // TODO find endpoint with suitable namespace --> build offline map of namespace to endpoint id // TODO cache endpoint id if namepsace was found //Query query = Query.query(Criteria.where("ns").regex(concept.getProtocol() + PROTOCOL_DIVIDER + urlString +".*","i")); //result = mongo.findOne(query, Endpoint.class, COLLECTION); } } while (result == null && urlString.lastIndexOf("/") != -1); // if no result was found, maybe the subdomain is wrong if (result == null) { urlString = concept.getHost() + concept.getPath(); do { int lastIndexofSlash = urlString.lastIndexOf("/"); if (lastIndexofSlash != -1) { urlString = urlString.substring(0, lastIndexofSlash); // TODO implement // Query query = Query.query(Criteria.where("ns").regex(concept.getProtocol() + PROTOCOL_DIVIDER + ".*" + urlString +".*","i")); // result = mongo.findOne(query, Endpoint.class, COLLECTION); } } while (result == null && urlString.lastIndexOf("/") != -1); } // TODO extend to query datahub.io } catch (MalformedURLException e) { return null; } if (result == null) { logger.debug("No endpoint found for URL=" + url); } else { logger.debug("Endpoints found for URL=" + url + " --> " + result.getEndpointID()); } return result; }
From source file:com.blackducksoftware.soleng.bdsplugin.ProtexConnector.java
public ApplicationPOJO populateApplicationWithProtexData(final ApplicationPOJO pojo, final SensorContext sensorContext) { try {/*from w w w.j ava2 s . c o m*/ pDAO.populateProjectInfo(pojo); // phone-home try { String protexHost = null; String protexServerVersion = null; try { final URL protexUrl = pDAO.getProtexServerUrl(); protexHost = protexUrl.getHost(); } catch (final Exception e) { log.debug("Could not get the Protex Host name."); } protexServerVersion = pDAO.getProtexServerVersion(); bdPhoneHome(protexHost, protexServerVersion); } catch (final Exception e) { log.debug("Unable to phone-home", e); } pDAO.populateProjectFileCounts(pojo, sensorContext); log.info("App information: " + pojo.toString()); } catch (final Exception e) { log.error("Unable to populate Protex data", e); pojo.setProtexErrorMsg(e.getMessage()); } catch (final Throwable t) { pojo.setProtexErrorMsg(t.getMessage()); log.error("Fatal Protex error: Unable to generate Protex information", t); } return pojo; }
From source file:com.mirth.connect.connectors.http.HttpConnectorServlet.java
@Override public ConnectionTestResponse testConnection(String channelId, String channelName, HttpDispatcherProperties properties) { try {// w ww. j a va 2 s. com URL url = new URL(replacer.replaceValues(properties.getHost(), channelId, channelName)); int port = url.getPort(); // If no port was provided, default to port 80 or 443. return ConnectorUtil.testConnection(url.getHost(), (port == -1) ? (StringUtils.equalsIgnoreCase(url.getProtocol(), "https") ? 443 : 80) : port, TIMEOUT); } catch (Exception e) { throw new MirthApiException(e); } }
From source file:com.apigee.sdk.apm.http.impl.client.cache.URIExtractor.java
public String canonicalizeUri(String uri) { try {/* w ww .j ava2s . co m*/ URL u = new URL(uri); String protocol = u.getProtocol().toLowerCase(); String hostname = u.getHost().toLowerCase(); int port = canonicalizePort(u.getPort(), protocol); String path = canonicalizePath(u.getPath()); if ("".equals(path)) path = "/"; String query = u.getQuery(); String file = (query != null) ? (path + "?" + query) : path; URL out = new URL(protocol, hostname, port, file); return out.toString(); } catch (MalformedURLException e) { return uri; } }