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

ServerHttpRequest getURI doesn't return the port the application is running on [SPR-15084] #19650

Closed
spring-issuemaster opened this issue Jan 3, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 3, 2017

Abhijit Sarkar opened SPR-15084 and commented

Brain dead simple application:

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RestController
    public static class DemoController {
        @GetMapping("/")
        public String getUri(ServerHttpRequest request) {
            return request.getURI().toString();
        }
    }
}

Test:

@RunWith(SpringRunner.class)
@SpringBootTest(
        webEnvironment = RANDOM_PORT
)
public class DemoApplicationTest {
    @LocalServerPort
    private int port;

    private WebClient webClient = WebClient.create(new ReactorClientHttpConnector());

    @Test
    public void testGetUri() {
        ClientRequest<Void> request = ClientRequest.GET("http://localhost:" + port)
                .build();

        URI uri = webClient.exchange(request)
                .then(response -> response.bodyToMono(String.class))
                .log()
                .map(URI::create)
                .block(Duration.ofSeconds(3l));

        assertThat(uri.getPort())
                .as("Application port: %d, returned port: %d.", port, uri.getPort())
                .isEqualTo(port);
    }
}

Failure:

org.junit.ComparisonFailure: [Application port: 14645, returned port: 55802.] 
Expected :14645
Actual   :55802

I've attached the Gradle project.


Affects: 5.0 M4

Attachments:

Referenced from: commits 5cac619

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jul 14, 2017

wufengbin commented

mabye it's due to your enverment。it calling other process when running your programs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.