当前位置: 首页>>代码示例>>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;未经允许,请勿转载。