From f5fadc88acf88469879bbada489a7298598d0a5d Mon Sep 17 00:00:00 2001 From: Michal Szynkiewicz Date: Fri, 15 Feb 2019 09:45:35 +0100 Subject: [PATCH] fixes #873, add content type to /health --- CONTRIBUTING.md | 2 +- .../smallrye/health/runtime/SmallRyeHealthServlet.java | 2 ++ .../org/jboss/shamrock/example/test/HealthTestCase.java | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2166673e4..9d7356c28 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ All submissions, including submissions by project members, need to be reviewed b ### Continuous Integration -Because we are all humans, the project use a continuous integration approach and each pull request triggers a full build. +Because we are all humans, the project uses a continuous integration approach and each pull request triggers a full build. Please make sure to monitor the output of the build and act accordingly. ### Tests and documentation are not optional diff --git a/extensions/smallrye-health/runtime/src/main/java/org/jboss/shamrock/smallrye/health/runtime/SmallRyeHealthServlet.java b/extensions/smallrye-health/runtime/src/main/java/org/jboss/shamrock/smallrye/health/runtime/SmallRyeHealthServlet.java index a1913a028..dd499a39f 100644 --- a/extensions/smallrye-health/runtime/src/main/java/org/jboss/shamrock/smallrye/health/runtime/SmallRyeHealthServlet.java +++ b/extensions/smallrye-health/runtime/src/main/java/org/jboss/shamrock/smallrye/health/runtime/SmallRyeHealthServlet.java @@ -43,6 +43,8 @@ public class SmallRyeHealthServlet extends HttpServlet { if (health.isDown()) { resp.setStatus(503); } + resp.setContentType("application/json"); + resp.setCharacterEncoding("UTF-8"); reporter.reportHealth(resp.getOutputStream(), health); } } diff --git a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/HealthTestCase.java b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/HealthTestCase.java index b0ba0959c..5af6a1b86 100644 --- a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/HealthTestCase.java +++ b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/HealthTestCase.java @@ -19,21 +19,22 @@ package org.jboss.shamrock.example.test; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; +import io.restassured.http.ContentType; +import org.hamcrest.Matchers; import org.jboss.shamrock.test.junit.ShamrockTest; import org.junit.jupiter.api.Test; import io.restassured.RestAssured; -import io.restassured.parsing.Parser; @ShamrockTest public class HealthTestCase { @Test public void testHealthCheck() { - // the health check does not set a content type so we need to force the parser try { - RestAssured.defaultParser = Parser.JSON; RestAssured.when().get("/health").then() + .contentType(ContentType.JSON) + .header("Content-Type", Matchers.containsString("charset=UTF-8")) .body("outcome", is("UP"), "checks.state", contains("UP"), "checks.name", contains("basic"));