private String buildCompositionSubTaskLink(String name) { final String compositionSubTaskId = getSelfId() + "-" + UriUtilsExtended.getValueEncoded(name); return UriUtils.buildUriPath(CompositionSubTaskFactoryService.SELF_LINK, compositionSubTaskId); }
private URI getHostUri(RegistryState hostState) { return UriUtilsExtended.buildDockerRegistryUri(hostState.address); }
URI uri = UriUtilsExtended.buildDockerUri(dockerHostScheme, dockerHostAddress, dockerHostPort, dockerHostPath); hostComputeState.customProperties.put(
public static String constructDashboardLink(ComputeState host, Service dashboard) { String scheme = Optional.ofNullable(UriUtilsExtended.extractScheme(host.address)) .orElse(UriUtils.HTTPS_SCHEME); String hostname = UriUtilsExtended.extractHost(host.address); String port = Optional.ofNullable(UriUtilsExtended.extractPort(host.address)).orElse("-1"); return UriUtils.buildUri(scheme, hostname, Integer.parseInt(port), KUBERNETES_DASHBOARD_ACCESS_LINK, null) .toString(); }
String decodedUri; try { decodedUri = getReverseProxyDecoded(encodedUri); } catch (Exception e) { flattenQueryParams(queryParams));
@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:")); } }
@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 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 testReverseProxyEncoding() { String encoded = UriUtilsExtended.getValueEncoded(SAMPLE_URL); assertNotEquals(SAMPLE_URL, encoded); String decoded = UriUtilsExtended.getReverseProxyDecoded(encoded); assertNotEquals(encoded, decoded); assertEquals(SAMPLE_URL, decoded); }
String address = UriUtilsExtended.buildDockerRegistryUri(registryState.address).toString(); if (!registryLinks.containsKey(address)) { registryLinks.put(address, registryState.documentSelfLink); result.name = UriUtilsExtended.extractHostAndPort(result.registry) + "/" + result.name;
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(); })); })); } }
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 testExtractHostPort() { assertEquals("5000" ,UriUtilsExtended.extractPort("localhost:5000")); assertEquals("5000" ,UriUtilsExtended.extractPort("https://test-host:5000")); assertEquals(null ,UriUtilsExtended.extractPort("localhost")); } }
private URI getTargetUri(final Operation op) { // try to get it directly from the request URI // the request URI should look like ../rp/{http://target-host/target-path} URI uri = op.getUri(); URI targetUri; try { targetUri = getReverseProxyTargetUri(uri); } catch (Exception e) { getHost().log(Level.WARNING, "Exception getting target uri: %s", e.getMessage()); targetUri = null; } if (targetUri == null) { getHost().log(Level.WARNING, "Unable to get target uri!"); return null; } return targetUri; } }
imageSearchUri = UriUtils.extendUriWithQuery(imageSearchUri, flattenQueryParams( queryParams));
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); targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2/ep1/ep2/", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2/ep1/ep2/?q1=v1", targetUri.toString()); rpUri = UriUtilsExtended.getReverseProxyUri(uri); targetUri = UriUtilsExtended.getReverseProxyTargetUri(rpUri); assertEquals("http://www.test-url.com:8080/p1/p2/ep1/ep2/?q1=v1&q2=v2", 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()); }
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); }
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 name = UriUtilsExtended.getValueEncoded(rn.name); String allocName = name + CompositionSubTaskService.ALLOC_SUFFIX; progress.remove(UriUtilsExtended.getValueEncoded(DEFAULT_COMPONENT_NAME));