org.apache.pivot.web
Class Query<V>

java.lang.Object
  extended by org.apache.pivot.util.concurrent.Task<V>
      extended by org.apache.pivot.io.IOTask<V>
          extended by org.apache.pivot.web.Query<V>
Type Parameters:
V - The type of the value retrieved or sent via the query. For GET operations, it is Object; for POST operations, the type is URL. For PUT and DELETE, it is Void.
Direct Known Subclasses:
DeleteQuery, GetQuery, PostQuery, PutQuery

public abstract class Query<V>
extends IOTask<V>

Abstract base class for web queries. A web query is an asynchronous operation that executes one of the following HTTP methods:


Nested Class Summary
static class Query.Method
          Supported HTTP methods.
static class Query.Status
          Query status codes.
 
Nested classes/interfaces inherited from class org.apache.pivot.io.IOTask
IOTask.MonitoredInputStream, IOTask.MonitoredOutputStream
 
Field Summary
static int DEFAULT_PORT
           
 
Fields inherited from class org.apache.pivot.io.IOTask
bytesReceived, bytesSent
 
Fields inherited from class org.apache.pivot.util.concurrent.Task
abort, DEFAULT_EXECUTOR_SERVICE, timeout
 
Constructor Summary
Query(String hostname, int port, String path, boolean secure, ExecutorService executorService)
          Creates a new web query.
 
Method Summary
protected  Object execute(Query.Method method, Object value)
           
 long getBytesExpected()
          Gets the number of bytes that are expected to be received from the server in the body of the server's HTTP response.
 long getBytesReceived()
          Gets the number of bytes that have been received from the server in the body of the server's HTTP response.
 long getBytesSent()
          Gets the number of bytes that have been sent in the body of this query's HTTP request.
 String getHostname()
           
 HostnameVerifier getHostnameVerifier()
           
 URL getLocation()
           
abstract  Query.Method getMethod()
           
 QueryDictionary getParameters()
          Returns the web query's parameter dictionary.
 String getPath()
           
 int getPort()
           
 Proxy getProxy()
          Gets the proxy associated with this query.
 ListenerList<QueryListener<V>> getQueryListeners()
          Returns the query listener list.
 QueryDictionary getRequestHeaders()
          Returns the web query's request header dictionary.
 QueryDictionary getResponseHeaders()
          Returns the web query's response header dictionary.
 Serializer<?> getSerializer()
          Returns the serializer used to stream the value passed to or from the web query.
 int getStatus()
          Returns the status of the most recent execution.
 boolean isSecure()
           
 void setHostnameVerifier(HostnameVerifier hostnameVerifier)
           
 void setProxy(Proxy proxy)
          Sets the proxy associated with this query.
 void setSerializer(Serializer<?> serializer)
          Sets the serializer used to stream the value passed to or from the web query.
 
Methods inherited from class org.apache.pivot.util.concurrent.Task
abort, execute, execute, execute, getExecutorService, getFault, getResult, getTimeout, isPending, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values
Constructor Detail

Query

public Query(String hostname,
             int port,
             String path,
             boolean secure,
             ExecutorService executorService)
Creates a new web query.

Parameters:
hostname -
port -
path -
secure -
Method Detail

getMethod

public abstract Query.Method getMethod()

getHostname

public String getHostname()

getPath

public String getPath()

getPort

public int getPort()

isSecure

public boolean isSecure()

getHostnameVerifier

public HostnameVerifier getHostnameVerifier()

setHostnameVerifier

public void setHostnameVerifier(HostnameVerifier hostnameVerifier)

getProxy

public Proxy getProxy()
Gets the proxy associated with this query.

Returns:
This query's proxy, or null if the query is using the default JVM proxy settings

setProxy

public void setProxy(Proxy proxy)
Sets the proxy associated with this query.

Parameters:
proxy - This query's proxy, or null to use the default JVM proxy settings

getLocation

public URL getLocation()

getParameters

public QueryDictionary getParameters()
Returns the web query's parameter dictionary. Parameters are passed via the query string of the web query's URL.


getRequestHeaders

public QueryDictionary getRequestHeaders()
Returns the web query's request header dictionary. Request headers are passed via HTTP headers when the query is executed.


getResponseHeaders

public QueryDictionary getResponseHeaders()
Returns the web query's response header dictionary. Response headers are returned via HTTP headers when the query is executed.


getStatus

public int getStatus()
Returns the status of the most recent execution.

Returns:
An HTTP code representing the most recent execution status.

getSerializer

public Serializer<?> getSerializer()
Returns the serializer used to stream the value passed to or from the web query. By default, an instance of JSONSerializer is used.


setSerializer

public void setSerializer(Serializer<?> serializer)
Sets the serializer used to stream the value passed to or from the web query.

Parameters:
serializer - The serializer (must be non-null).

getBytesSent

public long getBytesSent()
Gets the number of bytes that have been sent in the body of this query's HTTP request. This will only be non-zero for POST and PUT requests, as GET and DELETE requests send no content to the server.

For POST and PUT requests, this number will increment in between the connected and requestSent phases of the QueryListener lifecycle methods. Interested listeners can poll for this value during that phase.


getBytesReceived

public long getBytesReceived()
Gets the number of bytes that have been received from the server in the body of the server's HTTP response. This will generally only be non-zero for GET requests, as POST, PUT, and DELETE requests generally don't solicit response content from the server.

This number will increment in between the requestSent and responseReceived phases of the QueryListener lifecycle methods. Interested listeners can poll for this value during that phase.


getBytesExpected

public long getBytesExpected()
Gets the number of bytes that are expected to be received from the server in the body of the server's HTTP response. This value reflects the Content-Length HTTP response header and is thus merely an expectation. The actual total number of bytes that will be received is not known for certain until the full response has been received.

If the server did not specify a Content-Length HTTP response header, a value of -1 will be returned to indicate that this value is unknown.


execute

protected Object execute(Query.Method method,
                         Object value)
                  throws QueryException
Throws:
QueryException

getQueryListeners

public ListenerList<QueryListener<V>> getQueryListeners()
Returns the query listener list.