List of usage examples for org.springframework.web.util UriComponentsBuilder fromUri
public static UriComponentsBuilder fromUri(URI uri)
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java
private OwncloudRestResourceExtension renameOwncloudResource(OwncloudRestResourceExtension resource, OwncloudResourceConversionProperties conversionProperties) { if (StringUtils.isBlank(conversionProperties.getRenamedSearchPath())) { return resource; }/*from w w w.ja v a2 s . co m*/ URI resourcePath = URI.create(UriComponentsBuilder.fromUri(conversionProperties.getRootPath()) .path(resource.getHref().getPath()).toUriString()).normalize(); if (conversionProperties.getSearchPath().equals(resourcePath)) { log.debug("Rename OwncloudResource {} based by {} to {}", resource.getName(), resource.getHref(), conversionProperties.getRenamedSearchPath()); resource.setName(conversionProperties.getRenamedSearchPath()); } return resource; }
From source file:org.joyrest.oauth2.endpoint.AuthorizationEndpoint.java
private String append(String base, Map<String, ?> query, Map<String, String> keys, boolean fragment) { UriComponentsBuilder template = UriComponentsBuilder.newInstance(); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(base); URI redirectUri;//from w ww . jav a2 s . c o m try { // assume it's encoded to start with (if it came in over the wire) redirectUri = builder.build(true).toUri(); } catch (Exception e) { // ... but allow client registrations to contain hard-coded non-encoded values redirectUri = builder.build().toUri(); builder = UriComponentsBuilder.fromUri(redirectUri); } template.scheme(redirectUri.getScheme()).port(redirectUri.getPort()).host(redirectUri.getHost()) .userInfo(redirectUri.getUserInfo()).path(redirectUri.getPath()); if (fragment) { StringBuilder values = new StringBuilder(); if (redirectUri.getFragment() != null) { String append = redirectUri.getFragment(); values.append(append); } for (String key : query.keySet()) { if (values.length() > 0) { values.append("&"); } String name = key; if (keys != null && keys.containsKey(key)) { name = keys.get(key); } values.append(name + "={" + key + "}"); } if (values.length() > 0) { template.fragment(values.toString()); } UriComponents encoded = template.build().expand(query).encode(); builder.fragment(encoded.getFragment()); } else { for (String key : query.keySet()) { String name = key; if (nonNull(keys) && keys.containsKey(key)) { name = keys.get(key); } template.queryParam(name, "{" + key + "}"); } template.fragment(redirectUri.getFragment()); UriComponents encoded = template.build().expand(query).encode(); builder.query(encoded.getQuery()); } return builder.build().toUriString(); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java
private Stream<OwncloudResource> listParentOwncloudResourcesOf(URI searchPath) throws IOException { URI parentPath = URI.create(UriComponentsBuilder.fromUri(searchPath.normalize()).path("/../").toUriString()) .normalize();//from w w w.ja va 2s . c om log.debug("Get the List of WebDAV Resources based by Parent URI {}", parentPath); URI userRoot = getUserRoot(); val parentDirectoryConversionProperties = OwncloudResourceConversionProperties.builder().rootPath(userRoot) .searchPath(parentPath).renamedSearchPath("..").build(); Sardine sardine = getSardine(); List<DavResource> davResources = sardine.list(parentPath.toString(), 0); return davResources.stream() .map(davResource -> createOwncloudResourceFrom(davResource, parentDirectoryConversionProperties)) .map(modifyingResource -> renameOwncloudResource(modifyingResource, parentDirectoryConversionProperties)); }
From source file:com.gooddata.dataload.processes.ProcessService.java
/** * Get defined page of paged list of schedules by given project. * * @param project project of schedules/*www.java2 s. c om*/ * @param page page to be retrieved * @return list of found schedules or empty list */ public PageableList<Schedule> listSchedules(Project project, Page page) { notNull(project, "project"); notNull(page, "page"); return listSchedules(page.getPageUri(UriComponentsBuilder.fromUri(getSchedulesUri(project)))); }
From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImpl.java
/** * Builds an absolute HTTP URL from a supplied base URI, a relative path an an optional map of request parameters. * <p>/*from ww w . j a v a 2 s.co m*/ * Supports building URLs before URL template variables have been expanded - template variable placeholders ({...}) * will _not_ be encoded. * * @param baseUri The {@link URL base URI}. * @param relativeUrlPath The relative path to be appended to the base URI. * @param requestParams An optional, map representation of request parameters to be appended to the URL. Can be null. * @return A String representation of the absolute URL. A return type of String rather than {@link java.net.URI} is * used to avoid encoding the URL before any template variables have been replaced. */ private static String buildAbsoluteHttpUrl(URI baseUri, String relativeUrlPath, Map<String, List<String>> requestParams) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUri(baseUri); uriBuilder.path(relativeUrlPath); if (requestParams != null) { for (String paramName : requestParams.keySet()) { for (String paramValue : requestParams.get(paramName)) { uriBuilder.queryParam(paramName, paramValue); } } } UriComponents uriComponents = uriBuilder.build(); return uriComponents.toUriString(); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java
private URI resolveAsFileURI(URI relativeTo, String username) { URI userRoot = getResolvedRootUri(username); if (relativeTo == null || StringUtils.isBlank(relativeTo.getPath())) { return userRoot; }/*from w ww. j a va 2s . co m*/ return URI.create(UriComponentsBuilder.fromUri(userRoot).path(relativeTo.getPath()).toUriString()) .normalize(); }
From source file:com.thinkbiganalytics.metadata.rest.client.MetadataClient.java
private UriComponentsBuilder base(Path path) { return UriComponentsBuilder.fromUri(this.base).path("/").path(path.toString()); }
From source file:com.thinkbiganalytics.metadata.rest.client.MetadataClient.java
private UriComponentsBuilder baseProxy(Path path) { return UriComponentsBuilder.fromUri(this.proxyBase).path("/").path(path.toString()); }
From source file:org.cloudfoundry.identity.uaa.integration.feature.OpenIdTokenGrantsIT.java
@Test public void testImplicitGrant() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("client_id", "cf"); postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf"); postBody.add("response_type", "token id_token"); postBody.add("source", "credentials"); postBody.add("username", user.getUserName()); postBody.add("password", secret); ResponseEntity<Void> responseEntity = restOperations.exchange(loginUrl + "/oauth/authorize", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode()); UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation()) .build();/*from w w w . j a v a2s .co m*/ Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost()); Assert.assertEquals("/redirect/cf", locationComponents.getPath()); MultiValueMap<String, String> params = parseFragmentParams(locationComponents); Assert.assertThat(params.get("jti"), not(empty())); Assert.assertEquals("bearer", params.getFirst("token_type")); Assert.assertThat(Integer.parseInt(params.getFirst("expires_in")), Matchers.greaterThan(40000)); String[] scopes = UriUtils.decode(params.getFirst("scope"), "UTF-8").split(" "); Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write", "cloud_controller.write", "openid", "cloud_controller.read", "uaa.user")); validateToken("access_token", params.toSingleValueMap(), scopes, aud); validateToken("id_token", params.toSingleValueMap(), openid, new String[] { "cf" }); }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
@Test public void invalidScopeErrorMessageIsNotShowingAllClientScopes() throws Exception { String clientId = "testclient" + generator.generate(); String scopes = "openid"; setUpClients(clientId, scopes, scopes, "authorization_code", true); String username = "testuser" + generator.generate(); ScimUser developer = setUpUser(username, "scim.write", OriginKeys.UAA, IdentityZoneHolder.getUaaZone().getId()); MockHttpSession session = getAuthenticatedSession(developer); String basicDigestHeaderValue = "Basic " + new String( org.apache.commons.codec.binary.Base64.encodeBase64((clientId + ":" + SECRET).getBytes())); String state = generator.generate(); MockHttpServletRequestBuilder authRequest = get("/oauth/authorize") .header("Authorization", basicDigestHeaderValue).session(session) .param(OAuth2Utils.RESPONSE_TYPE, "code").param(OAuth2Utils.SCOPE, "scim.write") .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId) .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI); MvcResult mvcResult = getMockMvc().perform(authRequest).andExpect(status().is3xxRedirection()).andReturn(); UriComponents locationComponents = UriComponentsBuilder .fromUri(URI.create(mvcResult.getResponse().getHeader("Location"))).build(); MultiValueMap<String, String> queryParams = locationComponents.getQueryParams(); String errorMessage = URIUtil .encodeQuery("scim.write is invalid. Please use a valid scope name in the request"); assertTrue(!queryParams.containsKey("scope")); assertEquals(errorMessage, queryParams.getFirst("error_description")); }