@VisibleForTesting Request asApolloRequest(HttpServletRequest req) throws IOException { final String uri = req.getRequestURI() + (req.getQueryString() == null ? "" : "?" + req.getQueryString()); final String method = req.getMethod(); final int contentLength = req.getContentLength(); final ImmutableMap.Builder<String, String> headersBuilder = ImmutableMap.builder(); toStream(req.getHeaderNames()) .forEachOrdered( name -> headersBuilder.put( name, toStream(req.getHeaders(name)).collect(Collectors.joining(",")) )); final ImmutableMap<String, String> headers = headersBuilder.build(); Request request = Request.forUri(uri, method).withHeaders(headers); final Optional<String> callingService = request.header("X-Calling-Service"); if (callingService.isPresent() && !callingService.get().isEmpty()) { request = request.withService(callingService.get()); } Optional<ByteString> payload = readPayload(req, contentLength); if (payload.isPresent()) { request = request.withPayload(payload.get()); } return request; }
/** * Makes a call on the given uri. The uri can be an application relative path such as * {@code "/ping"} or a full path like {@link "http://<service-name>/ping"}. * * @param method The method of the call * @param uri The uri of the call * @param payload A payload body * @return A future of the response */ public CompletionStage<Response<ByteString>> request(String method, URI uri, ByteString payload) { final String uriString = addSchemaAuthForRelative(uri.toString()); return request(Request.forUri(uriString, method).withPayload(payload)); }
/** * Makes a call on the given uri. The uri can be an application relative path such as * {@code "/ping"} or a full path like {@link "http://<service-name>/ping"}. * * @param method The method of the call * @param uri The uri of the call * @param payload A payload body * @return A future of the response */ public CompletionStage<Response<ByteString>> request(String method, URI uri, ByteString payload) { final String uriString = addSchemaAuthForRelative(uri.toString()); return request(Request.forUri(uriString, method).withPayload(payload)); }
private CompletionStage<Boolean> haltActiveBackfillInstance(WorkflowInstance workflowInstance, Client client) { try { final ByteString payload = serialize(Event.halt(workflowInstance)); final Request request = Request.forUri(schedulerApiUrl("events"), "POST") .withPayload(payload); return client.send(request) .thenApply(response -> response.status().family().equals(SUCCESSFUL)); } catch (JsonProcessingException e) { return CompletableFuture.completedFuture(false); } }