Java Code Examples for java.net.URL#getDefaultPort()
The following examples show how to use
java.net.URL#getDefaultPort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpCallerInfo.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Constructor an un-schemed object for site access. */ public HttpCallerInfo(URL url) { this.url= url; prompt = ""; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } InetAddress ia; try { ia = InetAddress.getByName(url.getHost()); } catch (Exception e) { ia = null; } addr = ia; protocol = url.getProtocol(); authType = RequestorType.SERVER; scheme = ""; }
Example 2
Source File: AuthenticationInfo.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) { this.type = type; this.authScheme = authScheme; this.protocol = url.getProtocol().toLowerCase(); this.host = url.getHost().toLowerCase(); this.port = url.getPort(); if (this.port == -1) { this.port = url.getDefaultPort(); } this.realm = realm; String urlPath = url.getPath(); if (urlPath.length() == 0) this.path = urlPath; else { this.path = reducePath (urlPath); } }
Example 3
Source File: HttpCallerInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Constructor an un-schemed object for site access. */ public HttpCallerInfo(URL url, Authenticator a) { this.url= url; prompt = ""; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } InetAddress ia; try { ia = InetAddress.getByName(url.getHost()); } catch (Exception e) { ia = null; } addr = ia; protocol = url.getProtocol(); authType = RequestorType.SERVER; scheme = ""; authenticator = a; }
Example 4
Source File: HttpCallerInfo.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Constructor an un-schemed object for site access. */ public HttpCallerInfo(URL url) { this.url= url; prompt = ""; host = url.getHost(); int p = url.getPort(); if (p == -1) { port = url.getDefaultPort(); } else { port = p; } InetAddress ia; try { ia = InetAddress.getByName(url.getHost()); } catch (Exception e) { ia = null; } addr = ia; protocol = url.getProtocol(); authType = RequestorType.SERVER; scheme = ""; }
Example 5
Source File: AuthenticationInfo.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public AuthenticationInfo(char type, AuthScheme authScheme, URL url, String realm) { this.type = type; this.authScheme = authScheme; this.protocol = url.getProtocol().toLowerCase(); this.host = url.getHost().toLowerCase(); this.port = url.getPort(); if (this.port == -1) { this.port = url.getDefaultPort(); } this.realm = realm; String urlPath = url.getPath(); if (urlPath.length() == 0) this.path = urlPath; else { this.path = reducePath (urlPath); } }
Example 6
Source File: URLUtil.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 7
Source File: URLUtil.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 8
Source File: AuthenticationInfo.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Returns info for the URL, for an HTTP server auth. Used when we * don't yet know the realm * (i.e. when we're preemptively setting the auth). */ static AuthenticationInfo getServerAuth(URL url) { int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase() + ":" + url.getHost().toLowerCase() + ":" + port; return getAuth(key, url); }
Example 9
Source File: URLUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 10
Source File: URLUtil.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 11
Source File: HttpURLConnection.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static String connectRequestURI(URL url) { String host = url.getHost(); int port = url.getPort(); port = port != -1 ? port : url.getDefaultPort(); return host + ":" + port; }
Example 12
Source File: THttpClient.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public THttpClient(String url, HttpClient client) throws TTransportException { try { url_ = new URL(url); this.client = client; this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort() : url_.getPort(), url_.getProtocol()); } catch (IOException iox) { throw new TTransportException(iox); } }
Example 13
Source File: URLUtil.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 14
Source File: TalosHttpClient.java From galaxy-sdk-java with Apache License 2.0 | 5 votes |
public TalosHttpClient(String url, HttpClient client, Credential credential, AdjustableClock clock) throws TTransportException { try { url_ = new URL(url); this.client = client; this.host = new HttpHost(url_.getHost(), -1 == url_.getPort() ? url_.getDefaultPort() : url_.getPort(), url_.getProtocol()); this.credential = credential; this.clock = clock; } catch (IOException iox) { throw new TTransportException(iox); } }
Example 15
Source File: UPnPPluginService.java From TorrentEngine with GNU General Public License v3.0 | 5 votes |
public int getPort() { URL url = connection.getGenericService().getDevice().getRootDevice().getLocation(); int port = url.getPort(); if ( port == -1 ){ port = url.getDefaultPort(); } return( port ); }
Example 16
Source File: URLUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 17
Source File: AuthenticationInfo.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns info for the URL, for an HTTP server auth. Used when we * don't yet know the realm * (i.e. when we're preemptively setting the auth). */ static AuthenticationInfo getServerAuth(URL url) { int port = url.getPort(); if (port == -1) { port = url.getDefaultPort(); } String key = SERVER_AUTHENTICATION + ":" + url.getProtocol().toLowerCase() + ":" + url.getHost().toLowerCase() + ":" + port; return getAuth(key, url); }
Example 18
Source File: URLUtil.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 19
Source File: URLUtil.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns a string form of the url suitable for use as a key in HashMap/Sets. * * The string form should be behave in the same manner as the URL when * compared for equality in a HashMap/Set, except that no nameservice * lookup is done on the hostname (only string comparison), and the fragment * is not considered. * * @see java.net.URLStreamHandler.sameFile(java.net.URL) */ public static String urlNoFragString(URL url) { StringBuilder strForm = new StringBuilder(); String protocol = url.getProtocol(); if (protocol != null) { /* protocol is compared case-insensitive, so convert to lowercase */ protocol = protocol.toLowerCase(); strForm.append(protocol); strForm.append("://"); } String host = url.getHost(); if (host != null) { /* host is compared case-insensitive, so convert to lowercase */ host = host.toLowerCase(); strForm.append(host); int port = url.getPort(); if (port == -1) { /* if no port is specificed then use the protocols * default, if there is one */ port = url.getDefaultPort(); } if (port != -1) { strForm.append(":").append(port); } } String file = url.getFile(); if (file != null) { strForm.append(file); } return strForm.toString(); }
Example 20
Source File: TorrentUtils.java From BiglyBT with GNU General Public License v2.0 | 2 votes |
private static List<URL> applyAllDNSMods( URL url ) { List<URL> default_result = new ArrayList<>(1); default_result.add( url ); if ( DNS_HANDLING_ENABLE ){ DNSTXTEntry txt_entry = getDNSTXTEntry( url ); if ( txt_entry != null && txt_entry.hasRecords()){ boolean url_is_tcp = url.getProtocol().toLowerCase().startsWith( "http" ); int url_port = url.getPort(); if ( url_port == -1 ){ url_port = url.getDefaultPort(); } List<DNSTXTPortInfo> ports = txt_entry.getPorts(); if ( ports.size() == 0 ){ return( null ); // NULL here as no valid ports }else{ List<URL> result = new ArrayList<>(); for ( DNSTXTPortInfo port: ports ){ URL mod_url = url; int target_port = port.getPort(); if ( url_port != target_port ){ mod_url = UrlUtils.setPort( mod_url, target_port==mod_url.getDefaultPort()?0:target_port ); } if ( url_is_tcp != port.isTCP()){ mod_url = UrlUtils.setProtocol( mod_url, port.isTCP()?"http":"udp" ); } result.add( mod_url ); } return( result ); } }else{ return( default_result ); } }else{ return( default_result ); } }