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 |
---|---|
void |
accept(java.lang.String... mediaTypes)
Adds the given media types (e.g.
|
void |
addAllHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerMap)
Add all name/values from the given map.
|
void |
addHeader(java.lang.String name,
java.lang.String value)
Add a header value to the header with the given name.
|
void |
appendContent(byte[] data)
Appends the given bytes to the content.
|
void |
appendContent(java.io.InputStream inStream)
Appends the bytes from the given stream to the content.
|
void |
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() |
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.
|
MediaType |
getContentType()
Deprecated.
Use
getContentMediaType() instead. |
protected java.lang.String |
getContentTypeHeader()
Returns the "Content-Type" header unparsed.
|
protected java.nio.charset.Charset |
getDefaultCharset() |
java.nio.charset.Charset |
getEncoding()
Deprecated.
Use
getCharset() instead. |
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() |
void |
removeHeader(java.lang.String name)
Returns the header with the given name and all its associated values.
|
void |
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 void |
setContentDataStream(java.io.ByteArrayOutputStream bodyData) |
void |
setContentMediaType(MediaType mediaType)
Sets the media type in the Content-Type header
or removes the entire header if the given parameter is null.
|
void |
setContentType(MediaType mediaType)
Deprecated.
Use
setContentMediaType(MediaType) instead. |
void |
setContentType(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
protected void |
setContentTypeHeader(MediaType mediaType,
java.nio.charset.Charset charset)
Sets the "Content-Type" header.
|
void |
setEncoding(java.nio.charset.Charset charset)
Deprecated.
Use
setCharset(Charset) instead. |
void |
setHeader(java.lang.String name,
java.lang.String value)
A a header with a single value.
|
void |
setHttpMethod(HttpMethod httpMethod) |
void |
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 HttpMethod getHttpMethod()
public void setHttpMethod(HttpMethod httpMethod)
public java.net.URL getURL()
public void setURL(java.net.URL url)
public java.lang.String toString()
toString
in class java.lang.Object
public void accept(java.lang.String... mediaTypes)
public void appendContent(java.util.Map<java.lang.String,java.lang.String> parameters)
protected void checkIfHttpMethodAllowsBody()
public void 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 void setCharset(java.nio.charset.Charset charset)
java.lang.IllegalStateException
- If no media type is specified yet.public MediaType getContentMediaType()
public void setContentMediaType(MediaType mediaType)
@Deprecated public java.nio.charset.Charset getEncoding()
getCharset()
instead.@Deprecated public void setEncoding(java.nio.charset.Charset charset)
setCharset(Charset)
instead.@Deprecated public MediaType getContentType()
getContentMediaType()
instead.@Deprecated public void setContentType(MediaType mediaType)
setContentMediaType(MediaType)
instead.public boolean hasContentData()
public int getContentLength()
public void appendContent(byte[] data)
public void 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 void 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 void addHeader(java.lang.String name, java.lang.String value)
public void setHeader(java.lang.String name, java.lang.String value)
public java.lang.String getHeader(java.lang.String name)
public void removeHeader(java.lang.String name)
protected MediaType asMediaType(java.lang.String contentType)
protected java.nio.charset.Charset asCharset(java.lang.String contentType)
protected java.lang.String getContentTypeHeader()
protected void 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 void setContentDataStream(java.io.ByteArrayOutputStream bodyData)
protected Headers getHeaders()
protected int getReadBufferSize()
protected Logger getLogger()