本文整理汇总了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();
}
示例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;
}
示例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(";"));
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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();
}
}
示例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 "";
}