Search in sources :

Example 31 with UriComponents

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

the class MvcUriComponentsBuilder method fromMethodInternal.

private static UriComponentsBuilder fromMethodInternal(UriComponentsBuilder baseUrl, Class<?> controllerType, Method method, Object... args) {
    baseUrl = getBaseUrlToUse(baseUrl);
    String typePath = getTypeRequestMapping(controllerType);
    String methodPath = getMethodRequestMapping(method);
    String path = pathMatcher.combine(typePath, methodPath);
    baseUrl.path(path);
    UriComponents uriComponents = applyContributors(baseUrl, method, args);
    return UriComponentsBuilder.newInstance().uriComponents(uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents)

Example 32 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromControllerWithCustomBaseUrlViaStaticCall.

@Test
public void testFromControllerWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromController(builder, 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) Test(org.junit.Test)

Example 33 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromControllerTwoTypeLevelMappings.

@Test
public void testFromControllerTwoTypeLevelMappings() {
    UriComponents uriComponents = fromController(InvalidController.class).build();
    assertThat(uriComponents.toUriString(), is("http://localhost/persons"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 34 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNameNotMapped.

@Test
public void testFromMethodNameNotMapped() throws Exception {
    UriComponents uriComponents = fromMethodName(UnmappedController.class, "unmappedMethod").build();
    assertThat(uriComponents.toUriString(), is("http://localhost/"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 35 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodCallWithCustomBaseUrlViaStaticCall.

@Test
public void testFromMethodCallWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build();
    assertEquals("http://example.org:9090/base/something/else", 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) 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