@Immutable @Loggable(value=1) public final class JdkRequest extends Object implements Request
Request
, based on JDK.
This implementation will be enough in most situations. However,
sometimes you may need better tuning or an ability to fetch custom
HTTP methods (JDK doesn't support PATCH, for example). In this case,
use ApacheRequest
.
The class is immutable and thread-safe.
Constructor and Description |
---|
JdkRequest(String uri)
Public ctor.
|
JdkRequest(URI uri)
Public ctor.
|
JdkRequest(URL url)
Public ctor.
|
Modifier and Type | Method and Description |
---|---|
RequestBody |
body()
Get request body.
|
Response |
fetch()
Execute it with a specified HTTP method.
|
Response |
fetch(InputStream stream)
Execute this request using the content provided by the
InputStream being passed as the request body. |
Request |
header(String name,
Object value)
Set request header.
|
Request |
method(String method)
Use this method.
|
Request |
reset(String name)
Remove all headers with this name.
|
<T extends Wire> |
through(Class<T> type,
Object... args)
Send it through a decorating
Wire . |
RequestURI |
uri()
Get destination URI.
|
public JdkRequest(@NotNull(message="URL can\'t be NULL") URL url)
url
- The resource to work withpublic JdkRequest(@NotNull(message="URI can\'t be NULL") URI uri)
uri
- The resource to work withpublic JdkRequest(@NotNull(message="URI can\'t be NULL") String uri)
uri
- The resource to work with@NotNull public RequestURI uri()
Request
public Request header(@NotNull(message="header name can\'t be NULL") String name, @NotNull(message="header value can\'t be NULL") Object value)
Request
public Request reset(@NotNull(message="header name can\'t be NULL") String name)
Request
public RequestBody body()
Request
public Request method(@NotNull(message="method can\'t be NULL") String method)
Request
public Response fetch() throws IOException
Request
fetch
in interface Request
IOException
- If fails to fetch HTTP requestpublic Response fetch(InputStream stream) throws IOException
Request
InputStream
being passed as the request body. Note that the
request MUST have an empty body when this method is being invoked, or
it will throw an IllegalStateException
.fetch
in interface Request
stream
- The input stream to useIOException
- If fails to fetch HTTP requestCopyright © 2012–2014 jcabi.com. All rights reserved.