public class ClientRequest
extends java.lang.Object
Constructor and Description |
---|
ClientRequest() |
ClientRequest(HttpMethod method,
java.net.URL url) |
ClientRequest(java.net.URL url) |
Modifier and Type | Method and Description |
---|---|
ClientRequest |
accept(java.lang.String... mediaTypes)
Adds the given media types (e.g.
|
T |
addAllHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerMap)
Add all name/values from the given map.
|
T |
addHeader(HttpHeaderName name,
java.lang.String value)
Add a header value to the header with the given name.
|
T |
addHeader(java.lang.String name,
java.lang.String value)
Add a header value to the header with the given name.
|
T |
addHeaders(java.util.Map<HttpHeaderName,java.util.List<java.lang.String>> headerMap)
Add all name/values from the given map.
|
T |
appendContent(byte[] data)
Appends the given bytes to the content.
|
T |
appendContent(java.io.InputStream inStream)
Appends the bytes from the given stream to the content.
|
ClientRequest |
appendContent(java.util.Map<java.lang.String,java.lang.String> parameters)
Appends the given map as content key/value pairs.
|
void |
appendContent(java.lang.String text)
Appends the given text to the content using the currently defined
character encoding.
|
protected java.nio.charset.Charset |
asCharset(java.lang.String contentType) |
protected MediaType |
asMediaType(java.lang.String contentType) |
protected void |
checkIfHttpMethodAllowsBody() |
ClientRequest |
copy() |
static ClientRequest |
create() |
java.nio.charset.Charset |
getCharset()
Returns the character encoding defined in the Content-Type header
or null if it is not set.
|
protected java.nio.charset.Charset |
getCharsetEncoding() |
protected java.io.ByteArrayOutputStream |
getContentBuffer() |
byte[] |
getContentData()
Returns the content data or null if no content is available.
|
protected java.io.ByteArrayOutputStream |
getContentDataStream() |
int |
getContentLength() |
MediaType |
getContentMediaType()
Returns the media type specified in the "Content-Type" header
of null if not set.
|
java.io.Reader |
getContentReader()
Returns the content data as reader (with correct char encoding) or null
if no content is available.
|
java.lang.String |
getContentText()
Returns the content data as text (with correct char encoding) or null
if no content is available.
|
protected java.lang.String |
getContentTypeHeader()
Returns the "Content-Type" header unparsed.
|
protected java.nio.charset.Charset |
getDefaultCharset() |
java.lang.String |
getHeader(HttpHeaderName name)
Returns a single value (the first) of the header with the given name.
|
java.lang.String |
getHeader(java.lang.String name)
Returns a single value (the first) of the header with the given name.
|
protected Headers |
getHeaders() |
HttpMethod |
getHttpMethod() |
protected Logger |
getLogger() |
protected int |
getReadBufferSize() |
java.net.URL |
getURL() |
boolean |
hasContentData() |
T |
removeHeader(HttpHeaderName name)
Returns the header with the given name and all its associated values.
|
T |
removeHeader(java.lang.String name)
Returns the header with the given name and all its associated values.
|
T |
self() |
T |
setCharset(java.nio.charset.Charset charset)
Sets the character encoding in the Content-Type header
or removes it if the given parameter is null.
|
protected T |
setContentDataStream(java.io.ByteArrayOutputStream bodyData) |
T |
setContentMediaType(MediaType mediaType)
Sets the media type in the Content-Type header
or removes the entire header if the given parameter is null.
|
T |
setContentType(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
protected T |
setContentTypeHeader(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
T |
setHeader(HttpHeaderName name,
java.lang.String value)
A a header with a single value.
|
T |
setHeader(java.lang.String name,
java.lang.String value)
A a header with a single value.
|
ClientRequest |
setHttpMethod(HttpMethod httpMethod) |
ClientRequest |
setURL(java.net.URL url) |
java.lang.String |
toString() |
public ClientRequest()
public ClientRequest(java.net.URL url)
public ClientRequest(HttpMethod method, java.net.URL url)
public static ClientRequest create()
public ClientRequest copy()
public HttpMethod getHttpMethod()
public ClientRequest setHttpMethod(HttpMethod httpMethod)
public java.net.URL getURL()
public ClientRequest setURL(java.net.URL url)
public java.lang.String toString()
toString
in class java.lang.Object
public ClientRequest accept(java.lang.String... mediaTypes)
public ClientRequest appendContent(java.util.Map<java.lang.String,java.lang.String> parameters)
protected void checkIfHttpMethodAllowsBody()
public T setContentType(MediaType mediaType, java.nio.charset.Charset charset)
mediaType
- The media type to set. If null the header will be removed.charset
- The charset to be set. If null it will be ignored.public java.nio.charset.Charset getCharset()
public T setCharset(java.nio.charset.Charset charset)
java.lang.IllegalStateException
- If no media type is specified yet.public MediaType getContentMediaType()
public T setContentMediaType(MediaType mediaType)
public boolean hasContentData()
public int getContentLength()
public T appendContent(byte[] data)
public T appendContent(java.io.InputStream inStream) throws java.io.IOException
inStream
- The stream from which to read the bytes (must not be null).java.io.IOException
- If any problem with the input stream occurs.public void appendContent(java.lang.String text)
text
- The text to be appended (null will be ignored).java.lang.IllegalStateException
- If no encoding is set.public byte[] getContentData()
public java.io.Reader getContentReader()
public java.lang.String getContentText()
public T addAllHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerMap)
headerMap
- The header names and values to be a added (if null, nothing will be done).public T addHeaders(java.util.Map<HttpHeaderName,java.util.List<java.lang.String>> headerMap)
headerMap
- The header names and values to be a added (if null, nothing will be done).public T addHeader(java.lang.String name, java.lang.String value)
public T addHeader(HttpHeaderName name, java.lang.String value)
public T setHeader(java.lang.String name, java.lang.String value)
public T setHeader(HttpHeaderName name, java.lang.String value)
public java.lang.String getHeader(java.lang.String name)
public java.lang.String getHeader(HttpHeaderName name)
public T removeHeader(java.lang.String name)
public T removeHeader(HttpHeaderName name)
public T self()
self
in interface IExtensibleFluentApi<T extends org.pfsw.net.http.CommunicationData>
protected MediaType asMediaType(java.lang.String contentType)
protected java.nio.charset.Charset asCharset(java.lang.String contentType)
protected java.lang.String getContentTypeHeader()
protected T setContentTypeHeader(MediaType mediaType, java.nio.charset.Charset charset)
protected java.nio.charset.Charset getCharsetEncoding()
protected java.nio.charset.Charset getDefaultCharset()
protected java.io.ByteArrayOutputStream getContentBuffer()
protected java.io.ByteArrayOutputStream getContentDataStream()
protected T setContentDataStream(java.io.ByteArrayOutputStream bodyData)
protected Headers getHeaders()
protected int getReadBufferSize()
protected Logger getLogger()