Class HttpRequest
- java.lang.Object
-
- net.lenni0451.commons.httpclient.HeaderStore<HttpRequest>
-
- net.lenni0451.commons.httpclient.requests.HttpRequest
-
- Direct Known Subclasses:
DeleteRequest,GetRequest,HeadRequest,HttpContentRequest
public class HttpRequest extends HeaderStore<HttpRequest>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpRequest.FollowRedirects
-
Constructor Summary
Constructors Constructor Description HttpRequest(java.lang.String method, java.lang.String url)HttpRequest(java.lang.String method, java.net.URL url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequestbind(HttpClient client)Bind this request to a client for execution.HttpResponseexecute()Execute this request and return the response.
If a client is bound to this request it will be used for execution.
If no client is bound a new client will be created.<R> Rexecute(HttpResponseHandler<R> responseHandler)Execute this request and pass the response to the response handler.
If a client is bound to this request it will be used for execution.
If no client is bound a new client will be created.java.net.CookieManagergetCookieManager()HttpRequest.FollowRedirectsgetFollowRedirects()booleangetIgnoreInvalidSSL()java.lang.StringgetMethod()RetryConfiggetRetryHandler()java.net.URLgetURL()booleanisCookieManagerSet()booleanisIgnoreInvalidSSLSet()booleanisRetryHandlerSet()booleanisStreamedRequest()booleanisStreamedResponse()HttpRequestsetCookieManager(java.net.CookieManager cookieManager)Set the cookie manager to use for this request.HttpRequestsetFollowRedirects(boolean followRedirects)Set if redirects should be followed.HttpRequestsetFollowRedirects(HttpRequest.FollowRedirects followRedirects)Set if redirects should be followed.HttpRequestsetIgnoreInvalidSSL(boolean ignoreInvalidSSL)Set the ignore invalid SSL flag to use for this request.HttpRequestsetRetryHandler(RetryConfig retryConfig)Set the retry handler to use for this request.HttpRequestsetStreamedRequest(boolean streamedRequest)Set if the request should be streamed.
Streaming the request will not buffer the content and will allow you to write the content while it is being uploaded.
Streaming is not a mandatory feature and might not be supported by all executors.HttpRequestsetStreamedResponse(boolean streamedResponse)Set if the response should be streamed.
Streaming the response will not buffer the content and will allow you to read the content while it is being downloaded.
You are responsible for closing the input stream of the response to close the connection and free resources.
Streaming is not a mandatory feature and might not be supported by all executors.HttpRequestunsetCookieManager()Unset the cookie manager.HttpRequestunsetIgnoreInvalidSSL()Unset the ignore invalid SSL flag.HttpRequestunsetRetryHandler()Unset the retry handler.-
Methods inherited from class net.lenni0451.commons.httpclient.HeaderStore
appendHeader, appendHeader, appendHeader, clearHeaders, forEachHeader, getFirstHeader, getHeader, getHeaders, getLastHeader, hasHeader, hasHeader, hasHeader, removeHeader, setHeader, setHeader, setHeader
-
-
-
-
Method Detail
-
getMethod
public java.lang.String getMethod()
- Returns:
- The request method
-
getURL
public java.net.URL getURL()
- Returns:
- The request url
-
isStreamedRequest
public boolean isStreamedRequest()
- Returns:
- If the request should be streamed
-
setStreamedRequest
public HttpRequest setStreamedRequest(boolean streamedRequest)
Set if the request should be streamed.
Streaming the request will not buffer the content and will allow you to write the content while it is being uploaded.
Streaming is not a mandatory feature and might not be supported by all executors.- Parameters:
streamedRequest- If the request should be streamed- Returns:
- This instance for chaining
-
isStreamedResponse
public boolean isStreamedResponse()
- Returns:
- If the response should be streamed
-
setStreamedResponse
public HttpRequest setStreamedResponse(boolean streamedResponse)
Set if the response should be streamed.
Streaming the response will not buffer the content and will allow you to read the content while it is being downloaded.
You are responsible for closing the input stream of the response to close the connection and free resources.
Streaming is not a mandatory feature and might not be supported by all executors.- Parameters:
streamedResponse- If the response should be streamed- Returns:
- This instance for chaining
-
getFollowRedirects
public HttpRequest.FollowRedirects getFollowRedirects()
- Returns:
- If redirects should be followed
-
setFollowRedirects
public HttpRequest setFollowRedirects(boolean followRedirects)
Set if redirects should be followed.- Parameters:
followRedirects- If redirects should be followed- Returns:
- This instance for chaining
-
setFollowRedirects
public HttpRequest setFollowRedirects(@Nonnull HttpRequest.FollowRedirects followRedirects)
Set if redirects should be followed.- Parameters:
followRedirects- If redirects should be followed- Returns:
- This instance for chaining
-
isCookieManagerSet
public boolean isCookieManagerSet()
- Returns:
- If the cookie manager is set
-
unsetCookieManager
public HttpRequest unsetCookieManager()
Unset the cookie manager.- Returns:
- This instance for chaining
-
getCookieManager
@Nullable public java.net.CookieManager getCookieManager()
- Returns:
- The set cookie manager
- Throws:
java.lang.IllegalStateException- If the cookie manager is not set
-
setCookieManager
public HttpRequest setCookieManager(@Nullable java.net.CookieManager cookieManager)
Set the cookie manager to use for this request.- Parameters:
cookieManager- The cookie manager to use- Returns:
- This instance for chaining
-
isRetryHandlerSet
public boolean isRetryHandlerSet()
- Returns:
- If the retry handler is set
-
unsetRetryHandler
public HttpRequest unsetRetryHandler()
Unset the retry handler.- Returns:
- This instance for chaining
-
getRetryHandler
@Nonnull public RetryConfig getRetryHandler()
- Returns:
- The set retry handler
- Throws:
java.lang.IllegalStateException- If the retry handler is not set
-
setRetryHandler
public HttpRequest setRetryHandler(@Nonnull RetryConfig retryConfig)
Set the retry handler to use for this request.- Parameters:
retryConfig- The retry handler to use- Returns:
- This instance for chaining
-
isIgnoreInvalidSSLSet
public boolean isIgnoreInvalidSSLSet()
- Returns:
- If the ignore invalid SSL flag is set
-
unsetIgnoreInvalidSSL
public HttpRequest unsetIgnoreInvalidSSL()
Unset the ignore invalid SSL flag.- Returns:
- This instance for chaining
-
getIgnoreInvalidSSL
public boolean getIgnoreInvalidSSL()
- Returns:
- The set ignore invalid SSL flag
- Throws:
java.lang.IllegalStateException- If the ignore invalid SSL flag is not set
-
setIgnoreInvalidSSL
public HttpRequest setIgnoreInvalidSSL(boolean ignoreInvalidSSL)
Set the ignore invalid SSL flag to use for this request.- Parameters:
ignoreInvalidSSL- The ignore invalid SSL flag to use- Returns:
- This instance for chaining
-
bind
public HttpRequest bind(@Nullable HttpClient client)
Bind this request to a client for execution.- Parameters:
client- The client to bind to- Returns:
- This instance for chaining
-
execute
public HttpResponse execute() throws java.io.IOException
Execute this request and return the response.
If a client is bound to this request it will be used for execution.
If no client is bound a new client will be created.- Returns:
- The response of the request
- Throws:
java.io.IOException- If an I/O error occurs
-
execute
public <R> R execute(HttpResponseHandler<R> responseHandler) throws java.io.IOException
Execute this request and pass the response to the response handler.
If a client is bound to this request it will be used for execution.
If no client is bound a new client will be created.- Type Parameters:
R- The return type of the response handler- Parameters:
responseHandler- The response handler- Returns:
- The return value of the response handler
- Throws:
java.io.IOException- If an I/O error occurs
-
-