@Test public void shouldReturnInternalServerErrorIfAnErrorIsThrownInServiceCode() { when(distributedStore.getAll()).thenThrow(new IllegalStateException()); ClientResponse response = getClientResponseForUnsuccessfulRequest(); assertThat(response.getClientResponseStatus(), equalTo(ClientResponse.Status.INTERNAL_SERVER_ERROR)); assertThat(response.getLocation(), nullValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) public Collection<KeyValue> getAll() throws Exception { LOGGER.trace("get all keys"); try { ListenableFuture<Collection<KeyValue>> getAllFuture = distributedStore.getAll(); return getAllFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw new CannotSubmitCommandException((NotLeaderException) cause, members); } else { throw e; } } }
KeysResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<KeyValue> getAll() throws Exception { LOGGER.trace("get all keys"); try { ListenableFuture<Collection<KeyValue>> getAllFuture = distributedStore.getAll(); return getAllFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw new CannotSubmitCommandException((NotLeaderException) cause, members); } else { throw e; } } } }
KeysResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<KeyValue> getAll() throws Exception { LOGGER.trace("get all keys"); try { ListenableFuture<Collection<KeyValue>> getAllFuture = distributedStore.getAll(); return getAllFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw new CannotSubmitCommandException((NotLeaderException) cause, members); } else { throw e; } } } KeysResource(Set<ClusterMember> members, DistributedStore distributedStore); }
KeysResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<KeyValue> getAll() throws Exception { LOGGER.trace("get all keys"); try { ListenableFuture<Collection<KeyValue>> getAllFuture = distributedStore.getAll(); return getAllFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw new CannotSubmitCommandException((NotLeaderException) cause, members); } else { throw e; } } } KeysResource(Set<ClusterMember> members, DistributedStore distributedStore); @Path("/{key:" + KEY_PATTERN + "}") KeyResource forKey(@PathParam("key") String key); @GET @Produces(MediaType.APPLICATION_JSON) Collection<KeyValue> getAll(); }
KeysResource { @GET @Produces(MediaType.APPLICATION_JSON) public Collection<KeyValue> getAll() throws Exception { LOGGER.trace("get all keys"); try { ListenableFuture<Collection<KeyValue>> getAllFuture = distributedStore.getAll(); return getAllFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw new CannotSubmitCommandException((NotLeaderException) cause, members); } else { throw e; } } } KeysResource(Set<ClusterMember> members, DistributedStore distributedStore); @Path("/{key:" + KEY_PATTERN + "}") KeyResource forKey(@PathParam("key") String key); @GET @Produces(MediaType.APPLICATION_JSON) Collection<KeyValue> getAll();  }