I am trying to use a Java Callout policy and wanted to test it and see it working with an extremely simple example before moving on to something more substantial. I was emulating the example of simply adding an extra query parameter on the request - example found here: https://github.com/apigee/api-platform-samples/blob/master/doc-samples/java-cookbook/java/src/com/apigee/CityLookup.java
My code:
package com.test;
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 JavaCalloutTest implements Execution{
public ExecutionResult execute(MessageContext messageContext, ExecutionContext executionContext) {
try {
int woeid = 0;
String jurisdiction = messageContext.getMessage().getQueryParam("jurisdiction").toUpperCase();
if(jurisdiction.equals("NH"))
woeid=718345;
else if (jurisdiction.equals("MA"))
woeid=721943;
else if (jurisdiction.equals("IN"))
woeid=725746;
else {
woeid=1;
}
messageContext.getRequestMessage().setQueryParam("w", woeid);
return ExecutionResult.SUCCESS;
} catch (Exception e) {
return ExecutionResult.ABORT;
}
}
}
My Java Callout policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JavaCallout async="false" continueOnError="false" enabled="true" name="Java-Callout">
<DisplayName>Java Callout</DisplayName>
<ResourceURL>java://JavaCalloutTest.jar</ResourceURL>
<ClassName>com.test.JavaCalloutTest</ClassName>
</JavaCallout>
I’ve tried both with and without including expressions-1.0.0.jar and message-flow-1.0.0.jar jars in the proxy scripts.
Once I save the proxy and attempt to deploy I get the following error message:
"The revision is deployed, but traffic cannot flow. Failed to instantiate the JavaCallout Class com.test.JavaCalloutTest"
I’m not sure what I am doing wrong, but I think that I am missing something (maybe even something obvious)
My Solution: Do Not include expressions-1.0.0.jar or message-flow-1.0.0.jar in your jar for a Java Callout.