From 2a7e81619d6a9b1d82b4210e0b6e07418c7333ea Mon Sep 17 00:00:00 2001 From: Nykolas Lima Date: Wed, 14 Jan 2015 18:07:41 -0200 Subject: [PATCH 1/2] implementing internal server error status --- .../java/br/com/caelum/vraptor/view/DefaultStatus.java | 10 ++++++++-- .../main/java/br/com/caelum/vraptor/view/Status.java | 5 +++++ .../br/com/caelum/vraptor/view/DefaultStatusTest.java | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultStatus.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultStatus.java index c6f28a2d2..10cf5d9cb 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultStatus.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/DefaultStatus.java @@ -28,8 +28,6 @@ import javax.inject.Inject; import javax.servlet.http.HttpServletResponse; -import com.google.common.base.Joiner; - import br.com.caelum.vraptor.Result; import br.com.caelum.vraptor.config.Configuration; import br.com.caelum.vraptor.controller.HttpMethod; @@ -38,6 +36,8 @@ import br.com.caelum.vraptor.proxy.Proxifier; import br.com.caelum.vraptor.proxy.SuperMethod; +import com.google.common.base.Joiner; + /** * Allows header related results. * @@ -199,4 +199,10 @@ public void notModified() { public void notImplemented() { response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); } + + @Override + public void internalServerError() { + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/Status.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/Status.java index bcfa87f6b..085c0d231 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/view/Status.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/view/Status.java @@ -145,5 +145,10 @@ public interface Status extends View { */ void notImplemented(); + /** + * Return Internal Server Error (500) Status + */ + void internalServerError(); + void header(String key, String value); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java index 1a6b15af0..8bd24de4a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java @@ -136,6 +136,13 @@ public void shouldSetNotImplementedStatus() throws Exception { verify(response).setStatus(501); } + + @Test + public void shouldSetInternalServerErrorStatus() throws Exception { + status.internalServerError(); + + verify(response).setStatus(500); + } @Test public void shouldSetMethodNotAllowedStatus() throws Exception { From 225a2ab243c458822a1558b1aab881b2ce7dd711 Mon Sep 17 00:00:00 2001 From: Nykolas Lima Date: Wed, 14 Jan 2015 18:08:27 -0200 Subject: [PATCH 2/2] removing warnings --- .../test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java index 8bd24de4a..a45f7d37d 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultStatusTest.java @@ -186,6 +186,7 @@ public void shouldSetMovedPermanentlyStatusOfLogic() throws Exception { verify(response).addHeader("Location", "http://myapp.com/resource/method"); } + @SuppressWarnings("deprecation") @Test public void shouldSerializeErrorMessages() throws Exception { Message normal = new SimpleMessage("category", "The message"); @@ -206,6 +207,7 @@ public void shouldSerializeErrorMessages() throws Exception { assertThat(serialized, not(containsString(""))); } + @SuppressWarnings("deprecation") @Test public void shouldSerializeErrorMessagesInJSON() throws Exception { Message normal = new SimpleMessage("category", "The message");