org.mortbay.jetty.client
Class HttpExchange
java.lang.Object
org.mortbay.jetty.client.HttpExchange
- Direct Known Subclasses:
- CachedExchange
public class HttpExchange
- extends Object
An HTTP client API that encapsulates Exchange with a HTTP server.
This object encapsulates:
The HttpExchange class is intended to be used by a developer wishing to have close asynchronous
interaction with the the exchange. Typically a developer will extend the HttpExchange class with a derived
class that implements some or all of the onXxx callbacks. There are also some predefined HttpExchange subtypes
that can be used as a basis (see ContentExchange
and HttpExchange.CachedExchange
.
Typically the HttpExchange is passed to a the HttpClient.send(HttpExchange)
method, which in
turn selects a HttpDestination
and calls it's HttpDestination#send(HttpExchange), which
then creates or selects a {@link HttpConnection} and calls its {@link HttpConnection#send(HttpExchange).
A developer may wish to directly call send on the destination or connection if they wish to bypass
some handling provided (eg Cookie handling in the HttpDestination).
In some circumstances, the HttpClient or HttpDestination may wish to retry a HttpExchange (eg. failed
pipeline request, authentication retry or redirection). In such cases, the HttpClient and/or HttpDestination
may insert their own HttpExchangeListener to intercept and filter the call backs intended for the
HttpExchange.
- Author:
- gregw, Guillaume Nodet
STATUS_START
public static final int STATUS_START
- See Also:
- Constant Field Values
STATUS_WAITING_FOR_CONNECTION
public static final int STATUS_WAITING_FOR_CONNECTION
- See Also:
- Constant Field Values
STATUS_WAITING_FOR_COMMIT
public static final int STATUS_WAITING_FOR_COMMIT
- See Also:
- Constant Field Values
STATUS_SENDING_REQUEST
public static final int STATUS_SENDING_REQUEST
- See Also:
- Constant Field Values
STATUS_WAITING_FOR_RESPONSE
public static final int STATUS_WAITING_FOR_RESPONSE
- See Also:
- Constant Field Values
STATUS_PARSING_HEADERS
public static final int STATUS_PARSING_HEADERS
- See Also:
- Constant Field Values
STATUS_PARSING_CONTENT
public static final int STATUS_PARSING_CONTENT
- See Also:
- Constant Field Values
STATUS_COMPLETED
public static final int STATUS_COMPLETED
- See Also:
- Constant Field Values
STATUS_EXPIRED
public static final int STATUS_EXPIRED
- See Also:
- Constant Field Values
STATUS_EXCEPTED
public static final int STATUS_EXCEPTED
- See Also:
- Constant Field Values
HttpExchange
public HttpExchange()
getStatus
public int getStatus()
waitForStatus
public void waitForStatus(int status)
throws InterruptedException
- Deprecated.
- Throws:
InterruptedException
reset
public void reset()
getEventListener
public HttpEventListener getEventListener()
setEventListener
public void setEventListener(HttpEventListener listener)
setURL
public void setURL(String url)
- Parameters:
url
- Including protocol, host and port
setAddress
public void setAddress(InetSocketAddress address)
- Parameters:
address
-
getAddress
public InetSocketAddress getAddress()
- Returns:
setScheme
public void setScheme(Buffer scheme)
- Parameters:
scheme
-
getScheme
public Buffer getScheme()
- Returns:
setVersion
public void setVersion(int version)
- Parameters:
version
- as integer, 9, 10 or 11 for 0.9, 1.0 or 1.1
setVersion
public void setVersion(String version)
getVersion
public int getVersion()
- Returns:
setMethod
public void setMethod(String method)
- Parameters:
method
-
getMethod
public String getMethod()
- Returns:
getURI
public String getURI()
- Returns:
setURI
public void setURI(String uri)
- Parameters:
uri
-
addRequestHeader
public void addRequestHeader(String name,
String value)
- Parameters:
name
- value
-
addRequestHeader
public void addRequestHeader(Buffer name,
Buffer value)
- Parameters:
name
- value
-
setRequestHeader
public void setRequestHeader(String name,
String value)
- Parameters:
name
- value
-
setRequestHeader
public void setRequestHeader(Buffer name,
Buffer value)
- Parameters:
name
- value
-
setRequestContentType
public void setRequestContentType(String value)
- Parameters:
value
-
getRequestFields
public HttpFields getRequestFields()
- Returns:
setRequestContent
public void setRequestContent(Buffer requestContent)
- Parameters:
requestContent
-
setRequestContentSource
public void setRequestContentSource(InputStream in)
- Parameters:
in
-
getRequestContentSource
public InputStream getRequestContentSource()
getRequestContentChunk
public Buffer getRequestContentChunk()
throws IOException
- Throws:
IOException
getRequestContent
public Buffer getRequestContent()
getRetryStatus
public boolean getRetryStatus()
setRetryStatus
public void setRetryStatus(boolean retryStatus)
cancel
public void cancel()
- Cancel this exchange
Currently this implementation does nothing.
toString
public String toString()
- Overrides:
toString
in class Object
onRequestCommitted
protected void onRequestCommitted()
throws IOException
- Throws:
IOException
onRequestComplete
protected void onRequestComplete()
throws IOException
- Throws:
IOException
onResponseStatus
protected void onResponseStatus(Buffer version,
int status,
Buffer reason)
throws IOException
- Throws:
IOException
onResponseHeader
protected void onResponseHeader(Buffer name,
Buffer value)
throws IOException
- Throws:
IOException
onResponseHeaderComplete
protected void onResponseHeaderComplete()
throws IOException
- Throws:
IOException
onResponseContent
protected void onResponseContent(Buffer content)
throws IOException
- Throws:
IOException
onResponseComplete
protected void onResponseComplete()
throws IOException
- Throws:
IOException
onConnectionFailed
protected void onConnectionFailed(Throwable ex)
onException
protected void onException(Throwable ex)
onExpire
protected void onExpire()
onRetry
protected void onRetry()
Copyright © 2008 Mort Bay Consulting. All Rights Reserved.