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"));
}
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"));
}
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());
}
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"));
}
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;
}
Aggregations