Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from ctcudd/forward_query_string_with_request
Browse files Browse the repository at this point in the history
Query Strings are good
  • Loading branch information
nblair committed Sep 11, 2015
2 parents 4458cd3 + b701d0c commit 9fbe4fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public ResponseEntity<Object> proxyRequest(final String resourceKey, final HttpS
}
uri.append(resourcePath);
}

if(StringUtils.isNotBlank(request.getQueryString())) {
uri.append("?");
uri.append(request.getQueryString());
}

String username = env.getProperty(resourceKey + ".username");
String password = env.getProperty(resourceKey + ".password");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public void proxyRequest_control() {
assertEquals(result, proxy.proxyRequest("control", request));
}

@Test
public void withQueryString() {
final ResponseEntity<Object> result = new ResponseEntity<Object>(new Object(), HttpStatus.OK);

MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/control/foo");
request.setQueryString("search=bar&name=bucky");
env.setProperty("control.uri", "http://destination");

//note the resourceKey ('control' in this context) is stripped from the uri
ProxyRequestContext expected = new ProxyRequestContext("control").setUri("http://destination/foo?search=bar&name=bucky");

when(proxyDao.proxyRequest(expected)).thenReturn(result);
assertEquals(result, proxy.proxyRequest("control", request));
}
/**
* Test simulates a proxy request which fails with a http 400 error.
* An error like this could be encountered if you were to post invalid data to a form.
Expand Down

0 comments on commit 9fbe4fb

Please sign in to comment.