public class Connection extends Object
Modifier and Type | Field and Description |
---|---|
protected HttpURLConnection |
connection
The connection object for later streaming.
|
protected int |
connectionTimeout
Connection timeout in seconds.
|
protected int |
readTimeout
Reading timeout in seconds.
|
protected int |
redirectionCounter
The redirection what are already processed.
|
protected boolean |
redirectionEnabled
It enables HTTP and HTTPS redirection.
|
protected int |
redirectionLimit
The limit number.
|
protected ArrayList<Integer> |
statusHistory
The history of the redirection by status code.
|
protected ArrayList<String> |
urlHistory
The history of the redirection by URLs.
|
Constructor and Description |
---|
Connection() |
Modifier and Type | Method and Description |
---|---|
protected void |
addToHistory(HttpURLConnection connection)
It adds the current URL and response status to the property.
|
boolean |
connectWithEnabledRedirects(String stringUrl)
Connects to the host by URL.
|
boolean |
connectWithoutRedirects(String stringUrl)
Connects to the host by URL.
|
HttpURLConnection |
getConnection() |
ArrayList<Integer> |
getStatusHistory()
It retrieves the stored status codes from responses.
|
ArrayList<String> |
getUrlHistory()
It retrieves the stored urls from responses.
|
protected boolean |
isRedirectionLoop()
It retrieves that there are too many redirection or are not by the setted property.
|
protected boolean |
isRedirectionRequired(HttpURLConnection connection)
It checks that response header contains request for redirection.
|
protected boolean |
makeNewGetConnection(String stringUrl)
This method builds the connection and saves it to the property.
|
void |
setConnectionTimeout(int connectionTimeout) |
void |
setReadTimeout(int readTimeout) |
protected void |
setRedirectionEnabled(boolean redirectionEnabled)
It sets redirection in property to enabled or disabled.
|
void |
setRedirectionLimit(int redirectionLimit)
It sets the redirection limit to the property.
|
protected HttpURLConnection connection
protected ArrayList<Integer> statusHistory
protected ArrayList<String> urlHistory
protected boolean redirectionEnabled
protected int redirectionLimit
protected int redirectionCounter
protected int connectionTimeout
protected int readTimeout
public void setRedirectionLimit(int redirectionLimit)
redirectionLimit
- The limit number. How many redirection should be allowed.public void setConnectionTimeout(int connectionTimeout)
connectionTimeout
- Timeout in seconds.public void setReadTimeout(int readTimeout)
readTimeout
- Timeout in seconds.protected void setRedirectionEnabled(boolean redirectionEnabled)
redirectionEnabled
- It has to be true to enable redirection.public ArrayList<Integer> getStatusHistory()
public ArrayList<String> getUrlHistory()
public HttpURLConnection getConnection()
public boolean connectWithEnabledRedirects(String stringUrl)
stringUrl
- Regular HTTP or HTTPS URL.public boolean connectWithoutRedirects(String stringUrl)
stringUrl
- Regular HTTP or HTTPS url.protected boolean makeNewGetConnection(String stringUrl)
stringUrl
- Regular HTTP or HTTPS URL.protected boolean isRedirectionLoop()
protected boolean isRedirectionRequired(HttpURLConnection connection)
connection
- The connection object.protected void addToHistory(HttpURLConnection connection)
connection
- The connection object.Copyright © 2015. All rights reserved.