Failed to instantiate the JavaCallout Class {0} - What does this mean and how can I fix it?,

Not applicable

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/ap...

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.

Solved Solved
0 5 1,549
1 ACCEPTED SOLUTION

how are you generating your jar?

1)can you try?

jar tf <jar-file>

and make sure you have the com/test/JavaCalloutTest.class in it?

2) pls dont include expression and message flow in your jar

View solution in original post

5 REPLIES 5

Not applicable

Hi @David C. Burke. It looks like it might not have anything to do with your code. Please try the suggestions posted by my colleague in the meantime it gets fixed. @sriki77. https://community.apigee.com/content/kbentry/8352/revision-is-deployed-and-traffic-can-flow-but-flow....

Hello @Diego Zuluaga, thank you for your response.

I probably should have adjusted the formatting of my post, I apologize for that. But the "traffic cannot flow" isn't my issue. My issue is the "Failed to instantiate the JavaCallout Class com.test.JavaCalloutTest" which subsequently causes the "traffic cannot flow".

There has been no trace session started on this proxy when deploying and the proxy is not already deployed either. This error comes from the proxy being in an undeployed state.

I'm attaching an image of the error message to the original post for clarity.

Thanks for clarifying @David C. Burke. Yes, as @Mukundha Madhavan suggests, it's possible that the class file is not zipped in the right folder. If you please send us the bundle, I should be able to replicate the issue on my own org. You can also give us access to your org.

how are you generating your jar?

1)can you try?

jar tf <jar-file>

and make sure you have the com/test/JavaCalloutTest.class in it?

2) pls dont include expression and message flow in your jar

Hello @Mukundha Madhavan. I have been generating the jar using Eclipse IDE's export feature. I was able to verify that com/test/JavaCalloutTest.class was included in the jar.

Your second suggestion seems to have been my issue. I was able to deploy successfully when I used only my class file in the jar. So thank you! What I was doing: I was exporting the entire project which included the expression and message flow jars. What I started doing: Exporting the class file excluding those jars. This seems to have solved my problem!