Was this helpful?

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.

For relatively simple interaction with message content, such as modifying or extracting HTTP headers, parameters, or message content, you can use JavaScript or Python languages.

For a detailed code example, see Building a composite service using JavaScript.

Javadocs

To get started writing Java for the API Platform, refer to the JavaCallout Javadocs.

JavaCallout Samples

For commented sample code, see the JavaCallout samples repository.

Compiling, deploying, testing

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.

Configuring a JavaCallout policy

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.

Field Name Description
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

Policy schema

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.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JavaCallout name="MyJavaCalloutPolicy">
        <ResourceURL>java://MyJavaCallout.jar</ResourceURL>
        <ClassName>com.apigee.mypolicy.Javacallout.MyJavaCallout</ClassName>
</JavaCallout>