예제 #1
0
  @GET
  @Path("/{orderId}")
  public Response getOrder(
      @PathParam("orderId") Long orderId,
      @QueryParam("username") String username,
      @QueryParam("password") String password) {

    // Hardcore logging
    System.out.println("GET /{orderId} with {orderId}=" + orderId + ".");
    System.out.println("Result : " + OrderData.get(orderId));

    // Bad user and password association
    if (!authenticate(username, password)) {
      return Response.status(Response.Status.FORBIDDEN).build();
    }

    Order wantedOrder = OrderData.get(orderId);

    if (wantedOrder == null || !wantedOrder.getCart().getOwner().equals(username)) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }

    JSONArray result = new JSONArray();
    result.put(convertToJson(wantedOrder));
    return Response.ok().entity(result.toString(2)).build();
  }
예제 #2
0
  @GET
  @Path("/all")
  public Response getAllOrders() {

    // Hardcore logging
    System.out.println("GET /orders/all");

    JSONArray result = new JSONArray();
    for (Map.Entry<Long, Order> entry : OrderData.getData().entrySet()) {
      result.put(entryToJson(entry));
    }
    System.out.println(CartData.getData().size());
    return Response.ok().entity(result.toString(2)).build();
  }