From b701d0ced7306c52d70cfbdf7b1b25993d63f4a8 Mon Sep 17 00:00:00 2001 From: Collin Cudd Date: Fri, 11 Sep 2015 08:35:37 -0500 Subject: [PATCH] Modify RestProxyServiceImpl to set the query string of the proxied request. --- .../restproxy/service/RestProxyServiceImpl.java | 5 +++++ .../service/RestProxyServiceImplTest.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/edu/wisc/my/restproxy/service/RestProxyServiceImpl.java b/src/main/java/edu/wisc/my/restproxy/service/RestProxyServiceImpl.java index 4042da7..cf7c80b 100644 --- a/src/main/java/edu/wisc/my/restproxy/service/RestProxyServiceImpl.java +++ b/src/main/java/edu/wisc/my/restproxy/service/RestProxyServiceImpl.java @@ -80,6 +80,11 @@ public ResponseEntity 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"); diff --git a/src/test/java/edu/wisc/my/restproxy/service/RestProxyServiceImplTest.java b/src/test/java/edu/wisc/my/restproxy/service/RestProxyServiceImplTest.java index fb77cd6..e0b05aa 100644 --- a/src/test/java/edu/wisc/my/restproxy/service/RestProxyServiceImplTest.java +++ b/src/test/java/edu/wisc/my/restproxy/service/RestProxyServiceImplTest.java @@ -62,6 +62,22 @@ public void proxyRequest_control() { assertEquals(result, proxy.proxyRequest("control", request)); } + @Test + public void withQueryString() { + final ResponseEntity result = new ResponseEntity(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.