{"id":23338262,"url":"https://github.com/abhirockzz/fn-java-sdk-invoke","last_synced_at":"2025-10-14T16:12:15.077Z","repository":{"id":52540382,"uuid":"169377766","full_name":"abhirockzz/fn-java-sdk-invoke","owner":"abhirockzz","description":"Invoke Oracle Functions using the OCI Java SDK","archived":false,"fork":false,"pushed_at":"2021-04-26T18:50:07.000Z","size":50,"stargazers_count":2,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-04T15:35:27.412Z","etag":null,"topics":["faas","oracle-functions","orafunc-la","serverless"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhirockzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-06T08:55:55.000Z","updated_at":"2020-05-10T23:12:08.000Z","dependencies_parsed_at":"2022-09-08T05:04:34.790Z","dependency_job_id":null,"html_url":"https://github.com/abhirockzz/fn-java-sdk-invoke","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abhirockzz/fn-java-sdk-invoke","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Ffn-java-sdk-invoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Ffn-java-sdk-invoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Ffn-java-sdk-invoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Ffn-java-sdk-invoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhirockzz","download_url":"https://codeload.github.com/abhirockzz/fn-java-sdk-invoke/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhirockzz%2Ffn-java-sdk-invoke/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019557,"owners_count":26086749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["faas","oracle-functions","orafunc-la","serverless"],"created_at":"2024-12-21T03:13:25.380Z","updated_at":"2025-10-14T16:12:15.026Z","avatar_url":"https://github.com/abhirockzz.png","language":"Java","readme":"# Invoke Oracle Functions using the OCI Java SDK\n\nThis example demonstrates how to invoke a function on Oracle Functions using\n(a preview version of) the Oracle Cloud Infrastructure Java SDK. \n\n\n## Introduction\n\nTo be specifc, it shows how you can invoke a function by its name along with the\nname of the application name it belongs to, the OCI compartment containing the\napplication, and the OCID of your tenancy.\n\nThe OCI SDK exposes two endpoints specificially for Oracle Functions\n\n- `FunctionsManagementClient` - for CRUD operations e.g., creating applications,\n  listing functions etc.\n- `FunctionsInvokeClient` - required for invoking functions\n\nalong with a number of wrapper/handle objects like `FunctionSummary`,\n`ApplicationSummary`, and `Compartment`.\n \nThe `invokeFunction` method in `FunctionsUtils` takes a `FunctionSummary` for a\ngiven function, the desired payload, and uses a `FunctionsInvokeClient` to\nactually invoke the function.  This seems relatively straightforward but\nobtaining a `FunctionSummary` requires navigating from the OCI compartment, to\nthe application, to the function.  This involves multiple lookups (API calls).\n\nTo illustrate the steps, the `FunctionsUtils` class provides a number of methods\nthat capture the steps required to navigate the OCI object model\n\n- `getCompartment(compartmentName)` returns a Compartment with a given name\n  using the `IdentityClient.listCompartments` method - it looks for compartments\n  in the tenancy with the provided name\n- `getApplication(compartment, appName)` searches in the specified compartment\n  for the named application using the\n  `FunctionsManagementClient.listApplications` method\n- `getFunction(application, funcName)` searches in the specified application for\n  the named function using the `FunctionsManagementClient.listFunctions` method.\n  The result is a `FunctionSummary` object which provides the function ID, name,\n  and invoke endpoint\n\nThe key thing to note here is that the function ID and its invoke endpoint will\nnot change unless you delete the function (or the application it's a part of).\nAs a result you do not need to repeat the above mentioned flow of API calls -\nthe function ID and its invoke endpoint can be derived once and then **cached**\nin-memory (e.g. `HashMap`) or using an external data store.\n\nOnce we have a `FunctionSummary` (containing function OCID and invoke enpdoint)\nat our disposal we can use the \n`FunctionsUtils.invokeFunction(function,payload)` method which: \n\n- builds an `InvokeFunctionRequest` object with the function OCID and the\n  (optional) payload which we want to send to our function\n- calls `setEndpoint` in our `FunctionsInvokeClient` object to point it to the\n  service endpoint\n- and finally, calls `FunctionsInvokeClient.invokeFunction` with the\n  `InvokeFunctionRequest`returning the String response from the resulting\n  `InvokeFunctionResponse` object\n\n### Authentication\n\nFunctions clients need to authenticate with OCI before being able to make\nservice calls. The example uses standard OCI authenitcation which accepts the\nfollowing inputs (details below) - tenant OCID, user OCID, fingerprint, private\nkey and passphrase (optional). These details are required to instantiate a\n`SimpleAuthenticationDetailsProvider` object which is subsequently used by the\nservice client objects (`FunctionsInvokeClient`, `FunctionsManagementClient`,\n`IdentityClient`). \n\nThis example does not assume the presence of an OCI config file on the machine\nit is executing on. However, if you have one present as per the standard OCI\npractices i.e., a config file in your home directory, you can use the\n`ConfigFileAuthenticationDetailsProvider` for convenience\n\n## Pre-requisites\n\n1. Install/update the Fn CLI\n\n   `curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install |\n   sh`\n\n2. Create a function to invoke\n\n   Create a function using [Go Hello World\n   Function](https://github.com/abhirockzz/oracle-functions-hello-worlds/blob/master/golang-hello-world.md)\n\n### Install preview OCI Java SDK\n\nAs this example uses Maven, you need to install the OCI SDK JAR to your local\nMaven repository.\n\n1. Download and unzip the preview version of the OCI Java SDK\n\n        unzip oci-java-sdk-dist-1.5.7-preview1-20190524.232748-4.zip\n\n2. Change into the correct directory\n\n        cd oci-java-sdk-dist-1.5.7-preview1-20190524.232748-4\n\n3. Install the JAR to local Maven repo\n\n        mvn install:install-file -Dfile=lib/oci-java-sdk-full-1.5.7-preview1-SNAPSHOT.jar -DgroupId=com.oracle.oci.sdk -DartifactId=oci-java-sdk -Dversion=1.5.7-preview1-20190524.232748-4 -Dpackaging=jar\n\n### Build the JAR and configure environment variables\n\n1. Clone this repository\n\n   `git clone https://github.com/abhirockzz/fn-java-sdk-invoke`\n\n2. Change to the correct directory where you cloned the example: \n\n   `cd fn-java-sdk-invoke` \n\n3. Then build the JAR using \n\n   `mvn clean package`\n\n4. Set environment variables\n\n   ```shell\n   export TENANT_OCID=\u003cOCID of your tenancy\u003e\n   export USER_OCID=\u003cOCID of the OCI user\u003e\n   export PUBLIC_KEY_FINGERPRINT=\u003cpublic key fingerprint\u003e\n   export PRIVATE_KEY_LOCATION=\u003clocation of the private key on your machine\u003e\n   ```\n\n   \u003e please note that `PASSPHRASE` is optional i.e. only required if your\n   \u003e private key has one\n\n   ```shell\n   export PASSPHRASE=\u003cprivate key passphrase\u003e\n   ```\n\n   e.g.\n\n   ```shell\n   export TENANT_OCID=ocid1.tenancy.oc1..aaaaaaaaydrjd77otncda2xn7qrv7l3hqnd3zxn2u4siwdhniibwfv4wwhtz\n   export USER_OCID=ocid1.user.oc1..aaaaaaaavz5efd7jwjjipbvm536plgylg7rfr53obvtghpi2vbg3qyrnrtfa\n   export PUBLIC_KEY_FINGERPRINT=42:42:5f:42:ca:a1:2e:58:d2:63:6a:af:42:d5:3d:42\n   export PRIVATE_KEY_LOCATION=/Users/foobar/oci_api_key.pem\n   ```\n\n   \u003e and only if your private key has a passphrase:\n\n   ```shell\n   export PASSPHRASE=4242\n   ```\n\n## You can now invoke your function!\n\n`java -jar target/\u003cjar-name\u003e.jar \u003ccompartment-name\u003e \u003capp-name\u003e \u003cfunction-name\u003e\n\u003coptional-payload\u003e`\n\n\u003e Payload is optional. If your function doesn't expect any input parameters, you\n\u003e can omit the \u003coptional-payload\u003e\n\ne.g. with payload:\n\n`java -jar target/fn-java-sdk-invoke-1.0-SNAPSHOT.jar mycompartment\nhelloworld-app helloworld-func-go '{\"name\":\"foobar\"}'`\n\ne.g. without payload:\n\n`java -jar target/fn-java-sdk-invoke-1.0-SNAPSHOT.jar mycompartment\nhelloworld-app helloworld-func-go`\n\n\n## What if my function needs input in binary form ?\n\nThis example demonstrates how to invoke a boilerplate function which accepts (an\noptional) string payload (JSON data). But, it is possible to send binary payload\nas well.\n\nYou can use this Tensorflow based function as an example to explore the\npossibility of invoking a function using binary content -\nhttps://github.com/abhirockzz/fn-hello-tensorflow. This function expects the\nimage data (in binary form) as an input and returns what object that image\nresembles along with the percentage accuracy\n\nIf you were to deploy the Tensorflow function, the command to invoke it using Fn\nCLI would be something like this - `cat /home/foo/cat.jpeg | fn invoke\nfn-tensorflow-app classify`. In this case, the `cat.jpeg` image is being passed\nas an input to the function. The programmatic (using Java SDK) equivalent of\nthis would look something like the below snippet, where the function invocation\nrequest (`InvokeFunctionRequest`) is being built along with the binary input\n(image file content)\n\n```java\nInvokeFunctionRequest invokeFunctionRequest = \n\nInvokeFunctionRequest.builder()\n                     .functionId(function.getFunction().getId())\n                     .invokeFunctionBody(StreamUtils.toInputStream(new File(\"/home/foo/cat.jpeg\")))\n                     .build();\n```\n\nPay attention to the following line\n`invokeFunctionBody(StreamUtils.toInputStream(new File(\"/home/foo/cat.jpeg\")))`.\nThe `toInputStream` helper method from `com.oracle.bmc.util.StreamUtils` is\nbeing used to send the binary contents of file `/home/foo/cat.jpeg`\n\n\n## Troubleshooting\n\n1. If you fail to set the required environment variables like `TENANT_OCID` etc.\n\n   You will see the following error - `Exception in thread \"main\"\n   java.lang.Exception: Please ensure you have set the mandatory environment\n   variables - TENANT_OCID, USER_OCID, PUBLIC_KEY_FINGERPRINT,\n   PRIVATE_KEY_LOCATION`\n\n2.  If you do not provide required arguments i.e. function name etc.\n\n   You will see the following error - `Exception in thread \"main\"\n   java.lang.Exception: Usage: java -jar \u003cjar-name\u003e.jar \u003cfunction name\u003e \u003capp\n   name\u003e \u003ccompartment name\u003e \u003cfunction invoke payload\u003e`\n\n3. If you provide an invalid value for function name etc.\n\n   You will see something similar to - `Exception in thread \"main\"\n   java.lang.Exception: Could not find function with name test-function in\n   application test-app`\n\n4. If you provide an incorrect `TENANT_OCID` or `USER_OCID` or\n   `PUBLIC_KEY_FINGERPRINT`\n\n   You will get this error - `Exception in thread \"main\"\n   com.oracle.bmc.model.BmcException: (401, NotAuthenticated, false) The\n   required information to complete authentication was not provided or was\n   incorrect. (opc-request-id:\n   974452A5243XXXXX77194672D650/37DFE2AEXXXXXXX20ADFEB2E43/48B235F1D7XXXXXX273CFB889)`\n\n5. If your key has a passphrase but you failed to set the environment variable\n   PASSPHRASE\n\n   You will get this error - `Exception in thread \"main\"\n   java.lang.NullPointerException: The provided private key requires a\n   passphrase`\n\n6. If your key has a passphrase but you set an incorrect value in the\n   environment variable PASSPHRASE\n\n   You will get this error - `Exception in thread \"main\"\n   java.lang.IllegalArgumentException: The provided passphrase is incorrect.`\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhirockzz%2Ffn-java-sdk-invoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhirockzz%2Ffn-java-sdk-invoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhirockzz%2Ffn-java-sdk-invoke/lists"}