URL getPort - 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 getPort method.

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:getPath, getPort, getQuery
   * Shuffle specific utils - build string for encoding from URL 
   * @param url 
   * @return string for encoding 
   */ 
  public static String buildMsgFrom(URL url) {
    return buildMsgFrom(url.getPath(), url.getQuery(), url.getPort());
  } 
  /** 
   * Shuffle specific utils - build string for encoding from URL 
   * @param request 
   * @return string for encoding 
   */ 
  public static String buildMsgFrom(HttpServletRequest request ) {
    return buildMsgFrom(request.getRequestURI(), request.getQueryString(),
        request.getLocalPort());
  } 
  /** 
   * Shuffle specific utils - build string for encoding from URL 
   * @param uri_path 
   * @param uri_query 
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:getDefaultPort, getHost, getPath, getPort, getProtocol
	 *            the url to copy the contents from 
	 * @throws MalformedURLException 
	 *             if the URL is malformed 
	 */ 
	public synchronized void setURL(URL url) throws MalformedURLException {
		_protocol = url.getProtocol();
		_host = url.getHost();
		int port = url.getPort();
		if (port == -1 || port == url.getDefaultPort()) {
			_port = null;
		} 
		else { 
			_port = Integer.valueOf(port);
		} 
		_path = url.getPath();
		_ref = url.getRef();
		setQueryParameters(url.getQuery());
	} 
 
	/** 

7
CodeRank
This code example shows how to use the following methods:getHost, getPort, toURI
		Random random = new Random();
 
		int a = random.nextInt(50);
		int b = random.nextInt(50);
 
		final URL url = new URL(
			_url, "/api/jsonws/test.testweb/sum/a/" + a + "/b/" + b);
 
		credentialsProvider.setCredentials(
			new AuthScope(url.getHost(), url.getPort()),
			new UsernamePasswordCredentials("test@liferay.com", "test"));
 
		httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
 
		CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
 
		HttpGet httpGet = new HttpGet(url.toURI());
 
		CloseableHttpResponse closeableHttpResponse =
			closeableHttpClient.execute(httpGet);

7
CodeRank

Related URL getPort Questions & Answers:

getPort Method Overview
Gets the port number of this URL.
See Code Examples for other Java 8 URL Methods: