Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter/Predicate validation message are not returned when management.server.port is set for actuator #2466

Open
abelsromero opened this issue Dec 17, 2021 · 1 comment

Comments

@abelsromero
Copy link
Contributor

abelsromero commented Dec 17, 2021

Describe the bug
The feature added in f6bfd6e does not work when user sets a custom management port with management.server.port.

Sample

The test below copied from current test

when run in SCG repo (main branch) fails with

java.lang.AssertionError: No value at JSON path "$.message"
  ...
Caused by: java.lang.IllegalArgumentException: json can not be null or empty

The only difference with original test is the use of management.server.port=0 to change the port and removal of unnecessary code.

package org.springframework.cloud.gateway.actuate;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import java.net.URI;
import java.util.Collections;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.BodyInserters;

@RunWith(SpringRunner.class)
@SpringBootTest(properties = { "management.endpoints.web.exposure.include=*",
		"spring.cloud.gateway.actuator.verbose.enabled=true",
		"management.server.port=0"
		}, webEnvironment = RANDOM_PORT)
public class GatewayControllerEndpointWithCustomManagementPortTests {

	@Autowired
	WebTestClient testClient;

	@LocalServerPort
	int port;

	@LocalManagementPort
	int managementPort;

	@Test
	public void testPostRouteWithNotExistingPredicate() {

		RouteDefinition testRouteDefinition = new RouteDefinition();
		testRouteDefinition.setUri(URI.create("http://example.org"));

		PredicateDefinition predicateDefinition = new PredicateDefinition("NotExistingPredicate=test-config");
		testRouteDefinition.setPredicates(Collections.singletonList(predicateDefinition));

		testClient.post().uri("http://localhost:" + managementPort + "/actuator/gateway/routes/test-route")
				.accept(MediaType.APPLICATION_JSON).body(BodyInserters.fromValue(testRouteDefinition)).exchange()
				.expectStatus().isBadRequest().expectBody().jsonPath("$.message")
				.isEqualTo("Invalid PredicateDefinition: [NotExistingPredicate]");
	}

	@SpringBootConfiguration
	@EnableAutoConfiguration
	@Import(PermitAllSecurityConfiguration.class)
	static class TestConfig {
	}

}
@abelsromero
Copy link
Contributor Author

From what we've seen, it seems WebExceptionHandler are loaded in different order running WebFluxResponseStatusExceptionHandler first witch automatically responds.

Without management port

  1. ExceptionHandlingWebHander
  2. DefaultErrorWebExceptionHandler
  3. WebFluxResponseStatusExceptionHandler

With it

  1. ExceptionHandlingWebHander
  2. WebFluxResponseStatusExceptionHandler
  3. DefaultErrorWebExceptionHandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants