use of com.sun.jersey.samples.storageservice.Container in project enunciate by stoicflame.
the class ItemResource method putItem.
@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;
}
use of com.sun.jersey.samples.storageservice.Container in project enunciate by stoicflame.
the class TestJerseyStorageService method testContainers.
/**
* tests the containers.
*/
public void testContainers() throws Exception {
WebTarget resource = getStorageResource();
Response response = resource.path("containers").request("application/xml").get();
assertEquals(200, response.getStatus());
Containers containers = response.readEntity(Containers.class);
assertTrue(containers.getContainer() == null || containers.getContainer().isEmpty());
response = resource.path("containers").request("text/html").get();
assertEquals(200, response.getStatus());
response = resource.path("containers/one").request().get();
assertEquals(404, response.getStatus());
Container containerOne = new Container();
response = resource.path("containers/one").request().put(Entity.entity(containerOne, "application/xml"));
assertEquals(201, response.getStatus());
response = resource.path("containers").request("application/xml").get();
assertEquals(200, response.getStatus());
containers = response.readEntity(Containers.class);
assertEquals(1, containers.getContainer().size());
response = resource.path("containers/one").request().get();
assertEquals(200, response.getStatus());
containerOne = response.readEntity(Container.class);
assertEquals("one", containerOne.getName());
assertNotNull(containerOne.getUri());
assertTrue(containerOne.getItem() == null || containerOne.getItem().isEmpty());
String stringItem = "here is a string that we want to store";
response = resource.path("containers/one/string").request().put(Entity.entity(stringItem, "text/plain"));
assertEquals(201, response.getStatus());
response = resource.path("containers/one").request().get();
assertEquals(200, response.getStatus());
containerOne = response.readEntity(Container.class);
assertEquals(1, containerOne.getItem().size());
assertEquals("text/plain", containerOne.getItem("string").getMimeType());
response = resource.path("containers/one/string").request().get();
assertEquals(200, response.getStatus());
assertEquals(stringItem, response.readEntity(String.class));
}
use of com.sun.jersey.samples.storageservice.Container in project enunciate by stoicflame.
the class TestJerseyStorageService method tearDown.
@Override
protected void tearDown() throws Exception {
super.tearDown();
WebTarget resource = getStorageResource();
Response response = resource.path("containers").request("application/xml").get();
if (200 == response.getStatus()) {
Containers containers = response.readEntity(Containers.class);
if (containers.getContainer() != null) {
for (Container container : containers.getContainer()) {
resource.path("containers/" + container.getName()).request().delete();
}
}
}
}
use of com.sun.jersey.samples.storageservice.Container in project enunciate by stoicflame.
the class ContainerResource method putContainer.
@PUT
@TypeHint(Container.class)
public Response putContainer() throws WebApplicationException {
System.out.println("PUT CONTAINER " + container);
URI uri = uriInfo.getAbsolutePath();
Container c = new Container(container, uri.toString());
Response r;
if (!MemoryStore.MS.hasContainer(c)) {
r = Response.created(uri).build();
} else {
r = Response.noContent().build();
}
MemoryStore.MS.createContainer(c);
return r;
}
use of com.sun.jersey.samples.storageservice.Container in project enunciate by stoicflame.
the class ContainerResource method deleteContainer.
@DELETE
public void deleteContainer() {
System.out.println("DELETE CONTAINER " + container);
Container c = MemoryStore.MS.deleteContainer(container);
if (c == null)
throw new NotFoundException("Container not found");
}
Aggregations