simplify update method of AbstractResource

This commit is contained in:
Sebastian Sdorra
2010-11-23 17:53:30 +01:00
parent f788918165
commit 69c48bfc84
3 changed files with 7 additions and 8 deletions

View File

@@ -29,6 +29,8 @@
* *
*/ */
package sonia.scm.api.rest.resources; package sonia.scm.api.rest.resources;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -40,6 +42,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@@ -195,13 +198,12 @@ public abstract class AbstractResource<T>
* @param name * @param name
* @param item * @param item
* *
* @return
*/ */
@PUT @PUT
@Path("{name}") @Path("{name}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response update(@Context UriInfo uriInfo, public void update(@Context UriInfo uriInfo, @PathParam("name") String name,
@PathParam("name") String name, T item) T item)
{ {
try try
{ {
@@ -211,9 +213,6 @@ public abstract class AbstractResource<T>
{ {
throw new WebApplicationException(ex); throw new WebApplicationException(ex);
} }
return Response.created(
uriInfo.getAbsolutePath().resolve(getId(item))).build();
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@@ -228,6 +227,7 @@ public abstract class AbstractResource<T>
*/ */
@GET @GET
@Path("{name}") @Path("{name}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public T get(@PathParam("name") String name) public T get(@PathParam("name") String name)
{ {
T item = getItem(name); T item = getItem(name);
@@ -247,6 +247,7 @@ public abstract class AbstractResource<T>
* @return * @return
*/ */
@GET @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public T[] getAll() public T[] getAll()
{ {
return getAllItems(); return getAllItems();

View File

@@ -63,7 +63,6 @@ import javax.ws.rs.core.MediaType;
*/ */
@Path("repositories") @Path("repositories")
@Singleton @Singleton
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class RepositoryResource extends AbstractResource<Repository> public class RepositoryResource extends AbstractResource<Repository>
{ {

View File

@@ -58,7 +58,6 @@ import javax.ws.rs.core.MediaType;
*/ */
@Path("users") @Path("users")
@Singleton @Singleton
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public class UserResource extends AbstractResource<User> public class UserResource extends AbstractResource<User>
{ {