The Apigee API Platform provides a range of out-of-the-box policy capabilities that address common API management requirements. However, there are some cases where your API requires custom behavior that is not implemented in the out-of-the-box policy palette. In these cases, Apigee provides several options that enable developers to script or code customized API behavior. One approach is to implement the desired behavior in the Java programming language.
Note: You must be an Apigee Enterprise customer to use the JavaCallout policy.
For lightweight operations, such as API calls to remote services, the ServiceCallout policy is recommended. See Call services or APIs using ServiceCallout.
To get started writing Java for the API Platform, refer to the JavaCallout Javadocs.
For commented sample code, see the JavaCallout samples repository.
JavaCallouts depend on two JAR files that are available in the API Platform samples repository on Github. For instructions on compiling and deploying, see the instructions provided in the JavaCallout overview.
A JavaCallout policy merely references a JAR file. The referenced JAR file contains compiled Java code written to the Java API exposed by the API Platform processing pipeline. The compiled Java is included as a JAR file in an API proxy under /resources/java.
Configure the JavaCallout policy using the following elements.
|ResourceURL||Specifies the Java resource that is the name of the JAR file). Note that only resource of type java is allowed|
|ClassName||Specifies the name of the Java class that executes the callout|
Each policy must conform to a policy schema. All policy constructs such as elements and attributes mentioned above are defined in a schema. To download the schema, click here.
Example - Java Callout policy
In the example below, the element, ResourceURL specifies the name of the relevant JAR file.