Package org.ametys.core.util
Class HttpUrlUtils
- java.lang.Object
-
- org.ametys.core.util.HttpUrlUtils
-
- All Implemented Interfaces:
Component
public class HttpUrlUtils extends Object implements Component
Utility class for HTTP urls.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpUrlUtils.HttpCheck
The status of HTTP check
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
__logger
static Pattern
HTTP_URL_VALIDATOR
Regexp for HTTP urlstatic String
ROLE
The Avalon role
-
Constructor Summary
Constructors Constructor Description HttpUrlUtils()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static HttpUrlUtils.HttpCheck
_checkHttpUrl(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders, List<String> visitedUrl, int maxRedirects)
Map<String,Object>
checkHttpUrl(String httpUrl)
Method to check a HTTP url from client side.static HttpUrlUtils.HttpCheck
checkHttpUrl(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects)
Check the HTTP urlstatic HttpUrlUtils.HttpCheck
checkHttpUrl(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Check the HTTP urlstatic HttpUrlUtils.HttpCheck
checkHttpUrl(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Check the HTTP urlstatic HttpURLConnection
prepareConnection(String url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects)
Prepare the connection to the remote urlstatic HttpURLConnection
prepareConnection(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Prepare the connection to the remote urlstatic HttpURLConnection
prepareConnection(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Prepare the connection to the remote url
-
-
-
Field Detail
-
HTTP_URL_VALIDATOR
public static final Pattern HTTP_URL_VALIDATOR
Regexp for HTTP url
-
__logger
private static org.slf4j.Logger __logger
-
-
Constructor Detail
-
HttpUrlUtils
public HttpUrlUtils()
-
-
Method Detail
-
prepareConnection
public static HttpURLConnection prepareConnection(String url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects) throws MalformedURLException, IOException
Prepare the connection to the remote url- Parameters:
url
- The urluserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirects- Returns:
- The URL connection
- Throws:
MalformedURLException
- If the given url is a malformed URLIOException
- if an I/O exception occurs
-
prepareConnection
public static HttpURLConnection prepareConnection(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders) throws MalformedURLException, IOException
Prepare the connection to the remote url- Parameters:
httpUrl
- The HTTP urluserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirectsrequestHeaders
- The request headers.- Returns:
- The URL connection
- Throws:
MalformedURLException
- If the given url is a malformed URLIOException
- if an I/O exception occurs
-
prepareConnection
public static HttpURLConnection prepareConnection(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders) throws MalformedURLException, IOException
Prepare the connection to the remote url- Parameters:
url
- The urluserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirectsrequestHeaders
- The request headers.- Returns:
- The URL connection
- Throws:
MalformedURLException
- If the given url is a malformed URLIOException
- if an I/O exception occurs
-
checkHttpUrl
public static HttpUrlUtils.HttpCheck checkHttpUrl(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects)
Check the HTTP url- Parameters:
httpUrl
- The HTTP url to testuserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirects- Returns:
- The URL connection
-
checkHttpUrl
public static HttpUrlUtils.HttpCheck checkHttpUrl(String httpUrl, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Check the HTTP url- Parameters:
httpUrl
- The url to testuserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirectsrequestHeaders
- The request headers.- Returns:
- The URL connection
-
checkHttpUrl
public static HttpUrlUtils.HttpCheck checkHttpUrl(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders)
Check the HTTP url- Parameters:
url
- The url to testuserAgent
- The user agent. Can be null.method
- The method for teh URL request. Can be null.timeout
- The connection timeout in milliseconds. Set to -1 to not set a timeout.readTimeOut
- The read timeout in milliseconds. Set to -1 to not set a timeout.followRedirects
- Sets to true to follow HTTP redirectsrequestHeaders
- The request headers.- Returns:
- The URL connection
-
_checkHttpUrl
private static HttpUrlUtils.HttpCheck _checkHttpUrl(URL url, String userAgent, String method, int timeout, int readTimeOut, boolean followRedirects, Map<String,String> requestHeaders, List<String> visitedUrl, int maxRedirects)
-
checkHttpUrl
public Map<String,Object> checkHttpUrl(String httpUrl)
Method to check a HTTP url from client side. The HTTP redirects will be followed.- Parameters:
httpUrl
- the http url to check- Returns:
- the result of the check
-
-