Java Code Examples for org.springframework.mock.web.test.MockHttpServletRequest#setServerPort()
The following examples show how to use
org.springframework.mock.web.test.MockHttpServletRequest#setServerPort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UriComponentsBuilderTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-16262 public void fromHttpRequestForwardedHeaderWithProtoAndServerPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Forwarded", "proto=https"); request.setScheme("http"); request.setServerPort(8080); request.setServerName("example.com"); request.setRequestURI("/rest/mobile/users/1"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https", result.getScheme()); assertEquals("example.com", result.getHost()); assertEquals("/rest/mobile/users/1", result.getPath()); assertEquals(-1, result.getPort()); assertEquals("https://example.com/rest/mobile/users/1", result.toUriString()); }
Example 2
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void fromHttpRequestForwardedHeaderWithHostPortAndServerPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Forwarded", "proto=https; host=84.198.58.199:9090"); request.setScheme("http"); request.setServerPort(8080); request.setServerName("example.com"); request.setRequestURI("/rest/mobile/users/1"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https", result.getScheme()); assertEquals("84.198.58.199", result.getHost()); assertEquals("/rest/mobile/users/1", result.getPath()); assertEquals(9090, result.getPort()); assertEquals("https://84.198.58.199:9090/rest/mobile/users/1", result.toUriString()); }
Example 3
Source File: ServletUriComponentsBuilderTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void fromRequestWithForwardedHostAndPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(80); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Proto", "https"); request.addHeader("X-Forwarded-Host", "84.198.58.199"); request.addHeader("X-Forwarded-Port", "443"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https://84.198.58.199/mvc-showcase", result.toString()); }
Example 4
Source File: UriComponentsBuilderTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void fromHttpRequest() throws URISyntaxException { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/path"); request.setQueryString("a=1"); UriComponents result = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)).build(); assertEquals("http", result.getScheme()); assertEquals("localhost", result.getHost()); assertEquals(-1, result.getPort()); assertEquals("/path", result.getPath()); assertEquals("a=1", result.getQuery()); }
Example 5
Source File: UriComponentsBuilderTests.java From spring-analysis-note with MIT License | 6 votes |
@Test // SPR-12771 public void fromHttpRequestWithForwardedProtoAndDefaultPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(80); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Proto", "https"); request.addHeader("X-Forwarded-Host", "84.198.58.199"); request.addHeader("X-Forwarded-Port", "443"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https://84.198.58.199/mvc-showcase", result.toString()); }
Example 6
Source File: WebUtilsTests.java From spring-analysis-note with MIT License | 6 votes |
private void testWithXForwardedHeaders(String serverName, int port, String forwardedProto, String forwardedHost, int forwardedPort, String originHeader) throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setServerName(serverName); if (port != -1) { request.setServerPort(port); } if (forwardedProto != null) { request.addHeader("X-Forwarded-Proto", forwardedProto); } if (forwardedHost != null) { request.addHeader("X-Forwarded-Host", forwardedHost); } if (forwardedPort != -1) { request.addHeader("X-Forwarded-Port", String.valueOf(forwardedPort)); } request.addHeader(HttpHeaders.ORIGIN, originHeader); HttpServletRequest requestToUse = adaptFromForwardedHeaders(request); ServerHttpRequest httpRequest = new ServletServerHttpRequest(requestToUse); assertTrue(WebUtils.isSameOrigin(httpRequest)); }
Example 7
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 6 votes |
@Test // SPR-12816 public void fromHttpRequestWithForwardedProtoMultiValueHeader() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(8080); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "a.example.org"); request.addHeader("X-Forwarded-Port", "443"); request.addHeader("X-Forwarded-Proto", "https,https"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https://a.example.org/mvc-showcase", result.toString()); }
Example 8
Source File: UriComponentsBuilderTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("X-Forwarded-Proto", "https"); request.addHeader("X-Forwarded-Host", "84.198.58.199"); request.addHeader("X-Forwarded-Port", 443); request.setScheme("http"); request.setServerName("example.com"); request.setServerPort(80); request.setRequestURI("/rest/mobile/users/1"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https", result.getScheme()); assertEquals("84.198.58.199", result.getHost()); assertEquals(-1, result.getPort()); assertEquals("/rest/mobile/users/1", result.getPath()); }
Example 9
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void fromHttpRequest() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/path"); request.setQueryString("a=1"); UriComponents result = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)).build(); assertEquals("http", result.getScheme()); assertEquals("localhost", result.getHost()); assertEquals(-1, result.getPort()); assertEquals("/path", result.getPath()); assertEquals("a=1", result.getQuery()); }
Example 10
Source File: WebUtilsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private boolean checkValidOrigin(String serverName, int port, String originHeader, List<String> allowed) { MockHttpServletRequest servletRequest = new MockHttpServletRequest(); ServerHttpRequest request = new ServletServerHttpRequest(servletRequest); servletRequest.setServerName(serverName); if (port != -1) { servletRequest.setServerPort(port); } request.getHeaders().set(HttpHeaders.ORIGIN, originHeader); return WebUtils.isValidOrigin(request, allowed); }
Example 11
Source File: DefaultServerRequestTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void uri() { MockHttpServletRequest servletRequest = new MockHttpServletRequest("GET", "/"); servletRequest.setServerName("example.com"); servletRequest.setScheme("https"); servletRequest.setServerPort(443); DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters); assertEquals(URI.create("https://example.com/"), request.uri()); }
Example 12
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-12813 public void fromHttpRequestWithForwardedPortMultiValueHeader() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(9090); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "a.example.org"); request.addHeader("X-Forwarded-Port", "80,52022"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("http://a.example.org/mvc-showcase", result.toString()); }
Example 13
Source File: UriComponentsBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-16863 public void fromHttpRequestWithForwardedSsl() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("example.org"); request.setServerPort(10080); request.addHeader("X-Forwarded-Ssl", "on"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https", result.getScheme()); assertEquals("example.org", result.getHost()); assertEquals(-1, result.getPort()); }
Example 14
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-11872 public void fromHttpRequestWithForwardedHostWithDefaultPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(10080); request.addHeader("X-Forwarded-Host", "example.org"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("example.org", result.getHost()); assertEquals(-1, result.getPort()); }
Example 15
Source File: UriComponentsBuilderTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void fromHttpRequestWithForwardedHostWithDefaultPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(10080); request.addHeader("X-Forwarded-Host", "example.org"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("example.org", result.getHost()); assertEquals(-1, result.getPort()); }
Example 16
Source File: UriComponentsBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-10701 public void fromHttpRequestWithForwardedHostIncludingPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "webtest.foo.bar.com:443"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("webtest.foo.bar.com", result.getHost()); assertEquals(443, result.getPort()); }
Example 17
Source File: UriComponentsBuilderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-14761 public void fromHttpRequestWithForwardedIPv6HostAndPort() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "[1abc:2abc:3abc::5ABC:6abc]:8080"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("http://[1abc:2abc:3abc::5ABC:6abc]:8080/mvc-showcase", result.toString()); }
Example 18
Source File: UriComponentsBuilderTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void fromHttpRequestWithForwardedPortMultiValueHeader() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(9090); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "a.example.org"); request.addHeader("X-Forwarded-Port", "80,52022"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("http://a.example.org/mvc-showcase", result.toString()); }
Example 19
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void fromHttpRequestWithForwardedHost() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("localhost"); request.setServerPort(-1); request.setRequestURI("/mvc-showcase"); request.addHeader("X-Forwarded-Host", "anotherHost"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("http://anotherHost/mvc-showcase", result.toString()); }
Example 20
Source File: UriComponentsBuilderTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-16863 public void fromHttpRequestWithForwardedSsl() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme("http"); request.setServerName("example.org"); request.setServerPort(10080); request.addHeader("X-Forwarded-Ssl", "on"); HttpRequest httpRequest = new ServletServerHttpRequest(request); UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build(); assertEquals("https", result.getScheme()); assertEquals("example.org", result.getHost()); assertEquals(-1, result.getPort()); }