private void loadContainerShellURL(String containerDocumentId, Operation op) { String path = UriUtils.buildUriPath(ContainerFactoryService.SELF_LINK, containerDocumentId); sendRequest(Operation.createGet(this, path).setCompletion((o, e) -> { if (e != null) { op.fail(e); return; } ContainerState containerState = o.getBody(ContainerState.class); loadContainerShellURI(containerState.parentLink, op, (uri -> { URI shellUri = extendUri(extendUri(uri, SHELL_PATH), containerState.id); shellUri = getReverseProxyUri(shellUri); op.setContentType(Operation.MEDIA_TYPE_TEXT_PLAIN); op.setBody(shellUri.toString()).complete(); })); })); } }
URI rpUri = UriUtilsExtended.getReverseProxyUri(uri); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2/", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2/?q1=v1", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); rpUri = UriUtilsExtended.getReverseProxyUri(uri); rpUri = UriUtilsExtended.getReverseProxyUri(uri);
URI rpUri = UriUtilsExtended.getReverseProxyUri(uri); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2?q1=v1", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); rpUri = UriUtilsExtended.getReverseProxyUri(uri); rpUri = UriUtilsExtended.getReverseProxyUri(uri);
private void testOperation(final Function<URI, Operation> createOp, String inBody) throws Throwable { URI pingUri = UriUtils.buildUri(host, MockPingService.SELF_LINK); URI rpPingPath = UriUtilsExtended.getReverseProxyUri(pingUri); URI rpPingUri = UriUtils.buildUri(host, rpPingPath.toString()); Operation op = createOp.apply(rpPingUri); if (inBody != null) { op.setBody(inBody); } op.setCompletion((o, e) -> { if (e != null) { Operation.failActionNotSupported(o); return; } String outBody = o.getBody(String.class); assertEquals(MockPingService.BODY_PONG, outBody); }); verifyOperation(op); }
@Test public void testReverseProxyRequest() { assertNotNull(SAMPLE_URI); URI rpUri = UriUtilsExtended.getReverseProxyUri(SAMPLE_URI); assertNotEquals(SAMPLE_URI, rpUri); URI targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertNotEquals(rpUri, targetUri); assertEquals(SAMPLE_URI, targetUri); }
@Test public void testReverseProxyInvalidTransformations() { URI uri = UriUtilsExtended.getReverseProxyUri(null); assertNull(uri); uri = UriUtilsExtended.getReverseProxyTargetUri(null); assertNull(uri); URI opUri = UriUtils.buildUri("http://localhost/rp"); uri = UriUtilsExtended.getReverseProxyTargetUri(opUri); assertNull(uri); opUri = UriUtils.buildUri("http://localhost/rp/f-o-o/bar"); uri = UriUtilsExtended.getReverseProxyTargetUri(opUri); assertNull(uri); opUri = UriUtils.buildUri("http://localhost/rp/" + UriUtilsExtended.getValueEncoded("%0")); try { uri = UriUtilsExtended.getReverseProxyTargetUri(opUri); fail("URI should be invalid!"); } catch (LocalizableValidationException e) { assertTrue(e.getMessage().startsWith("Invalid target URI:")); } }