Commit bd5d00c0 by Spencer Gibb

encode uri if needed

fixes gh-347
parent 8bb578ad
...@@ -21,6 +21,10 @@ import java.net.URI; ...@@ -21,6 +21,10 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponentsBuilder;
import com.netflix.client.http.HttpRequest; import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpRequest.Builder; import com.netflix.client.http.HttpRequest.Builder;
import com.netflix.client.http.HttpRequest.Verb; import com.netflix.client.http.HttpRequest.Verb;
...@@ -35,7 +39,6 @@ import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy; ...@@ -35,7 +39,6 @@ import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
import com.netflix.niws.client.http.RestClient; import com.netflix.niws.client.http.RestClient;
import com.netflix.zuul.constants.ZuulConstants; import com.netflix.zuul.constants.ZuulConstants;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import org.springframework.util.MultiValueMap;
/** /**
* Hystrix wrapper around Eureka Ribbon command * Hystrix wrapper around Eureka Ribbon command
...@@ -77,7 +80,7 @@ public class RibbonCommand extends HystrixCommand<HttpResponse> { ...@@ -77,7 +80,7 @@ public class RibbonCommand extends HystrixCommand<HttpResponse> {
super(getSetter(commandKey)); super(getSetter(commandKey));
this.restClient = restClient; this.restClient = restClient;
this.verb = verb; this.verb = verb;
this.uri = new URI(uri); this.uri = (StringUtils.hasText(uri))? UriComponentsBuilder.fromUriString(uri).build().toUri() : new URI(uri);
this.retryable = retryable; this.retryable = retryable;
this.headers = headers; this.headers = headers;
this.params = params; this.params = params;
......
...@@ -132,6 +132,15 @@ public class SampleZuulProxyApplicationTests { ...@@ -132,6 +132,15 @@ public class SampleZuulProxyApplicationTests {
assertEquals("Gotten 1!", result.getBody()); assertEquals("Gotten 1!", result.getBody());
} }
@Test
public void routeWithSpace() {
ResponseEntity<String> result = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/simple/spa ce",
HttpMethod.GET, new HttpEntity<>((Void) null), String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("Hello space", result.getBody());
}
} }
// Don't use @SpringBootApplication because we don't want to component scan // Don't use @SpringBootApplication because we don't want to component scan
...@@ -169,6 +178,11 @@ class SampleZuulProxyApplication { ...@@ -169,6 +178,11 @@ class SampleZuulProxyApplication {
return "Hello world"; return "Hello world";
} }
@RequestMapping("/spa ce")
public String space() {
return "Hello space";
}
@Bean @Bean
public ZuulFilter sampleFilter() { public ZuulFilter sampleFilter() {
return new ZuulFilter() { return new ZuulFilter() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment