org.springframework.web.client.RestTemplate.getUriTemplateHandler()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中org.springframework.web.client.RestTemplate.getUriTemplateHandler方法的一些代码示例,展示了RestTemplate.getUriTemplateHandler的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.getUriTemplateHandler方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:getUriTemplateHandler

RestTemplate.getUriTemplateHandler介绍

[英]Return the configured URI template handler.
[中]返回已配置的URI模板处理程序。

代码示例

Official Spring framework guide

代码示例来源:origin: spring-guides/gs-rest-service-cors

private URI uri(String path) {
 return restTemplate.getRestTemplate().getUriTemplateHandler().expand(path);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
  return this.syncTemplate.getUriTemplateHandler();
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
  return this.syncTemplate.getUriTemplateHandler();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
 * but not both, consider using:
 * <ul>
 * <li>{@link #acceptHeaderRequestCallback(Class)}
 * <li>{@link #httpEntityCallback(Object)}
 * <li>{@link #httpEntityCallback(Object, Type)}
 * <li>{@link #responseEntityExtractor(Type)}
 * </ul>
 */
@Override
@Nullable
public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
    @Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
  URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  return doExecute(expanded, method, requestCallback, responseExtractor);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
 * but not both, consider using:
 * <ul>
 * <li>{@link #acceptHeaderRequestCallback(Class)}
 * <li>{@link #httpEntityCallback(Object)}
 * <li>{@link #httpEntityCallback(Object, Type)}
 * <li>{@link #responseEntityExtractor(Type)}
 * </ul>
 */
@Override
@Nullable
public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
    @Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
    throws RestClientException {
  URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  return doExecute(expanded, method, requestCallback, responseExtractor);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Configure default URI variable values. This is a shortcut for:
 * <pre class="code">
 * DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
 * handler.setDefaultUriVariables(...);
 *
 * AsyncRestTemplate restTemplate = new AsyncRestTemplate();
 * restTemplate.setUriTemplateHandler(handler);
 * </pre>
 * @param defaultUriVariables the default URI variable values
 * @since 4.3
 */
@SuppressWarnings("deprecation")
public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
  UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
  if (handler instanceof DefaultUriBuilderFactory) {
    ((DefaultUriBuilderFactory) handler).setDefaultUriVariables(defaultUriVariables);
  }
  else if (handler instanceof org.springframework.web.util.AbstractUriTemplateHandler) {
    ((org.springframework.web.util.AbstractUriTemplateHandler) handler)
        .setDefaultUriVariables(defaultUriVariables);
  }
  else {
    throw new IllegalArgumentException(
        "This property is not supported with the configured UriTemplateHandler.");
  }
}

代码示例来源:origin: org.springframework/spring-web

/**
 * {@inheritDoc}
 * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
 * but not both, consider using:
 * <ul>
 * <li>{@link #acceptHeaderRequestCallback(Class)}
 * <li>{@link #httpEntityCallback(Object)}
 * <li>{@link #httpEntityCallback(Object, Type)}
 * <li>{@link #responseEntityExtractor(Type)}
 * </ul>
 */
@Override
@Nullable
public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
    @Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
  URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  return doExecute(expanded, method, requestCallback, responseExtractor);
}

代码示例来源:origin: org.springframework/spring-web

/**
 * {@inheritDoc}
 * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
 * but not both, consider using:
 * <ul>
 * <li>{@link #acceptHeaderRequestCallback(Class)}
 * <li>{@link #httpEntityCallback(Object)}
 * <li>{@link #httpEntityCallback(Object, Type)}
 * <li>{@link #responseEntityExtractor(Type)}
 * </ul>
 */
@Override
@Nullable
public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
    @Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
    throws RestClientException {
  URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  return doExecute(expanded, method, requestCallback, responseExtractor);
}

代码示例来源: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/spring-web

/**
 * Configure default URI variable values. This is a shortcut for:
 * <pre class="code">
 * DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
 * handler.setDefaultUriVariables(...);
 *
 * AsyncRestTemplate restTemplate = new AsyncRestTemplate();
 * restTemplate.setUriTemplateHandler(handler);
 * </pre>
 * @param defaultUriVariables the default URI variable values
 * @since 4.3
 */
@SuppressWarnings("deprecation")
public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
  UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
  if (handler instanceof DefaultUriBuilderFactory) {
    ((DefaultUriBuilderFactory) handler).setDefaultUriVariables(defaultUriVariables);
  }
  else if (handler instanceof org.springframework.web.util.AbstractUriTemplateHandler) {
    ((org.springframework.web.util.AbstractUriTemplateHandler) handler)
        .setDefaultUriVariables(defaultUriVariables);
  }
  else {
    throw new IllegalArgumentException(
        "This property is not supported with the configured UriTemplateHandler.");
  }
}

代码示例来源: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: apache/servicemix-bundles

/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
  return this.syncTemplate.getUriTemplateHandler();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
  return this.syncTemplate.getUriTemplateHandler();
}

代码示例来源:origin: org.springframework.boot/spring-boot-test

private URI applyRootUriIfNecessary(URI uri) {
  UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
  if ((uriTemplateHandler instanceof RootUriTemplateHandler)
      && uri.toString().startsWith("/")) {
    return URI.create(((RootUriTemplateHandler) uriTemplateHandler).getRootUri()
        + uri.toString());
  }
  return uri;
}

代码示例来源:origin: com.lodsve/lodsve-web

private static URI expand(String url, Map<String, ?> uriVariables) {
    Assert.hasText(url);
    return restTemplate.getUriTemplateHandler().expand(url, uriVariables);
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot-test

/**
 * Returns the root URI applied by a {@link RootUriTemplateHandler} or {@code ""} if
 * the root URI is not available.
 * @return the root URI
 */
public String getRootUri() {
  UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
  if (uriTemplateHandler instanceof RootUriTemplateHandler) {
    return ((RootUriTemplateHandler) uriTemplateHandler).getRootUri();
  }
  return "";
}

代码示例来源:origin: com.lodsve/lodsve-web

private static URI expand(String url, Object... uriVariables) {
  Assert.hasText(url);
  return restTemplate.getUriTemplateHandler().expand(url, uriVariables);
}

代码示例来源: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: net.rakugakibox.spring.boot/logback-access-spring-boot-starter

/** {@inheritDoc} */
@Override
public void logbackAccessEvent() {
  RequestEntity<Void> request = RequestEntity
      .get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text"))
      .header("X-Forwarded-Host", "forwarded-host:12345")
      .build();
  ResponseEntity<String> response = rest.exchange(request, String.class);
  IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
  LogbackAccessEventQueuingListener.appendedEventQueue.pop();
  assertThat(response).hasStatusCode(HttpStatus.OK);
  assertThat(event).hasLocalPort(port);
}

代码示例来源:origin: net.rakugakibox.spring.boot/logback-access-spring-boot-starter

/** {@inheritDoc} */
@Override
public void logbackAccessEvent() {
  RequestEntity<Void> request = RequestEntity
      .get(rest.getRestTemplate().getUriTemplateHandler().expand("/test/text"))
      .header("X-Forwarded-Port", "12345")
      .build();
  ResponseEntity<String> response = rest.exchange(request, String.class);
  IAccessEvent event = LogbackAccessEventQueuingAppender.appendedEventQueue.pop();
  LogbackAccessEventQueuingListener.appendedEventQueue.pop();
  assertThat(response).hasStatusCode(HttpStatus.OK);
  assertThat(event).hasLocalPort(port);
}

相关文章