java.lang.Object
org.codelibs.curl.CurlRequest
The CurlRequest class represents an HTTP request that can be configured and executed.
It supports various HTTP methods, request parameters, headers, body content, and more.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe RequestProcessor class processes the HTTP request and handles the response. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe body content of the request.protected InputStreamThe input stream for the request body.protected StringThe compression type for the request.protected StringThe character encoding for the request.protected static final StringThe GZIP compression type.The list of request headers.protected static final LoggerLogger for logging request details.protected Curl.MethodThe HTTP method for the request.The list of request parameters.protected ProxyThe proxy to be used for the HTTP request.protected SSLSocketFactoryThe SSL socket factory for secure connections.protected ForkJoinPoolThe thread pool for executing the request.protected intThe threshold size for the request body.protected StringThe URL for the HTTP request. -
Constructor Summary
ConstructorsConstructorDescriptionCurlRequest(Curl.Method method, String url) Constructs a new CurlRequest with the specified HTTP method and URL. -
Method Summary
Modifier and TypeMethodDescriptionbody()Returns the body content of the request.body(InputStream stream) Sets the input stream for the request body.Sets the body content for the request.compression(String compression) Sets the compression type for the request.voidconnect(Consumer<HttpURLConnection> actionListener, Consumer<Exception> exceptionListener) Connects to the URL and executes the request.protected StringEncodes the specified value using the character encoding.encoding()Returns the character encoding for the request.Sets the character encoding for the request.execute()Executes the request and returns the response.voidexecute(Consumer<CurlResponse> actionListener, Consumer<Exception> exceptionListener) Executes the request and processes the response.gzip()Enables GZIP compression for the request.Adds a request header.method()Returns the HTTP method for the request.onConnect(BiConsumer<CurlRequest, HttpURLConnection> connectionBuilder) Sets the connection builder for customizing the connection.protected HttpURLConnectionOpens a connection to the specified URL.Adds a request parameter.proxy()Returns the proxy for the request.Sets the proxy for the request.sslSocketFactory(SSLSocketFactory sslSocketFactory) Sets the SSL socket factory for secure connections.threadPool(ForkJoinPool threadPool) Sets the thread pool for executing the request.intReturns the threshold size for the request body.threshold(int threshold) Sets the threshold size for the request body.
-
Field Details
-
GZIP
The GZIP compression type.- See Also:
-
logger
Logger for logging request details. -
url
The URL for the HTTP request. -
proxy
The proxy to be used for the HTTP request. -
encoding
The character encoding for the request. -
threshold
protected int thresholdThe threshold size for the request body. -
method
The HTTP method for the request. -
paramList
The list of request parameters. -
headerList
The list of request headers. -
body
The body content of the request. -
bodyStream
The input stream for the request body. -
compression
The compression type for the request. -
sslSocketFactory
The SSL socket factory for secure connections. -
threadPool
The thread pool for executing the request.
-
-
Constructor Details
-
CurlRequest
Constructs a new CurlRequest with the specified HTTP method and URL.- Parameters:
method- the HTTP methodurl- the URL
-
-
Method Details
-
proxy
Returns the proxy for the request.- Returns:
- the proxy
-
encoding
Returns the character encoding for the request.- Returns:
- the encoding
-
threshold
public int threshold()Returns the threshold size for the request body.- Returns:
- the threshold
-
method
Returns the HTTP method for the request.- Returns:
- the method
-
body
Returns the body content of the request.- Returns:
- the body
-
proxy
Sets the proxy for the request.- Parameters:
proxy- the proxy- Returns:
- this CurlRequest instance
-
encoding
Sets the character encoding for the request.- Parameters:
encoding- the encoding- Returns:
- this CurlRequest instance
- Throws:
CurlException- if the method is called after the param method
-
threshold
Sets the threshold size for the request body.- Parameters:
threshold- the threshold- Returns:
- this CurlRequest instance
-
gzip
Enables GZIP compression for the request.- Returns:
- this CurlRequest instance
-
compression
Sets the compression type for the request.- Parameters:
compression- the compression type- Returns:
- this CurlRequest instance
-
sslSocketFactory
Sets the SSL socket factory for secure connections.- Parameters:
sslSocketFactory- the SSL socket factory- Returns:
- this CurlRequest instance
-
body
Sets the body content for the request.- Parameters:
body- the body content- Returns:
- this CurlRequest instance
- Throws:
CurlException- if the body method is already called
-
body
Sets the input stream for the request body.- Parameters:
stream- the input stream- Returns:
- this CurlRequest instance
- Throws:
CurlException- if the body method is already called
-
onConnect
Sets the connection builder for customizing the connection.- Parameters:
connectionBuilder- the connection builder- Returns:
- this CurlRequest instance
-
param
Adds a request parameter.- Parameters:
key- the parameter keyvalue- the parameter value- Returns:
- this CurlRequest instance
-
header
Adds a request header.- Parameters:
key- the header keyvalue- the header value- Returns:
- this CurlRequest instance
-
connect
public void connect(Consumer<HttpURLConnection> actionListener, Consumer<Exception> exceptionListener) Connects to the URL and executes the request.- Parameters:
actionListener- the action listener for handling the responseexceptionListener- the exception listener for handling exceptions
-
open
Opens a connection to the specified URL.- Parameters:
u- the URL- Returns:
- the HttpURLConnection
- Throws:
IOException- if an I/O exception occurs
-
execute
Executes the request and processes the response.- Parameters:
actionListener- the action listener for handling the responseexceptionListener- the exception listener for handling exceptions
-
execute
Executes the request and returns the response.- Returns:
- the CurlResponse
-
encode
Encodes the specified value using the character encoding.- Parameters:
value- the value to encode- Returns:
- the encoded value
- Throws:
CurlException- if the encoding is unsupported
-
threadPool
Sets the thread pool for executing the request.- Parameters:
threadPool- the thread pool- Returns:
- this CurlRequest instance
-