Java Code Examples for org.springframework.web.client.RestTemplate#setUriTemplateHandler()
The following examples show how to use
org.springframework.web.client.RestTemplate#setUriTemplateHandler() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sdk File: AviRestUtils.java License: Apache License 2.0 | 6 votes |
public static RestTemplate getRestTemplate(AviCredentials creds) { RestTemplate restTemplate = null; if (creds != null) { try { restTemplate = getInitializedRestTemplate(creds); restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(getControllerURL(creds) + API_PREFIX)); List<ClientHttpRequestInterceptor> interceptors = Collections.<ClientHttpRequestInterceptor>singletonList( new AviAuthorizationInterceptor(creds)); restTemplate.setInterceptors(interceptors); restTemplate.setMessageConverters(getMessageConverters(restTemplate)); return restTemplate; } catch (Exception e) { LOGGER.severe("Exception during rest template initialization"); } } return restTemplate; }
Example 2
Source Project: spring-vault File: VaultClientsUnitTests.java License: Apache License 2.0 | 6 votes |
@Test void shouldAllowNamespaceOverride() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("foo/bar")); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); MockRestServiceServer mockRest = MockRestServiceServer.createServer(restTemplate); mockRest.expect(requestTo("/auth/foo")).andExpect(method(HttpMethod.GET)) .andExpect(header(VaultHttpHeaders.VAULT_NAMESPACE, "baz")).andRespond(withSuccess()); HttpHeaders headers = new HttpHeaders(); headers.add(VaultHttpHeaders.VAULT_NAMESPACE, "baz"); restTemplate.exchange("/auth/foo", HttpMethod.GET, new HttpEntity<>(headers), String.class); }
Example 3
Source Project: summerframework File: RestTemplatePostProcessor.java License: Apache License 2.0 | 5 votes |
@Override public void customize(RestTemplate restTemplate) { if (restTemplate.getInterceptors().contains(this.metricsClientHttpRequestInterceptor)) { return; } UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); templateHandler = this.metricsClientHttpRequestInterceptor.createUriTemplateHandler(templateHandler); restTemplate.setUriTemplateHandler(templateHandler); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); interceptors.add(this.metricsClientHttpRequestInterceptor); interceptors.addAll(restTemplate.getInterceptors()); restTemplate.setInterceptors(interceptors); }
Example 4
Source Project: egeria File: SpringRESTClientConnector.java License: Apache License 2.0 | 5 votes |
/** * Default constructor */ public SpringRESTClientConnector() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { super(); /* * Rather than creating a RestTemplate directly, the RestTemplateBuilder is used so that the * uriTemplateHandler can be specified. The URI encoding is set to VALUES_ONLY so that the * '+' character, which is used in queryParameters conveying searchCriteria, which can be a * regex, is encoded as '+' and not converted to a space character. * Prior to this change a regex containing a '+' character would be split into two space * separated words. For example, the regex "name_0+7" (which would match name_07, name_007, * name_0007, etc) would be sent to the server as "name_0 7". */ DefaultUriBuilderFactory builderFactory = new DefaultUriBuilderFactory(); builderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY); /* TODO: Disable SSL cert verification -- for now */ HttpsURLConnection.setDefaultHostnameVerifier(bypassVerifier); SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, INSECURE_MANAGER, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(builderFactory); /* Ensure that the REST template always uses UTF-8 */ List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters(); converters.removeIf(httpMessageConverter -> httpMessageConverter instanceof StringHttpMessageConverter); converters.add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8)); }
Example 5
Source Project: spring-credhub File: CredHubRestTemplateFactory.java License: Apache License 2.0 | 5 votes |
/** * Configure a {@link RestTemplate} for communication with a CredHub server. * @param restTemplate an existing {@link RestTemplate} to configure * @param baseUri the base URI for the CredHub server * @param clientHttpRequestFactory the {@link ClientHttpRequestFactory} to use when * creating new connections */ private static void configureRestTemplate(RestTemplate restTemplate, String baseUri, ClientHttpRequestFactory clientHttpRequestFactory) { restTemplate.setRequestFactory(clientHttpRequestFactory); restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(baseUri)); restTemplate.getInterceptors().add(new CredHubRequestInterceptor()); restTemplate.setMessageConverters( Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter(JsonUtils.buildObjectMapper()))); }
Example 6
Source Project: spring-vault File: PcfAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 7
Source Project: spring-vault File: AppRoleAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 8
Source Project: spring-vault File: CubbyholeAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 9
Source Project: spring-vault File: LoginTokenAdapterUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() throws Exception { RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 10
Source Project: spring-vault File: AuthenticationStepsExecutorUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 11
Source Project: spring-vault File: AzureMsiAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 12
Source Project: spring-vault File: AwsIamAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 13
Source Project: spring-vault File: GcpIamAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = new RestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 14
Source Project: spring-vault File: ClientCertificateAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 15
Source Project: spring-vault File: AwsEc2AuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 16
Source Project: spring-vault File: AppIdAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 17
Source Project: spring-vault File: KubernetesAuthenticationUnitTests.java License: Apache License 2.0 | 5 votes |
@BeforeEach void before() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); this.mockRest = MockRestServiceServer.createServer(restTemplate); this.restTemplate = restTemplate; }
Example 18
Source Project: spring-vault File: VaultClientsUnitTests.java License: Apache License 2.0 | 5 votes |
@Test void shouldApplyNamespace() { RestTemplate restTemplate = VaultClients.createRestTemplate(); restTemplate.getInterceptors().add(VaultClients.createNamespaceInterceptor("foo/bar")); restTemplate.setUriTemplateHandler(new PrefixAwareUriTemplateHandler()); MockRestServiceServer mockRest = MockRestServiceServer.createServer(restTemplate); mockRest.expect(requestTo("/auth/foo")).andExpect(method(HttpMethod.GET)) .andExpect(header(VaultHttpHeaders.VAULT_NAMESPACE, "foo/bar")).andRespond(withSuccess()); restTemplate.getForEntity("/auth/foo", String.class); }
Example 19
Source Project: mojito File: EvolveConfiguration.java License: Apache License 2.0 | 5 votes |
RestTemplate evolveRestTemplate() { RestTemplate restTemplate = new RestTemplate(); DefaultUriTemplateHandler defaultUriTemplateHandler = new DefaultUriTemplateHandler(); defaultUriTemplateHandler.setBaseUrl(evolveConfigurationProperties.getUrl()); restTemplate.setUriTemplateHandler(defaultUriTemplateHandler); restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { request.getHeaders().add(HttpHeaders.AUTHORIZATION, evolveConfigurationProperties.getToken()); return execution.execute(request, body); } }); restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { @Override public void handleError(ClientHttpResponse response) throws IOException { try { super.handleError(response); } catch (HttpServerErrorException | HttpClientErrorException e) { resttemplateLogger.debug(e.getResponseBodyAsString()); throw e; } } }); return restTemplate; }
Example 20
Source Project: spring-vault File: VaultClients.java License: Apache License 2.0 | 3 votes |
/** * 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; }