Permalink
Browse files

moved examples to restfulie project

  • Loading branch information...
guilhermesilveira committed Jan 25, 2010
1 parent 7a914d2 commit e75ed2c29ca522a7d253e890f44197b3a73700b7
Showing with 0 additions and 1,062 deletions.
  1. +0 −13 chapter05/client/.classpath
  2. +0 −17 chapter05/client/.project
  3. +0 −11 chapter05/client/examples/order.xml
  4. +0 −7 chapter05/client/examples/payment.xml
  5. BIN chapter05/client/lib/javassist.jar
  6. BIN chapter05/client/lib/restfulie-client-1.0.0-beta1.jar
  7. BIN chapter05/client/lib/stax-1.2.0.jar
  8. BIN chapter05/client/lib/stax-api-1.0.1.jar
  9. BIN chapter05/client/lib/xpp3_min-1.1.4c.jar
  10. BIN chapter05/client/lib/xstream-1.3.1.jar
  11. +0 −75 chapter05/client/src/main/java/br/com/caelum/restbucks/model/Item.java
  12. +0 −84 chapter05/client/src/main/java/br/com/caelum/restbucks/model/Order.java
  13. +0 −39 chapter05/client/src/main/java/br/com/caelum/restbucks/model/Ordering.java
  14. +0 −26 chapter05/client/src/main/java/br/com/caelum/restbucks/model/Payment.java
  15. +0 −24 chapter05/client/src/main/java/br/com/caelum/restbucks/model/Receipt.java
  16. +0 −77 chapter05/client/src/test/java/br/com/caelum/restbucks/Entry.java
  17. BIN chapter05/restfulie-1.0.0-examples.zip
  18. +0 −13 chapter05/service/.classpath
  19. +0 −36 chapter05/service/.project
  20. +0 −11 chapter05/service/.settings/.jsdtscope
  21. +0 −7 chapter05/service/.settings/org.eclipse.jdt.core.prefs
  22. +0 −10 chapter05/service/.settings/org.eclipse.wst.common.component
  23. +0 −7 chapter05/service/.settings/org.eclipse.wst.common.project.facet.core.xml
  24. +0 −1 chapter05/service/.settings/org.eclipse.wst.jsdt.ui.superType.container
  25. +0 −1 chapter05/service/.settings/org.eclipse.wst.jsdt.ui.superType.name
  26. +0 −3 chapter05/service/WebContent/META-INF/MANIFEST.MF
  27. +0 −10 chapter05/service/WebContent/WEB-INF/jsp/index/index.jsp
  28. +0 −16 chapter05/service/WebContent/WEB-INF/jsp/ordering/index.jsp
  29. 0 chapter05/service/WebContent/WEB-INF/lib/.jars
  30. BIN chapter05/service/WebContent/WEB-INF/lib/aspectjrt.jar
  31. BIN chapter05/service/WebContent/WEB-INF/lib/cglib-nodep-2.1_3.jar
  32. BIN chapter05/service/WebContent/WEB-INF/lib/commons-fileupload-1.2.1.jar
  33. BIN chapter05/service/WebContent/WEB-INF/lib/commons-io-1.3.2.jar
  34. BIN chapter05/service/WebContent/WEB-INF/lib/commons-logging.jar
  35. BIN chapter05/service/WebContent/WEB-INF/lib/commons-vfs-1.0.jar
  36. BIN chapter05/service/WebContent/WEB-INF/lib/google-collect-1.0-rc2.jar
  37. BIN chapter05/service/WebContent/WEB-INF/lib/javassist-3.8.0.GA.jar
  38. BIN chapter05/service/WebContent/WEB-INF/lib/jstl.jar
  39. BIN chapter05/service/WebContent/WEB-INF/lib/log4j-1.2.15.jar
  40. BIN chapter05/service/WebContent/WEB-INF/lib/mirror-1.5.1.jar
  41. BIN chapter05/service/WebContent/WEB-INF/lib/objenesis-1.1.jar
  42. BIN chapter05/service/WebContent/WEB-INF/lib/ognl-2.7.3.jar
  43. BIN chapter05/service/WebContent/WEB-INF/lib/paranamer-1.5.jar
  44. BIN chapter05/service/WebContent/WEB-INF/lib/restfulie-vraptor-1.0.0-beta1.jar
  45. BIN chapter05/service/WebContent/WEB-INF/lib/slf4j-api-1.5.6.jar
  46. BIN chapter05/service/WebContent/WEB-INF/lib/slf4j-log4j12-1.5.6.jar
  47. BIN chapter05/service/WebContent/WEB-INF/lib/spring-2.5.5.jar
  48. BIN chapter05/service/WebContent/WEB-INF/lib/standard-1.1.2.jar
  49. BIN chapter05/service/WebContent/WEB-INF/lib/vraptor-3.0.3-SNAPSHOT.jar
  50. BIN chapter05/service/WebContent/WEB-INF/lib/xpp3_min-1.1.4c.jar
  51. BIN chapter05/service/WebContent/WEB-INF/lib/xstream-1.3.1.jar
  52. +0 −28 chapter05/service/WebContent/WEB-INF/web.xml
  53. +0 −5 chapter05/service/WebContent/index.html
  54. +0 −55 chapter05/service/src/com/restbucks/Item.java
  55. +0 −96 chapter05/service/src/com/restbucks/Order.java
  56. +0 −21 chapter05/service/src/com/restbucks/OrderControllerInterceptor.java
  57. +0 −69 chapter05/service/src/com/restbucks/OrderDatabase.java
  58. +0 −20 chapter05/service/src/com/restbucks/OrderMachineController.java
  59. +0 −26 chapter05/service/src/com/restbucks/OrderStateControl.java
  60. +0 −103 chapter05/service/src/com/restbucks/OrderingController.java
  61. +0 −23 chapter05/service/src/com/restbucks/Payment.java
  62. +0 −28 chapter05/service/src/com/restbucks/Receipt.java
  63. +0 −31 chapter05/service/src/com/restbucks/XmlDeserializer.java
  64. +0 −31 chapter05/service/src/com/restbucks/XmlSerializer.java
  65. +0 −30 chapter05/service/src/com/restbucks/restfulie/CustomRoutes.java
  66. +0 −8 chapter05/service/src/com/restbucks/restfulie/StateMachineController.java
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="lib" path="lib/javassist.jar"/>
- <classpathentry kind="lib" path="lib/stax-1.2.0.jar"/>
- <classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/>
- <classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
- <classpathentry kind="lib" path="lib/xpp3_min-1.1.4c.jar"/>
- <classpathentry kind="lib" path="lib/restfulie-client-1.0.0-beta1.jar"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
View
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>chapter05-client</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
@@ -1,11 +0,0 @@
-<order>
- <location>takeAway</location>
- <items>
- <item>
- <name>latte</name>
- <quantity>2</quantity>
- <milk>skim</milk>
- <size>medium</size>
- </item>
- </items>
-</order>
@@ -1,7 +0,0 @@
-<payment>
- <amount>15</amount>
- <cardholderName>Guilherme Silveira</cardholderName>
- <cardNumber>123456789012</cardNumber>
- <expiryMonth>12</expiryMonth>
- <expiryYear>12</expiryYear>
-</payment>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,75 +0,0 @@
-package br.com.caelum.restbucks.model;
-
-import java.math.BigDecimal;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-import com.thoughtworks.xstream.annotations.XStreamImplicitCollection;
-
-@XStreamAlias("item")
-public class Item {
- enum Coffee {
- latte(2.0), cappuccino(2.0), espresso(1.5);
- private final BigDecimal price;
-
- Coffee(double price) {
- this.price = new BigDecimal(price);
- }
- }
-
- enum Milk {
- skim, semi, whole
- };
-
- enum Size {
- small, medium, large
- };
-
- private Coffee name;
- private int quantity;
- private Milk milk;
- private Size size;
-
- public Item(Coffee name, int quantity, Milk milk, Size size) {
- this.name = name;
- this.quantity = quantity;
- this.milk = milk;
- this.size = size;
- }
-
- public Coffee getName() {
- return name;
- }
-
- public void setName(Coffee name) {
- this.name = name;
- }
-
- public int getQuantity() {
- return quantity;
- }
-
- public void setQuantity(int quantity) {
- this.quantity = quantity;
- }
-
- public Milk getMilk() {
- return milk;
- }
-
- public void setMilk(Milk milk) {
- this.milk = milk;
- }
-
- public Size getSize() {
- return size;
- }
-
- public void setSize(Size size) {
- this.size = size;
- }
-
- public BigDecimal getPrice() {
- return name.price;
- }
-
-}
@@ -1,84 +0,0 @@
-package br.com.caelum.restbucks.model;
-
-import static br.com.caelum.restfulie.Restfulie.resource;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-@XStreamAlias("order")
-public class Order {
-
- private String id;
- private Location location;
-
- private List<Item> items;
-
- private String status;
- private Payment payment;
-
- public enum Location {
- takeAway, drinkIn
- };
-
- public Order(String status, List<Item> items, Location location) {
- this.status = status;
- this.items = items;
- this.location = location;
- }
-
- public Order() {
- this.items = new ArrayList<Item>();
- }
-
- public void setLocation(Location location) {
- this.location = location;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public Payment getPayment() {
- return payment;
- }
-
- public void add(Item item) {
- this.items.add(item);
- }
-
- public BigDecimal getCost() {
- BigDecimal total = BigDecimal.ZERO;
- for (Item item : items) {
- total= total.add(item.getPrice());
- }
- return total;
- }
-
- public String getLatestUri() {
- return resource(this).getTransition("latest").getHref();
- }
-
- public Receipt pay(Payment payment) {
- return resource(this).getTransition("pay").executeAndRetrieve(payment);
- }
-
- public void cancel() {
- resource(this).getTransition("cancel").execute();
- }
-
-}
@@ -1,39 +0,0 @@
-package br.com.caelum.restbucks.model;
-
-import br.com.caelum.restbucks.model.Item.Coffee;
-import br.com.caelum.restbucks.model.Item.Milk;
-import br.com.caelum.restbucks.model.Item.Size;
-import br.com.caelum.restbucks.model.Order.Location;
-
-public class Ordering {
-
- private final Order order = new Order();
-
- public static Ordering order() {
- return new Ordering();
- }
-
- public Ordering withRandomItems() {
- int quantity = random(2, 5);
- for (int i = 0; i < quantity; i++) {
- Item item = new Item(random(Coffee.class), random(1, 3), random(Milk.class), random(Size.class));
- order.add(item);
- }
- return this;
- }
-
- private <T extends Enum> T random(Class<T> type) {
- return type.getEnumConstants()[random(0,type.getEnumConstants().length)];
- }
-
- private int random(int from, int to) {
- return (int) (Math.random() * (to-from) +from);
- }
-
- public Order build() {
- order.setLocation(random(Location.class));
- order.setStatus("unpaid");
- return this.order;
- }
-
-}
@@ -1,26 +0,0 @@
-package br.com.caelum.restbucks.model;
-
-import java.math.BigDecimal;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-@XStreamAlias("payment")
-public class Payment {
-
- private String cardNumber;
- private String cardholderName;
- private int expiryMonth;
- private int expiryYear;
- private BigDecimal amount;
-
- public Payment(String cardNumber, String cardholderName, int expiryMonth,
- int expiryYear, BigDecimal amount) {
- super();
- this.cardNumber = cardNumber;
- this.cardholderName = cardholderName;
- this.expiryMonth = expiryMonth;
- this.expiryYear = expiryYear;
- this.amount = amount;
- }
-
-}
@@ -1,24 +0,0 @@
-package br.com.caelum.restbucks.model;
-
-import static br.com.caelum.restfulie.Restfulie.resource;
-
-import java.util.Calendar;
-
-import br.com.caelum.restfulie.http.HttpMethod;
-
-import com.thoughtworks.xstream.annotations.XStreamAlias;
-
-@XStreamAlias("receipt")
-public class Receipt {
-
- private Calendar paymentTime;
-
- public Calendar getPaymentTime() {
- return paymentTime;
- }
-
- public Order getOrder() {
- return resource(this).getTransition("order").method(HttpMethod.GET).executeAndRetrieve();
- }
-
-}
@@ -1,77 +0,0 @@
-package br.com.caelum.restbucks;
-
-import static br.com.caelum.restbucks.model.Ordering.order;
-import static br.com.caelum.restfulie.Restfulie.resource;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import br.com.caelum.restbucks.model.Order;
-import br.com.caelum.restbucks.model.Payment;
-import br.com.caelum.restbucks.model.Receipt;
-import br.com.caelum.restfulie.Resources;
-import br.com.caelum.restfulie.Response;
-import br.com.caelum.restfulie.Restfulie;
-import br.com.caelum.restfulie.http.HttpMethod;
-
-public class Entry {
-
- public static void main(String[] args) throws Exception {
- URI uri = processCommandLineArgs(args);
- happyPathTest(uri);
- }
-
- private static void happyPathTest(URI uri) throws Exception {
-
- Resources server = Restfulie.resources();
- server.configure(Order.class).implicit("items");
- server.configure(Payment.class);
- server.configure(Receipt.class);
-
- // Place the order
- System.out.println(String.format("About to start happy path test. Placing order at [%s] via POST", uri.toString()));
- Order order = order().withRandomItems().build();
- order = server.entryAt(uri).post(order);
-
- System.out.println(String.format("Order placed at [%s]", order.getLatestUri()));
-
- // Pay for the order
- Payment payment = new Payment("12345677878", "guilherme silveira", 12, 2999, order.getCost());
- System.out.println(String.format("About to create a payment resource at [%s] via PUT", resource(order).getTransition("pay").getHref()));
- Receipt receipt = order.pay(payment);
- System.out.println("Payment made, receipt created at: " + receipt.getPaymentTime().getTime());
-
- // Check on the order status
- System.out.println(String.format("About to check order status at [%s] via GET", resource(receipt).getTransition("order").getHref()));
- Order finalOrder = receipt.getOrder();
- System.out.println(String.format("Final order placed, current status [%s]", finalOrder.getStatus()));
-
- // Allow the barista some time to make the order
- System.out.println("Pausing the client, press a key to continue");
- System.in.read();
-
- // Take the order if possible
- System.out.println(String.format("Trying to take the ready order from [%s] via DELETE. Note: the internal state machine must progress the order to ready before this should work, otherwise expect a 405 response.", resource(receipt).getTransition("order").getHref()));
- finalOrder = receipt.getOrder();
- Response finalResponse = resource(finalOrder).getTransition("retrieve").method(HttpMethod.DELETE).execute();
- System.out.println(String.format("Tried to take final order, HTTP status [%d]", finalResponse.getCode()));
- if(finalResponse.getCode() == 200) {
- System.out.println(String.format("Order status [%s], enjoy your drink", finalResponse.getCode()));
- }
- }
-
-
- /**
- * Code from Jim Webber's restbucks example app
- */
- private static URI processCommandLineArgs(String[] args) throws URISyntaxException {
- if(args.length != 1) {
- System.out.println("Must specify entry point URI as the only command line argument ");
- System.exit(1);
- } else {
- System.out.println("Binding to service at: " + args[0]);
- }
- return new URI(args[0]);
- }
-
-}
Binary file not shown.
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (MacOS X Default)">
- <attributes>
- <attribute name="owner.project.facets" value="jst.java"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
- <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
- <classpathentry kind="lib" path="/Users/guilherme/Applications/apache-tomcat-6.0.20/lib/servlet-api.jar"/>
- <classpathentry kind="output" path="build/classes"/>
-</classpath>
Oops, something went wrong.

0 comments on commit e75ed2c

Please sign in to comment.