List of usage examples for org.springframework.web.util UriComponentsBuilder fromUri
public static UriComponentsBuilder fromUri(URI uri)
From source file:org.opencredo.couchdb.inbound.CouchDbAllDocumentsMessageSource.java
public Message<URI> receive() { if (toBeReceived.isEmpty()) { URI skipUri = UriComponentsBuilder.fromUri(databaseUri).replaceQueryParam("limit", limit) .replaceQueryParam("skip", skip).build().toUri(); ObjectNode response = couchDbDocumentOperations.readDocument(skipUri, ObjectNode.class); ArrayNode rows = (ArrayNode) response.get("rows"); int size = rows.size(); Assert.isTrue(size <= limit, "Retrieved more rows than limit"); for (int i = 0; i < size; i++) { JsonNode node = rows.get(i); String id = node.get("id").textValue(); try { toBeReceived.add(new URI(baseUri + "/" + id)); skip++;/* w w w.j av a 2 s .c om*/ } catch (URISyntaxException e) { logger.error("Error creating the URI of document from baseUri and ID", e); return null; } } } Map<String, String> headers = createHeaderMap(databaseUri, skip, limit); return prepareMessage(toBeReceived.poll(), headers); }
From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClient.java
@Override public RibbonApacheHttpResponse execute(RibbonApacheHttpRequest request, final IClientConfig configOverride) throws Exception { final RequestConfig.Builder builder = RequestConfig.custom(); IClientConfig config = configOverride != null ? configOverride : this.config; builder.setConnectTimeout(config.get(CommonClientConfigKey.ConnectTimeout, this.connectTimeout)); builder.setSocketTimeout(config.get(CommonClientConfigKey.ReadTimeout, this.readTimeout)); builder.setRedirectsEnabled(config.get(CommonClientConfigKey.FollowRedirects, this.followRedirects)); final RequestConfig requestConfig = builder.build(); if (isSecure(configOverride)) { final URI secureUri = UriComponentsBuilder.fromUri(request.getUri()).scheme("https").build().toUri(); request = request.withNewUri(secureUri); }//from w ww.j av a2 s .c om final HttpUriRequest httpUriRequest = request.toRequest(requestConfig); final HttpResponse httpResponse = this.delegate.execute(httpUriRequest); return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI()); }
From source file:com.expedia.seiso.web.hateoas.link.PaginationLinkBuilder.java
private UriComponentsBuilder uriComponentsBuilder() { return UriComponentsBuilder.fromUri(uriComponents.toUri()); }
From source file:io.pivotal.xd.chaoslemur.infrastructure.StandardDirectorUtils.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a 2 s .c om public Set<String> getDeployments() { URI deploymentsUri = UriComponentsBuilder.fromUri(this.root).path("deployments").build().toUri(); List<Map<String, String>> deployments = this.restTemplate.getForObject(deploymentsUri, List.class); return deployments.stream().map(deployment -> deployment.get("name")).collect(Collectors.toSet()); }
From source file:io.bosh.client.internal.AbstractSpringOperations.java
protected final <T, R> Observable<ResponseEntity<R>> exchangeForEntity(T request, Class<R> responseType, HttpHeaders headers, HttpMethod method, Consumer<UriComponentsBuilder> builderCallback) { return createObservable(() -> { UriComponentsBuilder builder = UriComponentsBuilder.fromUri(this.root); builderCallback.accept(builder); URI uri = builder.build().toUri(); RequestEntity<T> requestEntity = new RequestEntity<T>(request, headers, HttpMethod.PUT, uri); this.logger.debug("{} {}", method, uri); return this.restOperations.exchange(requestEntity, responseType); });/*from w w w . j a va2 s. c om*/ }
From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java
@Test public void testDefaultScopes() 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"); postBody.add("source", "credentials"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode()); UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation()) .build();/* w w w . j a v a2 s .c o 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")); Jwt access_token = JwtHelper.decode(params.getFirst("access_token")); Map<String, Object> claims = new ObjectMapper().readValue(access_token.getClaims(), new TypeReference<Map<String, Object>>() { }); Assert.assertThat((String) claims.get("jti"), is(params.getFirst("jti"))); Assert.assertThat((String) claims.get("client_id"), is("cf")); Assert.assertThat((String) claims.get("cid"), is("cf")); Assert.assertThat((String) claims.get("user_name"), is(testAccounts.getUserName())); Assert.assertThat(((List<String>) claims.get("scope")), containsInAnyOrder(scopes)); Assert.assertThat(((List<String>) claims.get("aud")), containsInAnyOrder("cf", "scim", "openid", "cloud_controller", "password")); }
From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiControllerLinkBuilder.java
/** * Returns a {@link UriComponentsBuilder} to continue to build the already built URI in a more fine grained way. * /*from w ww . ja v a 2s.c om*/ * @return */ public UriComponentsBuilder toUriComponentsBuilder() { return UriComponentsBuilder.fromUri(toUri()); }
From source file:org.springframework.cloud.netflix.ribbon.apache.RetryableRibbonLoadBalancingHttpClient.java
@Override public RibbonApacheHttpResponse execute(final RibbonApacheHttpRequest request, final IClientConfig configOverride) throws Exception { final RequestConfig.Builder builder = RequestConfig.custom(); IClientConfig config = configOverride != null ? configOverride : this.config; builder.setConnectTimeout(config.get(CommonClientConfigKey.ConnectTimeout, this.connectTimeout)); builder.setSocketTimeout(config.get(CommonClientConfigKey.ReadTimeout, this.readTimeout)); builder.setRedirectsEnabled(config.get(CommonClientConfigKey.FollowRedirects, this.followRedirects)); final RequestConfig requestConfig = builder.build(); final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this); RetryCallback retryCallback = new RetryCallback() { @Override/* w ww .j a v a 2s . c om*/ public RibbonApacheHttpResponse doWithRetry(RetryContext context) throws Exception { //on retries the policy will choose the server and set it in the context //extract the server and update the request being made RibbonApacheHttpRequest newRequest = request; if (context instanceof LoadBalancedRetryContext) { ServiceInstance service = ((LoadBalancedRetryContext) context).getServiceInstance(); if (service != null) { //Reconstruct the request URI using the host and port set in the retry context newRequest = newRequest .withNewUri(new URI(service.getUri().getScheme(), newRequest.getURI().getUserInfo(), service.getHost(), service.getPort(), newRequest.getURI().getPath(), newRequest.getURI().getQuery(), newRequest.getURI().getFragment())); } } if (isSecure(configOverride)) { final URI secureUri = UriComponentsBuilder.fromUri(newRequest.getUri()).scheme("https").build() .toUri(); newRequest = newRequest.withNewUri(secureUri); } HttpUriRequest httpUriRequest = newRequest.toRequest(requestConfig); final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate .execute(httpUriRequest); if (retryPolicy.retryableStatusCode(httpResponse.getStatusLine().getStatusCode())) { throw new RetryableStatusCodeException(RetryableRibbonLoadBalancingHttpClient.this.clientName, httpResponse.getStatusLine().getStatusCode()); } return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI()); } }; return this.executeWithRetry(request, retryPolicy, retryCallback); }