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 #14 from ctcudd/remove-resource-key-from-proxyd-uri
Browse files Browse the repository at this point in the history
Strip the resourceKey from the proxy'd uri.
  • Loading branch information
nblair committed Aug 10, 2015
2 parents 9b1cbae + f3801c0 commit dbce140
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public Object proxyRequest(final String resourceKey, final HttpServletRequest re

String resourcePath = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE );
if(StringUtils.isNotBlank(resourcePath)) {
if(resourcePath.startsWith("/"+resourceKey)) {
resourcePath = resourcePath.replaceFirst("/"+resourceKey, "");
}
if(!StringUtils.endsWith(uri, "/") && !resourcePath.startsWith("/")) {
uri.append("/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public void proxyRequest_control() {

MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("GET");
env.setProperty("control.uri", "http://localhost/foo");
ProxyRequestContext expected = new ProxyRequestContext("control").setUri("http://localhost/foo");
request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/control/foo");
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");

when(proxyDao.proxyRequest(expected)).thenReturn(result);
assertEquals(result, proxy.proxyRequest("control", request));
Expand Down

0 comments on commit dbce140

Please sign in to comment.