cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r584583 - in /incubator/cxf/branches/jliu: distribution/src/main/release/samples/ distribution/src/main/release/samples/restful_jaxrs/ distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/ distribution/src/main/release/...
Date Sun, 14 Oct 2007 19:13:13 GMT
Author: jliu
Date: Sun Oct 14 12:13:12 2007
New Revision: 584583

URL: http://svn.apache.org/viewvc?rev=584583&view=rev
Log:
Update jax-rs demo. 

Modified:
    incubator/cxf/branches/jliu/distribution/src/main/release/samples/common_build.xml
    incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/README.txt
    incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
    incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
    incubator/cxf/branches/jliu/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java

Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/common_build.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/common_build.xml?rev=584583&r1=584582&r2=584583&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/common_build.xml (original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/common_build.xml Sun
Oct 14 12:13:12 2007
@@ -112,8 +112,8 @@
         </javac>
 
         <copy todir="${build.classes.dir}">
-            <fileset dir="${basedir}/src" includes="**/*.xml" />
-            <fileset dir="${build.src.dir}" includes="**/*.xml" />
+            <fileset dir="${basedir}/src" includes="**/*.xml, **/*.txt" />
+            <fileset dir="${build.src.dir}" includes="**/*.xml, **/*.txt" />
         </copy>
     </target>
 

Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/README.txt
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/README.txt?rev=584583&r1=584582&r2=584583&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/README.txt
(original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/README.txt
Sun Oct 14 12:13:12 2007
@@ -6,28 +6,36 @@
 A RESTful customer service is provided on URL http://localhost:9000/customers. 
 Users access this URI to operate on customer.
 
-A HTTP GET request to URL http://localhost:9000/customers/1234 
-returns a customer instance whose id is 1234. The XML document returned:
+A HTTP GET request to URL http://localhost:9000/customerservice/customers/123
+returns a customer instance whose id is 123. The XML document returned:
 
 <Customer>
-  <id>1234</id>
+  <id>123</id>
   <name>John</name>
-  <phoneNumber>123456</phoneNumber>
 </Customer>
 
-A HTTP POST request to URL http://localhost:9000/customers 
+A HTTP POST request to URL http://localhost:9000/customerservice/customers
 with the data:
 
 <Customer>
-  <id>1234</id>
+  <name>Jack</name>
+</Customer>
+
+adds a customer whose name is Jack 
+
+
+A HTTP PUT request to URL http://localhost:9000/customerservice/customers
+with the data:
+
+<Customer>
+  <id>123</id>
   <name>John</name>
-  <phoneNumber>123456</phoneNumber>
 </Customer>
 
-updates customer 1234 with the data provided. 
+updates the customer instance whose id is 123
+
 
-The client code demonstrates how to send HTTP POST with XML data using 
-JAX-WS Dispatch and how to send HTTP GET using URL.openStream(). The 
+The client code demonstrates how to send HTTP GET/POST/PUT/DELETE request. The 
 server code demonstrates how to build a RESTful endpoints through 
 JAX-RS (JSR-311) APIs.
 

Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java?rev=584583&r1=584582&r2=584583&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
(original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
Sun Oct 14 12:13:12 2007
@@ -47,16 +47,17 @@
          */
 
         // Sent HTTP GET request to query customer info
-        URL url = new URL("http://localhost:9000/customers/123");
-        System.out.println("Invoking server through HTTP GET to query customer info");
+        System.out.println("Sent HTTP GET request to query customer info");
+        URL url = new URL("http://localhost:9000/customerservice/customers/123");
         InputStream in = url.openStream();
         System.out.println(getStringFromInputStream(in));
 
         // Sent HTTP PUT request to update customer info
+        System.out.println("Sent HTTP PUT request to update customer info");
         Client client = new Client();
         String inputFile = client.getClass().getResource("update_customer.txt").getFile();
         File input = new File(inputFile);
-        PutMethod put = new PutMethod("http://localhost:9000/customers");
+        PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
         RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
         put.setRequestEntity(entity);
         HttpClient httpclient = new HttpClient();
@@ -73,9 +74,10 @@
         }
 
         // Sent HTTP POST request to add customer
+        System.out.println("Sent HTTP POST request to add customer");
         inputFile = client.getClass().getResource("add_customer.txt").getFile();
         input = new File(inputFile);
-        PostMethod post = new PostMethod("http://localhost:9000/customers");
+        PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
         entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
         post.setRequestEntity(entity);
         httpclient = new HttpClient();
@@ -90,6 +92,13 @@
             // done
             post.releaseConnection();
         }
+
+        // Sent HTTP GET request to query customer info, expect JSON.
+        System.out.println("Sent HTTP GET request to query customer info");
+        url = new URL("http://localhost:9000/customerservice/customersjson/123");
+        in = url.openStream();
+        System.out.println(getStringFromInputStream(in));
+
 
         System.out.println("Client Invoking is succeeded!");
         System.exit(0);

Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java?rev=584583&r1=584582&r2=584583&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
(original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
Sun Oct 14 12:13:12 2007
@@ -22,14 +22,14 @@
 import java.util.Map;
 
 import javax.ws.rs.HttpMethod;
-// import javax.ws.rs.ProduceMime;
+import javax.ws.rs.ProduceMime;
 import javax.ws.rs.UriParam;
 import javax.ws.rs.UriTemplate;
 import javax.ws.rs.core.HttpContext;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
-@UriTemplate("/customers/")
+@UriTemplate("/customerservice/")
 public class CustomerService {
     @HttpContext UriInfo uriInfo;
 
@@ -43,9 +43,10 @@
 
     @HttpMethod("GET")
     @UriTemplate("/customers/{id}/")
-    Customer getCustomer(@UriParam("id") String id) {
+    public Customer getCustomer(@UriParam("id") String id) {
         System.out.println("----invoking getCustomer, Customer id is: " + id);
-        Customer c = customers.get(id);
+        long idNumber = Long.parseLong(id);
+        Customer c = customers.get(idNumber);
         return c;
     }
 
@@ -66,9 +67,9 @@
     }
 
     @HttpMethod("POST")
-    @UriTemplate("/customers")
+    @UriTemplate("/customers/")
     public Response addCustomer(Customer customer) {
-        System.out.println("----invoking addCustomer, customer name is: " + customer.getName());
+        System.out.println("----invoking addCustomer, Customer name is: " + customer.getName());
         customer.setId(++currentId);
 
         customers.put(customer.getId(), customer);
@@ -79,9 +80,8 @@
     @HttpMethod("DELETE")
     @UriTemplate("/customers/{id}/")
     public Response deleteCustomer(@UriParam("id") String id) {
-        System.out.println("----invoking deleteCustomer with id: " + id);
+        System.out.println("----invoking deleteCustomer, Customer id is: " + id);
         long idNumber = Long.parseLong(id);
-        boolean found = false;
         Customer c = customers.get(idNumber);
 
         Response r;
@@ -93,6 +93,22 @@
         }
 
         return r;
+    }
+
+    @HttpMethod("GET")
+    @UriTemplate("/customersjson/{id}/")
+    @ProduceMime("application/json")
+    public Customer getCustomerJSON(@UriParam("id") String id) {
+        System.out.println("----invoking getCustomerJSON, Customer id is: " + id);
+        long idNumber = Long.parseLong(id);
+        Customer c = customers.get(idNumber);
+        return c;
+    }
+
+    //FIXME: wont work if remove this method, has to set hasSubResource to true
+    @UriTemplate("/items")
+    public Response getItem(@UriParam("id") String id) {
+        return null;
     }
 
     final Customer createCustomer() {

Modified: incubator/cxf/branches/jliu/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=584583&r1=584582&r2=584583&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ incubator/cxf/branches/jliu/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Sun Oct 14 12:13:12 2007
@@ -28,7 +28,7 @@
 
     protected void run() {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        sf.setResourceClasses(BookStore.class);
+        sf.setResourceClasses(CustomerService.class);
         sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
         sf.setAddress("http://localhost:9080/xml/");
 



Mime
View raw message