Package com.luciad.net.http
Class HttpRequest.Builder
java.lang.Object
com.luciad.net.http.HttpRequest.Builder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
HttpRequest
A builder of
HttpRequest
s.
Instances of HttpRequest.Builder
are created by calling HttpRequest#newBuilder
.
The builder can be used to configure the request URI, the request method (default is GET unless explicitly set), specific request headers, etc. The build method returns a new HttpRequest
each time it is invoked. Once built an HttpRequest
is immutable.
- Since:
- 2023.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbody
(DataEntity body) Sets the HTTP request content.build()
Returns anHttpRequest
, based on the properties set on this builder.void
close()
protected void
finalize()
header
(HttpHeader header) Sets the given http header to the set of headers for this request.Sets the given name value pair to the set of headers for this request.method
(HttpRequestMethod method) Sets the request method of this builder.queryParameter
(UriQueryParameter queryParameter) Sets the given query parameter to the set of query parameters for this request.queryParameter
(String name, String value) Sets the given name value pair to the set of query parameters for this request.Sets thisHttpRequest
's request URI.
-
Constructor Details
-
Builder
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
build
Returns anHttpRequest
, based on the properties set on this builder.- Returns:
- an
HttpRequest
, based on the properties set on this builder. - Throws:
IllegalStateException
- if a URI has not been set.
-
uri
Sets thisHttpRequest
's request URI.The provided URI can have a query string. This parameter is mandatory. If it is not set,
HttpRequest.Builder#build
will throw an exception.- Parameters:
uri
- request URI string.- Returns:
- this builder.
-
method
Sets the request method of this builder.This parameter is optional. If not set, default is GET.
- Parameters:
method
- the method to use.- Returns:
- this builder.
-
body
Sets the HTTP request content.This parameter is optional unless this
HttpRequest
's method has been set to POST or PUT. If not set when the request method is POST or PUT,HttpRequest.Builder#build
will throw an exception.- Parameters:
body
- the request content.- Returns:
- this builder.
-
header
Sets the given name value pair to the set of headers for this request.- Parameters:
name
- header namevalue
- header value- Returns:
- this builder.
-
header
Sets the given http header to the set of headers for this request.- Parameters:
header
- anHttpHeader
.- Returns:
- this builder.
-
queryParameter
Sets the given name value pair to the set of query parameters for this request.- Parameters:
name
- query parameter name.value
- query parameter value.- Returns:
- this builder.
-
queryParameter
Sets the given query parameter to the set of query parameters for this request.- Parameters:
queryParameter
- anUriQueryParameter
.- Returns:
- this builder.
-