public FunctionInvocationException(HttpResponse functionResponse) { super(new String(functionResponse.getBodyAsBytes())); this.functionResponse = functionResponse; }
List<APIModel.HTTPHeader> callHeaders = new ArrayList<>(); for (Map.Entry<String, List<String>> e : res.getHeaders().asMap().entrySet()) { for (String v : e.getValue()) { callHeaders.add(APIModel.HTTPHeader.create(e.getKey(), v)); BlobResponse blobResponse = writeBlob(flowId.getId(), res.getBodyAsBytes(), res.getHeaders().get("Content-type").orElse("application/octet-stream")); apiResp.statusCode = res.getStatusCode();
/** * Invoke a JSON function on a given flow by mapping the input to JSON and composing a result stage that maps the argument back into the requested type. * * @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 responseType the response type to map the function result to * @param <T> the return type * @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 <T extends Serializable, U> FlowFuture<T> invokeFunction(Flow flow, String functionId, HttpMethod method, Headers headers, U input, Class<T> responseType) { return invokeFunction(flow, functionId, method, headers, input) .thenApply((httpResponse) -> { try { return getObjectMapper().readValue(httpResponse.getBodyAsBytes(), responseType); } catch (IOException e) { throw new IllegalStateException("Failed to extract function response as JSON", e); } }); }
public Response handleRequest(byte[] imageBuffer) { String id = java.util.UUID.randomUUID().toString(); Flow runtime = Flows.currentFlow(); runtime.allOf( runtime.invokeFunction(resize128ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer) .thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-128.png")), runtime.invokeFunction(resize256ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer) .thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-256.png")), runtime.invokeFunction(resize512ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer) .thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-512.png")), runtime.supply(() -> objectUpload(imageBuffer, id + ".png")) ); return new Response(id); }