Search in sources :

Example 41 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromControllerUriTemplate.

@Test
public void testFromControllerUriTemplate() {
    UriComponents uriComponents = fromController(PersonsAddressesController.class).buildAndExpand(15);
    assertThat(uriComponents.toUriString(), endsWith("/people/15/addresses"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 42 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNameTypeLevelPathVariable.

@Test
public void testFromMethodNameTypeLevelPathVariable() throws Exception {
    this.request.setContextPath("/myapp");
    UriComponents uriComponents = fromMethodName(PersonsAddressesController.class, "getAddressesForCountry", "DE").buildAndExpand("1");
    assertThat(uriComponents.toUriString(), is("http://localhost/myapp/people/1/addresses/DE"));
}
Also used : UriComponents(org.springframework.web.util.UriComponents) Test(org.junit.Test)

Example 43 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNameWithCustomBaseUrlViaStaticCall.

@Test
public void testFromMethodNameWithCustomBaseUrlViaStaticCall() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromMethodName(builder, ControllerWithMethods.class, "methodWithPathVariable", new Object[] { "1" }).build();
    assertEquals("http://example.org:9090/base/something/1/foo", 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 44 with UriComponents

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

the class MvcUriComponentsBuilderTests method testFromMethodNameWithMetaAnnotation.

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

Example 45 with UriComponents

use of org.springframework.web.util.UriComponents in project libresonic by Libresonic.

the class JWTAuthenticationProvider method roughlyEqual.

private static boolean roughlyEqual(String expectedRaw, String requestedPathRaw) {
    logger.debug("Comparing expected [{}] vs requested [{}]", expectedRaw, requestedPathRaw);
    if (StringUtils.isEmpty(expectedRaw)) {
        logger.debug("False: empty expected");
        return false;
    }
    try {
        UriComponents expected = UriComponentsBuilder.fromUriString(expectedRaw).build();
        UriComponents requested = UriComponentsBuilder.fromUriString(requestedPathRaw).build();
        if (!Objects.equals(expected.getPath(), requested.getPath())) {
            logger.debug("False: expected path [{}] does not match requested path [{}]", expected.getPath(), requested.getPath());
            return false;
        }
        MapDifference<String, List<String>> difference = Maps.difference(expected.getQueryParams(), requested.getQueryParams());
        if (difference.entriesDiffering().size() != 0 || difference.entriesOnlyOnLeft().size() != 0 || difference.entriesOnlyOnRight().size() != 1 || difference.entriesOnlyOnRight().get(JWTSecurityService.JWT_PARAM_NAME) == null) {
            logger.debug("False: expected query params [{}] do not match requested query params [{}]", expected.getQueryParams(), requested.getQueryParams());
            return false;
        }
    } catch (Exception e) {
        logger.warn("Exception encountered while comparing paths", e);
        return false;
    }
    return true;
}
Also used : UriComponents(org.springframework.web.util.UriComponents) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) AuthenticationException(org.springframework.security.core.AuthenticationException)

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