org.springframework.http.client.AsyncClientHttpRequestInterceptor#org.springframework.web.util.UriTemplateHandler源码实例Demo

下面列出了org.springframework.http.client.AsyncClientHttpRequestInterceptor#org.springframework.web.util.UriTemplateHandler 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-analysis-note   文件: AsyncRestTemplate.java
/**
 * 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.");
	}
}
 
源代码2 项目: java-technology-stack   文件: AsyncRestTemplate.java
/**
 * 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.");
	}
}
 
@Test
public void uriTemplateHandlerTest() {
    UriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
    Map<String, String> uriVariables = new HashMap<>();
    uriVariables.put("orderNo", "12345");
    URI expand = uriTemplateHandler.expand("https://chaojihao.com/user/order/detail?orderno={orderNo}", uriVariables);
    System.out.println(expand.toString());
    assertThat(expand.toString()).isEqualTo("https://chaojihao.com/user/order/detail?orderno=12345");
}
 
源代码4 项目: hesperides   文件: CustomRestTemplate.java
public CustomRestTemplate(Gson gson, UriTemplateHandler uriTemplateHandler, CloseableHttpClient httpClient) {
    super();
    this.gson = gson;
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    if (httpClient != null) {
        requestFactory.setHttpClient(httpClient);
    }
    requestFactory.setBufferRequestBody(false);
    setRequestFactory(requestFactory);
    setUriTemplateHandler(uriTemplateHandler);
    setErrorHandler(new NoOpResponseErrorHandler());
    // On vire Jackson:
    List<HttpMessageConverter<?>> converters = getMessageConverters().stream()
            .filter(httpMessageConverter -> !(httpMessageConverter instanceof MappingJackson2HttpMessageConverter))
            .collect(Collectors.toList());
    configureMessageConverters(converters, gson);
    setMessageConverters(converters);
}
 
public void customize(final AsyncRestTemplate restTemplate) {
    if (restTemplate.getInterceptors().contains(this.metricsClientHttpRequestInterceptor)) {
        return;
    }
    UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
    templateHandler = this.metricsClientHttpRequestInterceptor.createUriTemplateHandler(templateHandler);
    restTemplate.setUriTemplateHandler(templateHandler);
    List<AsyncClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(this.metricsClientHttpRequestInterceptor);
    interceptors.addAll(restTemplate.getInterceptors());
    restTemplate.setInterceptors(interceptors);
}
 
@Override
public void customize(RestTemplate restTemplate) {
    if (restTemplate.getInterceptors().contains(this.metricsClientHttpRequestInterceptor)) {
        return;
    }
    UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler();
    templateHandler = this.metricsClientHttpRequestInterceptor.createUriTemplateHandler(templateHandler);
    restTemplate.setUriTemplateHandler(templateHandler);
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(this.metricsClientHttpRequestInterceptor);
    interceptors.addAll(restTemplate.getInterceptors());
    restTemplate.setInterceptors(interceptors);
}
 
@Test
public void dotNotSetUriTemplateHandlerWithUnderlying() {
  UriTemplateHandler uriTemplateHandler = mock(UriTemplateHandler.class);

  wrapper.setUriTemplateHandler(uriTemplateHandler);

  assertThat(wrapper.getUriTemplateHandler(), is(uriTemplateHandler));
  assertThat(wrapper.defaultRestTemplate.getUriTemplateHandler(), is(uriTemplateHandler));

  verify(underlying, never()).setUriTemplateHandler(uriTemplateHandler);
}
 
@Test
public void uriTemplateHandlerWithTwoQueryStringTest() {
    UriTemplateHandler uriTemplateHandler = new DefaultUriTemplateHandler();
    Map<String, String> uriVariables = new HashMap<>();
    uriVariables.put("orderNo", "12345");
    URI expand = uriTemplateHandler.expand("https://chaojihao.com/user/order/detail?orderno={orderNo}&logtoSensor=1", uriVariables);
    System.out.println(expand.toString());
    assertThat(expand.toString()).isEqualTo("https://chaojihao.com/user/order/detail?orderno=12345&logtoSensor=1");
}
 
源代码9 项目: spring-analysis-note   文件: RestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.uriTemplateHandler;
}
 
源代码10 项目: spring-analysis-note   文件: AsyncRestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.syncTemplate.getUriTemplateHandler();
}
 
源代码11 项目: java-technology-stack   文件: RestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.uriTemplateHandler;
}
 
源代码12 项目: java-technology-stack   文件: AsyncRestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.syncTemplate.getUriTemplateHandler();
}
 
@Override
public void setUriTemplateHandler(UriTemplateHandler handler) {
  super.setUriTemplateHandler(handler);
  defaultRestTemplate.setUriTemplateHandler(handler);
}
 
源代码14 项目: lams   文件: RestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.uriTemplateHandler;
}
 
源代码15 项目: lams   文件: AsyncRestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.syncTemplate.getUriTemplateHandler();
}
 
源代码16 项目: FastBootWeixin   文件: WxApiTemplate.java
public void setUriTemplateHandler(UriTemplateHandler handler) {
    restTemplate.setUriTemplateHandler(handler);
}
 
源代码17 项目: FastBootWeixin   文件: WxApiTemplate.java
public UriTemplateHandler getUriTemplateHandler() {
    return restTemplate.getUriTemplateHandler();
}
 
源代码18 项目: spring4-understanding   文件: RestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.uriTemplateHandler;
}
 
源代码19 项目: spring4-understanding   文件: AsyncRestTemplate.java
/**
 * Return the configured URI template handler.
 */
public UriTemplateHandler getUriTemplateHandler() {
	return this.syncTemplate.getUriTemplateHandler();
}
 
源代码20 项目: hesperides   文件: CustomRestTemplate.java
public CustomRestTemplate(Gson gson, UriTemplateHandler uriTemplateHandler) {
    this(gson, uriTemplateHandler, null);
}
 
源代码21 项目: lams   文件: AsyncRestTemplate.java
/**
 * 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
 */
public void setDefaultUriVariables(Map<String, ?> defaultUriVariables) {
	UriTemplateHandler handler = this.syncTemplate.getUriTemplateHandler();
	Assert.isInstanceOf(AbstractUriTemplateHandler.class, handler,
			"Can only use this property in conjunction with a DefaultUriTemplateHandler");
	((AbstractUriTemplateHandler) handler).setDefaultUriVariables(defaultUriVariables);
}
 
源代码22 项目: spring-analysis-note   文件: RestTemplate.java
/**
 * Configure a strategy for expanding URI templates.
 * <p>By default, {@link DefaultUriBuilderFactory} is used and for
 * backwards compatibility, the encoding mode is set to
 * {@link EncodingMode#URI_COMPONENT URI_COMPONENT}. As of 5.0.8, prefer
 * using {@link EncodingMode#TEMPLATE_AND_VALUES TEMPLATE_AND_VALUES}.
 * <p><strong>Note:</strong> in 5.0 the switch from
 * {@link org.springframework.web.util.DefaultUriTemplateHandler
 * DefaultUriTemplateHandler} (deprecated in 4.3), as the default to use, to
 * {@link DefaultUriBuilderFactory} brings in a different default for the
 * {@code parsePath} property (switching from false to true).
 * @param handler the URI template handler to use
 */
public void setUriTemplateHandler(UriTemplateHandler handler) {
	Assert.notNull(handler, "UriTemplateHandler must not be null");
	this.uriTemplateHandler = handler;
}
 
源代码23 项目: spring-analysis-note   文件: AsyncRestTemplate.java
/**
 * 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);
}
 
源代码24 项目: java-technology-stack   文件: RestTemplate.java
/**
 * Configure a strategy for expanding URI templates.
 * <p>By default, {@link DefaultUriBuilderFactory} is used and for
 * backwards compatibility, the encoding mode is set to
 * {@link EncodingMode#URI_COMPONENT URI_COMPONENT}. As of 5.0.8, prefer
 * using {@link EncodingMode#TEMPLATE_AND_VALUES TEMPLATE_AND_VALUES}.
 * <p><strong>Note:</strong> in 5.0 the switch from
 * {@link org.springframework.web.util.DefaultUriTemplateHandler
 * DefaultUriTemplateHandler} (deprecated in 4.3), as the default to use, to
 * {@link DefaultUriBuilderFactory} brings in a different default for the
 * {@code parsePath} property (switching from false to true).
 * @param handler the URI template handler to use
 */
public void setUriTemplateHandler(UriTemplateHandler handler) {
	Assert.notNull(handler, "UriTemplateHandler must not be null");
	this.uriTemplateHandler = handler;
}
 
源代码25 项目: java-technology-stack   文件: AsyncRestTemplate.java
/**
 * 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);
}
 
源代码26 项目: lams   文件: RestTemplate.java
/**
 * Configure the {@link UriTemplateHandler} to use to expand URI templates.
 * By default the {@link DefaultUriTemplateHandler} 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) {
	Assert.notNull(handler, "UriTemplateHandler must not be null");
	this.uriTemplateHandler = handler;
}
 
源代码27 项目: lams   文件: AsyncRestTemplate.java
/**
 * 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);
}
 
源代码28 项目: spring4-understanding   文件: RestTemplate.java
/**
 * Set a custom {@link UriTemplateHandler} for expanding URI templates.
 * <p>By default, RestTemplate uses {@link DefaultUriTemplateHandler}.
 * @param handler the URI template handler to use
 */
public void setUriTemplateHandler(UriTemplateHandler handler) {
	Assert.notNull(handler, "UriTemplateHandler must not be null");
	this.uriTemplateHandler = handler;
}
 
源代码29 项目: spring4-understanding   文件: AsyncRestTemplate.java
/**
 * Set a custom {@link UriTemplateHandler} for expanding URI templates.
 * <p>By default, RestTemplate uses {@link DefaultUriTemplateHandler}.
 * @param handler the URI template handler to use
 */
public void setUriTemplateHandler(UriTemplateHandler handler) {
	this.syncTemplate.setUriTemplateHandler(handler);
}