Java 类org.springframework.web.util.DefaultUriTemplateHandler 实例源码

项目:put-it-to-rest    文件:RestClientPostProcessor.java   
private String registerRestTemplate(final String id, final String factoryId, final String convertersId,
        @Nullable final String baseUrl) {
    return registry.register(id, RestTemplate.class, () -> {
        LOG.debug("Client [{}]: Registering RestTemplate", id);

        final BeanDefinitionBuilder restTemplate = genericBeanDefinition(RestTemplate.class);

        restTemplate.addConstructorArgReference(factoryId);

        final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
        handler.setBaseUrl(baseUrl);
        restTemplate.addPropertyValue("uriTemplateHandler", handler);

        final AbstractBeanDefinition converters = BeanDefinitionBuilder.genericBeanDefinition()
                .setFactoryMethod("getConverters")
                .getBeanDefinition();
        converters.setFactoryBeanName(convertersId);
        restTemplate.addPropertyValue("messageConverters", converters);

        return restTemplate;
    });
}
项目:put-it-to-rest    文件:RestClientPostProcessor.java   
private String registerAsyncRestTemplate(final String id, final String factoryId, final String convertersId,
        @Nullable final String baseUrl) {
    return registry.register(id, AsyncRestTemplate.class, () -> {
        LOG.debug("Client [{}]: Registering AsyncRestTemplate", id);

        final BeanDefinitionBuilder restTemplate = genericBeanDefinition(AsyncRestTemplate.class);

        restTemplate.addConstructorArgReference(factoryId);

        final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
        handler.setBaseUrl(baseUrl);
        restTemplate.addPropertyValue("uriTemplateHandler", handler);

        final AbstractBeanDefinition converters = BeanDefinitionBuilder.genericBeanDefinition()
                .setFactoryMethod("getConverters")
                .getBeanDefinition();
        converters.setFactoryBeanName(convertersId);
        restTemplate.addPropertyValue("messageConverters", converters);

        return restTemplate;
    });
}
项目:riptide    文件:DefaultRiptideRegistrar.java   
private void registerTemplate(final String id, final Class<?> type, final String factoryId,
        @Nullable final String baseUrl, final BeanDefinition converters, final List<BeanMetadataElement> plugins) {
    registry.registerIfAbsent(id, type, () -> {
        log.debug("Client [{}]: Registering AsyncRestTemplate", id);

        final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
        handler.setBaseUrl(baseUrl);

        final BeanDefinitionBuilder template = genericBeanDefinition(type);
        template.addConstructorArgReference(factoryId);
        template.addPropertyValue("uriTemplateHandler", handler);
        template.addPropertyValue("messageConverters", converters);
        template.addPropertyValue("interceptors", plugins.stream()
                .map(plugin -> genericBeanDefinition(PluginInterceptors.class)
                        .setFactoryMethod("adapt")
                        .addConstructorArgValue(plugin)
                        .getBeanDefinition())
                .collect(toCollection(Registry::list)));

        return template;
    });
}
项目:spring4-understanding    文件:RestTemplateTests.java   
@Test
public void getForObjectWithCustomUriTemplateHandler() throws Exception {

    DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
    uriTemplateHandler.setParsePath(true);
    template.setUriTemplateHandler(uriTemplateHandler);

    URI expectedUri = new URI("http://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150");
    given(requestFactory.createRequest(expectedUri, HttpMethod.GET)).willReturn(request);

    given(request.getHeaders()).willReturn(new HttpHeaders());
    given(request.execute()).willReturn(response);
    given(errorHandler.hasError(response)).willReturn(false);

    given(response.getStatusCode()).willReturn(HttpStatus.OK);
    given(response.getHeaders()).willReturn(new HttpHeaders());
    given(response.getBody()).willReturn(null);

    Map<String, String> uriVariables = new HashMap<String, String>(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();
}
项目:cassandra-unit-spring-demo    文件:AbstractEmbeddedCassandraTest.java   
@PostConstruct
public void init() {
    DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
    handler.setBaseUrl(url + ":" + port);
    handler.setParsePath(true);

    client = new TestRestTemplate();
    client.setUriTemplateHandler(handler);
}
项目:riptide    文件:ManualConfiguration.java   
@Bean
public RestTemplate exampleRestTemplate(final ClientHttpRequestFactory requestFactory,
        final ClientHttpMessageConverters converters) {
    final RestTemplate template = new RestTemplate();

    final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
    handler.setBaseUrl("https://www.example.com");
    template.setUriTemplateHandler(handler);
    template.setRequestFactory(requestFactory);
    template.setMessageConverters(converters.getConverters());

    return template;
}
项目:riptide    文件:ManualConfiguration.java   
@Bean
public AsyncRestTemplate exampleAsyncRestTemplate(final AsyncClientHttpRequestFactory requestFactory,
        final ClientHttpMessageConverters converters) {
    final AsyncRestTemplate template = new AsyncRestTemplate();

    final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
    handler.setBaseUrl("https://www.example.com");
    template.setUriTemplateHandler(handler);
    template.setAsyncRequestFactory(requestFactory);
    template.setMessageConverters(converters.getConverters());

    return template;
}
项目:incubator-servicecomb-java-chassis    文件:TestRestTemplateWrapper.java   
private Map<String, ?> defaultUriVariablesOf(RestTemplate wrapper1) {
  return ((DefaultUriTemplateHandler) wrapper1.getUriTemplateHandler()).getDefaultUriVariables();
}
项目:spring-vault    文件:VaultClients.java   
private static DefaultUriTemplateHandler createUriTemplateHandler(
        VaultEndpointProvider endpointProvider) {

    return new PrefixAwareUriTemplateHandler(endpointProvider);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LocalHostUriTemplateHandler.java   
public LocalHostUriTemplateHandler(Environment environment) {
    super(new DefaultUriTemplateHandler());
    Assert.notNull(environment, "Environment must not be null");
    this.environment = environment;
}
项目:spring-boot-concourse    文件:LocalHostUriTemplateHandler.java   
public LocalHostUriTemplateHandler(Environment environment) {
    super(new DefaultUriTemplateHandler());
    Assert.notNull(environment, "Environment must not be null");
    this.environment = environment;
}
项目:spring-credhub    文件:CredHubClient.java   
/**
 * Create a {@link UriTemplateHandler} that prefixes all {@link RestTemplate} calls
 * with the configured {@literal baseUri}.
 *
 * @param baseUri the base URI for the CredHub server
 * @return a configured {@link UriTemplateHandler}
 */
private static DefaultUriTemplateHandler createUriTemplateHandler(String baseUri) {
    DefaultUriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
    uriTemplateHandler.setBaseUrl(baseUri);
    return uriTemplateHandler;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RootUriTemplateHandler.java   
/**
 * Create a new {@link RootUriTemplateHandler} instance.
 * @param rootUri the root URI to be used to prefix relative URLs
 */
public RootUriTemplateHandler(String rootUri) {
    this(rootUri, new DefaultUriTemplateHandler());
}
项目:spring-boot-concourse    文件:RootUriTemplateHandler.java   
/**
 * Create a new {@link RootUriTemplateHandler} instance.
 * @param rootUri the root URI to used to prefix relative URLs
 */
public RootUriTemplateHandler(String rootUri) {
    this(rootUri, new DefaultUriTemplateHandler());
}