Search in sources :

Example 11 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromControllerWithCustomBaseUrlViaInstance.

@Test
public void testFromControllerWithCustomBaseUrlViaInstance() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    MvcUriComponentsBuilder mvcBuilder = MvcUriComponentsBuilder.relativeTo(builder);
    UriComponents uriComponents = mvcBuilder.withController(PersonControllerImpl.class).build();
    assertEquals("http://example.org:9090/base/people", uriComponents.toString());
    assertEquals("http://example.org:9090/base", builder.toUriString());
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Test(org.junit.Test)

Example 12 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method usesFirstHostOfXForwardedHost.

@Test
public void usesFirstHostOfXForwardedHost() {
    request.addHeader("X-Forwarded-Host", "barfoo:8888, localhost:8088");
    UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
    assertThat(uriComponents.toUriString(), startsWith("http://barfoo:8888"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 13 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMappingNameWithOptionalParam.

// SPR-14405
@Test
public void testFromMappingNameWithOptionalParam() throws Exception {
    UriComponents uriComponents = fromMethodName(ControllerWithMethods.class, "methodWithOptionalParam", new Object[] { null }).build();
    assertThat(uriComponents.toUriString(), is("http://localhost/something/optional-param"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 14 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method usesForwardedHostAndPortFromHeader.

@Test
public void usesForwardedHostAndPortFromHeader() {
    request.addHeader("X-Forwarded-Host", "foobar:8088");
    UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
    assertThat(uriComponents.toUriString(), startsWith("http://foobar:8088"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 15 with UriComponents

use of org.springframework.web.util.UriComponents in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodNameTypeLevelPathVariableWithoutArgumentValue.

// SPR-11391
@Test
public void testFromMethodNameTypeLevelPathVariableWithoutArgumentValue() throws Exception {
    UriComponents uriComponents = fromMethodName(UserContactController.class, "showCreate", 123).build();
    assertThat(uriComponents.getPath(), is("/user/123/contacts/create"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Aggregations

UriComponents (org.springframework.web.util.UriComponents)48 Test (org.junit.Test)32 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)10 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)6 HttpRequest (org.springframework.http.HttpRequest)2 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)2 AuthenticationException (org.springframework.security.core.AuthenticationException)2 JsonParseException (com.google.gson.JsonParseException)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 MethodParameter (org.springframework.core.MethodParameter)1 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1