URL getHost - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for URL getHost method.

This code example shows how to use the following methods:getHost
     
    private static final Logger log = Logger.getLogger(RolloutPlanTestServlet.class); 
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException { 
         
        URL requestURL = new URL(request.getRequestURL().toString());
        host = requestURL.getHost();
         
        String op = request.getParameter(OP_PARAM);
        if (OP_BIND.equals(op)) {
            bindPort = Integer.valueOf(request.getParameter(BIND_PORT_PARAM));
            bind(); 
        } else if (OP_UNBIND.equals(op))
            unbind(); 
         
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.print(String.valueOf(initDate.getTime()));
        out.close();
    } 
9
CodeRank
This code example shows how to use the following methods:getHost, getPort, getProtocol
        return !failed;
 
    } 
 
    public static String getBaseURL(URL url) throws MalformedURLException {
        return new URL(url.getProtocol(), url.getHost(), url.getPort(), "/").toString();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getFile, getHost, getPort, getProtocol
    } 
  } 
 
  static URL qualifyHost(URL url) {
    try { 
      InetAddress a = InetAddress.getByName(url.getHost());
      String qualHost = a.getCanonicalHostName();
      URL q = new URL(url.getProtocol(), qualHost, url.getPort(), url.getFile());
      return q;
    } catch (IOException io) {
      return url;
    } 
  } 
 
  static final String regexpSpecials = "[]()?*+|.!^-\\~@";
 
  public static String regexpEscape(String plain) {
    StringBuffer buf = new StringBuffer();
    char[] ch = plain.toCharArray();
    int csup = ch.length;
8
CodeRank
This code example shows how to use the following methods:getHost, getPort, getProtocol
 
        // deploy to virtual server 
        deployer.deploy("vsdeployment");
 
        // check the deployment is available on and only on virtual server 
        URL vURL = new URL(url.getProtocol(), virtualHost, url.getPort(), "/vsDeployment/index.html");
        String response = HttpRequest.get(vURL.toString(), 10, TimeUnit.SECONDS);
        assertTrue("Invalid response: " + response, response.indexOf("Virtual Server Deployment") >=0);
 
        URL dURL = new URL(url.getProtocol(), defaultHost, url.getPort(), "/vsDeployment/index.html");
        boolean failed = false;
        try { 
            response = HttpRequest.get(dURL.toString(), 10, TimeUnit.SECONDS);
        } catch (Exception e) {
            failed = true;
        } 
        assertTrue("Deployment also on default server. " , failed);
 
        // undeploy form virtual server 
        deployer.undeploy("vsdeployment");

8
CodeRank
This code example shows how to use the following methods:getHost, getPort, getProtocol
            cli = null;
        } 
    } 
 
    protected final String getBaseURL(URL url) throws MalformedURLException {
        return new URL(url.getProtocol(), url.getHost(), url.getPort(), "/").toString();
    } 
 
    protected boolean checkUndeployed(String spec) {
        try { 
            final long firstTry = System.currentTimeMillis();
            HttpRequest.get(spec, 10, TimeUnit.SECONDS);
            while (System.currentTimeMillis() - firstTry <= 1000) {
                try { 
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    break; 
                } finally { 
                    HttpRequest.get(spec, 10, TimeUnit.SECONDS);
                } 
8
CodeRank
This code example shows how to use the following methods:getFile, getHost, getPort, getProtocol
    assertEquals(selenium.getTitle(), "Welcome"); 
  } 
 
  private String getUrl() throws MalformedURLException {
    AppServer appServer = GlobalTestEnvironment.get().getAppServer();
    URL url = new URL(appServer.whereIs("/selenium-server/tests/html/basicAuth/index.html"));
 
    return String.format("%s://alice:foo@%s:%d%s",
        url.getProtocol(), url.getHost(), url.getPort(), url.getFile());
  } 
} 
8
CodeRank
This code example shows how to use the following methods:getFile, getHost, getPort, getProtocol
                if (url == null) {
                    // The catalogPath does not exist, but construct a feasible 
                    // URL so that the error message makes sense. 
                    url = servletContext.getResource("/");
                    url = new URL(
                        url.getProtocol(),
                        url.getHost(),
                        url.getPort(),
                        url.getFile() + catalogPath.substring(1));
                } 
                catalogPath = url.toString();
            } catch (MalformedURLException ignored) {
            } 
        } 
        return catalogPath;
    } 
} 
 
// End ServletContextCatalogLocator.java 
8
CodeRank
This code example shows how to use the following methods:getHost, getPort
    } 
 
    @Test 
    @RunAsClient 
    public void testServletCall(@ArquillianResource @OperateOnDeployment("test") URL baseUrl) throws Exception {
        String url = "http://" + baseUrl.getHost() + ":" + baseUrl.getPort() + "/ejbinwar/servlet?archive=jar";
        log.info(url);
        String res = HttpRequest.get(url, 2, TimeUnit.SECONDS);
        Assert.assertEquals(JAR_SUCCESS_STRING, res);
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getAuthority, getFile, getHost, getPath, getProtocol
      return null; 
    } 
 
    if (lastUrlStr == null || !urlStr.equals(lastUrlStr)) {
      try { 
        url = new URL(urlStr);
      } catch (Exception e) {
        return null; 
      } 
    } 
    lastUrlStr = urlStr;
 
    if (partToExtract.equals("HOST")) {
      return url.getHost();
    } 
    if (partToExtract.equals("PATH")) {
      return url.getPath();
    } 
    if (partToExtract.equals("QUERY")) {
      return url.getQuery();

8
CodeRank
This code example shows how to use the following methods:getHost
 */ 
public class HostUtils { 
 
	public static boolean canResolv(String urlString) throws MalformedURLException {
		try { 
			URL url = new URL(urlString);
			String host = url.getHost();
			return InetAddress.getByName(host) != null;
		} catch (UnknownHostException e) {
			return false; 
		} 
	} 
 
} 
8
CodeRank

Related URL getHost Questions & Answers:

getHost Method Overview
Gets the host name of this URL, if applicable.
See Code Examples for other Java 8 URL Methods: