Пример #1
0
  @PUT
  public Response putItem(@Context HttpHeaders headers, byte[] data) {
    System.out.println("PUT ITEM " + container + " " + item);

    URI uri = uriInfo.getAbsolutePath();
    MediaType mimeType = headers.getMediaType();
    GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.MILLISECOND, 0);
    Item i = new Item(item, uri.toString(), mimeType.toString(), gc);
    String digest = computeDigest(data);
    i.setDigest(digest);

    Response r;
    if (!MemoryStore.MS.hasItem(container, item)) {
      r = Response.created(uri).build();
    } else {
      r = Response.noContent().build();
    }

    Item ii = MemoryStore.MS.createOrUpdateItem(container, i, data);
    if (ii == null) {
      // Create the container if one has not been created
      URI containerUri = uriInfo.getAbsolutePathBuilder().path("..").build().normalize();
      Container c = new Container(container, containerUri.toString());
      MemoryStore.MS.createContainer(c);
      i = MemoryStore.MS.createOrUpdateItem(container, i, data);
      if (i == null) throw new NotFoundException("Container not found");
    }

    return r;
  }
Пример #2
0
  @GET
  public Response getItem() {
    System.out.println("GET ITEM " + container + " " + item);

    Item i = MemoryStore.MS.getItem(container, item);
    if (i == null) throw new NotFoundException("Item not found");
    Date lastModified = i.getLastModified().getTime();
    EntityTag et = new EntityTag(i.getDigest());
    ResponseBuilder rb = request.evaluatePreconditions(lastModified, et);
    if (rb != null) return rb.build();

    byte[] b = MemoryStore.MS.getItemData(container, item);
    return Response.ok(b, i.getMimeType()).lastModified(lastModified).tag(et).build();
  }
Пример #3
0
  @DELETE
  public void deleteItem() {
    System.out.println("DELETE ITEM " + container + " " + item);

    Item i = MemoryStore.MS.deleteItem(container, item);
    if (i == null) {
      throw new NotFoundException("Item not found");
    }
  }