You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/05/22 17:16:41 UTC
svn commit: r777568 - in /incubator/pivot/trunk/web: .classpath
src/pivot/web/DeleteQuery.java src/pivot/web/GetQuery.java
src/pivot/web/PostQuery.java src/pivot/web/PutQuery.java
src/pivot/web/Query.java test/pivot/web/test/WebQueryTestClient.java
Author: gbrown
Date: Fri May 22 15:16:40 2009
New Revision: 777568
URL: http://svn.apache.org/viewvc?rev=777568&view=rev
Log:
Update web project (remove dependency on WTK and add test as a source folder); add getStatus() and getMethod() methods to pivot.web.Query.
Modified:
incubator/pivot/trunk/web/.classpath
incubator/pivot/trunk/web/src/pivot/web/DeleteQuery.java
incubator/pivot/trunk/web/src/pivot/web/GetQuery.java
incubator/pivot/trunk/web/src/pivot/web/PostQuery.java
incubator/pivot/trunk/web/src/pivot/web/PutQuery.java
incubator/pivot/trunk/web/src/pivot/web/Query.java
incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java
Modified: incubator/pivot/trunk/web/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/.classpath?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/.classpath (original)
+++ incubator/pivot/trunk/web/.classpath Fri May 22 15:16:40 2009
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry kind="lib" path="lib/servlet-api.jar"/>
Modified: incubator/pivot/trunk/web/src/pivot/web/DeleteQuery.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/DeleteQuery.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/DeleteQuery.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/DeleteQuery.java Fri May 22 15:16:40 2009
@@ -22,6 +22,8 @@
* @author gbrown
*/
public class DeleteQuery extends Query<Void> {
+ public static final Method METHOD = Method.DELETE;
+
public DeleteQuery(String hostname, String path) {
this(hostname, DEFAULT_PORT, path, false);
}
@@ -30,12 +32,16 @@
super(hostname, port, path, secure);
}
+ public Method getMethod() {
+ return METHOD;
+ }
+
/**
* Synchronously executes the DELETE operation.
*/
@Override
public Void execute() throws QueryException {
- execute(Method.DELETE, null);
+ execute(METHOD, null);
return null;
}
}
Modified: incubator/pivot/trunk/web/src/pivot/web/GetQuery.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/GetQuery.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/GetQuery.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/GetQuery.java Fri May 22 15:16:40 2009
@@ -22,6 +22,8 @@
* @author gbrown
*/
public class GetQuery extends Query<Object> {
+ public static final Method METHOD = Method.GET;
+
public GetQuery(String hostname, String path) {
this(hostname, DEFAULT_PORT, path, false);
}
@@ -30,6 +32,10 @@
super(hostname, port, path, secure);
}
+ public Method getMethod() {
+ return METHOD;
+ }
+
/**
* Synchronously executes the GET operation.
*
@@ -38,6 +44,6 @@
*/
@Override
public Object execute() throws QueryException {
- return execute(Method.GET, null);
+ return execute(METHOD, null);
}
}
Modified: incubator/pivot/trunk/web/src/pivot/web/PostQuery.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/PostQuery.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/PostQuery.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/PostQuery.java Fri May 22 15:16:40 2009
@@ -27,6 +27,8 @@
public class PostQuery extends Query<URL> {
private Object value = null;
+ public static final Method METHOD = Method.POST;
+
public PostQuery(String hostname, String path) {
this(hostname, DEFAULT_PORT, path, false);
}
@@ -35,6 +37,10 @@
super(hostname, port, path, secure);
}
+ public Method getMethod() {
+ return METHOD;
+ }
+
/**
* Returns the value that will be POSTed to the server when the query is
* executed.
@@ -66,7 +72,7 @@
public URL execute() throws QueryException {
URL valueLocation = null;
- execute(Method.POST, value);
+ execute(METHOD, value);
String location = getResponseProperties().get("Location");
if (location != null) {
Modified: incubator/pivot/trunk/web/src/pivot/web/PutQuery.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/PutQuery.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/PutQuery.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/PutQuery.java Fri May 22 15:16:40 2009
@@ -24,6 +24,8 @@
public class PutQuery extends Query<Void> {
private Object value = null;
+ public static final Method METHOD = Method.DELETE;
+
public PutQuery(String hostname, String path) {
this(hostname, DEFAULT_PORT, path, false);
}
@@ -32,6 +34,10 @@
super(hostname, port, path, secure);
}
+ public Method getMethod() {
+ return METHOD;
+ }
+
/**
* Returns the value that will be PUT to the server when the query is
* executed.
@@ -56,7 +62,7 @@
*/
@Override
public Void execute() throws QueryException {
- execute(Method.PUT, value);
+ execute(METHOD, value);
return null;
}
}
Modified: incubator/pivot/trunk/web/src/pivot/web/Query.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/Query.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/Query.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/Query.java Fri May 22 15:16:40 2009
@@ -201,16 +201,16 @@
private ArgumentsDictionary argumentsDictionary = new ArgumentsDictionary();
private RequestPropertiesDictionary requestPropertiesDictionary = new RequestPropertiesDictionary();
private ResponsePropertiesDictionary responsePropertiesDictionary = new ResponsePropertiesDictionary();
-
- private Serializer<?> serializer = new JSONSerializer();
+ private int status = 0;
private volatile long bytesExpected = -1;
- private QueryListenerList<V> queryListeners = new QueryListenerList<V>();
+ private Serializer<?> serializer = new JSONSerializer();
- private static Dispatcher DEFAULT_DISPATCHER = new Dispatcher();
+ private QueryListenerList<V> queryListeners = new QueryListenerList<V>();
public static final int DEFAULT_PORT = -1;
+ public static final Dispatcher DEFAULT_DISPATCHER = new Dispatcher();
private static final String HTTP_PROTOCOL = "http";
private static final String HTTPS_PROTOCOL = "https";
@@ -236,6 +236,8 @@
}
}
+ public abstract Method getMethod();
+
public String getHostname() {
return locationContext.getHost();
}
@@ -318,6 +320,16 @@
}
/**
+ * Returns the status of the most recent execution.
+ *
+ * @return
+ * An HTTP code representing the most recent execution status.
+ */
+ public int getStatus() {
+ return status;
+ }
+
+ /**
* Returns the serializer used to stream the value passed to or from the
* web query. By default, an instance of {@link JSONSerializer} is used.
*/
@@ -398,7 +410,7 @@
bytesReceived = 0;
bytesExpected = -1;
- int status = -1;
+ status = 0;
String message = null;
try {
Modified: incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java?rev=777568&r1=777567&r2=777568&view=diff
==============================================================================
--- incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java (original)
+++ incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java Fri May 22 15:16:40 2009
@@ -28,10 +28,8 @@
import pivot.web.DeleteQuery;
import pivot.web.PostQuery;
import pivot.web.PutQuery;
-import pivot.wtk.Application;
-import pivot.wtk.Display;
-public class WebQueryTestClient implements Application {
+public class WebQueryTestClient {
final static boolean useProxy = true;
final static String HOSTNAME = "localhost";
@@ -39,8 +37,7 @@
final static int PORT = 8080;
final static boolean SECURE = false;
- public void startup(Display display, Dictionary<String, String> properties)
- throws Exception {
+ public static void main(String[] args) throws Exception {
final BasicAuthentication authentication = new BasicAuthentication("foo", "bar");
// GET
@@ -52,12 +49,14 @@
getQuery.execute(new TaskListener<Object>() {
@SuppressWarnings("unchecked")
public void taskExecuted(Task<Object> task) {
- Dictionary<String, Object> result = (Dictionary<String, Object>)task.getResult();
+ GetQuery getQuery = (GetQuery)task;
+ Dictionary<String, Object> result = (Dictionary<String, Object>)getQuery.getResult();
System.out.println("GET result: "
+ "username: " + result.get("username") + ", "
+ "pathInfo: " + result.get("pathInfo") + ", "
- + "queryString: " + result.get("queryString"));
+ + "queryString: " + result.get("queryString")
+ + "status: " + getQuery.getStatus());
}
public void executeFailed(Task<Object> task) {
@@ -108,15 +107,8 @@
System.out.println("DELETE fault: " + task.getFault());
}
});
- }
-
- public boolean shutdown(boolean optional) {
- return true;
- }
-
- public void suspend() {
- }
- public void resume() {
+ // HACK - wait for all requests to complete
+ Thread.sleep(3000);
}
}