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-projects-issues opened this issue Jan 3, 2017 · 1 comment
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants