當前位置: 首頁>>代碼示例>>Java>>正文


Java URL.getPort方法代碼示例

本文整理匯總了Java中java.net.URL.getPort方法的典型用法代碼示例。如果您正苦於以下問題:Java URL.getPort方法的具體用法?Java URL.getPort怎麽用?Java URL.getPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URL的用法示例。


在下文中一共展示了URL.getPort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: HttpsClient

import java.net.URL; //導入方法依賴的package包/類
/**
 *  Same as previous constructor except using a Proxy
 */
HttpsClient(SSLSocketFactory sf, URL url, Proxy proxy,
            int connectTimeout)
    throws IOException {
    PlatformLogger logger = HttpURLConnection.getHttpLogger();
    if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
         logger.finest("Creating new HttpsClient with url:" + url + " and proxy:" + proxy +
         " with connect timeout:" + connectTimeout);
    }
    this.proxy = proxy;
    setSSLSocketFactory(sf);
    this.proxyDisabled = true;

    this.host = url.getHost();
    this.url = url;
    port = url.getPort();
    if (port == -1) {
        port = getDefaultPort();
    }
    setConnectTimeout(connectTimeout);
    openServer();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:HttpsClient.java

示例2: getHostNameAndPort

import java.net.URL; //導入方法依賴的package包/類
public static String[] getHostNameAndPort(String hostName, int port, SessionId session) {
    String[] hostAndPort = new String[2];
    String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: \n";

    try {
        HttpHost host = new HttpHost(hostName, port);
        CloseableHttpClient client = HttpClients.createSystem();
        URL sessionURL = new URL("http://" + hostName + ":" + port + "/grid/api/testsession?session=" + session);
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
        HttpResponse response = client.execute(host, r);
        String url = extractUrlFromResponse(response);
        if (url != null) {
            URL myURL = new URL(url);
            if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                hostAndPort[0] = myURL.getHost();
                hostAndPort[1] = Integer.toString(myURL.getPort());
            }
        }
    } catch (Exception e) {
        Logger.getLogger(GridInfoExtractor.class.getName()).log(Level.SEVERE, null, errorMsg + e);
    }
    return hostAndPort;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:24,代碼來源:GridInfoExtractor.java

示例3: MiniFtp

import java.net.URL; //導入方法依賴的package包/類
/**
 * Initial MiniFtp by url string.
 *
 * @param urlStr
 * @throws Exception
 */
public MiniFtp(String urlStr) throws Exception {
    URL url = new URL(urlStr);

    /** Parse user info. */
    String userInfo = url.getUserInfo();
    if (userInfo != null && !"".equals(userInfo)) {
        String[] userInfoArray = userInfo.split(":");
        user = userInfoArray[0];
        password = userInfoArray[1];
    }

    /** Parse host and port. */
    commandPort = url.getPort();
    host = url.getHost();

    /** Parse file and type. */
    file = url.getPath();
    if (file.contains(";")) {
        type = file.substring(file.lastIndexOf(";") + 1).replace("type=", "");
        file = file.substring(0, file.lastIndexOf(";"));
    }
}
 
開發者ID:xyhuangjinfu,項目名稱:MiniDownloader,代碼行數:29,代碼來源:MiniFtp.java

示例4: resolveURI

import java.net.URL; //導入方法依賴的package包/類
/** Use xml:base attributes at feed and entry level to resolve relative links */
private String resolveURI(URL baseURI, Parent parent, String url) {
    url = (url.equals(".") || url.equals("./")) ? "" : url;
    if (isRelativeURI(url) && parent != null && parent instanceof Element) {
        Attribute baseAtt = ((Element)parent).getAttribute("base", Namespace.XML_NAMESPACE);
        String xmlBase = (baseAtt == null) ? "" : baseAtt.getValue();
        if (!isRelativeURI(xmlBase) && !xmlBase.endsWith("/")) {
            xmlBase = xmlBase.substring(0, xmlBase.lastIndexOf("/")+1);
        }
        return resolveURI(baseURI, parent.getParent(), xmlBase + url);
    } else if (isRelativeURI(url) && parent == null) {
        return baseURI + url;
    } else if (baseURI != null && url.startsWith("/")) {
        String hostURI = baseURI.getProtocol() + "://" + baseURI.getHost();
        if (baseURI.getPort() != baseURI.getDefaultPort()) {
            hostURI = hostURI + ":" + baseURI.getPort();
        }
        return hostURI + url;
    }
    return url;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:22,代碼來源:Atom10Parser.java

示例5: load

import java.net.URL; //導入方法依賴的package包/類
/**
 * Creates a new URL object that retrieves the content specified by the
 * given URL with credentials. Internally the content is pre-fetched with
 * the given credentials. The returned URL has a custom protocol handler
 * that simply returns the pre-fetched content.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return an URL with a custom protocol handler
 * @throws IOException
 *             if an I/O exception occurs.
 */
public static URL load(final URL url, final String username,
        final String password) throws IOException {

    final byte[] content = getUrlContent(url, username, password);

    final URLStreamHandler handler = new URLStreamHandler() {

        @Override
        protected URLConnection openConnection(URL u) throws IOException {
            return new URLConnection(url) {
                @Override
                public void connect() throws IOException {
                }

                @Override
                public InputStream getInputStream() throws IOException {
                    return new ByteArrayInputStream(content);
                }
            };
        }
    };
    return new URL(url.getProtocol(), url.getHost(), url.getPort(), url
            .getFile(), handler);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:39,代碼來源:BasicAuthLoader.java

示例6: setUp

import java.net.URL; //導入方法依賴的package包/類
@BeforeClass
public static void setUp() throws MalformedURLException {
    // set base URI and port number to use for all requests
    serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    username = System.getProperty("test.user");
    password = System.getProperty("test.pwd");

    if (username != null && password != null) {
        RestAssured.authentication = RestAssured.basic(username, password);
        RestAssured.useRelaxedHTTPSValidation();
    }
    RestAssured.defaultParser = Parser.JSON;

    if (StringUtils.isBlank(serverUrl)) {
        serverUrl = DEFAULT_PROTOCOL + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT;
    }
    headers.put(YamlToJsonConverterServlet.TCK_HEADER_SERVERURL, serverUrl);
    if (StringUtils.isNotBlank(username)) {
        headers.put(YamlToJsonConverterServlet.TCK_HEADER_USERNAME, username);
    }
    if (StringUtils.isNotBlank(password)) {
        headers.put(YamlToJsonConverterServlet.TCK_HEADER_PASSWORD, password);
    }
}
 
開發者ID:eclipse,項目名稱:microprofile-open-api,代碼行數:39,代碼來源:AppTestBase.java

示例7: calculateNonProxyUri

import java.net.URL; //導入方法依賴的package包/類
private static URI calculateNonProxyUri(HttpServletRequest request) throws MalformedURLException, URISyntaxException {
    URL url = new URL(request.getRequestURL().toString());
    String host = url.getHost();
    String scheme = url.getProtocol();
    int port = url.getPort();
    String userInfo = url.getUserInfo();
    return new URI(scheme, userInfo, host, port, urlPathHelper.getContextPath(request), null, null);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:9,代碼來源:NetworkService.java

示例8: getScaledImageURL

import java.net.URL; //導入方法依賴的package包/類
private static URL getScaledImageURL(URL url) {
    try {
        String scaledImagePath = getScaledImageName(url.getPath());
        return scaledImagePath == null ? null : new URL(url.getProtocol(),
                url.getHost(), url.getPort(), scaledImagePath);
    } catch (MalformedURLException e) {
        return null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:LWCToolkit.java

示例9: KeepAliveKey

import java.net.URL; //導入方法依賴的package包/類
/**
 * Constructor
 *
 * @param url the URL containing the protocol, host and port information
 */
public KeepAliveKey(URL url, Object obj) {
    this.protocol = url.getProtocol();
    this.host = url.getHost();
    this.port = url.getPort();
    this.obj = obj;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:KeepAliveCache.java

示例10: getOriginUrl

import java.net.URL; //導入方法依賴的package包/類
public String getOriginUrl(){
    String ou = "";
    if (mVisitVectorUrl == null){
        return ou;
    }
    try {
        ou =  mVisitVectorUrl.lastElement();
        URL url = new URL(ou);
        int port = url.getPort();
        ou=  url.getProtocol()+"://"+url.getHost()+(port==-1?"":":"+port);
    }catch (Exception e){
    }
    return ou;
}
 
開發者ID:yale8848,項目名稱:CacheWebView,代碼行數:15,代碼來源:CacheWebViewClient.java

示例11: getOriginAddress

import java.net.URL; //導入方法依賴的package包/類
public static String getOriginAddress(URL url) {
  int port = url.getPort();
  String result = url.getHost();
  if (port > 0 && port != getDefaultPort(url.getProtocol())) {
    result = result + ":" + port;
  }
  return result;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:9,代碼來源:HttpEngine.java

示例12: proxyUrlToJava

import java.net.URL; //導入方法依賴的package包/類
private static void proxyUrlToJava(String urlString, String prefix) {
	if (urlString == null || "".equals(urlString)) {
		return;
	}
	URL url = url(urlString);
	String host = url.getHost();
	int port = url.getPort();
	System.setProperty(prefix + ".proxyHost", host);
	if (port >= 0) {
		System.setProperty(prefix + ".proxyPort", Integer.toString(port));
	}
}
 
開發者ID:wipu,項目名稱:iwant-demo,代碼行數:13,代碼來源:Iwant.java

示例13: connectRequestURI

import java.net.URL; //導入方法依賴的package包/類
static String connectRequestURI(URL url) {
    String host = url.getHost();
    int port = url.getPort();
    port = port != -1 ? port : url.getDefaultPort();

    return host + ":" + port;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:HttpURLConnection.java

示例14: setup

import java.net.URL; //導入方法依賴的package包/類
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

}
 
開發者ID:eclipse,項目名稱:microprofile-metrics,代碼行數:29,代碼來源:ReusableMetricsTest.java

示例15: getAbsolutePath

import java.net.URL; //導入方法依賴的package包/類
/**
 * 根據網址和href相對路徑計算出絕對路徑
 *
 * @param url
 * @param href
 * @return
 */
public static String getAbsolutePath(String url, String href) {
    try {
        URL urlStr = new URL(url);
        String port = urlStr.getPort() == -1 ? "" : ":" + urlStr.getPort();
        String path = urlStr.getPath();

        if (StringUtils.isBlank(path) || !path.matches("^/.+/.+$") || href.matches("^/.+")) {// 根目錄
            return urlStr.getProtocol() + "://" + urlStr.getHost() + port + convertHref(href);
        }

        if (href.matches("^\\./.+") || href.matches("^(?!(/|./|../)).+")) {// 表示當前目錄
            path = path.substring(0, path.lastIndexOf("/"));
            return urlStr.getProtocol() + "://" + urlStr.getHost() + port + path + convertHref(href);
        }

        if (href.matches("^\\.\\./.+")) {// 表示當前上一級目錄
            int countHref = href.split("\\.\\./").length - 1;
            int countPath = path.split("/").length - 1;
            href = "/" + href.split("\\.\\./")[countHref];
            if (countPath <= countHref + 1) {
                return urlStr.getProtocol() + "://" + urlStr.getHost() + port + convertHref(href);
            }

            String[] strs = path.split("/");
            StringBuffer pathBuffer = new StringBuffer();
            for (int i = 0; i < countPath - countHref; i++) {
                if (StringUtils.isNotBlank(strs[i])) {
                    pathBuffer.append("/" + strs[i]);
                }
            }
            return urlStr.getProtocol() + "://" + urlStr.getHost() + port + pathBuffer + convertHref(href);
        }
    } catch (MalformedURLException e) {
        logger.error("獲取絕對路徑失敗,url={},href={},失敗原因:", url, href, e);
    }
    return "";
}
 
開發者ID:hexiaohong-code,項目名稱:LoginCrawler,代碼行數:45,代碼來源:LoginUtils.java


注:本文中的java.net.URL.getPort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。