/** * The content type of the response. * <p> * * @return The name of the content type. */ default Optional<String> getContentType(){ return getHeaders().get(CONTENT_TYPE_HEADER); }
/** * Invoke a void JSON function on a given flow by mapping the input to JSON, returns a future that completes with the HttpResponse of the function * if the function returns a successful http response, and completes with an error if the function invocation fails. * * @param flow the flow to invoke the subsequent call onto * @param functionId the function ID to invoke * @param method the HTTP method to use * @param headers additional headers to pass - the content * @param input the input object * @param <U> the input type * @return a future that returns the object value of JSON function or throws an error if that function fails. */ public static <U> FlowFuture<HttpResponse> invokeFunction(Flow flow, String functionId, HttpMethod method, Headers headers, U input) { try { String inputString = getObjectMapper().writeValueAsString(input); Headers newHeaders; if (!headers.get("Content-type").isPresent()) { newHeaders = headers.addHeader("Content-type", "application/json"); } else { newHeaders = headers; } return flow.invokeFunction(functionId, method, newHeaders, inputString.getBytes()); } catch (JsonProcessingException e) { throw new IllegalArgumentException("Failed to coerce function input to JSON", e); } }
@Override public CompletionId invokeFunction(FlowId flowId, String functionId, byte[] data, HttpMethod method, Headers headers, CodeLocation codeLocation) { APIModel.HTTPReq httpReq = new APIModel.HTTPReq(); if (headers != null) { if (data.length > 0) { BlobResponse blobResponse = blobStoreClient.writeBlob(flowId.getId(), data, headers.get(CONTENT_TYPE_HEADER).orElse(CONTENT_TYPE_OCTET_STREAM)); httpReq.body = APIModel.Blob.fromBlobResponse(blobResponse); } httpReq.headers = new ArrayList<>(); headers.asMap().forEach((k, vs) -> vs.forEach(v -> httpReq.headers.add(APIModel.HTTPHeader.create(k, v)))); Map<String, List<String>> headersMap = headers.asMap(); headersMap.forEach((key, values) -> values.forEach(value -> httpReq.headers.add(APIModel.HTTPHeader.create(key, value)))); } httpReq.method = APIModel.HTTPMethod.fromFlow(method); APIModel.AddInvokeFunctionStageRequest addInvokeFunctionStageRequest = new APIModel.AddInvokeFunctionStageRequest(); addInvokeFunctionStageRequest.arg = httpReq; addInvokeFunctionStageRequest.codeLocation = codeLocation.getLocation(); addInvokeFunctionStageRequest.callerId = FlowRuntimeGlobals.getCurrentCompletionId().map(CompletionId::getId).orElse(null); addInvokeFunctionStageRequest.functionId = functionId; try { return executeAddInvokeFunctionStageRequest(flowId, addInvokeFunctionStageRequest); } catch (IOException e) { throw new PlatformCommunicationException("Failed to create invokeFunction stage", e); } }
BlobResponse blobResponse = writeBlob(flowId.getId(), res.getBodyAsBytes(), res.getHeaders().get("Content-type").orElse("application/octet-stream"));
Optional<String> graphIdOption = evt.getHeaders().get(FLOW_ID_HEADER);