public class UrlValidator
extends java.lang.Object
Constructor and Description |
---|
UrlValidator()
Constructs an instance using the default parameter values.
|
Modifier and Type | Method and Description |
---|---|
void |
setConnectTimeout(int connectTimeout)
Sets the connect timeout.
|
void |
setFollowRedirects(boolean followRedirects)
Sets whether to follow HTTP redirects, or return them as the
response.
|
void |
setReadTimeout(int readTimeout)
Sets the read timeout.
|
void |
setRequestMethod(java.lang.String requestMethod)
Sets the HTTP request method.
|
void |
setRequireFullyQualifiedHostNames(boolean requireFullyQualifiedHostNames)
Sets whether fully qualified host names are required in the URL.
|
int |
validate(java.lang.String urlString)
Attempts to validate the given URL by making an HTTP request.
|
public UrlValidator()
public void setRequestMethod(java.lang.String requestMethod)
requestMethod
- should be either "GET" or "HEAD"HttpURLConnection.setRequestMethod(java.lang.String)
public void setFollowRedirects(boolean followRedirects)
false
, which returns the
redirect as the HTTP response.followRedirects
- true
to follow HTTP
redirects, or false
to return them as the HTTP
responseHttpURLConnection.setInstanceFollowRedirects(boolean)
public void setRequireFullyQualifiedHostNames(boolean requireFullyQualifiedHostNames)
false
, which allows non-fully qualified
host names, even thought the GSA requires one in most cases.requireFullyQualifiedHostNames
- true
if host
names must be fully qualified, false
if notpublic void setConnectTimeout(int connectTimeout)
connectTimeout
- the connect timeout in millisecondsURLConnection.setConnectTimeout(int)
public void setReadTimeout(int readTimeout)
readTimeout
- the read timeout in millisecondsURLConnection.setReadTimeout(int)
public int validate(java.lang.String urlString) throws java.security.GeneralSecurityException, java.io.IOException, UrlValidatorException
The 405 (Method Not Allowed) is related because the Sun Java System Web Server, and possibly Apache, return this code rather than a 404 if you attempt to access a CGI program in an unknown directory.
When testing an HTTPS URL, we override server certificate validation to skip trying to verify the server's certificate, and we accept hostname mismatches. In this case, all we care about is that the configured URL can be reached; it's up to the connector administrator to enter the right URL.
urlString
- the URL to testjava.security.GeneralSecurityException
- if there is an error configuring
the HTTPS connectionjava.io.IOException
- if the URL is malformed, or if there is an
error connecting or reading the responseUrlValidatorException
- if the HTTP status code was invalid