This example provides a simple Apigee Proxy that uses a Java Callout Policy.
The Java Callout Policy offers a way to extend the capabilities of your API proxies by allowing you to execute custom Java code within the proxy flow. This policy enables users to implement specialized logic that isn't covered by built-in Apigee policies using Java Code. You can leverage a Java Callout to manipulate request and response messages, read and set flow variables, perform custom error handling, or specific calculations.
You'll package your custom Java code into a JAR file and then deploy it to Apigee. The Java Callout policy then references this JAR, allowing your code to interact with the current API proxy context.
Refer to Java Callout Policy Documentation for supported Java version information: Java Callout Policy Documentation
-
Configure external access for API traffic to your Apigee X instance
-
A Linux-based shell with bash, and the following tools available in your terminal's $PATH:
- gcloud CLI
- unzip
- curl
- jq
- npm
Cloud Shell is sufficient, and has all of these preconfigured, but you can use your own workstation.
-
Make sure your Google Cloud user has all the relevant IAM roles for executing this script
roles/iam.serviceAccountCreatorroles/resourcemanager.projectIamAdminroles/apigee.apiAdminV2
The way roles work in Google Cloud: think of them as a way to group a set of related permissions that are often used together. For example, the iam.serviceAccountCreator role grants these permissions:
- iam.serviceAccounts.create
- iam.serviceAccounts.get
- iam.serviceAccounts.list
- resourcemanager.projects.get
- resourcemanager.projects.list
Use the following GCP CloudShell tutorial, and follow the instructions.
- Clone the apigee-samples repo, and switch the java-callout directory
git clone https://github.com/GoogleCloudPlatform/apigee-samples.git
cd apigee-samples/java-callout-
Edit the
env.shand configure the required environment variables:PROJECTthe project where your Apigee organization is locatedAPIGEE_ENVthe Apigee environment where the demo resources should be createdAPIGEE_HOSTthe externally reachable hostname of the Apigee environment group that contains APIGEE_ENV
Now source the
env.shfilesource ./env.sh -
Deploy Apigee API proxy
./deploy-java-callout.sh
Make a call to the deployed java-callout proxy
curl -i https://$APIGEE_HOST/v1/samples/java-calloutIf you want, consider also checking the call in the Debug view
Successful deployment of the proxy will return a “Hello, World!” response.
If you want to clean up the artifacts from this example in your Apigee Organization, first source your
env.sh script, and then run
./clean-up-java-callout.sh