下面列出了怎么用org.springframework.boot.actuate.endpoint.http.ActuatorMediaType的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void should_convert_v1_actuator() {
ExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoint(new TestLegacyEndpointConverter());
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.attribute(ATTRIBUTE_ENDPOINT, "test")
.build();
ClientResponse response = ClientResponse.create(HttpStatus.OK)
.header(CONTENT_TYPE, ActuatorMediaType.V1_JSON)
.body(Flux.just(ORIGINAL))
.build();
Mono<ClientResponse> convertedResponse = filter.filter(request, r -> Mono.just(response));
StepVerifier.create(convertedResponse)
.assertNext(r -> StepVerifier.create(r.body(BodyExtractors.toDataBuffers()))
.expectNext(CONVERTED)
.verifyComplete())
.verifyComplete();
}
@Test
public void should_not_convert_v2_actuator() {
ExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoint(new TestLegacyEndpointConverter());
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.attribute(ATTRIBUTE_ENDPOINT, "test")
.build();
ClientResponse response = ClientResponse.create(HttpStatus.OK)
.header(CONTENT_TYPE, ActuatorMediaType.V2_JSON)
.body(Flux.just(ORIGINAL))
.build();
Mono<ClientResponse> convertedResponse = filter.filter(request, r -> Mono.just(response));
StepVerifier.create(convertedResponse)
.assertNext(r -> StepVerifier.create(r.body(BodyExtractors.toDataBuffers()))
.expectNext(ORIGINAL)
.verifyComplete())
.verifyComplete();
}
@Test
public void should_return_endpoints() {
//given
Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", wireMock.url("/mgmt/health"))
.managementUrl(wireMock.url("/mgmt"))
.build());
String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}";
wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)
.withHeader("Content-Length",
Integer.toString(body.length())
)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient);
//when
StepVerifier.create(strategy.detectEndpoints(instance))
//then
.expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))//
.verifyComplete();
}
@Test
public void should_return_empty_on_empty_endpoints() {
//given
Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", wireMock.url("/mgmt/health"))
.managementUrl(wireMock.url("/mgmt"))
.build());
String body = "{\"_links\":{}}";
wireMock.stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)
.withHeader("Content-Length",
Integer.toString(body.length())
)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient);
//when
StepVerifier.create(strategy.detectEndpoints(instance))
//then
.verifyComplete();
}
@RequestMapping(
value = "${edison.application.management.base-path:/internal}/loggers/{name:.*}",
consumes = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
produces = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
method = POST)
@ResponseBody
public Object post(@PathVariable String name,
@RequestBody Map<String, String> configuration) {
final String level = configuration.get("configuredLevel");
final LogLevel logLevel = level == null ? null : LogLevel.valueOf(level.toUpperCase());
loggersEndpoint.configureLogLevel(name, logLevel);
return HttpEntity.EMPTY;
}
@Test
void should_convert_v1_actuator() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.attribute(ATTRIBUTE_ENDPOINT, "test").build();
@SuppressWarnings("deprecation")
ClientResponse legacyResponse = ClientResponse.create(HttpStatus.OK)
.header(CONTENT_TYPE, ACTUATOR_V1_MEDIATYPE.toString())
.header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount()))
.body(Flux.just(this.original)).build();
Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (r) -> Mono.just(legacyResponse));
StepVerifier.create(response).assertNext((r) -> {
assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON));
assertThat(r.headers().contentLength()).isEmpty();
StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.converted).verifyComplete();
}).verifyComplete();
}
@Test
void should_convert_json() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.attribute(ATTRIBUTE_ENDPOINT, "test").build();
ClientResponse legacyResponse = ClientResponse.create(HttpStatus.OK)
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount()))
.body(Flux.just(this.original)).build();
Mono<ClientResponse> response = this.filter.filter(INSTANCE, request, (r) -> Mono.just(legacyResponse));
StepVerifier.create(response).assertNext((r) -> {
assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON));
assertThat(r.headers().contentLength()).isEmpty();
StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.converted).verifyComplete();
}).verifyComplete();
}
@Test
void should_not_convert_v2_actuator() {
InstanceExchangeFilterFunction filter = InstanceExchangeFilterFunctions.convertLegacyEndpoints(
singletonList(new LegacyEndpointConverter("test", (from) -> Flux.just(this.converted)) {
}));
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("/test"))
.attribute(ATTRIBUTE_ENDPOINT, "test").build();
ClientResponse response = ClientResponse.create(HttpStatus.OK)
.header(CONTENT_TYPE, ActuatorMediaType.V2_JSON)
.header(CONTENT_LENGTH, Integer.toString(this.original.readableByteCount()))
.body(Flux.just(this.original)).build();
Mono<ClientResponse> convertedResponse = filter.filter(INSTANCE, request, (r) -> Mono.just(response));
StepVerifier.create(convertedResponse).assertNext((r) -> {
assertThat(r.headers().contentType()).hasValue(MediaType.valueOf(ActuatorMediaType.V2_JSON));
assertThat(r.headers().contentLength()).hasValue(this.original.readableByteCount());
StepVerifier.create(r.body(BodyExtractors.toDataBuffers())).expectNext(this.original).verifyComplete();
}).verifyComplete();
}
@Test
public void should_return_endpoints() {
// given
Instance instance = Instance.create(InstanceId.of("id")).register(Registration
.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
String host = "https://localhost:" + this.wireMock.httpsPort();
String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host
+ "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host
+ "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host
+ "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";
this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
// when
StepVerifier.create(strategy.detectEndpoints(instance))
// then
.expectNext(Endpoints.single("metrics", host + "/mgmt/stats").withEndpoint("info", host + "/mgmt/info"))//
.verifyComplete();
}
@Test
public void should_return_endpoints_with_aligned_scheme() {
// given
Instance instance = Instance.create(InstanceId.of("id")).register(Registration
.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
String host = "http://localhost:" + this.wireMock.httpsPort();
String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"" + host
+ "/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"" + host
+ "/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"" + host
+ "/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"" + host + "/mgmt/info\"}}}";
this.wireMock.stubFor(get("/mgmt").willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
// when
String secureHost = "https://localhost:" + this.wireMock.httpsPort();
StepVerifier.create(strategy.detectEndpoints(instance))
// then
.expectNext(Endpoints.single("metrics", secureHost + "/mgmt/stats").withEndpoint("info",
secureHost + "/mgmt/info"))//
.verifyComplete();
}
@Test
public void should_return_empty_on_empty_endpoints() {
// given
Instance instance = Instance.create(InstanceId.of("id")).register(Registration
.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
String body = "{\"_links\":{}}";
this.wireMock
.stubFor(get("/mgmt").willReturn(okJson(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
// when
StepVerifier.create(strategy.detectEndpoints(instance))
// then
.verifyComplete();
}
@Test
public void should_retry() {
// given
Instance instance = Instance.create(InstanceId.of("id")).register(Registration
.create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build());
String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"/mgmt/metrics/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"/mgmt/stats\"},\"info\":{\"templated\":false,\"href\":\"/mgmt/info\"}}}";
this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs(STARTED)
.willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER)).willSetStateTo("recovered"));
this.wireMock.stubFor(get("/mgmt").inScenario("retry").whenScenarioStateIs("recovered")
.willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(this.instanceWebClient);
// when
StepVerifier.create(strategy.detectEndpoints(instance))
// then
.expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))//
.verifyComplete();
}
@Test
public void should_add_default_accept_headers() {
Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", wireMock.url("/status")).build());
wireMock.stubFor(get("/status").willReturn(ok()));
Mono<ClientResponse> exchange = instanceWebClient.instance(instance).get().uri("health").exchange();
StepVerifier.create(exchange).expectNextCount(1).verifyComplete();
wireMock.verify(1,
getRequestedFor(urlEqualTo("/status")).withHeader(ACCEPT, containing(MediaType.APPLICATION_JSON_VALUE))
.withHeader(ACCEPT, containing(ActuatorMediaType.V1_JSON))
.withHeader(ACCEPT, containing(ActuatorMediaType.V2_JSON))
);
}
@Test
public void should_convert_legacy_endpont() {
Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", wireMock.url("/status")).build());
String responseBody = "{ \"status\" : \"UP\", \"foo\" : \"bar\" }";
wireMock.stubFor(get("/status").willReturn(okForContentType(ActuatorMediaType.V1_JSON, responseBody).withHeader(CONTENT_LENGTH,
Integer.toString(responseBody.length())
).withHeader("X-Custom", "1234")));
Mono<ClientResponse> exchange = instanceWebClient.instance(instance).get().uri("health").exchange();
StepVerifier.create(exchange).assertNext(response -> {
assertThat(response.headers().contentLength()).isEmpty();
assertThat(response.headers().contentType()).contains(MediaType.parseMediaType(ActuatorMediaType.V2_JSON));
assertThat(response.headers().header("X-Custom")).containsExactly("1234");
assertThat(response.headers().header(CONTENT_TYPE)).containsExactly(ActuatorMediaType.V2_JSON);
assertThat(response.headers().header(CONTENT_LENGTH)).isEmpty();
assertThat(response.headers().asHttpHeaders().get("X-Custom")).containsExactly("1234");
assertThat(response.headers().asHttpHeaders().get(CONTENT_TYPE)).containsExactly(ActuatorMediaType.V2_JSON);
assertThat(response.headers().asHttpHeaders().get(CONTENT_LENGTH)).isNull();
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
}).verifyComplete();
String expectedBody = "{\"status\":\"UP\",\"details\":{\"foo\":\"bar\"}}";
StepVerifier.create(exchange.flatMap(r -> r.bodyToMono(String.class)))
.assertNext(actualBody -> assertThat(actualBody).isEqualTo(expectedBody))
.verifyComplete();
wireMock.verify(2, getRequestedFor(urlEqualTo("/status")));
}
@Test
public void should_change_status_to_down() {
String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }";
wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body).withHeader("Content-Length",
Integer.toString(body.length())
)));
StepVerifier.create(eventStore)
.expectSubscription()
.then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete())
.assertNext(event -> {
assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class);
assertThat(event.getInstance()).isEqualTo(instance.getId());
InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event;
assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP");
assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo",
"bar"
));
})
.thenCancel()
.verify();
StepVerifier.create(repository.find(instance.getId()))
.assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP"))
.verifyComplete();
StepVerifier.create(repository.computeIfPresent(instance.getId(),
(key, instance) -> Mono.just(instance.deregister())
))
.then(() -> StepVerifier.create(updater.updateStatus(instance.getId())).verifyComplete())
.thenCancel()
.verify();
StepVerifier.create(repository.find(instance.getId()))
.assertNext(app -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN"))
.verifyComplete();
}
@Test
public void should_retry() {
//given
Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", wireMock.url("/mgmt/health"))
.managementUrl(wireMock.url("/mgmt"))
.build());
String body = "{\"_links\":{\"metrics-requiredMetricName\":{\"templated\":true,\"href\":\"\\/mgmt\\/metrics\\/{requiredMetricName}\"},\"self\":{\"templated\":false,\"href\":\"\\/mgmt\"},\"metrics\":{\"templated\":false,\"href\":\"\\/mgmt\\/stats\"},\"info\":{\"templated\":false,\"href\":\"\\/mgmt\\/info\"}}}";
wireMock.stubFor(get("/mgmt").inScenario("retry")
.whenScenarioStateIs(STARTED)
.willReturn(aResponse().withFixedDelay(5000))
.willSetStateTo("recovered"));
wireMock.stubFor(get("/mgmt").inScenario("retry")
.whenScenarioStateIs("recovered")
.willReturn(ok(body).withHeader("Content-Type", ActuatorMediaType.V2_JSON)
.withHeader("Content-Length",
Integer.toString(body.length())
)));
QueryIndexEndpointStrategy strategy = new QueryIndexEndpointStrategy(instanceWebClient);
//when
StepVerifier.create(strategy.detectEndpoints(instance))
//then
.expectNext(Endpoints.single("metrics", "/mgmt/stats").withEndpoint("info", "/mgmt/info"))//
.verifyComplete();
}
@RequestMapping(
value = "${edison.application.management.base-path:/internal}/loggers",
produces = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
method = GET)
@ResponseBody
public Object get() {
final Map<String, Object> levels = loggersEndpoint.loggers();
return (levels == null ? notFound().build() : levels);
}
@RequestMapping(
value = "${edison.application.management.base-path:/internal}/loggers/{name:.*}",
produces = {
ActuatorMediaType.V2_JSON,
APPLICATION_JSON_VALUE},
method = GET)
@ResponseBody
public Object get(@PathVariable String name) {
final LoggerLevels levels = loggersEndpoint.loggerLevels(name);
return (levels == null ? notFound().build() : levels);
}
@Test
public void health() throws SSLException {
webClient.get().uri("/actuator/health").
exchange().expectStatus().isUnauthorized();
webClient.get().uri("/actuator/health").
header(HttpHeaders.AUTHORIZATION, basicAuthHeader()).
exchange().
expectStatus().isOk().
expectHeader().valueEquals(HttpHeaders.CONTENT_TYPE, ActuatorMediaType.V3_JSON);
}
private void stubForInstance(String managementPath) {
String managementUrl = this.wireMock.url(managementPath);
//@formatter:off
String actuatorIndex = "{ \"_links\": { " +
"\"env\": { \"href\": \"" + managementUrl + "/env\", \"templated\": false }," +
"\"test\": { \"href\": \"" + managementUrl + "/test\", \"templated\": false }," +
"\"post\": { \"href\": \"" + managementUrl + "/post\", \"templated\": false }," +
"\"delete\": { \"href\": \"" + managementUrl + "/delete\", \"templated\": false }," +
"\"invalid\": { \"href\": \"" + managementUrl + "/invalid\", \"templated\": false }," +
"\"timeout\": { \"href\": \"" + managementUrl + "/timeout\", \"templated\": false }" +
" } }";
//@formatter:on
this.wireMock.stubFor(get(urlEqualTo(managementPath + "/health"))
.willReturn(ok("{ \"status\" : \"UP\" }").withHeader(CONTENT_TYPE, ActuatorMediaType.V2_JSON)));
this.wireMock.stubFor(get(urlEqualTo(managementPath + "/info"))
.willReturn(ok("{ }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
this.wireMock.stubFor(options(urlEqualTo(managementPath + "/env")).willReturn(
ok().withHeader(ALLOW, HttpMethod.HEAD.name(), HttpMethod.GET.name(), HttpMethod.OPTIONS.name())));
this.wireMock.stubFor(get(urlEqualTo(managementPath + ""))
.willReturn(ok(actuatorIndex).withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
this.wireMock.stubFor(
get(urlEqualTo(managementPath + "/invalid")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
this.wireMock.stubFor(get(urlEqualTo(managementPath + "/timeout")).willReturn(ok().withFixedDelay(10000)));
this.wireMock.stubFor(get(urlEqualTo(managementPath + "/test"))
.willReturn(ok("{ \"foo\" : \"bar\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
this.wireMock.stubFor(get(urlEqualTo(managementPath + "/test/has%20spaces"))
.willReturn(ok("{ \"foo\" : \"bar-with-spaces\" }").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
this.wireMock.stubFor(post(urlEqualTo(managementPath + "/post")).willReturn(ok()));
this.wireMock.stubFor(delete(urlEqualTo(managementPath + "/delete")).willReturn(serverError()
.withBody("{\"error\": \"You're doing it wrong!\"}").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
}
@Test
public void should_change_status_to_down() {
String body = "{ \"status\" : \"UP\", \"details\" : { \"foo\" : \"bar\" } }";
this.wireMock.stubFor(get("/health").willReturn(okForContentType(ActuatorMediaType.V2_JSON, body)
.withHeader("Content-Length", Integer.toString(body.length()))));
StepVerifier.create(this.eventStore).expectSubscription()
.then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete())
.assertNext((event) -> {
assertThat(event).isInstanceOf(InstanceStatusChangedEvent.class);
assertThat(event.getInstance()).isEqualTo(this.instance.getId());
InstanceStatusChangedEvent statusChangedEvent = (InstanceStatusChangedEvent) event;
assertThat(statusChangedEvent.getStatusInfo().getStatus()).isEqualTo("UP");
assertThat(statusChangedEvent.getStatusInfo().getDetails()).isEqualTo(singletonMap("foo", "bar"));
}).thenCancel().verify();
StepVerifier.create(this.repository.find(this.instance.getId()))
.assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UP")).verifyComplete();
StepVerifier
.create(this.repository.computeIfPresent(this.instance.getId(),
(key, instance) -> Mono.just(instance.deregister())))
.then(() -> StepVerifier.create(this.updater.updateStatus(this.instance.getId())).verifyComplete())
.thenCancel().verify();
StepVerifier.create(this.repository.find(this.instance.getId()))
.assertNext((app) -> assertThat(app.getStatusInfo().getStatus()).isEqualTo("UNKNOWN")).verifyComplete();
}
public void setUpClient(ConfigurableApplicationContext context) {
int localPort = context.getEnvironment().getProperty("local.server.port", Integer.class, 0);
client = WebTestClient.bindToServer()
.baseUrl("http://localhost:" + localPort)
.responseTimeout(Duration.ofSeconds(10))
.build();
String managementUrl = "http://localhost:" + wireMock.port() + "/mgmt";
//@formatter:off
String actuatorIndex = "{ \"_links\": { " +
"\"env\": { \"href\": \"" + managementUrl + "/env\", \"templated\": false }," +
"\"test\": { \"href\": \"" + managementUrl + "/test\", \"templated\": false }," +
"\"invalid\": { \"href\": \"" + managementUrl + "/invalid\", \"templated\": false }," +
"\"timeout\": { \"href\": \"" + managementUrl + "/timeout\", \"templated\": false }" +
" } }";
//@formatter:on
wireMock.stubFor(get(urlEqualTo("/mgmt/health")).willReturn(ok("{ \"status\" : \"UP\" }").withHeader(CONTENT_TYPE,
ActuatorMediaType.V2_JSON
)));
wireMock.stubFor(get(urlEqualTo("/mgmt/info")).willReturn(ok("{ }").withHeader(CONTENT_TYPE,
ACTUATOR_CONTENT_TYPE
)));
wireMock.stubFor(options(urlEqualTo("/mgmt/env")).willReturn(ok().withHeader(ALLOW,
HttpMethod.HEAD.name(),
HttpMethod.GET.name(),
HttpMethod.OPTIONS.name()
)));
wireMock.stubFor(get(urlEqualTo("/mgmt")).willReturn(ok(actuatorIndex).withHeader(CONTENT_TYPE,
ACTUATOR_CONTENT_TYPE
)));
wireMock.stubFor(get(urlEqualTo("/mgmt/invalid")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
wireMock.stubFor(get(urlEqualTo("/mgmt/timeout")).willReturn(ok().withFixedDelay(10000)));
wireMock.stubFor(get(urlEqualTo("/mgmt/test")).willReturn(ok("{ \"foo\" : \"bar\" }").withHeader(CONTENT_TYPE,
ACTUATOR_CONTENT_TYPE
)));
wireMock.stubFor(get(urlEqualTo("/mgmt/test/has%20spaces")).willReturn(ok("{ \"foo\" : \"bar-with-spaces\" }").withHeader(CONTENT_TYPE,
ACTUATOR_CONTENT_TYPE
)));
wireMock.stubFor(post(urlEqualTo("/mgmt/test")).willReturn(ok()));
wireMock.stubFor(delete(urlEqualTo("/mgmt/test")).willReturn(serverError().withBody(
"{\"error\": \"You're doing it wrong!\"}").withHeader(CONTENT_TYPE, ACTUATOR_CONTENT_TYPE)));
instanceId = registerInstance(managementUrl);
}
private static ClientResponse convertLegacyResponse(LegacyEndpointConverter converter, ClientResponse response) {
return ClientResponse.from(response).headers((headers) -> {
headers.replace(HttpHeaders.CONTENT_TYPE, singletonList(ActuatorMediaType.V2_JSON));
headers.remove(HttpHeaders.CONTENT_LENGTH);
}).body(response.bodyToFlux(DataBuffer.class).transform(converter::convert)).build();
}