List of usage examples for java.net URL getHost
public String getHost()
From source file:org.talend.components.dataprep.connection.DataPrepConnectionHandler.java
private String fetchDataSetId() throws IOException { if (dataSetName == null || authorisationHeader == null) { return null; }//from ww w.jav a2s . c o m String result = null; URI uri = null; URL localUrl = new URL(url); try { uri = new URI(localUrl.getProtocol(), null, localUrl.getHost(), localUrl.getPort(), "/api/datasets", "name=" + dataSetName, null); } catch (URISyntaxException e) { throw new ComponentException(e); } Request request = Request.Get(uri); request.addHeader(authorisationHeader); HttpResponse response = request.execute().returnResponse(); String content = extractResponseInformationAndConsumeResponse(response); if (returnStatusCode(response) != HttpServletResponse.SC_OK) { throw new IOException(content); } if (content != null && !"".equals(content)) { Object object = JsonReader.jsonToJava(content); if (object != null && object instanceof Object[]) { Object[] array = (Object[]) object; if (array.length > 0) { @SuppressWarnings("rawtypes") JsonObject jo = (JsonObject) array[0]; result = (String) jo.get("id"); } } } return result; }
From source file:com.connectsdk.core.upnp.Device.java
public Device(String url, String searchTarget) throws IOException { URL urlObject = new URL(url); if (urlObject.getPort() == -1) { baseURL = String.format("%s://%s", urlObject.getProtocol(), urlObject.getHost()); } else {/* w w w .j a v a 2 s . c om*/ baseURL = String.format("%s://%s:%d", urlObject.getProtocol(), urlObject.getHost(), urlObject.getPort()); } ipAddress = urlObject.getHost(); port = urlObject.getPort(); this.searchTarget = searchTarget; UUID = null; if (searchTarget.equalsIgnoreCase("urn:dial-multiscreen-org:service:dial:1")) applicationURL = getApplicationURL(url); }
From source file:com.google.acre.script.NHttpAsyncUrlfetch.java
public NHttpAsyncUrlfetch() { _costCollector = CostCollector.getInstance(); _nhttp = new NHttpClient(Configuration.Values.ACRE_MAX_ASYNC_CONNECTIONS.getInteger()); String proxy_host = Configuration.Values.HTTP_PROXY_HOST.getValue(); int proxy_port = 0; if (!(proxy_host.length() == 0)) { proxy_port = Configuration.Values.HTTP_PROXY_PORT.getInteger(); NHttpClient.NHttpProxyHost proxy = new NHttpClient.NHttpProxyHost(proxy_host, proxy_port) { public boolean use_proxy(String surl) { String ACRE_METAWEB_API_ADDR = Configuration.Values.ACRE_METAWEB_API_ADDR.getValue(); String ACRE_FREEBASE_SITE_ADDR = Configuration.Values.ACRE_FREEBASE_SITE_ADDR.getValue(); try { URL url = new URL(surl); String host = url.getHost(); return !(ACRE_METAWEB_API_ADDR.equals(host) || ACRE_FREEBASE_SITE_ADDR.equals(host)); } catch (MalformedURLException e) { // if the url parsing threw, it's safer to consider it // an external URL and let the proxy do the guarding job return true; }//ww w . j a va2 s . c o m } }; _nhttp.proxy(proxy); } }
From source file:org.fao.geonet.utils.AbstractHttpRequest.java
public void setUrl(URL url) { host = url.getHost(); port = url.getPort();//from w w w.j av a 2 s . com protocol = url.getProtocol(); address = url.getPath(); query = url.getQuery(); }
From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
/** * Parsing an URL from the descriptionXML file * @param url the string representation fo the URL * @param baseURL the base device URL, needed if the url param is relative * @return an URL object defining the url param * @throws MalformedURLException if the url param or baseURL.toExternalForm() + url * cannot be parsed to create an URL object */// w w w . j a v a 2s .co m public final static URL getURL(String url, URL baseURL) throws MalformedURLException { URL rtrVal; if (url == null || url.trim().length() == 0) return null; try { rtrVal = new URL(url); } catch (MalformedURLException malEx) { // maybe that the url is relative, we add the baseURL and reparse it // if relative then we take the device baser url root and add the url if (baseURL != null) { url = url.replace('\\', '/'); if (url.charAt(0) != '/') { // the path is relative to the device baseURL String externalForm = baseURL.toExternalForm(); if (!externalForm.endsWith("/")) { externalForm += "/"; } rtrVal = new URL(externalForm + url); } else { // the path is not relative String URLRoot = baseURL.getProtocol() + "://" + baseURL.getHost() + ":" + baseURL.getPort(); rtrVal = new URL(URLRoot + url); } } else { throw malEx; } } return rtrVal; }
From source file:org.artifactory.util.HttpClientConfigurator.java
/** * May throw a runtime exception when the given URL is invalid. *//*from w ww . j av a 2 s .c o m*/ public HttpClientConfigurator hostFromUrl(String urlStr) { if (StringUtils.isNotBlank(urlStr)) { try { URL url = new URL(urlStr); host(url.getHost()); } catch (MalformedURLException e) { throw new IllegalArgumentException("Cannot parse the url " + urlStr, e); } } return this; }
From source file:org.aludratest.service.gui.web.selenium.httpproxy.AuthenticatingHttpProxy.java
public String mapTargetToProxyUrl(String requestedUrlString) { try {//w w w . java 2 s . co m URL requestedUrl = new URL(requestedUrlString); int requestedPort = requestedUrl.getPort(); if (requestedPort == -1) { requestedPort = 80; // NOSONAR } if (requestedUrl.getHost().equals(realHost.getHostName()) && requestedPort == realHost.getPort()) { URL proxyUrl = new URL(requestedUrl.getProtocol(), localHost, localPort, requestedUrl.getFile()); return proxyUrl.toString(); } else { return requestedUrlString; } } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:io.selendroid.server.grid.SelfRegisteringRemote.java
/** * Extracts the configuration./*w ww. j a v a2s . co 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("maxInstances", 5); // adding hub details URL registrationUrl; try { registrationUrl = new URL(config.getRegistrationUrl()); } catch (MalformedURLException e) { e.printStackTrace(); 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("remoteHost", "http://" + config.getServerHost() + ":" + config.getPort()); return configuration; }
From source file:ed.net.CookieJar.java
/** * Return <tt>true</tt> if the cookie should be submitted with a request * with given attributes, <tt>false</tt> otherwise. * @param destination the destination of the request * @param cookie {@link Cookie} to be matched * @return true if the cookie matches the criterium *///from w w w. j a v a 2 s . c o m private boolean match(URL destination, final Cookie cookie) { String host = destination.getHost(); int port = destination.getPort(); String path = destination.getPath(); boolean secure = "https".equals(destination.getProtocol()); if (host == null) { throw new IllegalArgumentException("Host of origin may not be null"); } if (host.trim().equals("")) { throw new IllegalArgumentException("Host of origin may not be blank"); } if (port < 0) { port = 80; } if (path == null) { throw new IllegalArgumentException("Path of origin may not be null."); } if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null"); } if (path.trim().equals("")) { path = "/"; } host = host.toLowerCase(); if (cookie.getDomain() == null) { return false; } if (cookie.getPath() == null) { return false; } return // only add the cookie if it hasn't yet expired !isExpired(cookie) // and the domain pattern matches && (domainMatch(host, cookie.getDomain())) // and the path is null or matching && (pathMatch(path, cookie.getPath())) // and if the secure flag is set, only if the request is // actually secure && (cookie.getSecure() ? secure : true); }