Java Code Examples for java.net.URL#getDefaultPort()

The following examples show how to use java.net.URL#getDefaultPort() . These examples are extracted from open source projects. 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
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 2
/**
 * 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 3
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 4
/**
 * 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 5
/**
 * 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 6
Source Project: Bytecoder   File: URLUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 Project: hottub   File: URLUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 Project: jdk8u-jdk   File: URLUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 9
/**
 * 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 10
/**
 * 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
public int
getPort()
{
	URL	url = connection.getGenericService().getDevice().getRootDevice().getLocation();
	
	int	port = url.getPort();
	
	if ( port == -1 ){
		
		port = url.getDefaultPort();
	}
	
	return( port );
}
 
Example 12
Source Project: galaxy-sdk-java   File: TalosHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: openjdk-8   File: URLUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
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 15
static String connectRequestURI(URL url) {
    String host = url.getHost();
    int port = url.getPort();
    port = port != -1 ? port : url.getDefaultPort();

    return host + ":" + port;
}
 
Example 16
/**
 * 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
/**
 * 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 18
/**
 * 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 19
Source Project: jdk8u-jdk   File: URLUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
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 );
	}
}