Search in sources :

Example 86 with UriComponents

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

the class JWTSecurityService method createToken.

private static String createToken(String jwtKey, String path, Date expireDate) {
    UriComponents components = UriComponentsBuilder.fromUriString(path).build();
    String query = components.getQuery();
    String claim = components.getPath() + (!StringUtils.isBlank(query) ? "?" + components.getQuery() : "");
    logger.debug("Creating token with claim " + claim);
    return JWT.create().withClaim(CLAIM_PATH, claim).withExpiresAt(expireDate).sign(getAlgorithm(jwtKey));
}
Also used : UriComponents(org.springframework.web.util.UriComponents)

Example 87 with UriComponents

use of org.springframework.web.util.UriComponents in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Object... uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponentsBuilder, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 88 with UriComponents

use of org.springframework.web.util.UriComponents in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Map<String, ?> uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponentsBuilder, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 89 with UriComponents

use of org.springframework.web.util.UriComponents in project cuba by cuba-platform.

the class EntitiesController method createEntity.

@PostMapping("/{entityName}")
public ResponseEntity<String> createEntity(@RequestBody String entityJson, @PathVariable String entityName, @RequestParam(required = false) String modelVersion, HttpServletRequest request) {
    CreatedEntityInfo entityInfo = entitiesControllerManager.createEntity(entityJson, entityName, modelVersion);
    UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString()).path("/{id}").buildAndExpand(entityInfo.getId().toString());
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(uriComponents.toUri());
    return new ResponseEntity<>(entityInfo.getJson(), httpHeaders, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) UriComponents(org.springframework.web.util.UriComponents) ResponseEntity(org.springframework.http.ResponseEntity) CreatedEntityInfo(com.haulmont.restapi.data.CreatedEntityInfo)

Example 90 with UriComponents

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

the class HateoasPageableHandlerMethodArgumentResolverUnitTests method assertTemplateEnrichment.

private void assertTemplateEnrichment(String baseUri, String expected) {
    UriComponents uriComponents = UriComponentsBuilder.fromUriString(baseUri).build();
    HateoasPageableHandlerMethodArgumentResolver resolver = getResolver();
    assertThat(resolver.getPaginationTemplateVariables(null, uriComponents).toString()).isEqualTo(expected);
}
Also used : UriComponents(org.springframework.web.util.UriComponents)

Aggregations

UriComponents (org.springframework.web.util.UriComponents)133 Test (org.junit.jupiter.api.Test)43 Test (org.junit.Test)37 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)26 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)7 URI (java.net.URI)5 HashMap (java.util.HashMap)5 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)4 MethodParameter (org.springframework.core.MethodParameter)3 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Matchers.anyString (org.mockito.Matchers.anyString)2