B
- the type of the builder itself.M
- the type of HttpMessage
that the builder creates.public abstract class HttpMessageBuilder<B extends HttpMessageBuilder,M extends HttpMessage> extends Object
HttpMessage
builder. Implementations should extend it and indicate their type and the type of
the message they build.Modifier and Type | Field and Description |
---|---|
protected HttpEntity |
entity |
protected MultiMap<String,String> |
headers |
Modifier | Constructor and Description |
---|---|
|
HttpMessageBuilder() |
protected |
HttpMessageBuilder(HttpMessage httpMessage) |
Modifier and Type | Method and Description |
---|---|
B |
addHeader(String name,
String value)
Includes a new header to be sent in the desired
HttpMessage . |
B |
addHeaders(String name,
Collection<String> values)
Includes a new header with multiple values to be sent in the desired
HttpMessage . |
abstract M |
build() |
B |
entity(HttpEntity entity) |
MultiMap<String,String> |
getHeaders() |
Optional<String> |
getHeaderValue(String name)
Returns the value of a given HTTP request.
|
Collection<String> |
getHeaderValues(String name)
Gives access to all current values of a given HTTP header.
|
B |
headers(MultiMap<String,String> headersMap) |
protected void |
initHeaders() |
B |
removeHeader(String name)
Removes a header.
|
protected HttpEntity entity
public HttpMessageBuilder()
protected HttpMessageBuilder(HttpMessage httpMessage)
protected void initHeaders()
public B entity(HttpEntity entity)
entity
- the HttpEntity
that should be used as body for the HttpMessage
. Non null.public B headers(MultiMap<String,String> headersMap)
headersMap
- a MultiMap
representing the HTTP headers of the HttpRequest
desired. Non null.public B addHeader(String name, String value)
HttpMessage
. Since HTTP headers are case insensitive and can have
several values, multiple calls to this method using the same header name will accumulate the values and all of them will be sent.name
- the name of the HTTP headervalue
- the value of the HTTP headerpublic B addHeaders(String name, Collection<String> values)
HttpMessage
.name
- the name of the HTTP headervalues
- the values of the HTTP headerpublic B removeHeader(String name)
name
- the name of the HTTP header to removepublic Optional<String> getHeaderValue(String name)
getHeaderValues(String)
instead if all values are required.name
- the name of the desired HTTP headernull
if there isn't onepublic Collection<String> getHeaderValues(String name)
name
- the name of the desired HTTP headerCollection
of String
values for the headerpublic MultiMap<String,String> getHeaders()
public abstract M build()
Copyright © 2018. All rights reserved.