I am trying to add a JavaCallout policy, based on the sample interface
http://docs.apigee.com/api-services/reference/java-callout-policy
When I go to deploy the API Proxy, I get message "The revision is deployed, but traffic cannot flow. Failed to instantiate the JavaCallout Class com.telstra.authorization.pep.ApigeeCalloutPolicy"
I have added expressions-1.0.0.jar and message-flow-1.0.0.jar to the proxys' scripts > java folder. Can't figure out why i'm getting this error. Source for the class below:
/* * see apigee documentation at http://docs.apigee.com/api-services/cookbook/use-java-customize-api */ package com.telstra.authorization.pep; import com.apigee.flow.execution.ExecutionContext; import com.apigee.flow.execution.ExecutionResult; import com.apigee.flow.execution.spi.Execution; import com.apigee.flow.message.MessageContext; public class ApigeeCalloutPolicy implements Execution { public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) { System.out.println( "reached apigee callout policy" ); /* // call our own stub PEP AxiomaticsPolicyEnforcementPoint pep = new AxiomaticsPolicyEnforcementPoint(); String xacmlResult = pep.callPolicyDescisionPoint(null); //TODO im not sure how we want to return the permit/deny //response. do we set it on the request and give it back, // like messageContext.getRequestMessage().setQueryParam("w", 20148584); // or return ExecutionResult like below ?? if (!xacmlResult.equalsIgnoreCase("PERMIT")) { return ExecutionResult.ABORT; } */ return ExecutionResult.SUCCESS; } }
Solved! Go to Solution.
Hi
You definitely DO NOT want to include expressions-1.0.0.jar and message-flow-1.0.0.jar in the scripts > java directory. Those JARs are included in Apigee Edge. It's not necessary for you to include them in every Java callout you publish. I don't know if it's harmful, but it might be. Don't do that. Delete those JARs from the api proxy. You DO need to upload your own custom JAR to the PAI proxy.
The most common problem I've seen when Java callouts fail to instantiate is an error in the configuration of the policy. Often, the class name for the class you want Apigee Edge to instantiate, isn't quite right. The second most common problem is a missing dependency. Since your simple callout doesn't have any dependencies (yet!) I'm going to rule that out.
You didn't show your policy config. Can I see it? In any case, check it. By default when you drag in a Java callout policy using the API proxy editor, you will get an incomplete configuration that looks like this:
<JavaCallout name="Java-Callout-1"> <DisplayName>Java Callout-1</DisplayName> <Properties/> <ClassName>class</ClassName> <ResourceURL>java://the-name-of-your-custom-jar-here.jar</ResourceURL> </JavaCallout>
Notice the ClassName by default is specified as "class". This is probably wrong. In your case, it ought to be
com.telstra.authorization.pep.ApigeeCalloutPolicy
From the error message you mentioned, it sounds as if you have this part right. Do you have the correct custom JAR specified? And do you have that JAR included in the API Proxy?
What you're doing sounds interesting. PEP - I'm assuming policy-execution-point. I'm guessing it will grant authorization based on some data stored in a backend system (PDP). What's the backend? Whoops! Now I see it: It's Axiomatics. I'd love to be able to see how that works out for you. Will you be open-sourcing that code, sharing with the community?