hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r936621 - in /hadoop/zookeeper/trunk: ./ src/contrib/rest/ src/contrib/rest/lib/ src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/
Date Thu, 22 Apr 2010 05:42:52 GMT
Author: phunt
Date: Thu Apr 22 05:42:51 2010
New Revision: 936621

URL: http://svn.apache.org/viewvc?rev=936621&view=rev
Log:
ZOOKEEPER-741. root level create on REST proxy fails

Added:
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java
Removed:
    hadoop/zookeeper/trunk/src/contrib/rest/lib/
Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/ivysettings.xml
    hadoop/zookeeper/trunk/src/contrib/rest/NOTICE.txt
    hadoop/zookeeper/trunk/src/contrib/rest/README.txt
    hadoop/zookeeper/trunk/src/contrib/rest/build.xml
    hadoop/zookeeper/trunk/src/contrib/rest/ivy.xml
    hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java
    hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Thu Apr 22 05:42:51 2010
@@ -18,6 +18,8 @@ BUGFIXES: 
   ZOOKEEPER-722. zkServer.sh uses sh's builtin echo on BSD, behaves
   incorrectly. (Ivan Kelly via phunt)
 
+  ZOOKEEPER-741. root level create on REST proxy fails (phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/ivysettings.xml
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/ivysettings.xml?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/ivysettings.xml (original)
+++ hadoop/zookeeper/trunk/ivysettings.xml Thu Apr 22 05:42:51 2010
@@ -21,6 +21,8 @@
     value="http://repo1.maven.org/maven2/" override="false"/>
   <property name="repo.jboss.org"
     value="http://repository.jboss.com/maven2/" override="false"/>
+  <property name="repo.sun.org"
+    value="http://download.java.net/maven/2/" override="false"/>
   <property name="maven2.pattern"
     value="[organisation]/[module]/[revision]/[module]-[revision]"/>
   <property name="maven2.pattern.ext" value="${maven2.pattern}.[ext]"/>
@@ -31,10 +33,13 @@
       pattern="${maven2.pattern.ext}" m2compatible="true"/>
     <ibiblio name="jboss-maven2" root="${repo.jboss.org}"
       pattern="${maven2.pattern.ext}" m2compatible="true"/>
+    <ibiblio name="sun-maven2" root="${repo.sun.org}"
+      pattern="${maven2.pattern.ext}" m2compatible="true"/>
 
     <chain name="default" dual="true">
       <resolver ref="maven2"/>
       <resolver ref="jboss-maven2"/>
+      <resolver ref="sun-maven2"/>
     </chain>
 
   </resolvers>

Modified: hadoop/zookeeper/trunk/src/contrib/rest/NOTICE.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/NOTICE.txt?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/NOTICE.txt (original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/NOTICE.txt Thu Apr 22 05:42:51 2010
@@ -1,7 +1,7 @@
 This contrib module includes software developed under the
 COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
 
-The lib sub-directory includes binary only jar libraries developed at:
+This contrib depends on binary only jar libraries developed at:
 
 https://jersey.dev.java.net/
 https://grizzly.dev.java.net/

Modified: hadoop/zookeeper/trunk/src/contrib/rest/README.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/README.txt?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/README.txt (original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/README.txt Thu Apr 22 05:42:51 2010
@@ -28,3 +28,28 @@ or use the provided src/python scripts 
 Tests:
 
 1) the full testsuite can be run via "ant test" target
+
+
+----------
+Examples Using CURL
+
+First review the spec SPEC.txt in this directory.
+
+#get the root node data
+curl http://localhost:9998/znodes/v1/
+
+#get children of the root node
+curl http://localhost:9998/znodes/v1/?view=children
+
+#get "/cluster1/leader" as xml (default is json)
+curl -H'Accept: application/xml' http://localhost:9998/znodes/v1/cluster1/leader
+
+#get the data as text
+curl -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster1/leader?dataformat=utf8"
+
+#set a node (data.txt contains the ascii text you want to set on the node)
+curl -T data.txt -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster1/leader?dataformat=utf8"
+
+#create a node
+curl -d "data1" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/?op=create&name=cluster2&dataformat=utf8"
+curl -d "data2" -H'Content-Type: application/octet-stream' -w "\n%{http_code}\n" "http://localhost:9998/znodes/v1/cluster2?op=create&name=leader&dataformat=utf8"

Modified: hadoop/zookeeper/trunk/src/contrib/rest/build.xml
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/build.xml?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/build.xml (original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/build.xml Thu Apr 22 05:42:51 2010
@@ -35,8 +35,6 @@
     <property name="test.junit.maxmem" value="512m" />
 
   <target name="setjarname">
-    <property name="main.jarname"
-              value="${zk.root}/build/zookeeper-${version}.jar"/>
     <property name="jarname"
               value="${build.dir}/zookeeper-${version}-${name}.jar"/>
   </target>
@@ -129,8 +127,8 @@
       <arg value="localhost:2181" />
       <classpath>
         <pathelement path="${jarname}" />
-        <pathelement path="${main.jarname}" />
-        <fileset dir="${root}" includes="lib/*.jar"/>
+        <fileset dir="${build.dir}/lib" includes="*.jar"/>
+        <fileset dir="${zk.root}/build" includes="zookeeper-*.jar"/>
         <pathelement path="${zk.root}/conf" />
         <fileset dir="${zk.root}/src/java/lib">
           <include name="**/*.jar" />

Modified: hadoop/zookeeper/trunk/src/contrib/rest/ivy.xml
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/ivy.xml?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/ivy.xml (original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/ivy.xml Thu Apr 22 05:42:51 2010
@@ -22,7 +22,7 @@
         module="${name}" revision="${version}">
     <license name="Apache 2.0"/>
     <ivyauthor name="Apache Hadoop" url="http://hadoop.apache.org"/>
-    <description>ZooKeeper-REST</description>
+    <description>ZooKeeper REST</description>
   </info>
 
   <configurations defaultconfmapping="default">
@@ -33,8 +33,13 @@
   <dependencies>
     <!-- transitive false turns off dependency checking, log4j deps seem borked -->
     <dependency org="log4j" name="log4j" rev="1.2.15" transitive="false"/>
+    <dependency org="asm" name="asm" rev="3.1" />
+    <dependency org="com.sun.grizzly" name="grizzly-servlet-webserver" rev="1.9.8" />
+    <dependency org="com.sun.jersey" name="jersey-server" rev="1.1.5.1" />
+    <dependency org="com.sun.jersey" name="jersey-json" rev="1.1.5.1" />
 
-    <dependency org="junit" name="junit" rev="4.7" conf="test->default"/>
+    <dependency org="junit" name="junit" rev="4.8.1" conf="test->default"/>
+    <dependency org="com.sun.jersey" name="jersey-client" rev="1.1.5.1" conf="test->default"/>
   </dependencies>
 
 </ivy-module>

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/RuntimeExceptionMapper.java
Thu Apr 22 05:42:51 2010
@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper.server.jersey.resources;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
@@ -40,9 +41,15 @@ public class RuntimeExceptionMapper
     }
 
     public Response toResponse(RuntimeException e) {
+        // don't try to handle jersey exceptions ourselves
+        if (e instanceof WebApplicationException) { 
+            WebApplicationException ie =(WebApplicationException) e; 
+            return ie.getResponse(); 
+        } 
+
         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
                 new ZError(ui.getRequestUri().toString(),
-                        "Error processing request due to " + e.getMessage()
+                        "Error processing request due to " + e
                         )).build();
     }
 }

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/java/org/apache/zookeeper/server/jersey/resources/ZNodeResource.java
Thu Apr 22 05:42:51 2010
@@ -58,7 +58,7 @@ import com.sun.jersey.api.json.JSONWithP
  * Version 1 implementation of the ZooKeeper REST specification.
  */
 // TODO test octet fully
-@Path("znodes/v1/{path: .*}")
+@Path("znodes/v1{path: /.*}")
 public class ZNodeResource {
     private final ZooKeeper zk;
 
@@ -66,17 +66,37 @@ public class ZNodeResource {
         zk = ZooKeeperService.getClient(ui.getBaseUri().toString());
     }
 
+    private void ensurePathNotNull(String path) {
+        if (path == null) {
+            throw new IllegalArgumentException("Invalid path \"" + path + "\"");
+        }
+    }
+
     @HEAD
     @Produces({MediaType.APPLICATION_JSON, "application/javascript",
-        MediaType.APPLICATION_XML, MediaType.APPLICATION_OCTET_STREAM})
-    public void existsZNode(@PathParam("path") String path, @Context UriInfo ui)
+        MediaType.APPLICATION_XML})
+    public Response existsZNode(@PathParam("path") String path,
+            @Context UriInfo ui)
+        throws InterruptedException, KeeperException
+    {
+        Stat stat = zk.exists(path, false);
+        if (stat == null) {
+            throwNotFound(path, ui);
+        }
+        return Response.status(Response.Status.OK).build();
+    }
+
+    @HEAD
+    @Produces({MediaType.APPLICATION_OCTET_STREAM})
+    public Response existsZNodeAsOctet(@PathParam("path") String path,
+            @Context UriInfo ui)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
         Stat stat = zk.exists(path, false);
         if (stat == null) {
             throwNotFound(path, ui);
         }
+        return Response.status(Response.Status.NO_CONTENT).build();
     }
 
     /*
@@ -115,7 +135,8 @@ public class ZNodeResource {
             String view, String dataformat, UriInfo ui)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
+        ensurePathNotNull(path);
+
         if (view.equals("children")) {
             List<String> children = new ArrayList<String>();
             for (String child : zk.getChildren(path, false)) {
@@ -171,7 +192,8 @@ public class ZNodeResource {
     public Response getZNodeListAsOctet(@PathParam("path") String path)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
+        ensurePathNotNull(path);
+
         Stat stat = new Stat();
         byte[] data = zk.getData(path, false, stat);
 
@@ -195,7 +217,7 @@ public class ZNodeResource {
             byte[] data)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
+        ensurePathNotNull(path);
 
         int version;
         try {
@@ -235,7 +257,7 @@ public class ZNodeResource {
             byte[] data)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
+        ensurePathNotNull(path);
 
         int version;
         try {
@@ -269,7 +291,13 @@ public class ZNodeResource {
             byte[] data)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path + "/" + name;
+        ensurePathNotNull(path);
+
+        if (path.equals("/")) {
+            path += name;
+        } else {
+            path += "/" + name;
+        }
 
         if (!op.equals("create")) {
             throw new WebApplicationException(Response.status(
@@ -311,7 +339,13 @@ public class ZNodeResource {
             byte[] data)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path + "/" + name;
+        ensurePathNotNull(path);
+
+        if (path.equals("/")) {
+            path += name;
+        } else {
+            path += "/" + name;
+        }
 
         if (!op.equals("create")) {
             throw new WebApplicationException(Response.status(
@@ -348,7 +382,7 @@ public class ZNodeResource {
             @Context UriInfo ui)
         throws InterruptedException, KeeperException
     {
-        path = "/" + path;
+        ensurePathNotNull(path);
 
         int version;
         try {

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/CreateTest.java
Thu Apr 22 05:42:51 2010
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.WatchedEvent;
@@ -51,7 +50,7 @@ public class CreateTest extends Base {
     private String path;
     private String name;
     private String encoding;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
     private ZPath expectedPath;
     private byte[] data;
     private boolean sequence;
@@ -69,38 +68,38 @@ public class CreateTest extends Base {
         return Arrays.asList(new Object[][] {
           {MediaType.APPLICATION_JSON,
               baseZnode, "foo bar", "utf8",
-              Response.Status.CREATED,
+              ClientResponse.Status.CREATED,
               new ZPath(baseZnode + "/foo bar"), null,
               false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-t1"), null,
-              false },
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t1"),
+              null, false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t1", "utf8",
-              Response.Status.CONFLICT, null, null, false },
+              ClientResponse.Status.CONFLICT, null, null, false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-t2"),
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t2"),
               "".getBytes(), false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t2", "utf8",
-              Response.Status.CONFLICT, null, null, false },
+              ClientResponse.Status.CONFLICT, null, null, false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-t3"),
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t3"),
               "foo".getBytes(), false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t3", "utf8",
-              Response.Status.CONFLICT, null, null, false },
+              ClientResponse.Status.CONFLICT, null, null, false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-t4", "base64",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-t4"),
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-t4"),
               "foo".getBytes(), false },
           {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-"), null,
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null,
               true },
           {MediaType.APPLICATION_JSON, baseZnode, "c-", "utf8",
-              Response.Status.CREATED, new ZPath(baseZnode + "/c-"), null,
+              ClientResponse.Status.CREATED, new ZPath(baseZnode + "/c-"), null,
               true }
           });
     }
 
     public CreateTest(String accept, String path, String name, String encoding,
-            Response.Status status, ZPath expectedPath, byte[] data,
+            ClientResponse.Status status, ZPath expectedPath, byte[] data,
             boolean sequence)
     {
         this.accept = accept;
@@ -134,7 +133,7 @@ public class CreateTest extends Base {
         } else {
             cr = builder.post(ClientResponse.class, data);
         }
-        assertEquals(expectedStatus, cr.getResponseStatus());
+        assertEquals(expectedStatus, cr.getClientResponseStatus());
 
         if (expectedPath == null) {
             return;

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/DeleteTest.java
Thu Apr 22 05:42:51 2010
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
@@ -47,7 +46,7 @@ public class DeleteTest extends Base {
     protected static final Logger LOG = Logger.getLogger(DeleteTest.class);
 
     private String zpath;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
 
     public static class MyWatcher implements Watcher {
         public void process(WatchedEvent event) {
@@ -60,25 +59,25 @@ public class DeleteTest extends Base {
         String baseZnode = Base.createBaseZNode();
 
         return Arrays.asList(new Object[][] {
-          {baseZnode, baseZnode, Response.Status.NO_CONTENT },
-          {baseZnode, baseZnode, Response.Status.NO_CONTENT }
+          {baseZnode, baseZnode, ClientResponse.Status.NO_CONTENT },
+          {baseZnode, baseZnode, ClientResponse.Status.NO_CONTENT }
         });
     }
 
-    public DeleteTest(String path, String zpath, Response.Status status) {
+    public DeleteTest(String path, String zpath, ClientResponse.Status status) {
         this.zpath = zpath;
         this.expectedStatus = status;
     }
 
     public void verify(String type) throws Exception {
-        if (expectedStatus != Response.Status.NOT_FOUND) {
+        if (expectedStatus != ClientResponse.Status.NOT_FOUND) {
             zpath = zk.create(zpath, null, Ids.OPEN_ACL_UNSAFE,
                     CreateMode.PERSISTENT_SEQUENTIAL);
         }
 
         ClientResponse cr = r.path(zpath).accept(type).type(type)
             .delete(ClientResponse.class);
-        assertEquals(expectedStatus, cr.getResponseStatus());
+        assertEquals(expectedStatus, cr.getClientResponseStatus());
 
         // use out-of-band method to verify
         Stat stat = zk.exists(zpath, false);

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/ExistsTest.java
Thu Apr 22 05:42:51 2010
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.junit.Test;
@@ -42,19 +41,19 @@ public class ExistsTest extends Base {
     protected static final Logger LOG = Logger.getLogger(ExistsTest.class);
 
     private String path;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
 
     @Parameters
     public static Collection<Object[]> data() throws Exception {
         String baseZnode = Base.createBaseZNode();
 
      return Arrays.asList(new Object[][] {
-      {baseZnode, Response.Status.OK },
-      {baseZnode + "dkdk38383", Response.Status.NOT_FOUND }
+      {baseZnode, ClientResponse.Status.OK },
+      {baseZnode + "dkdk38383", ClientResponse.Status.NOT_FOUND }
      });
     }
 
-    public ExistsTest(String path, Response.Status status) {
+    public ExistsTest(String path, ClientResponse.Status status) {
         this.path = path;
         this.expectedStatus = status;
     }
@@ -62,10 +61,11 @@ public class ExistsTest extends Base {
     private void verify(String type) {
         ClientResponse cr = r.path(path).accept(type).type(type).head();
         if (type.equals(MediaType.APPLICATION_OCTET_STREAM)
-                && expectedStatus == Response.Status.OK) {
-            assertEquals(Response.Status.NO_CONTENT, cr.getResponseStatus());
+                && expectedStatus == ClientResponse.Status.OK) {
+            assertEquals(ClientResponse.Status.NO_CONTENT,
+                    cr.getClientResponseStatus());
         } else {
-            assertEquals(expectedStatus, cr.getResponseStatus());
+            assertEquals(expectedStatus, cr.getClientResponseStatus());
         }
     }
 

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetChildrenTest.java
Thu Apr 22 05:42:51 2010
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
@@ -49,7 +48,7 @@ public class GetChildrenTest extends Bas
 
     private String accept;
     private String path;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
     private String expectedPath;
     private List<String> expectedChildren;
 
@@ -64,30 +63,30 @@ public class GetChildrenTest extends Bas
 
         return Arrays.asList(new Object[][] {
           {MediaType.APPLICATION_JSON, baseZnode + "abddkdkd",
-              Response.Status.NOT_FOUND, null, null },
+              ClientResponse.Status.NOT_FOUND, null, null },
           {MediaType.APPLICATION_XML, baseZnode + "abddkdkd",
-              Response.Status.NOT_FOUND, null, null },
-          {MediaType.APPLICATION_JSON, baseZnode, Response.Status.OK,
+              ClientResponse.Status.NOT_FOUND, null, null },
+          {MediaType.APPLICATION_JSON, baseZnode, ClientResponse.Status.OK,
               baseZnode, Arrays.asList(new String[] {}) },
-          {MediaType.APPLICATION_XML, baseZnode, Response.Status.OK,
+          {MediaType.APPLICATION_XML, baseZnode, ClientResponse.Status.OK,
               baseZnode, Arrays.asList(new String[] {}) },
-          {MediaType.APPLICATION_JSON, baseZnode, Response.Status.OK,
+          {MediaType.APPLICATION_JSON, baseZnode, ClientResponse.Status.OK,
               baseZnode, Arrays.asList(new String[] {"c1"}) },
-          {MediaType.APPLICATION_XML, baseZnode4, Response.Status.OK,
+          {MediaType.APPLICATION_XML, baseZnode4, ClientResponse.Status.OK,
               baseZnode4, Arrays.asList(new String[] {"c1"}) },
-          {MediaType.APPLICATION_JSON, baseZnode2, Response.Status.OK,
+          {MediaType.APPLICATION_JSON, baseZnode2, ClientResponse.Status.OK,
               baseZnode2, Arrays.asList(new String[] {"c1", "c2"}) },
-          {MediaType.APPLICATION_XML, baseZnode5, Response.Status.OK,
+          {MediaType.APPLICATION_XML, baseZnode5, ClientResponse.Status.OK,
               baseZnode5, Arrays.asList(new String[] {"c1", "c2"}) },
-          {MediaType.APPLICATION_JSON, baseZnode3, Response.Status.OK,
+          {MediaType.APPLICATION_JSON, baseZnode3, ClientResponse.Status.OK,
               baseZnode3, Arrays.asList(new String[] {"c1", "c2", "c3", "c4"}) },
-          {MediaType.APPLICATION_XML, baseZnode6, Response.Status.OK,
+          {MediaType.APPLICATION_XML, baseZnode6, ClientResponse.Status.OK,
               baseZnode6, Arrays.asList(new String[] {"c1", "c2", "c3", "c4"}) }
 
           });
     }
 
-    public GetChildrenTest(String accept, String path, Response.Status status,
+    public GetChildrenTest(String accept, String path, ClientResponse.Status status,
             String expectedPath, List<String> expectedChildren)
     {
         this.accept = accept;
@@ -110,7 +109,7 @@ public class GetChildrenTest extends Bas
 
         ClientResponse cr = r.path(path).queryParam("view", "children")
             .accept(accept).get(ClientResponse.class);
-        assertEquals(expectedStatus, cr.getResponseStatus());
+        assertEquals(expectedStatus, cr.getClientResponseStatus());
 
         if (expectedChildren == null) {
             return;

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/GetTest.java
Thu Apr 22 05:42:51 2010
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.server.jersey.jaxb.ZStat;
@@ -45,7 +44,7 @@ public class GetTest extends Base {
     private String accept;
     private String path;
     private String encoding;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
     private ZStat expectedStat;
 
     @Parameters
@@ -54,39 +53,39 @@ public class GetTest extends Base {
 
      return Arrays.asList(new Object[][] {
       {MediaType.APPLICATION_JSON, baseZnode, "utf8",
-          Response.Status.OK, new ZStat(baseZnode, null, null) },
+          ClientResponse.Status.OK, new ZStat(baseZnode, null, null) },
       {MediaType.APPLICATION_JSON, baseZnode, "utf8",
-          Response.Status.OK, new ZStat(baseZnode, null, "") },
+          ClientResponse.Status.OK, new ZStat(baseZnode, null, "") },
       {MediaType.APPLICATION_JSON, baseZnode, "utf8",
-          Response.Status.OK, new ZStat(baseZnode, null, "foo") },
+          ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo") },
       {MediaType.APPLICATION_JSON, baseZnode, "base64",
-          Response.Status.OK, new ZStat(baseZnode, null, null) },
+          ClientResponse.Status.OK, new ZStat(baseZnode, null, null) },
       {MediaType.APPLICATION_JSON, baseZnode, "base64",
-          Response.Status.OK, new ZStat(baseZnode, "".getBytes(), null) },
+          ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null) },
       {MediaType.APPLICATION_JSON, baseZnode, "base64",
-          Response.Status.OK, new ZStat(baseZnode, "".getBytes(), null) },
+          ClientResponse.Status.OK, new ZStat(baseZnode, "".getBytes(), null) },
       {MediaType.APPLICATION_JSON, baseZnode, "base64",
-              Response.Status.OK, new ZStat(baseZnode, "foo".getBytes(), null) },
+              ClientResponse.Status.OK, new ZStat(baseZnode, "foo".getBytes(), null) },
       {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "utf8",
-                      Response.Status.NOT_FOUND, null },
+                      ClientResponse.Status.NOT_FOUND, null },
       {MediaType.APPLICATION_JSON, baseZnode + "abaddkdk", "base64",
-              Response.Status.NOT_FOUND, null },
+              ClientResponse.Status.NOT_FOUND, null },
 
       {MediaType.APPLICATION_XML, baseZnode, "utf8",
-                  Response.Status.OK, new ZStat(baseZnode, null, "foo") },
+                  ClientResponse.Status.OK, new ZStat(baseZnode, null, "foo") },
       {MediaType.APPLICATION_XML, baseZnode, "base64",
-                      Response.Status.OK,
+                      ClientResponse.Status.OK,
                       new ZStat(baseZnode, "foo".getBytes(), null) },
       {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "utf8",
-                      Response.Status.NOT_FOUND, null },
+                      ClientResponse.Status.NOT_FOUND, null },
       {MediaType.APPLICATION_XML, baseZnode + "abaddkdk", "base64",
-              Response.Status.NOT_FOUND, null }
+              ClientResponse.Status.NOT_FOUND, null }
 
      });
     }
 
     public GetTest(String accept, String path, String encoding,
-            Response.Status status, ZStat stat)
+            ClientResponse.Status status, ZStat stat)
     {
         this.accept = accept;
         this.path = path;
@@ -110,7 +109,7 @@ public class GetTest extends Base {
 
         ClientResponse cr = r.path(path).queryParam("dataformat", encoding)
             .accept(accept).get(ClientResponse.class);
-        assertEquals(expectedStatus, cr.getResponseStatus());
+        assertEquals(expectedStatus, cr.getClientResponseStatus());
 
         if (expectedStat == null) {
             return;

Added: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java?rev=936621&view=auto
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java
(added)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/RootTest.java
Thu Apr 22 05:42:51 2010
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper.server.jersey;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.log4j.Logger;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.data.Stat;
+import org.apache.zookeeper.server.jersey.jaxb.ZPath;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.WebResource.Builder;
+
+
+/**
+ * Test stand-alone server.
+ *
+ */
+public class RootTest extends Base {
+    protected static final Logger LOG = Logger.getLogger(RootTest.class);
+
+    @Test
+    public void testCreate() throws Exception {
+        LOG.info("STARTING " + getName());
+        
+        String path = "/";
+        String name = "roottest-create";
+        byte[] data = "foo".getBytes();
+
+        WebResource wr = r.path(path).queryParam("dataformat", "utf8")
+            .queryParam("name", name);
+        Builder builder = wr.accept(MediaType.APPLICATION_JSON);
+
+        ClientResponse cr;
+        cr = builder.post(ClientResponse.class, data);
+        assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());
+
+        ZPath zpath = cr.getEntity(ZPath.class);
+        assertEquals(new ZPath(path + name), zpath);
+        assertEquals(r.path(path).toString(), zpath.uri);
+
+        // use out-of-band method to verify
+        byte[] rdata = zk.getData(zpath.path, false, new Stat());
+        assertTrue(new String(rdata) + " == " + new String(data),
+                Arrays.equals(rdata, data));
+    }
+}

Modified: hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java?rev=936621&r1=936620&r2=936621&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java
(original)
+++ hadoop/zookeeper/trunk/src/contrib/rest/src/test/org/apache/zookeeper/server/jersey/SetTest.java
Thu Apr 22 05:42:51 2010
@@ -22,7 +22,6 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
@@ -52,7 +51,7 @@ public class SetTest extends Base {
     private String accept;
     private String path;
     private String encoding;
-    private Response.Status expectedStatus;
+    private ClientResponse.Status expectedStatus;
     private ZStat expectedStat;
     private byte[] data;
 
@@ -68,33 +67,33 @@ public class SetTest extends Base {
 
         return Arrays.asList(new Object[][] {
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t1", "utf8",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t1", null, null), null },
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t2", "utf8",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t2", null, null), new byte[0] },
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t3", "utf8",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t3", null, null), "foobar".getBytes() },
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t4", "base64",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t4", null, null), null },
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t5", "base64",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t5", null, null), new byte[0] },
           {MediaType.APPLICATION_JSON, baseZnode + "/s-t6", "base64",
-              Response.Status.OK,
+              ClientResponse.Status.OK,
               new ZStat(baseZnode + "/s-t6", null, null),
               "foobar".getBytes() },
           {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "utf8",
-              Response.Status.NOT_FOUND, null, null },
+              ClientResponse.Status.NOT_FOUND, null, null },
           {MediaType.APPLICATION_JSON, baseZnode + "/dkdkdkd", "base64",
-              Response.Status.NOT_FOUND, null, null },
+              ClientResponse.Status.NOT_FOUND, null, null },
           });
     }
 
     public SetTest(String accept, String path, String encoding,
-            Response.Status status, ZStat expectedStat, byte[] data)
+            ClientResponse.Status status, ZStat expectedStat, byte[] data)
     {
         this.accept = accept;
         this.path = path;
@@ -131,7 +130,7 @@ public class SetTest extends Base {
             // TODO investigate
             cr = builder.put(ClientResponse.class, new String(data));
         }
-        assertEquals(expectedStatus, cr.getResponseStatus());
+        assertEquals(expectedStatus, cr.getClientResponseStatus());
 
         if (expectedStat == null) {
             return;



Mime
View raw message