@Test public void testGetToDoException() { try { errorApi.getToDo("123"); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus()); } }
@GET @Path("/{id}") @Produces("application/json") public ToDo getToDo(@PathParam("id") String id) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } try { ToDo td = store.get(id); if(td == null) { throw new WebApplicationException("ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return td; } catch (ToDoStoreException e) { throw new WebApplicationException("Error getting ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } }
ToDoAPI { @GET @Path("/{id}") @Produces("application/json") public ToDo getToDo(@PathParam("id") String id) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } try { ToDo td = store.get(id); if(td == null) { throw new WebApplicationException("ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return td; } catch (ToDoStoreException e) { throw new WebApplicationException("Error getting ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } } }
ToDoAPI { @GET @Path("/{id}") @Produces("application/json") public ToDo getToDo(@PathParam("id") String id) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } try { ToDo td = store.get(id); if(td == null) { throw new WebApplicationException("ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return td; } catch (ToDoStoreException e) { throw new WebApplicationException("Error getting ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } } ToDoAPI();  ToDoAPI(ToDoStore store); }
ToDoAPI { @GET @Path("/{id}") @Produces("application/json") public ToDo getToDo(@PathParam("id") String id) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } try { ToDo td = store.get(id); if(td == null) { throw new WebApplicationException("ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return td; } catch (ToDoStoreException e) { throw new WebApplicationException("Error getting ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } } ToDoAPI();  ToDoAPI(ToDoStore store); @GET @Path("/{id}") @Produces("application/json") ToDo getToDo(@PathParam("id") String id); @GET @Produces("application/json") Collection<ToDo> getToDos(); @POST @Consumes("application/json") @Produces("application/json") ToDo newToDo(ToDo td); @PUT @Path("/{id}") @Produces("application/json") @Consumes("application/json") ToDo updateToDo(@PathParam("id") String id, ToDo td); @DELETE @Path("/{id}") void deleteToDo(@PathParam("id") String id); }
ToDoAPI { @GET @Path("/{id}") @Produces("application/json") public ToDo getToDo(@PathParam("id") String id) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } try { ToDo td = store.get(id); if(td == null) { throw new WebApplicationException("ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return td; } catch (ToDoStoreException e) { throw new WebApplicationException("Error getting ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } } ToDoAPI();  ToDoAPI(ToDoStore store); @GET @Path("/{id}") @Produces("application/json") ToDo getToDo(@PathParam("id") String id); @GET @Produces("application/json") Collection<ToDo> getToDos(); @POST @Consumes("application/json") @Produces("application/json") ToDo newToDo(ToDo td); @PUT @Path("/{id}") @Produces("application/json") @Consumes("application/json") ToDo updateToDo(@PathParam("id") String id, ToDo td); @DELETE @Path("/{id}") void deleteToDo(@PathParam("id") String id);  }