You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/12/19 16:38:17 UTC

svn commit: r605587 - in /incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs: README.txt src/demo/jaxrs/server/CustomerService.java src/demo/jaxrs/server/Order.java src/demo/jaxrs/server/Product.java

Author: jliu
Date: Wed Dec 19 07:38:16 2007
New Revision: 605587

URL: http://svn.apache.org/viewvc?rev=605587&view=rev
Log:
Update jax-rs demo to show how sub-resource works. 

Added:
    incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java   (with props)
    incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java   (with props)
Modified:
    incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/README.txt
    incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/README.txt
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/README.txt?rev=605587&r1=605586&r2=605587&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/README.txt (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/README.txt Wed Dec 19 07:38:16 2007
@@ -14,6 +14,10 @@
   <name>John</name>
 </Customer>
 
+A HTTP GET request to URL http://localhost:9000/customerservice/orders/223/products/1
+returns product 1 from order 223. 
+
+
 A HTTP POST request to URL http://localhost:9000/customerservice/customers
 with the data:
 

Modified: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java?rev=605587&r1=605586&r2=605587&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java Wed Dec 19 07:38:16 2007
@@ -35,10 +35,10 @@
 
     long currentId = 123;
     Map<Long, Customer> customers = new HashMap<Long, Customer>();
+    Map<Long, Order> orders = new HashMap<Long, Order>();
 
     public CustomerService() {
-        Customer customer = createCustomer();
-        customers.put(customer.getId(), customer);
+        init();
     }
 
     @HttpMethod("GET")
@@ -50,6 +50,16 @@
         return c;
     }
 
+    @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;
+    }
+
     @HttpMethod("PUT")
     @UriTemplate("/customers/")
     public Response updateCustomer(Customer customer) {
@@ -95,21 +105,24 @@
         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);
+    @UriTemplate("/orders/{orderId}/")
+    public Order getOrder(@UriParam("orderId") String orderId) {
+        System.out.println("----invoking getOrder, Order id is: " + orderId);
+        long idNumber = Long.parseLong(orderId);
+        Order c = orders.get(idNumber);
         return c;
     }
 
-    final Customer createCustomer() {
+    final void init() {
         Customer c = new Customer();
         c.setName("John");
         c.setId(123);
-        return c;
+        customers.put(c.getId(), c);
+
+        Order o = new Order();
+        o.setDescription("order 223");
+        o.setId(223);
+        orders.put(o.getId(), o);
     }
 
 }

Added: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java?rev=605587&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java Wed Dec 19 07:38:16 2007
@@ -0,0 +1,64 @@
+/**
+ * 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 demo.jaxrs.server;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.UriParam;
+import javax.ws.rs.UriTemplate;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Order")
+public class Order {
+    private long id;
+    private String description;
+    private Map<Long, Product> products = new HashMap<Long, Product>();
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String d) {
+        this.description = d;
+    }
+
+    @HttpMethod("GET")
+    @UriTemplate("products/{productId}/")
+    public Product getProduct(@UriParam("productId")int productId) {
+        System.out.println("----invoking getProduct with id: " + productId);
+
+        return products.get(new Long(productId));
+    }
+
+    final void init() {
+        Product p = new Product();
+        p.setId(1);
+        p.setDescription("product 1");
+        products.put(p.getId(), p);
+    }
+}

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Order.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java?rev=605587&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java Wed Dec 19 07:38:16 2007
@@ -0,0 +1,43 @@
+/**
+ * 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 demo.jaxrs.server;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Product")
+public class Product {
+    private long id;
+    private String description;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String d) {
+        this.description = d;
+    }
+}

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Product.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date