Java Code Examples for org.springframework.http.RequestEntity#HeadersBuilder
The following examples show how to use
org.springframework.http.RequestEntity#HeadersBuilder .
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 File: AbstractRequestMappingIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
private void addHeaders(RequestEntity.HeadersBuilder<?> builder, HttpHeaders headers) { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { for (String value : entry.getValue()) { builder.header(entry.getKey(), value); } } }
Example 2
Source File: AbstractRequestMappingIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
private void addHeaders(RequestEntity.HeadersBuilder<?> builder, HttpHeaders headers) { for (Map.Entry<String, List<String>> entry : headers.entrySet()) { for (String value : entry.getValue()) { builder.header(entry.getKey(), value); } } }
Example 3
Source File: OAuth2ConfigResourceClient.java From spring-cloud-services-starters with Apache License 2.0 | 5 votes |
private Resource getResource(String profile, String label, String path, ResourceType resourceType) { Assert.isTrue(configClientProperties.getName() != null && !configClientProperties.getName().isEmpty(), "Spring application name is undefined."); Assert.notEmpty(configClientProperties.getUri(), "Config server URI is undefined"); Assert.hasText(configClientProperties.getUri()[0], "Config server URI is undefined."); if (profile == null) { profile = configClientProperties.getProfile(); if (profile == null || profile.isEmpty()) { profile = "default"; } } if (label == null) { label = configClientProperties.getLabel(); } UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(configClientProperties.getUri()[0]) .pathSegment(configClientProperties.getName()).pathSegment(profile).pathSegment(label) .pathSegment(path); if (label == null) { urlBuilder.queryParam("useDefaultLabel"); } RequestEntity.HeadersBuilder<?> requestBuilder = RequestEntity.get(urlBuilder.build().toUri()); if (StringUtils.hasText(configClientProperties.getToken())) { requestBuilder.header(TOKEN_HEADER, configClientProperties.getToken()); } if (resourceType == ResourceType.BINARY) { requestBuilder.accept(MediaType.APPLICATION_OCTET_STREAM); } ResponseEntity<Resource> forEntity = restTemplate.exchange(requestBuilder.build(), Resource.class); return forEntity.getBody(); }
Example 4
Source File: AbstractRequestMappingIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
private RequestEntity<Void> prepareGet(String url, HttpHeaders headers) throws Exception { URI uri = new URI("http://localhost:" + this.port + url); RequestEntity.HeadersBuilder<?> builder = get(uri); addHeaders(builder, headers); return builder.build(); }
Example 5
Source File: AbstractRequestMappingIntegrationTests.java From spring-analysis-note with MIT License | 4 votes |
private RequestEntity<Void> prepareOptions(String url, HttpHeaders headers) throws Exception { URI uri = new URI("http://localhost:" + this.port + url); RequestEntity.HeadersBuilder<?> builder = options(uri); addHeaders(builder, headers); return builder.build(); }
Example 6
Source File: AbstractRequestMappingIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
private RequestEntity<Void> prepareGet(String url, HttpHeaders headers) throws Exception { URI uri = new URI("http://localhost:" + this.port + url); RequestEntity.HeadersBuilder<?> builder = get(uri); addHeaders(builder, headers); return builder.build(); }
Example 7
Source File: AbstractRequestMappingIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
private RequestEntity<Void> prepareOptions(String url, HttpHeaders headers) throws Exception { URI uri = new URI("http://localhost:" + this.port + url); RequestEntity.HeadersBuilder<?> builder = options(uri); addHeaders(builder, headers); return builder.build(); }
Example 8
Source File: OAuth2ConfigResourceClient.java From spring-cloud-services-connector with Apache License 2.0 | 4 votes |
private Resource getResource(String profile, String label, String path, ResourceType resourceType) { Assert.isTrue( configClientProperties.getName() != null && !configClientProperties.getName().isEmpty(), "Spring application name is undefined."); Assert.notEmpty(configClientProperties.getUri(), "Config server URI is undefined"); Assert.hasText(configClientProperties.getUri()[0], "Config server URI is undefined."); if (profile == null) { profile = configClientProperties.getProfile(); if (profile == null || profile.isEmpty()) { profile = "default"; } } if (label == null) { label = configClientProperties.getLabel(); } UriComponentsBuilder urlBuilder = UriComponentsBuilder .fromHttpUrl(configClientProperties.getUri()[0]) .pathSegment(configClientProperties.getName()) .pathSegment(profile) .pathSegment(label) .pathSegment(path); if (label == null) { urlBuilder.queryParam("useDefaultLabel"); } RequestEntity.HeadersBuilder<?> requestBuilder = RequestEntity.get(urlBuilder.build().toUri()); if (StringUtils.hasText(configClientProperties.getToken())) { requestBuilder.header(TOKEN_HEADER, configClientProperties.getToken()); } if (resourceType == ResourceType.BINARY) { requestBuilder.accept(MediaType.APPLICATION_OCTET_STREAM); } ResponseEntity<Resource> forEntity = restTemplate.exchange(requestBuilder.build(), Resource.class); return forEntity.getBody(); }