List of usage examples for java.net URL getHost
public String getHost()
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URI newEncodedURI(String u) throws MalformedURLException, URISyntaxException { URL tmpUrl = new URL(u); return new URI(tmpUrl.getProtocol(), tmpUrl.getUserInfo(), tmpUrl.getHost(), tmpUrl.getPort(), tmpUrl.getPath(), tmpUrl.getQuery(), tmpUrl.getRef()); }
From source file:Urls.java
public static boolean hasHost(java.net.URL url) { String host = url.getHost(); return host != null && !"".equals(host); }
From source file:com.cloudera.sqoop.util.JdbcUrl.java
/** * @return the hostname from the connect string, or null if we can't. *//*from w ww .j a v a2s . c o m*/ public static String getHostName(String connectString) { try { String sanitizedString = null; int schemeEndOffset = connectString.indexOf("://"); if (-1 == schemeEndOffset) { // Couldn't find one? ok, then there's no problem, it should work as a // URL. sanitizedString = connectString; } else { sanitizedString = "http" + connectString.substring(schemeEndOffset); } URL connectUrl = new URL(sanitizedString); return connectUrl.getHost(); } catch (MalformedURLException mue) { LOG.error("Malformed connect string URL: " + connectString + "; reason is " + mue.toString()); return null; } }
From source file:it.govpay.web.console.utils.HttpClientUtils.java
public static HttpResponse getEsitoPagamento(String urlToInvoke, Logger log) throws Exception { HttpResponse responseGET = null;/* www .ja va2s .co m*/ try { log.debug("Richiesta Esito del pagamento in corso..."); URL urlObj = new URL(urlToInvoke); HttpHost target = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol()); CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build(); HttpGet richiestaPost = new HttpGet(); richiestaPost.setURI(urlObj.toURI()); log.debug("Invio tramite client Http in corso..."); responseGET = client.execute(target, richiestaPost); if (responseGET == null) throw new NullPointerException("La Response HTTP e' null"); log.debug("Invio tramite client Http completato."); return responseGET; } catch (Exception e) { log.error("Errore durante l'invio della richiesta di pagamento: " + e.getMessage(), e); throw e; } }
From source file:it.govpay.web.console.utils.HttpClientUtils.java
public static HttpResponse sendRichiestaPagamento(String urlToInvoke, RichiestaPagamento richiestaPagamento, Logger log) throws Exception { HttpResponse responseGET = null;/*from w w w. j a v a2 s. c om*/ try { log.debug("Invio del pagamento in corso..."); URL urlObj = new URL(urlToInvoke); HttpHost target = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol()); CloseableHttpClient client = HttpClientBuilder.create().disableRedirectHandling().build(); HttpPost richiestaPost = new HttpPost(); richiestaPost.setURI(urlObj.toURI()); log.debug("Serializzazione pagamento in corso..."); byte[] bufferPagamento = JaxbUtils.toBytes(richiestaPagamento); log.debug("Serializzazione pagamento completata."); HttpEntity bodyEntity = new InputStreamEntity(new ByteArrayInputStream(bufferPagamento), ContentType.APPLICATION_XML); richiestaPost.setEntity(bodyEntity); richiestaPost.setHeader("Content-Type", ContentType.APPLICATION_XML.getMimeType()); log.debug("Invio tramite client Http in corso..."); responseGET = client.execute(target, richiestaPost); if (responseGET == null) throw new NullPointerException("La Response HTTP e' null"); log.debug("Invio tramite client Http completato."); return responseGET; } catch (Exception e) { log.error("Errore durante l'invio della richiesta di pagamento: " + e.getMessage(), e); throw e; } }
From source file:com.shishu.utility.url.TableUtil.java
/** * Reverses a url's domain. This form is better for storing in hbase. Because * scans within the same domain are faster. * <p>/*from w w w. j av a2 s .co m*/ * E.g. "http://bar.foo.com:8983/to/index.html?a=b" becomes * "com.foo.bar:http:8983/to/index.html?a=b". * * @param url * url to be reversed * @return Reversed url */ public static String reverseUrl(URL url) { String host = url.getHost(); String file = url.getFile(); String protocol = url.getProtocol(); int port = url.getPort(); StringBuilder buf = new StringBuilder(); /* reverse host */ reverseAppendSplits(host, buf); /* add protocol */ buf.append(':'); buf.append(protocol); /* add port if necessary */ if (port != -1) { buf.append(':'); buf.append(port); } /* add path */ if (file.length() > 0 && '/' != file.charAt(0)) { buf.append('/'); } buf.append(file); return buf.toString(); }
From source file:HttpUtil.java
public static String getDomainName(String url) { URL u; try {/*from w w w .j a va 2s.c o m*/ u = new URL(url); } catch (Exception e) { return ""; } return u.getHost(); }
From source file:org.jboss.as.test.clustering.cluster.web.authentication.BasicAuthenticationWebFailoverTestCase.java
private static void setCredentials(CredentialsProvider provider, String user, String password, URL... urls) { for (URL url : urls) { provider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(user, password)); }/* w w w .j a va 2 s. co m*/ }
From source file:com.ibm.xsp.xflow.activiti.util.HttpClientUtil.java
public static String get(String url, Cookie[] cookies) { String body = null;// w ww . j a v a 2s.co m try { StringBuffer buffer = new StringBuffer(); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); httpClient.setCookieStore(new BasicCookieStore()); for (int i = 0; i < cookies.length; i++) { logger.finest("Cookie:" + cookies[i].getName() + ":" + cookies[i].getValue() + ":" + cookies[i].getDomain() + ":" + cookies[i].getPath()); BasicClientCookie cookie = new BasicClientCookie(cookies[i].getName(), cookies[i].getValue()); cookie.setVersion(0); URL urlParse = new URL(url); String host = urlParse.getHost(); String domain = null; if (host != null && host.indexOf('.') > 0) { domain = host.substring(host.indexOf('.') + 1); } logger.finest("Domain:" + domain); cookie.setDomain(domain); cookie.setPath("/"); httpClient.getCookieStore().addCookie(cookie); } HttpResponse response = httpClient.execute(getRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output; logger.finest("Output from Server .... \n"); while ((output = br.readLine()) != null) { logger.finest(output); buffer.append(output); } httpClient.getConnectionManager().shutdown(); body = buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return body; }
From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
private static InputStream action_NOT_NEEDED(URL url) throws IOException { HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); DefaultHttpClient httpclient = new DefaultHttpClient(connMgr, params); HttpGet req = new HttpGet(url.getPath()); log.info("executing request to " + target); HttpResponse rsp = httpclient.execute(target, req); HttpEntity entity = rsp.getEntity(); /*/*from w ww. j ava 2 s .c om*/ if (entity != null) { log.info(EntityUtils.toString(entity)); } */ return entity.getContent(); // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources //TODO: httpclient.getConnectionManager().shutdown(); }