Package org.restlet.engine.adapter
Class ClientCall
- java.lang.Object
-
- org.restlet.engine.adapter.Call
-
- org.restlet.engine.adapter.ClientCall
-
- Direct Known Subclasses:
HttpMethodCall,HttpUrlConnectionCall,JettyClientCall
public abstract class ClientCall extends Call
Low-level HTTP client call.
-
-
Field Summary
Fields Modifier and Type Field Description private HttpClientHelperhelperThe parent HTTP client helper.
-
Constructor Summary
Constructors Constructor Description ClientCall(HttpClientHelper helper, java.lang.String method, java.lang.String requestUri)Constructor setting the request address to the local host.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected longgetContentLength()Returns the content length of the request entity if know,Representation.UNKNOWN_SIZEotherwise.HttpClientHelpergetHelper()Returns the HTTP client helper.static java.lang.StringgetLocalAddress()Returns the local IP address or 127.0.0.1 if the resolution fails.abstract java.nio.channels.WritableByteChannelgetRequestEntityChannel()Returns the request entity channel if it exists.abstract java.io.OutputStreamgetRequestEntityStream()Returns the request entity stream if it exists.abstract java.io.OutputStreamgetRequestHeadStream()Returns the request head stream if it exists.RepresentationgetResponseEntity(Response response)Returns the response entity if available.abstract java.nio.channels.ReadableByteChannelgetResponseEntityChannel(long size)Returns the response channel if it exists.abstract java.io.InputStreamgetResponseEntityStream(long size)Returns the response entity stream if it exists.private java.io.InputStreamgetUnClosedResponseEntityStream(java.io.InputStream inputStream)Checks if the given input stream really contains bytes to be read.protected booleanisClientKeepAlive()Indicates if the client wants a persistent connection.protected booleanisServerKeepAlive()Indicates if the server wants a persistent connection.StatussendRequest(Request request)Sends the request to the client.voidsendRequest(Request request, Response response, Uniform callback)Sends the request to the client.protected booleanshouldRequestBeChunked(Request request)Indicates if the request entity should be chunked.-
Methods inherited from class org.restlet.engine.adapter.Call
getClientAddress, getClientPort, getHostDomain, getHostPort, getLogger, getMethod, getProtocol, getReasonPhrase, getRepresentation, getRepresentation, getRequestHeaders, getRequestUri, getResponseHeaders, getServerAddress, getServerPort, getStatusCode, getUserPrincipal, getVersion, isBroken, isConfidential, isConnectionBroken, isKeepAlive, isRequestChunked, isResponseChunked, setClientAddress, setClientPort, setConfidential, setHostDomain, setHostPort, setMethod, setProtocol, setReasonPhrase, setRequestUri, setServerAddress, setServerPort, setStatusCode, setUserPrincipal, setVersion
-
-
-
-
Field Detail
-
helper
private volatile HttpClientHelper helper
The parent HTTP client helper.
-
-
Constructor Detail
-
ClientCall
public ClientCall(HttpClientHelper helper, java.lang.String method, java.lang.String requestUri)
Constructor setting the request address to the local host.- Parameters:
helper- The parent HTTP client helper.method- The method name.requestUri- The request URI.
-
-
Method Detail
-
getLocalAddress
public static java.lang.String getLocalAddress()
Returns the local IP address or 127.0.0.1 if the resolution fails.- Returns:
- The local IP address or 127.0.0.1 if the resolution fails.
-
getContentLength
protected long getContentLength()
Returns the content length of the request entity if know,Representation.UNKNOWN_SIZEotherwise.- Returns:
- The request content length.
-
getHelper
public HttpClientHelper getHelper()
Returns the HTTP client helper.- Returns:
- The HTTP client helper.
-
getRequestEntityChannel
public abstract java.nio.channels.WritableByteChannel getRequestEntityChannel()
Returns the request entity channel if it exists.- Returns:
- The request entity channel if it exists.
-
getRequestEntityStream
public abstract java.io.OutputStream getRequestEntityStream()
Returns the request entity stream if it exists.- Returns:
- The request entity stream if it exists.
-
getRequestHeadStream
public abstract java.io.OutputStream getRequestHeadStream()
Returns the request head stream if it exists.- Returns:
- The request head stream if it exists.
-
getResponseEntity
public Representation getResponseEntity(Response response)
Returns the response entity if available. Note that no metadata is associated by default, you have to manually set them from your headers.- Parameters:
response- the Response to get the entity from- Returns:
- The response entity if available.
-
getResponseEntityChannel
public abstract java.nio.channels.ReadableByteChannel getResponseEntityChannel(long size)
Returns the response channel if it exists.- Parameters:
size- The expected entity size or -1 if unknown.- Returns:
- The response channel if it exists.
-
getResponseEntityStream
public abstract java.io.InputStream getResponseEntityStream(long size)
Returns the response entity stream if it exists.- Parameters:
size- The expected entity size or -1 if unknown.- Returns:
- The response entity stream if it exists.
-
getUnClosedResponseEntityStream
private java.io.InputStream getUnClosedResponseEntityStream(java.io.InputStream inputStream)
Checks if the given input stream really contains bytes to be read. If so, returns the inputStream otherwise returns null.- Parameters:
inputStream- the inputStream to check.- Returns:
- null if the given inputStream does not contain any byte, an inputStream otherwise.
-
isClientKeepAlive
protected boolean isClientKeepAlive()
Description copied from class:CallIndicates if the client wants a persistent connection.- Specified by:
isClientKeepAlivein classCall- Returns:
- True if the client wants a persistent connection.
-
isServerKeepAlive
protected boolean isServerKeepAlive()
Description copied from class:CallIndicates if the server wants a persistent connection.- Specified by:
isServerKeepAlivein classCall- Returns:
- True if the server wants a persistent connection.
-
sendRequest
public Status sendRequest(Request request)
Sends the request to the client. Commits the request line, headers and optional entity and send them over the network.- Parameters:
request- The high-level request.- Returns:
- the status of the communication
-
sendRequest
public void sendRequest(Request request, Response response, Uniform callback) throws java.lang.Exception
Sends the request to the client. Commits the request line, headers and optional entity and send them over the network.- Parameters:
request- The high-level request.response- The high-level response.callback- The callback invoked upon request completion.- Throws:
java.lang.Exception
-
shouldRequestBeChunked
protected boolean shouldRequestBeChunked(Request request)
Indicates if the request entity should be chunked.- Returns:
- True if the request should be chunked
-
-