本文整理了Java中org.springframework.web.client.RestTemplate.setUriTemplateHandler
方法的一些代码示例,展示了RestTemplate.setUriTemplateHandler
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.setUriTemplateHandler
方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:setUriTemplateHandler
[英]Configure a strategy for expanding URI templates.
By default, DefaultUriBuilderFactory is used and for backwards compatibility, the encoding mode is set to EncodingMode#URI_COMPONENT. As of 5.0.8, prefer using EncodingMode#TEMPLATE_AND_VALUES.
Note: in 5.0 the switch from org.springframework.web.util.DefaultUriTemplateHandler (deprecated in 4.3), as the default to use, to DefaultUriBuilderFactory brings in a different default for the parsePath property (switching from false to true).
[中]配置扩展URI模板的策略。
默认情况下,使用DefaultUriBuilderFactory,为了向后兼容,编码模式设置为EncodingMode#URI_COMPONENT。从5.0.8开始,更喜欢使用编码模式#模板_和_值。
注意:在5.0中,从org切换。springframework。网状物util。DefaultUriTemplateHandler(在4.3中已弃用)作为DefaultUriBuilderFactory的默认值,为parsePath属性引入了不同的默认值(从false切换为true)。
代码示例来源:origin: spring-projects/spring-framework
/**
* 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);
}
代码示例来源:origin: org.springframework/spring-web
/**
* 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);
}
代码示例来源:origin: org.springframework.boot/spring-boot
/**
* 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;
}
代码示例来源:origin: org.springframework.boot/spring-boot
restTemplate.setUriTemplateHandler(this.uriTemplateHandler);
代码示例来源:origin: spring-projects/spring-framework
@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();
}
代码示例来源:origin: apache/servicecomb-java-chassis
@Override
public void setUriTemplateHandler(UriTemplateHandler handler) {
super.setUriTemplateHandler(handler);
defaultRestTemplate.setUriTemplateHandler(handler);
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@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);
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-test
/**
* 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);
}
代码示例来源:origin: org.apache.servicecomb/provider-springmvc
@Override
public void setUriTemplateHandler(UriTemplateHandler handler) {
super.setUriTemplateHandler(handler);
defaultRestTemplate.setUriTemplateHandler(handler);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web
/**
* 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);
}
代码示例来源:origin: io.servicecomb/provider-springmvc
@Override
public void setUriTemplateHandler(UriTemplateHandler handler) {
super.setUriTemplateHandler(handler);
defaultRestTemplate.setUriTemplateHandler(handler);
}
代码示例来源:origin: apache/servicemix-bundles
/**
* 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);
}
代码示例来源:origin: FastBootWeixin/FastBootWeixin
public void setUriTemplateHandler(UriTemplateHandler handler) {
restTemplate.setUriTemplateHandler(handler);
}
代码示例来源:origin: io.micrometer/micrometer-spring-legacy
@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);
}
代码示例来源:origin: spring-io/bomr
@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);
}
代码示例来源:origin: griddynamics/jagger
restTemplate.setUriTemplateHandler((UriTemplateHandler) clientParams.get(URI_TEMPLATE_HANDLER.value));
代码示例来源:origin: org.springframework.vault/spring-vault-core
/**
* 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;
}
内容来源于网络,如有侵权,请联系作者删除!