pivot.web
Class Query<V>

java.lang.Object
  extended by pivot.util.concurrent.Task<V>
      extended by pivot.io.IOTask<V>
          extended by 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:

Author:
gbrown, tvolkert

Nested Class Summary
 class Query.ArgumentsDictionary
          Arguments dictionary implementation.
protected static class Query.Method
          The supported HTTP methods.
 class Query.RequestPropertiesDictionary
          Request properties dictionary implementation.
 class Query.ResponsePropertiesDictionary
          Response properties dictionary implementation.
 
Nested classes/interfaces inherited from class pivot.io.IOTask
IOTask.MonitoredInputStream, IOTask.MonitoredOutputStream
 
Field Summary
static int DEFAULT_PORT
           
 
Fields inherited from class pivot.io.IOTask
bytesReceived, bytesSent
 
Fields inherited from class pivot.util.concurrent.Task
abort, timeout
 
Constructor Summary
Query(java.lang.String hostname, int port, java.lang.String path, boolean secure)
          Creates a new web query.
 
Method Summary
protected  java.lang.Object execute(Query.Method method, java.lang.Object value)
           
 Query.ArgumentsDictionary getArguments()
          Returns the web query's arguments dictionary.
 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.
 java.lang.String getHostname()
           
 javax.net.ssl.HostnameVerifier getHostnameVerifier()
           
 java.net.URL getLocation()
           
 java.lang.String getPath()
           
 int getPort()
           
 ListenerList<QueryListener<V>> getQueryListeners()
          Returns the query listener list.
 Query.RequestPropertiesDictionary getRequestProperties()
          Returns the web query's request property dictionary.
 Query.ResponsePropertiesDictionary getResponseProperties()
          Returns the web query's response property dictionary.
 Serializer<?> getSerializer()
          Returns the serializer used to stream the value passed to or from the web query.
 boolean isSecure()
           
 void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
           
 void setSerializer(Serializer<?> serializer)
          Sets the serializer used to stream the value passed to or from the web query.
 
Methods inherited from class pivot.util.concurrent.Task
abort, execute, execute, getDispatcher, 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(java.lang.String hostname,
             int port,
             java.lang.String path,
             boolean secure)
Creates a new web query.

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

getHostname

public java.lang.String getHostname()

getPath

public java.lang.String getPath()

getPort

public int getPort()

isSecure

public boolean isSecure()

getHostnameVerifier

public javax.net.ssl.HostnameVerifier getHostnameVerifier()

setHostnameVerifier

public void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)

getLocation

public java.net.URL getLocation()

getArguments

public Query.ArgumentsDictionary getArguments()
Returns the web query's arguments dictionary. Arguments are passed via the query string of the web query's URL.


getRequestProperties

public Query.RequestPropertiesDictionary getRequestProperties()
Returns the web query's request property dictionary. Request properties are passed via HTTP headers when the query is executed.


getResponseProperties

public Query.ResponsePropertiesDictionary getResponseProperties()
Returns the web query's response property dictionary. Response properties are returned via HTTP headers when the query is executed.


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 java.lang.Object execute(Query.Method method,
                                   java.lang.Object value)
                            throws QueryException
Throws:
QueryException

getQueryListeners

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