/** * This property has the same purpose as the corresponding property on the * {@code RestTemplate}. For more details see * {@link RestTemplate#setUriTemplateHandler}. * @param handler the URI template handler to use */ public void setUriTemplateHandler(UriTemplateHandler handler) { this.syncTemplate.setUriTemplateHandler(handler); }
/** * This property has the same purpose as the corresponding property on the * {@code RestTemplate}. For more details see * {@link RestTemplate#setUriTemplateHandler}. * @param handler the URI template handler to use */ public void setUriTemplateHandler(UriTemplateHandler handler) { this.syncTemplate.setUriTemplateHandler(handler); }
/** * Add a {@link RootUriTemplateHandler} instance to the given {@link RestTemplate}. * @param restTemplate the {@link RestTemplate} to add the handler to * @param rootUri the root URI * @return the added {@link RootUriTemplateHandler}. */ public static RootUriTemplateHandler addTo(RestTemplate restTemplate, String rootUri) { Assert.notNull(restTemplate, "RestTemplate must not be null"); RootUriTemplateHandler handler = new RootUriTemplateHandler(rootUri, restTemplate.getUriTemplateHandler()); restTemplate.setUriTemplateHandler(handler); return handler; }
restTemplate.setUriTemplateHandler(this.uriTemplateHandler);
@Test public void getForObjectWithCustomUriTemplateHandler() throws Exception { DefaultUriBuilderFactory uriTemplateHandler = new DefaultUriBuilderFactory(); template.setUriTemplateHandler(uriTemplateHandler); mockSentRequest(GET, "http://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150"); mockResponseStatus(HttpStatus.OK); given(response.getHeaders()).willReturn(new HttpHeaders()); given(response.getBody()).willReturn(StreamUtils.emptyInput()); Map<String, String> uriVariables = new HashMap<>(2); uriVariables.put("hotel", "1"); uriVariables.put("publicpath", "pics/logo.png"); uriVariables.put("scale", "150x150"); String url = "http://example.com/hotels/{hotel}/pic/{publicpath}/size/{scale}"; template.getForObject(url, String.class, uriVariables); verify(response).close(); }
@Override public void setUriTemplateHandler(UriTemplateHandler handler) { super.setUriTemplateHandler(handler); defaultRestTemplate.setUriTemplateHandler(handler); }
@Override public void customize(RestTemplate restTemplate) { UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); templateHandler = this.interceptor.createUriTemplateHandler(templateHandler); restTemplate.setUriTemplateHandler(templateHandler); List<ClientHttpRequestInterceptor> existingInterceptors = restTemplate .getInterceptors(); if (!existingInterceptors.contains(this.interceptor)) { List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); interceptors.add(this.interceptor); interceptors.addAll(existingInterceptors); restTemplate.setInterceptors(interceptors); } }
/** * Configure the {@link UriTemplateHandler} to use to expand URI templates. By default * the {@link DefaultUriBuilderFactory} is used which relies on Spring's URI template * support and exposes several useful properties that customize its behavior for * encoding and for prepending a common base URL. An alternative implementation may be * used to plug an external URI template library. * @param handler the URI template handler to use */ public void setUriTemplateHandler(UriTemplateHandler handler) { this.restTemplate.setUriTemplateHandler(handler); }
@Override public void setUriTemplateHandler(UriTemplateHandler handler) { super.setUriTemplateHandler(handler); defaultRestTemplate.setUriTemplateHandler(handler); }
/** * This property has the same purpose as the corresponding property on the * {@code RestTemplate}. For more details see * {@link RestTemplate#setUriTemplateHandler}. * @param handler the URI template handler to use */ public void setUriTemplateHandler(UriTemplateHandler handler) { this.syncTemplate.setUriTemplateHandler(handler); }
@Override public void setUriTemplateHandler(UriTemplateHandler handler) { super.setUriTemplateHandler(handler); defaultRestTemplate.setUriTemplateHandler(handler); }
/** * This property has the same purpose as the corresponding property on the * {@code RestTemplate}. For more details see * {@link RestTemplate#setUriTemplateHandler}. * @param handler the URI template handler to use */ public void setUriTemplateHandler(UriTemplateHandler handler) { this.syncTemplate.setUriTemplateHandler(handler); }
public void setUriTemplateHandler(UriTemplateHandler handler) { restTemplate.setUriTemplateHandler(handler); }
@Override public void customize(RestTemplate restTemplate) { UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); templateHandler = this.interceptor.createUriTemplateHandler(templateHandler); restTemplate.setUriTemplateHandler(templateHandler); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); interceptors.add(this.interceptor); interceptors.addAll(restTemplate.getInterceptors()); restTemplate.setInterceptors(interceptors); }
@Override public GitHubRepository getRepository(String organization, String name) { RestTemplate restTemplate = new RestTemplate(); restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { request.getHeaders().add("User-Agent", StandardGitHub.this.username); request.getHeaders() .add("Authorization", "Basic " + Base64.getEncoder() .encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password) .getBytes())); request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE); return execution.execute(request, body); } }); UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory( "https://api.github.com/repos/" + organization + "/" + name + "/"); restTemplate.setUriTemplateHandler(uriTemplateHandler); return new StandardGitHubRepository(restTemplate); }
restTemplate.setUriTemplateHandler((UriTemplateHandler) clientParams.get(URI_TEMPLATE_HANDLER.value));
/** * Create a {@link RestTemplate} configured with {@link VaultEndpointProvider} and * {@link ClientHttpRequestFactory}. The template accepts relative URIs without a * leading slash that are expanded to use {@link VaultEndpoint}. {@link RestTemplate} * is configured with a {@link ClientHttpRequestInterceptor} to enforce serialization * to a byte array prior continuing the request. Eager serialization leads to a known * request body size that is required to send a * {@link org.springframework.http.HttpHeaders#CONTENT_LENGTH} request header. * Otherwise, Vault will deny body processing. * <p> * Requires Jackson 2 for Object-to-JSON mapping. * * @param endpointProvider must not be {@literal null}. * @param requestFactory must not be {@literal null}. * @return the {@link RestTemplate}. * @see org.springframework.http.client.Netty4ClientHttpRequestFactory * @see MappingJackson2HttpMessageConverter * @since 1.1 */ public static RestTemplate createRestTemplate(VaultEndpointProvider endpointProvider, ClientHttpRequestFactory requestFactory) { RestTemplate restTemplate = createRestTemplate(); restTemplate.setRequestFactory(requestFactory); restTemplate.setUriTemplateHandler(createUriBuilderFactory(endpointProvider)); return restTemplate; }