public class UriUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UriUtils.HttpMethod |
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
URI_IS_NOT_ABSOLUTE |
Constructor and Description |
---|
UriUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkServiceAvailable(java.lang.String host,
int port) |
static java.net.URI |
createUri(java.net.URL baseUrl,
java.lang.String subPath,
java.util.List<org.apache.http.NameValuePair> qparams,
java.lang.String fragment)
Creates a
URI based on the baseUrl and the given subPath, qParams and fragment |
static java.net.URL |
fileToURL(java.io.File file) |
static java.io.InputStream |
getContent(org.apache.http.HttpResponse response)
Retrieves the content of an
HttpResponse as an InputStream |
static java.io.InputStream |
getInputStream(java.net.URI uri)
|
static java.io.InputStream |
getInputStream(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> requestHeaders)
Retrieves an
input stream of the resource located at the given uri. |
static org.apache.http.HttpResponse |
getPostResponse(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> requestHeaders,
org.apache.http.HttpEntity entity)
Sends a HTTP POST request to the defined URI and returns the
HttpResponse . |
static long |
getResourceLength(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> requestHeaders)
Retrieves the size of the resource defined by the given uri in bytes
|
static org.apache.http.HttpResponse |
getResponse(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> requestHeaders)
Sends a HTTP GET request to the defined URI and returns the
HttpResponse . |
static org.apache.http.HttpResponse |
getResponseByType(java.net.URI uri,
java.util.Map<java.lang.String,java.lang.String> requestHeaders,
UriUtils.HttpMethod httpMethod,
org.apache.http.HttpEntity entity)
Sends a HTTP request of the given
UriUtils.HttpMethod to the defined URI and returns the HttpResponse . |
static java.lang.String |
getStatus(org.apache.http.HttpResponse response)
Gets the status of the given
HttpResponse as a string |
static boolean |
isInternetAvailable(java.net.URI firstUriToTest)
Tests internet connectivity by testing HEAD request for 4 known URL's.
If non of them is available false is returned. |
static boolean |
isOk(org.apache.http.HttpResponse response)
Checks if the given HTTP return status is OK
|
static boolean |
isRootServerAvailable(java.lang.String hostNameToResolve)
Tests reachability of a root server by trying to resolve a host name.
|
static boolean |
isServiceAvailable(java.net.URI serviceUri)
Performs HEAD request for the given URI.
If any exception occurs false is returned. |
static boolean |
isServiceAvailable(java.net.URI serviceUri,
java.lang.Integer timeout)
Performs HEAD request for the given URI.
If any exception occurs false is returned. |
static java.io.File |
urlToFile(java.net.URL url) |
protected static final java.lang.String URI_IS_NOT_ABSOLUTE
public static java.io.InputStream getInputStream(java.net.URI uri) throws java.io.IOException, org.apache.http.HttpException
uri
- java.io.IOException
org.apache.http.HttpException
public static java.io.InputStream getInputStream(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> requestHeaders) throws java.io.IOException, org.apache.http.HttpException
input stream
of the resource located at the given uri.uri
- java.io.IOException
org.apache.http.HttpException
public static long getResourceLength(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> requestHeaders) throws org.apache.http.client.ClientProtocolException, java.io.IOException, org.apache.http.HttpException
uri
- the resourcerequestHeaders
- additional headers. May be null
org.apache.http.client.ClientProtocolException
java.io.IOException
org.apache.http.HttpException
public static boolean isOk(org.apache.http.HttpResponse response)
response
- the HttpResponse
to checktrue
if response is OK, false
otherwisepublic static java.io.InputStream getContent(org.apache.http.HttpResponse response) throws java.io.IOException
HttpResponse
as an InputStream
response
- the HTTPResponse to retrieve the content fromjava.io.IOException
public static java.lang.String getStatus(org.apache.http.HttpResponse response)
HttpResponse
as a stringresponse
- the response to get the status forpublic static org.apache.http.HttpResponse getResponse(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> requestHeaders) throws org.apache.http.client.ClientProtocolException, java.io.IOException
HttpResponse
.uri
- the URI of this HTTP requestrequestHeaders
- the parameters (name-value pairs) of the connection added to the header of the requestHttpResponse
of the requestjava.io.IOException
org.apache.http.client.ClientProtocolException
public static org.apache.http.HttpResponse getPostResponse(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> requestHeaders, org.apache.http.HttpEntity entity) throws org.apache.http.client.ClientProtocolException, java.io.IOException
HttpResponse
.uri
- the URI of this HTTP requestrequestHeaders
- the parameters (name-value pairs) of the connection added to the header of the requestentity
- the HttpEntity
attached to a HTTP POST requestHttpResponse
of the requestjava.io.IOException
org.apache.http.client.ClientProtocolException
public static org.apache.http.HttpResponse getResponseByType(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> requestHeaders, UriUtils.HttpMethod httpMethod, org.apache.http.HttpEntity entity) throws java.io.IOException, org.apache.http.client.ClientProtocolException
UriUtils.HttpMethod
to the defined URI and returns the HttpResponse
.uri
- the URI of this HTTP requestrequestHeaders
- the parameters (name-value pairs) of the connection added to the header of the requesthttpMethod
- defines if method is POST or GETentity
- the HttpEntity
attached to a HTTP POST requestHttpResponse
of the requestjava.io.IOException
org.apache.http.client.ClientProtocolException
public static java.net.URI createUri(java.net.URL baseUrl, java.lang.String subPath, java.util.List<org.apache.http.NameValuePair> qparams, java.lang.String fragment) throws java.net.URISyntaxException
URI
based on the baseUrl and the given subPath, qParams and fragmentsubPath
- the sub path of the URIqparams
- the parameters added as GET parameters to the URIfragment
- the fragment of the URIjava.net.URISyntaxException
public static boolean isInternetAvailable(java.net.URI firstUriToTest)
false
is returned. Otherwise true.firstUriToTest
- if not null
this URI is tested before testing the standard URLs.public static boolean isServiceAvailable(java.net.URI serviceUri)
false
is returned. Otherwise true. serviceUri
- the URI to test.public static boolean isServiceAvailable(java.net.URI serviceUri, java.lang.Integer timeout)
false
is returned. Otherwise true. serviceUri
- the URI to test.timeout
- the timeout of the request in millisecondspublic static boolean isRootServerAvailable(java.lang.String hostNameToResolve)
hostNameToResolve
- the host name to resolve. If null
a default host name is tested.public static java.net.URL fileToURL(java.io.File file)
public static java.io.File urlToFile(java.net.URL url)
public static boolean checkServiceAvailable(java.lang.String host, int port)
Copyright © 2007-2020 EDIT. All Rights Reserved.