diff --git a/build.gradle b/build.gradle index 41912323..7e9a22af 100755 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { group = 'com.ofg' description = 'Microservice default infrastructure Spring configuration' -version = '0.2.1-SNAPSHOT' +version = '0.2.1' sourceCompatibility = 1.7 task addHashFile << { diff --git a/src/main/groovy/com/ofg/infrastructure/healthcheck/PingController.groovy b/src/main/groovy/com/ofg/infrastructure/healthcheck/PingController.groovy old mode 100644 new mode 100755 index bc91d171..6f2c8fd9 --- a/src/main/groovy/com/ofg/infrastructure/healthcheck/PingController.groovy +++ b/src/main/groovy/com/ofg/infrastructure/healthcheck/PingController.groovy @@ -7,6 +7,11 @@ import org.springframework.http.MediaType import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMethod import org.springframework.web.bind.annotation.RestController + +import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE +import static org.springframework.web.bind.annotation.RequestMethod.GET +import static org.springframework.web.bind.annotation.RequestMethod.HEAD + /** * {@link RestController} that responds with OK when server is alive */ @@ -16,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController @Api(value = "ping", description = "PING API") class PingController { - @RequestMapping(value = "/ping", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) + @RequestMapping(value = "/ping", method = [GET, HEAD], produces = TEXT_PLAIN_VALUE) @ApiOperation(value = "Ping server", notes = "Returns OK if server is alive") String ping() { return "OK" diff --git a/src/test/groovy/com/ofg/infrastructure/healthcheck/PingControllerMvcSpec.groovy b/src/test/groovy/com/ofg/infrastructure/healthcheck/PingControllerMvcSpec.groovy old mode 100644 new mode 100755 index d75c833d..ea87bdb2 --- a/src/test/groovy/com/ofg/infrastructure/healthcheck/PingControllerMvcSpec.groovy +++ b/src/test/groovy/com/ofg/infrastructure/healthcheck/PingControllerMvcSpec.groovy @@ -3,7 +3,9 @@ package com.ofg.infrastructure.healthcheck import com.ofg.infrastructure.base.BaseConfiguration import com.ofg.infrastructure.base.MvcIntegrationSpec import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.http.HttpMethod import org.springframework.test.context.ContextConfiguration +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder import static org.springframework.http.MediaType.TEXT_PLAIN import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -19,4 +21,20 @@ class PingControllerMvcSpec extends MvcIntegrationSpec { .andExpect(status().isOk()) .andExpect(content().string('OK')) } + + def "should return OK for HEAD requests from run.sh scripts"() { + expect: + mockMvc.perform(head('/ping')) + .andExpect(status().isOk()) + } + + /** + * Create a {@link org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder} for a HEAD request. + * @param urlTemplate a URL template; the resulting URL will be encoded + * @param urlVariables zero or more URL variables + */ + public static MockHttpServletRequestBuilder head(String urlTemplate, Object... urlVariables) { + return new MockHttpServletRequestBuilder(HttpMethod.HEAD, urlTemplate, urlVariables); + } + }