Use DefaultUriBuilderFactory instead of DefaultUriTemplateHandler

Closes gh-8247
pull/8230/merge
Andy Wilkinson 8 years ago
parent 16b7bf7f73
commit 13791cad53

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,7 +20,7 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.web.client.RootUriTemplateHandler; import org.springframework.boot.web.client.RootUriTemplateHandler;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler; import org.springframework.web.util.UriTemplateHandler;
/** /**
@ -58,12 +58,13 @@ public class LocalHostUriTemplateHandler extends RootUriTemplateHandler {
* @since 1.4.1 * @since 1.4.1
*/ */
public LocalHostUriTemplateHandler(Environment environment, String scheme) { public LocalHostUriTemplateHandler(Environment environment, String scheme) {
super(new DefaultUriTemplateHandler()); super(new DefaultUriBuilderFactory());
Assert.notNull(environment, "Environment must not be null"); Assert.notNull(environment, "Environment must not be null");
Assert.notNull(scheme, "Scheme must not be null"); Assert.notNull(scheme, "Scheme must not be null");
this.environment = environment; this.environment = environment;
this.scheme = scheme; this.scheme = scheme;
this.servletPropertyResolver = new RelaxedPropertyResolver(environment, "server.servlet."); this.servletPropertyResolver = new RelaxedPropertyResolver(environment,
"server.servlet.");
} }
@Override @Override

@ -57,7 +57,7 @@ import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.ResponseExtractor; import org.springframework.web.client.ResponseExtractor;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler; import org.springframework.web.util.UriTemplateHandler;
/** /**
@ -161,7 +161,7 @@ public class TestRestTemplate {
/** /**
* Configure the {@link UriTemplateHandler} to use to expand URI templates. By default * Configure the {@link UriTemplateHandler} to use to expand URI templates. By default
* the {@link DefaultUriTemplateHandler} is used which relies on Spring's URI template * the {@link DefaultUriBuilderFactory} is used which relies on Spring's URI template
* support and exposes several useful properties that customize its behavior for * support and exposes several useful properties that customize its behavior for
* encoding and for prepending a common base URL. An alternative implementation may be * encoding and for prepending a common base URL. An alternative implementation may be
* used to plug an external URI template library. * used to plug an external URI template library.

@ -47,12 +47,12 @@ import org.springframework.util.ReflectionUtils.MethodCallback;
import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestOperations; import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.DefaultUriBuilderFactory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -102,7 +102,7 @@ public class TestRestTemplateTests {
public void restOperationsAreAvailable() throws Exception { public void restOperationsAreAvailable() throws Exception {
RestTemplate delegate = mock(RestTemplate.class); RestTemplate delegate = mock(RestTemplate.class);
given(delegate.getUriTemplateHandler()) given(delegate.getUriTemplateHandler())
.willReturn(new DefaultUriTemplateHandler()); .willReturn(new DefaultUriBuilderFactory());
final TestRestTemplate restTemplate = new TestRestTemplate(delegate); final TestRestTemplate restTemplate = new TestRestTemplate(delegate);
ReflectionUtils.doWithMethods(RestOperations.class, new MethodCallback() { ReflectionUtils.doWithMethods(RestOperations.class, new MethodCallback() {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,7 @@ import java.util.Map;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler; import org.springframework.web.util.UriTemplateHandler;
/** /**
@ -47,7 +47,7 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
* @param rootUri the root URI to be used to prefix relative URLs * @param rootUri the root URI to be used to prefix relative URLs
*/ */
public RootUriTemplateHandler(String rootUri) { public RootUriTemplateHandler(String rootUri) {
this(rootUri, new DefaultUriTemplateHandler()); this(rootUri, new DefaultUriBuilderFactory());
} }
/** /**

Loading…
Cancel
Save