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

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

本文整理了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

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

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

  1. /**
  2. * Return the configured URI template handler.
  3. */
  4. public UriTemplateHandler getUriTemplateHandler() {
  5. return this.syncTemplate.getUriTemplateHandler();
  6. }

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

  1. /**
  2. * Return the configured URI template handler.
  3. */
  4. public UriTemplateHandler getUriTemplateHandler() {
  5. return this.syncTemplate.getUriTemplateHandler();
  6. }

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

  1. /**
  2. * {@inheritDoc}
  3. * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
  4. * but not both, consider using:
  5. * <ul>
  6. * <li>{@link #acceptHeaderRequestCallback(Class)}
  7. * <li>{@link #httpEntityCallback(Object)}
  8. * <li>{@link #httpEntityCallback(Object, Type)}
  9. * <li>{@link #responseEntityExtractor(Type)}
  10. * </ul>
  11. */
  12. @Override
  13. @Nullable
  14. public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
  15. @Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
  16. URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  17. return doExecute(expanded, method, requestCallback, responseExtractor);
  18. }

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

  1. /**
  2. * {@inheritDoc}
  3. * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
  4. * but not both, consider using:
  5. * <ul>
  6. * <li>{@link #acceptHeaderRequestCallback(Class)}
  7. * <li>{@link #httpEntityCallback(Object)}
  8. * <li>{@link #httpEntityCallback(Object, Type)}
  9. * <li>{@link #responseEntityExtractor(Type)}
  10. * </ul>
  11. */
  12. @Override
  13. @Nullable
  14. public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
  15. @Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
  16. throws RestClientException {
  17. URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  18. return doExecute(expanded, method, requestCallback, responseExtractor);
  19. }

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

  1. /**
  2. * Configure default URI variable values. This is a shortcut for:
  3. * <pre class="code">
  4. * DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
  5. * handler.setDefaultUriVariables(...);
  6. *
  7. * AsyncRestTemplate restTemplate = new AsyncRestTemplate();
  8. * restTemplate.setUriTemplateHandler(handler);
  9. * </pre>
  10. * @param defaultUriVariables the default URI variable values
  11. * @since 4.3
  12. */
  13. @SuppressWarnings("deprecation")
  14. public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
  15. UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
  16. if (handler instanceof DefaultUriBuilderFactory) {
  17. ((DefaultUriBuilderFactory) handler).setDefaultUriVariables(defaultUriVariables);
  18. }
  19. else if (handler instanceof org.springframework.web.util.AbstractUriTemplateHandler) {
  20. ((org.springframework.web.util.AbstractUriTemplateHandler) handler)
  21. .setDefaultUriVariables(defaultUriVariables);
  22. }
  23. else {
  24. throw new IllegalArgumentException(
  25. "This property is not supported with the configured UriTemplateHandler.");
  26. }
  27. }

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

  1. /**
  2. * {@inheritDoc}
  3. * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
  4. * but not both, consider using:
  5. * <ul>
  6. * <li>{@link #acceptHeaderRequestCallback(Class)}
  7. * <li>{@link #httpEntityCallback(Object)}
  8. * <li>{@link #httpEntityCallback(Object, Type)}
  9. * <li>{@link #responseEntityExtractor(Type)}
  10. * </ul>
  11. */
  12. @Override
  13. @Nullable
  14. public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
  15. @Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
  16. URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  17. return doExecute(expanded, method, requestCallback, responseExtractor);
  18. }

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

  1. /**
  2. * {@inheritDoc}
  3. * <p>To provide a {@code RequestCallback} or {@code ResponseExtractor} only,
  4. * but not both, consider using:
  5. * <ul>
  6. * <li>{@link #acceptHeaderRequestCallback(Class)}
  7. * <li>{@link #httpEntityCallback(Object)}
  8. * <li>{@link #httpEntityCallback(Object, Type)}
  9. * <li>{@link #responseEntityExtractor(Type)}
  10. * </ul>
  11. */
  12. @Override
  13. @Nullable
  14. public <T> T execute(String url, HttpMethod method, @Nullable RequestCallback requestCallback,
  15. @Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
  16. throws RestClientException {
  17. URI expanded = getUriTemplateHandler().expand(url, uriVariables);
  18. return doExecute(expanded, method, requestCallback, responseExtractor);
  19. }

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

  1. /**
  2. * Add a {@link RootUriTemplateHandler} instance to the given {@link RestTemplate}.
  3. * @param restTemplate the {@link RestTemplate} to add the handler to
  4. * @param rootUri the root URI
  5. * @return the added {@link RootUriTemplateHandler}.
  6. */
  7. public static RootUriTemplateHandler addTo(RestTemplate restTemplate,
  8. String rootUri) {
  9. Assert.notNull(restTemplate, "RestTemplate must not be null");
  10. RootUriTemplateHandler handler = new RootUriTemplateHandler(rootUri,
  11. restTemplate.getUriTemplateHandler());
  12. restTemplate.setUriTemplateHandler(handler);
  13. return handler;
  14. }

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

  1. /**
  2. * Configure default URI variable values. This is a shortcut for:
  3. * <pre class="code">
  4. * DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
  5. * handler.setDefaultUriVariables(...);
  6. *
  7. * AsyncRestTemplate restTemplate = new AsyncRestTemplate();
  8. * restTemplate.setUriTemplateHandler(handler);
  9. * </pre>
  10. * @param defaultUriVariables the default URI variable values
  11. * @since 4.3
  12. */
  13. @SuppressWarnings("deprecation")
  14. public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
  15. UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
  16. if (handler instanceof DefaultUriBuilderFactory) {
  17. ((DefaultUriBuilderFactory) handler).setDefaultUriVariables(defaultUriVariables);
  18. }
  19. else if (handler instanceof org.springframework.web.util.AbstractUriTemplateHandler) {
  20. ((org.springframework.web.util.AbstractUriTemplateHandler) handler)
  21. .setDefaultUriVariables(defaultUriVariables);
  22. }
  23. else {
  24. throw new IllegalArgumentException(
  25. "This property is not supported with the configured UriTemplateHandler.");
  26. }
  27. }

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

  1. @Override
  2. public void customize(RestTemplate restTemplate) {
  3. UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
  4. templateHandler = this.interceptor.createUriTemplateHandler(templateHandler);
  5. restTemplate.setUriTemplateHandler(templateHandler);
  6. List<ClientHttpRequestInterceptor> existingInterceptors = restTemplate
  7. .getInterceptors();
  8. if (!existingInterceptors.contains(this.interceptor)) {
  9. List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
  10. interceptors.add(this.interceptor);
  11. interceptors.addAll(existingInterceptors);
  12. restTemplate.setInterceptors(interceptors);
  13. }
  14. }

代码示例来源:origin: apache/servicemix-bundles

  1. /**
  2. * Return the configured URI template handler.
  3. */
  4. public UriTemplateHandler getUriTemplateHandler() {
  5. return this.syncTemplate.getUriTemplateHandler();
  6. }

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

  1. /**
  2. * Return the configured URI template handler.
  3. */
  4. public UriTemplateHandler getUriTemplateHandler() {
  5. return this.syncTemplate.getUriTemplateHandler();
  6. }

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

  1. private URI applyRootUriIfNecessary(URI uri) {
  2. UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
  3. if ((uriTemplateHandler instanceof RootUriTemplateHandler)
  4. && uri.toString().startsWith("/")) {
  5. return URI.create(((RootUriTemplateHandler) uriTemplateHandler).getRootUri()
  6. + uri.toString());
  7. }
  8. return uri;
  9. }

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

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

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

  1. /**
  2. * Returns the root URI applied by a {@link RootUriTemplateHandler} or {@code ""} if
  3. * the root URI is not available.
  4. * @return the root URI
  5. */
  6. public String getRootUri() {
  7. UriTemplateHandler uriTemplateHandler = this.restTemplate.getUriTemplateHandler();
  8. if (uriTemplateHandler instanceof RootUriTemplateHandler) {
  9. return ((RootUriTemplateHandler) uriTemplateHandler).getRootUri();
  10. }
  11. return "";
  12. }

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

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

代码示例来源:origin: io.micrometer/micrometer-spring-legacy

  1. @Override
  2. public void customize(RestTemplate restTemplate) {
  3. UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
  4. templateHandler = this.interceptor.createUriTemplateHandler(templateHandler);
  5. restTemplate.setUriTemplateHandler(templateHandler);
  6. List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
  7. interceptors.add(this.interceptor);
  8. interceptors.addAll(restTemplate.getInterceptors());
  9. restTemplate.setInterceptors(interceptors);
  10. }

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

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

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

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

相关文章