Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 2e9ef3d

Browse files
committed
FP-307: forwarding query parameters to backend
1 parent 665e996 commit 2e9ef3d

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/main/java/eu/fusepool/p3/proxy/ProxyHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class ProxyHandler extends AbstractHandler {
8989
public void handle(String target, Request baseRequest,
9090
final HttpServletRequest inRequest, final HttpServletResponse outResponse)
9191
throws IOException, ServletException {
92-
final String targetUriString = targetBaseUri + inRequest.getRequestURI();
92+
final String targetUriString = targetBaseUri + getFullRequestUriPath(inRequest);
9393
final String requestUri = getFullRequestUrl(inRequest);
9494
//System.out.println(targetUriString);
9595
final URI targetUri;
@@ -195,6 +195,14 @@ private static String getFullRequestUrl(HttpServletRequest request) {
195195
}
196196
return requestURL.toString();
197197
}
198+
199+
private static String getFullRequestUriPath(HttpServletRequest request) {
200+
final StringBuffer requestURL = new StringBuffer(request.getRequestURI());
201+
if (request.getQueryString() != null) {
202+
requestURL.append("?").append(request.getQueryString());
203+
}
204+
return requestURL.toString();
205+
}
198206

199207
/**
200208
* If uri is a transforming container returns the URI of the associated

src/test/java/eu/fusepool/p3/proxy/ProxyTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ public void nonTransformingContainer() throws Exception {
105105

106106
}
107107

108+
@Test
109+
public void queryParamsForwarded() throws Exception {
110+
111+
final String textResponse = "hello";
112+
113+
stubFor(get(urlEqualTo("/my/test?a=1&b=2"))
114+
.withHeader("Accept", equalTo("text/plain"))
115+
.willReturn(aResponse()
116+
.withStatus(200)
117+
.withHeader("Content-Type", "text/plain")
118+
.withBody(textResponse)));
119+
120+
RestAssured.given().header("Accept", "text/plain")
121+
.expect().statusCode(HttpStatus.SC_OK)
122+
.header("Content-Type", "text/plain")
123+
.body(new IsEqual(textResponse)).when()
124+
.get("/my/test?a=1&b=2");
125+
126+
}
127+
108128
@Test
109129
public void transformingContainer() throws Exception {
110130

0 commit comments

Comments
 (0)