From 3a251e2a380cb36cd557c8b91537dbd861b4f291 Mon Sep 17 00:00:00 2001 From: Dave Syer <dsyer@pivotal.io> Date: Thu, 28 Apr 2016 12:03:10 +0100 Subject: [PATCH] Revert "Use the original query string when forwarding the request" This reverts commit 8952cff24dec2ea9981089f501c7559202aadd01. --- spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java | 14 ++------------ spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java | 17 ++++++++++------- spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java | 11 ----------- 3 files changed, 12 insertions(+), 30 deletions(-) diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java index 868a0af..e5db5a8 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java @@ -230,20 +230,14 @@ public class ProxyRequestHelper { } public Map<String, Object> debug(String verb, String uri, - MultiValueMap<String, String> headers, MultiValueMap<String, String> params, - InputStream requestEntity) throws IOException { - return debug(verb, uri, headers, getQueryString(params), requestEntity); - } - - public Map<String, Object> debug(String verb, String uri, - MultiValueMap<String, String> headers, String queryString, + MultiValueMap<String, String> headers, MultiValueMap<String, String> params, InputStream requestEntity) throws IOException { Map<String, Object> info = new LinkedHashMap<>(); if (this.traces != null) { RequestContext context = RequestContext.getCurrentContext(); info.put("method", verb); info.put("path", uri); - info.put("query", queryString); + info.put("query", getQueryString(params)); info.put("remote", true); info.put("proxy", context.get("proxy")); Map<String, Object> trace = new LinkedHashMap<>(); @@ -340,8 +334,4 @@ public class ProxyRequestHelper { UriTemplate template = new UriTemplate("?" + query.toString().substring(1)); return template.expand(singles).toString(); } - - public String formatQueryString(String queryString) { - return (queryString == null) ? "": "?" + queryString; - } } diff --git a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java index 2d38e68..90a5e85 100644 --- a/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java +++ b/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java @@ -158,6 +158,8 @@ public class SimpleHostRoutingFilter extends ZuulFilter { HttpServletRequest request = context.getRequest(); MultiValueMap<String, String> headers = this.helper .buildZuulRequestHeaders(request); + MultiValueMap<String, String> params = this.helper + .buildZuulRequestQueryParams(request); String verb = getVerb(request); InputStream requestEntity = getRequestBody(request); if (request.getContentLength() < 0) { @@ -169,7 +171,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter { try { HttpResponse response = forward(this.httpClient, verb, uri, request, headers, - request.getQueryString(), requestEntity); + params, requestEntity); setResponse(response); } catch (Exception ex) { @@ -246,9 +248,9 @@ public class SimpleHostRoutingFilter extends ZuulFilter { private HttpResponse forward(HttpClient httpclient, String verb, String uri, HttpServletRequest request, MultiValueMap<String, String> headers, - String queryString, InputStream requestEntity) + MultiValueMap<String, String> params, InputStream requestEntity) throws Exception { - Map<String, Object> info = this.helper.debug(verb, uri, headers, queryString, + Map<String, Object> info = this.helper.debug(verb, uri, headers, params, requestEntity); URL host = RequestContext.getCurrentContext().getRouteHost(); HttpHost httpHost = getHttpHost(host); @@ -259,23 +261,24 @@ public class SimpleHostRoutingFilter extends ZuulFilter { ContentType.create(request.getContentType())); switch (verb.toUpperCase()) { case "POST": - HttpPost httpPost = new HttpPost(uri + this.helper.formatQueryString(queryString)); + HttpPost httpPost = new HttpPost(uri + this.helper.getQueryString(params)); httpRequest = httpPost; httpPost.setEntity(entity); break; case "PUT": - HttpPut httpPut = new HttpPut(uri + this.helper.formatQueryString(queryString)); + HttpPut httpPut = new HttpPut(uri + this.helper.getQueryString(params)); httpRequest = httpPut; httpPut.setEntity(entity); break; case "PATCH": - HttpPatch httpPatch = new HttpPatch(uri + this.helper.formatQueryString(queryString)); + HttpPatch httpPatch = new HttpPatch(uri + this.helper.getQueryString(params)); httpRequest = httpPatch; httpPatch.setEntity(entity); break; default: httpRequest = new BasicHttpRequest(verb, - uri + this.helper.formatQueryString(queryString)); + uri + this.helper.getQueryString(params)); + log.debug(uri + this.helper.getQueryString(params)); } try { httpRequest.setHeaders(convertHeaders(headers)); diff --git a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java index 4688ed8..b2c5539 100644 --- a/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java +++ b/spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java @@ -259,15 +259,4 @@ public class ProxyRequestHelperTests { assertThat(queryString, is("?wsdl")); } - @Test - public void formatQueryStringShouldPrependQuestionMark() { - String queryString = new ProxyRequestHelper().formatQueryString("a=1234&b=5678"); - - assertThat(queryString, is("?a=1234&b=5678")); - } - - @Test - public void formatQueryStringShouldReturnEmptyStringForNullValue() { - assertThat(new ProxyRequestHelper().formatQueryString(null), is("")); - } } -- libgit2 0.27.1