public interface Request
Request
represents a HTTP request, and offers a fluent interface to customize
various attributes such as the path, the headers, the content, etc.
You can create Request
objects via HttpClient.newRequest(String)
and
you can send them using either send()
for a blocking semantic, or
#send(Response.Listener)
for an asynchronous semantic.
Response
Modifier and Type | Interface and Description |
---|---|
static interface |
Request.BeginListener |
static interface |
Request.FailureListener |
static interface |
Request.HeadersListener |
static interface |
Request.Listener
Listener for all request events
|
static interface |
Request.QueuedListener |
static interface |
Request.RequestListener |
static interface |
Request.SuccessListener |
long getConversationID()
String getScheme()
Request scheme(String scheme)
scheme
- the scheme of this request, such as "http" or "https"String getHost()
int getPort()
HttpMethod getMethod()
Request method(HttpMethod method)
method
- the method of this request, such as GET or POSTString getPath()
Request path(String path)
path
- the path of this request, such as "/"String getURI()
HttpVersion getVersion()
Request version(HttpVersion version)
version
- the HTTP version of this request, such as "HTTP/1.1"Fields getParams()
Request param(String name, String value)
name
- the name of the query parametervalue
- the value of the query parameterHttpFields getHeaders()
Request header(String name, String value)
name
- the name of the headervalue
- the value of the headerRequest attribute(String name, Object value)
name
- the name of the attributevalue
- the value of the attributeContentProvider getContent()
Request content(ContentProvider content)
content
- the content provider of this requestRequest file(java.nio.file.Path file) throws IOException
file
- the file to uploadIOException
- if the file does not exist or cannot be readRequest file(java.nio.file.Path file, String contentType) throws IOException
file
- the file to uploadcontentType
- the content type of the fileIOException
- if the file does not exist or cannot be readString getAgent()
Request agent(String agent)
agent
- the user agent for this requestlong getIdleTimeout()
Request idleTimeout(long timeout)
timeout
- the idle timeout for this requestboolean isFollowRedirects()
Request followRedirects(boolean follow)
follow
- whether this request follows redirects<T extends Request.RequestListener> List<T> getRequestListeners(Class<T> listenerClass)
listenerClass
- the class of the listener, or null for all listeners classesRequest listener(Request.Listener listener)
listener
- a listener for request eventsRequest onRequestQueued(Request.QueuedListener listener)
listener
- a listener for request queued eventRequest onRequestBegin(Request.BeginListener listener)
listener
- a listener for request begin eventRequest onRequestHeaders(Request.HeadersListener listener)
listener
- a listener for request headers eventRequest onRequestSuccess(Request.SuccessListener listener)
listener
- a listener for request success eventRequest onRequestFailure(Request.FailureListener listener)
listener
- a listener for request failure eventRequest onResponseBegin(Response.BeginListener listener)
listener
- a listener for response begin eventRequest onResponseHeaders(Response.HeadersListener listener)
listener
- a listener for response headers eventRequest onResponseContent(Response.ContentListener listener)
listener
- a listener for response content eventsRequest onResponseSuccess(Response.SuccessListener listener)
listener
- a listener for response success eventRequest onResponseFailure(Response.FailureListener listener)
listener
- a listener for response failure eventFuture<ContentResponse> send()
Future
that can be used to wait for the
request and the response to be completed (either with a success or a failure).
This method should be used when a simple blocking semantic is needed, and when it is known
that the response content can be buffered without exceeding memory constraints.
For example, this method is not appropriate to download big files from a server; consider using
#send(Response.Listener)
instead, passing your own Response.Listener
or a utility
listener such as InputStreamResponseListener
.
The future will return when Response.CompleteListener.onComplete(Result)
is invoked.Future
to wait on for request and response completionResponse.CompleteListener.onComplete(Result)
void send(Response.CompleteListener listener)
listener
- the listener that receives response eventsboolean abort(Throwable cause)
cause
- the abort cause, must not be nullThrowable getAbortCause()
abort(Throwable)
,
or null if this request has not been abortedCopyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.