Refine search
/** * Checks whether a principal ID was specified. Ignores suffixes like {@link #ROLES_SUFFIX} * or {@link #SECURITY_CONTEXT_SUFFIX}. Additional checks are needed when those are expected. */ private boolean isPrincipalByIdRequest(Operation op) { return op.getUri().getPath().length() > SELF_LINK.length() + 1; }
@Override public void handleGet(Operation get) { String path = get.getUri().getPath(); if (path.contains("..")) { // prevent serving any file by means of path manipulation get.fail(Operation.STATUS_CODE_NOT_FOUND); return; } path = path.substring(getSelfLink().length() + 1); File file = this.root.resolve(path).toFile(); if (file.isDirectory() || !file.canRead()) { get.fail(Operation.STATUS_CODE_NOT_FOUND); return; } FileUtils.readFileAndComplete(get, file); } }
@Override public void handleRequest(Operation op) { if (op.getAction() != Action.GET) { logWarning("Unsupported method: %s", op.getAction().toString()); Operation.failActionNotSupported(op); return; } URI requestUri = op.getUri(); if (isRepositoriesRequest(requestUri)) { handleRepositoryGet(op); } else if (isProjectDeleteVerifyRequest(requestUri)) { handleProjectDeleteVerify(op); } else { logWarning("Unsupported URI path: %s", getHarborPath(requestUri.getPath())); op.fail(new IllegalStateException( String.format("Path %s is not supported by the mock service.", getHarborPath(requestUri.getPath())))); } }
private void forwardRequest(final Operation op, final Function<URI, Operation> createOp) { String targetUri = op.getUri().toString(); targetUri = targetUri.replace(ManagementUriParts.CREDENTIALS_PROXY, ServiceUriPaths.CORE_CREDENTIALS); URI updatedUri = null; try { updatedUri = new URI(targetUri); } catch (URISyntaxException e) { op.fail(e); return; } ReverseProxyService.forwardRequest(updatedUri, op, createOp, this); } }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String containerId = params.remove(CONTAINER_ID_QUERY_PARAM); if (containerId == null || containerId.isEmpty()) { get.fail(new IllegalArgumentException( "URL parameter 'id' expected with container id as value.")); return; } getContainerStateAndProcess(get, containerId); }
@Override public void completed(Integer result, AtomicInteger bytesWritten) { int total = bytesWritten.addAndGet(result); if (total >= range.fileSize) { try { ch.close(); Logger.getAnonymousLogger().log(Level.INFO, String.format( "done download of %s (bytes %s)", parentOp.getUri().toString(), total)); parentOp.complete(); } catch (Exception e) { parentOp.fail(e); } } }
private void doLogging(Operation operation) { long startTime = System.nanoTime(); log.trace("Performing {} on {}", operation.getAction(), operation.getUri()); operation.nestCompletion((completedOp, failure) -> { if (failure == null) { log.debug("Operation {} on {} Succeeded. It took {}", operation.getAction(), operation.getUri(), System.nanoTime() - startTime); operation.complete(); } else { log.info("Operation {} on {} failed. It took {}", operation.getAction(), operation.getUri(), System.nanoTime() - startTime); operation.fail(failure); } }); }