In this article, we discuss how to invoke SOAP services from Oracle Functions built on Java. We consider the use case of calling Universal Content Management (UCM) SOAP API from Oracle Functions to download an attachment from Oracle Engagement Cloud UCM server. API Gateway exposes this function as a REST endpoint, so the function can be invoked and tested from REST clients, like Postman.
Where to Begin
In our example, we use the Java development kit (JDK) 8 package javax.xml.soap. This package is deprecated in JDK 11. When we create a function using the Fn init command, the function always uses the default JDK (JDK 11). So, specify the JDK version as JDK 8 in the function.
Let’s check the default JDK version used in the function by creating a function. Use the following command to create new function:
fn init --runtime java testFunctionChandan
The following func.yaml file is generated for this function:
schema_version: 20180708
name: testfunctionchandan
version: 0.0.1
runtime: java
build_image: fnproject/fn-java-fdk-build:jdk11-1.0.109
run_image: fnproject/fn-java-fdk:jre11-1.0.109
cmd: com.example.fn.HelloFunction::handleRequest
In the func.yaml, we can see that it uses the JDK as 11 when the JDK version is not specified in the Fn init command. To create a function to use JDK 8, use the following Fn init command:
fn init --runtime java8 attachment-demo
This command creates a new function with func.yaml:
schema_version: 20180708
name: attachment-demo
version: 0.0.1
runtime: java8
build_image: fnproject/fn-java-fdk-build:1.0.109
run_image: fnproject/fn-java-fdk:1.0.109
cmd: com.example.fn.HelloFunction::handleRequest
Then, we modify this func.yaml to use our own function’s name with the package.
schema_version: 20180708
name: attachment-demo
version: 0.0.1
runtime: java8
build_image: fnproject/fn-java-fdk-build:1.0.109
run_image: fnproject/fn-java-fdk:1.0.109
cmd: com.function.demo.AttachmentDemoFunction::handleRequest
timeout: 120
We’ve also added the timeout as 120 seconds, which is the maximum timeout supported by Oracle Functions.
We recommend modifying the pom.xml file generated by Fn init to include dependencies for this function. You can download the updated pom.xml file from pom.xml.
UCM SOAP APIs are secured, and you need to pass user credentials to access it. When we call this function, we have to pass the Authorization token in the header of the request. This token is used to access the UCM SOAP API.
To access the http header, use the following import statements in the Java class AttachmentDemoFunction.java:
import com.fnproject.fn.api.httpgateway.HTTPGatewayContext;
import com.fnproject.fn.api.Headers;
The getInputParameters(context) method in the attached Java class AttachmentDemoFunction.java extracts the token from the http header and extracts path parameter from the REST Endpoint of this function. This path parameter in the endpoint stores the value of the UCM Content ID of the attachment.
You can find the source code of the java class at AttachmentDemoFunction.java.
API Gateway Configuration
To call this function, we configure an API gateway in the Oracle Cloud Infrastructure Console. We’ve configured the path of the deployment as “/attachment/{documentId}” where {documentId} is the UCM Content ID of the attachment.

When the API gateway deployment is successful, the endpoint is be displayed in the Console. The REST endpoint of this function is something like https://host:port/demo/attachment/{documentId}.

We haven’t configured any security for this REST Endpoint in API gateway. If you want, you can secure this endpoint by configuring any of the following authentication and authorization functionalities:
-
HTTP basic authentication
-
API key authentication
-
OAuth authentication and authorization
-
Oracle Identity Cloud Service (IDCS) authentication
To learn more about authentication and authorization functionality in API Gateway, see Adding Authentication and Authorization to API Deployments.
Testing of the REST Endpoint using Postman
We can use Postman to invoke this API Gateway REST endpoint. We used a bearer token in the authorization header, as shown in the following image. To generate the bearer token, we configured SSO between IDCS and OEC.

If you don’t have any bearer tokens, you can pass basic authentication in the header.
Authorization: Basic <base64 encoded string of username:password>
While sending the request from Postman, click Save and Download, and the attachment is downloaded and saved to a local directory.

Conclusion
In this post, we looked at the capabilities of Oracle Functions to invoke SOAP services using JDK 8 packages. We also looked at how this function was exposed as a REST endpoint by configuring API gateway. Finally, we tested this REST endpoint from Postman by passing a bearer token to download and save the attachment from OEC UCM server.
For more information, see the following resources: