@Test public void testReverseProxyLocationTransformationsWithTrailingSlash() { String url = "http://www.test-url.com:8080/p1/p2"; URI uri = UriUtils.buildUri(url); // location: http://localhost/foo/bar -> // http://abc:80/rp/{http://localhost/foo/bar} String location = "http://localhost/foo/bar/"; String targetLocation = UriUtilsExtended.getReverseProxyLocation(location, null, null); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(ReverseProxyService.SELF_LINK)); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar/", targetUri.toString()); // location: /foo/bar & referer: http://localhost/p -> // http://abc:80/rp/{http://localhost/foo/bar} location = "/foo/bar/"; URI referer = UriUtils.buildUri("http://localhost/p"); targetLocation = UriUtilsExtended.getReverseProxyLocation(location, referer, null); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(ReverseProxyService.SELF_LINK)); targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar/", targetUri.toString()); }
@Test public void testReverseProxyLocationTransformations() { String url = "http://www.test-url.com:8080/p1/p2"; URI uri = UriUtils.buildUri(url); // location: http://localhost/foo/bar -> // http://abc:80/rp/{http://localhost/foo/bar} String location = "http://localhost/foo/bar"; String targetLocation = UriUtilsExtended.getReverseProxyLocation(location, null, null); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(ReverseProxyService.SELF_LINK)); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar", targetUri.toString()); // location: /foo/bar & referer: http://localhost/p -> // http://abc:80/rp/{http://localhost/foo/bar} location = "/foo/bar"; URI referer = UriUtils.buildUri("http://localhost/p"); targetLocation = UriUtilsExtended.getReverseProxyLocation(location, referer, null); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(ReverseProxyService.SELF_LINK)); targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar", targetUri.toString()); }
o.getStatusCode() == Operation.STATUS_CODE_MOVED_TEMP) { String location = o.getResponseHeader(Operation.LOCATION_HEADER); String newLocation = getReverseProxyLocation(location, o.getUri(), op.getUri()); op.getResponseHeaders().put(Operation.LOCATION_HEADER, newLocation);
@Test public void testReverseProxyLocationTransformationsWithRelativeToParam() { String RP_RELATIVE_TO = "/relative-path"; String originalUrl = "http://www.test-url.com/path?rp-relative-to=" + RP_RELATIVE_TO; URI originalUri = UriUtils.buildUri(originalUrl); String url = "http://www.test-url.com:8080/p1/p2"; URI uri = UriUtils.buildUri(url); // location: http://localhost/foo/bar -> // http://abc:80/rp/{http://localhost/foo/bar} String location = "http://localhost/foo/bar/"; String targetLocation = UriUtilsExtended.getReverseProxyLocation(location, null, originalUri); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(RP_RELATIVE_TO + ReverseProxyService.SELF_LINK)); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar/", targetUri.toString()); // location: /foo/bar & referer: http://localhost/p -> // http://abc:80/rp/{http://localhost/foo/bar} location = "/foo/bar/"; URI referer = UriUtils.buildUri("http://localhost/p"); targetLocation = UriUtilsExtended.getReverseProxyLocation(location, referer, originalUri); assertNotNull(targetLocation); assertTrue(targetLocation.startsWith(RP_RELATIVE_TO + ReverseProxyService.SELF_LINK)); targetUri = UriUtilsExtended.getReverseProxyTargetUri( UriUtils.buildUri(uri, targetLocation)); assertEquals("http://localhost/foo/bar/", targetUri.toString()); }
o.getStatusCode() == Operation.STATUS_CODE_MOVED_TEMP) { String location = o.getResponseHeader(Operation.LOCATION_HEADER); String newLocation = getReverseProxyLocation(location, o.getUri(), op.getUri()); op.getResponseHeaders().put(Operation.LOCATION_HEADER, newLocation);
String newLocation = o.getResponseHeader(Operation.LOCATION_HEADER); String expectedLocation = UriUtilsExtended.getReverseProxyLocation(movedLocation, targetUri, SAMPLE_PROXY_URI);