This directory contains the Java source code and pom.xml file required to compile a simple Java callout for Apigee. The callout uses java.security.SecureRandom to generate random numbers (ints, UUIDs, or Gaussian values) within a policy Apigee proxy, and sets a context variable with that information.
This example is not an official Google product, nor is it part of an official Google product.
You do not need to compile the callout to use it. It is usable as is, in pre-built form. Just grab the jar from this repository and use it.
Configure the policy like this:
<JavaCallout name='Java-PRNG-gaussian'>
<ClassName>com.google.apigee.edgecallouts.prng.SecureRandomCallout</ClassName>
<Properties>
<Property name='algorithm'>SHA1PRNG</Property>
<Property name='output-type'>int</Property>
</Properties>
<ResourceURL>java://edge-java-callout-prng-1.0.2.jar</ResourceURL>
</JavaCallout>
The callout sets the context variable prng_random
to a randomly-generated value.
The properties:
Property | Required? | description |
---|---|---|
algorithm | no | one of the algorithms returned by Java's java.security.Security.getProviders(). Typically you will use one of these:
|
output-type | no | uuid , gaussian , or int . Defaults to int. A Gaussian output will return the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0, as returned by java.util.Random.nextGaussian() |
decimal-digits | no | The number of decimal digits with which to render the value generated for the Gaussian distribution. The default is 12. Used only when output-type is gaussian . |
range | no | The min,max range for integer values, inclusive. Used only when output-type is int . |
The policy caches the java.security.SecureRandom and re-uses it for multiple threads. This means it should perform well at high load and concurrency.
Example successive values of prng_random
for int:
- -1604942246
- 1436054319
- 55498893
- -1631105169
- 1950692777
- -1103022666
- -79584472
- 1752902214
- 1820421062
- -22240590
- -13385112
Example successive values of prng_random
for gaussian:
- -1.026991678598
- 1.579345979370
- -1.585246137998
- 1.567258571580
- -0.914702253954
- 0.363466074537
- -0.453967291420
Example successive values of prng_random
for uuid:
- 778b4e42-065c-4535-8e1f-1f9d23e6516c
- eb0c4a87-7100-4ce9-b425-0d99c4f1597f
- 8a256fa0-ac54-4103-a43f-2b6dd21cf2a1
- 2386a528-06bd-4043-9ac1-1f9d2aa8361e
- fd0b04bc-734a-4e82-a262-78eae85f897a
- 0f0534bd-f623-4fca-bff2-ba58145852c7
Presumably you will use this value in a subsequent policy. See the example apiproxy for suggestions.
You do not need to compile the callout to use it. It is usable as is, in pre-built form. Just grab the jar from this repository and use it. But if YOU DO wish to build it, here's how you can do so:
-
clone this repo
git clone
-
configure the build on your machine by loading the Apigee jars into your local cache. You need to do this once, ever, on the machine doing the compilation.
./buildsetup.sh
-
Build with maven.
mvn clean package
-
if you edit proxy bundles offline, copy the resulting jar file, available in target/apigee-java-callout-prng-20220802.jar to your apiproxy/resources/java directory. If you don't edit proxy bundles offline, upload the jar file into the API Proxy via the Apigee API Proxy Editor .
-
include an XML file for the Java callout policy in your apiproxy/resources/policies directory. It should look as shown above.
-
use the APigee UI, or a command-line tool like apigeecli or importAndDeploy or similar to import the proxy into an Apigee organization, and then deploy the proxy . Eg,
node importAndDeploy.js -v -o ORGNAME -e test -n prng -d bundle
-
Use a client to generate and send http requests to the example proxy. Eg,
endpoint=https://whatever.api.com curl -i $endpoint/prng/int
or
curl -i $endpoint/prng/gaussian
or
curl -i $endpoint/prng/uuid
- Apigee Edge expressions v1.0
- Apigee Edge message-flow v1.0
The first two jars must be available on the classpath for the compile to succeed. The buildsetup.sh script will download these files for you automatically, and will insert them into your maven cache.
If you want to download them manually:
These jars are produced by Apigee; contact Apigee support to obtain these jars to allow the compile, or get them here: https://github.com/apigee/api-platform-samples/tree/master/doc-samples/java-cookbook/lib
There is one callout class, com.google.apigee.callouts.prng.SecureRandomCallout , which uses java.security.SecureRandom to generate random values.
This callout is open-source software, and is not a supported part of Apigee Edge. If you need assistance, you can try inquiring on the Apigee Community Site. There is no service-level guarantee for responses to inquiries regarding this callout.
This material is Copyright © 2015-2022 Google LLC. and is licensed under the Apache 2.0 license. See the LICENSE file.