@Override public void handleStart(Operation startOp) { sendRequest(Operation .createGet(getHost(), UriUtils.buildUriPath(ManagementUriParts.CONFIG_PROPS, FileUtil.USER_RESOURCES_PATH_VARIABLE)) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion((res, ex) -> { if (ex == null && res.hasBody()) { ConfigurationState body = res.getBody(ConfigurationState.class); if (body.value != null && !body.value.isEmpty()) { String userResourcesPath = body.value; startExternalContainerImageIconResourceServices(userResourcesPath); } } startOp.complete(); })); }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String containerImageIcon = params.remove(CONTAINER_IMAGE_QUERY_PARAM); if (containerImageIcon == null || containerImageIcon.isEmpty()) { String errorMsg = String.format( "URL parameter '%s' expected with container image name as value.", CONTAINER_IMAGE_QUERY_PARAM); get.fail(new LocalizableValidationException(errorMsg, "ui.container-image.container.name.missing", CONTAINER_IMAGE_QUERY_PARAM)); return; } String expectedImageName = String.format(CONTIANER_IMAGE_FORMAT, containerImageIcon); String expectedImagePath = UriUtils.buildUriPath( ManagementUriParts.CONTAINER_ICONS_RESOURCE_PATH, expectedImageName); int identiconHash = Math.abs(containerImageIcon.hashCode() % IDENTICONS_COUNT); String expectedIdenticonName = String.format(IDENTICON_IMAGE_FORMAT, identiconHash); String expectedIdenticonPath = UriUtils.buildUriPath( ManagementUriParts.CONTAINER_IDENTICONS_RESOURCE_PATH, expectedIdenticonName); getIcon(expectedImagePath, get, () -> { getIcon(expectedIdenticonPath, get, null); }); }
private void startExternalContainerImageIconResourceServices(String resourcesPath) { Path iconResourcePath = Paths.get(resourcesPath, ManagementUriParts.CONTAINER_ICONS_RESOURCE_PATH); if (!iconResourcePath.toFile().exists()) { logInfo("Skip loading container icons from user resource path"); return; } else { logInfo("Loading container icons from user resource path"); } List<File> files = FileUtils.findFiles(iconResourcePath, new HashSet<>(), false); for (File f : files) { String subPath = f.getAbsolutePath().replace( iconResourcePath.toAbsolutePath().toString(), ""); Path servicePath = Paths .get(ManagementUriParts.CONTAINER_ICONS_RESOURCE_PATH.substring(1), subPath); String servicePathString = FileUtil.getForwardSlashesPathString(servicePath); Operation post = Operation .createPost(UriUtils.buildUri(getHost(), servicePathString)); RestrictiveFileContentService fcs = new RestrictiveFileContentService(f); getHost().startService(post, fcs); } } }
private void getIcon(String path, Operation get, Runnable notFoundHandler) { Operation getOp = Operation.createGet(this, path) .setCompletion((op, ex) -> { if (op.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND && notFoundHandler != null) { notFoundHandler.run(); } else if (ex != null) { get.fail(ex); } else { get.transferResponseHeadersFrom(op); get.getResponseHeaders().put(Operation.CONTENT_TYPE_HEADER, op.getContentType()); get.getResponseHeaders().put(CACHE_CONTROL_HEADER, CACHE_CONTROL_VALUE); get.setBody(op.getBodyRaw()); get.setStatusCode(op.getStatusCode()); get.complete(); } }); String originalUiProxyHeader = get.getRequestHeader(ConfigurationUtil.UI_PROXY_FORWARD_HEADER); if (originalUiProxyHeader != null) { getOp.addRequestHeader(ConfigurationUtil.UI_PROXY_FORWARD_HEADER, originalUiProxyHeader); } sendRequest(getOp); }