Getting fault string as "Failed to execute JavaCallout. null" while executing java callout

Not applicable

Hello,

I am getting the following error while running the java-callout jar with "no-target" api proxy.

{"fault":{"faultstring":"Failed to execute JavaCallout. null","detail":{"errorcode":"steps.javacallout.ExecutionError"}}}

Attached the revision zip for the Api ,

organization name :: globallogic

Api proxy name :: No-Target

Solved Solved
0 10 1,224
1 ACCEPTED SOLUTION

Even in this source code you have additional Apigee classes. Please remove that and bundle only the CityLookup class.

You are using ExceptionUtils from apache commons. I am not sure if that is available or you have to package it along with your code. It might be the later , please check there.

Also the policy needs to be attached on the Response side and not on request side. I just used your code and it works perfectly if I put it on Response but throws the same error if used on Request side.

View solution in original post

10 REPLIES 10

Can you please also upload the source code of the jar file ?

Not applicable

@sarthak

Sure here is the source code

public class CityLookup implements Execution {
	public ExecutionResult execute(MessageContext messageContext,
			ExecutionContext executionContext) {
		try {
			messageContext.getResponseMessage().setContent("Hi This is Anand");
			return ExecutionResult.SUCCESS;
		} catch (Exception e) {
			messageContext.getErrorMessage().setContent(
					"Stack: " + ExceptionUtils.getStackTrace(e)); // sets the
																	// stacktrace
																	// as the
																	// error
																	// message
			return ExecutionResult.ABORT;
		}
	}
}

Also attaching the whole src package by zipping it.

Hi @Anand Jayant Kadhi I just tried out and it works fine.

Couple of observations :

In the jar you have a whole lot of classes - you only need one - CityLookup

Do not include the message-flow.jar and expressions jar in the jar file.

For debugging Java callouts please follow these instructions : https://community.apigee.com/articles/5314/debugging-java-callouts.html

Also while making the call please remember to send the queryparam city=MILAN etc. Without sending the right queryparam I was getting similar errors too.

Let me know if it solves your issue.

Sarthak

Hi @sarthak,

As i am not making request to the yahoo weather API, i don't need to send the query parameter as MILAN. I have created custom "No-Target" proxy. Which will only get the request and in the preflow will make a java-callout from that class i want to return the response to the client.

I have modified the jar to have only one class i.e. CityLookup, also removed rest of the referenced libraries and jars.But still no luck getting the same error.

Also you can see that in my java class i have set

 catch (Exception e) {
			messageContext.getErrorMessage().setContent(
					"Stack: " + ExceptionUtils.getStackTrace(e)); 
			return ExecutionResult.ABORT;
		}

So ideally if there is an exception happening in the code i should get

"Stack" +"error message"

But i am not getting this i am getting only

{"fault":{"faultstring":"Failed to execute JavaCallout. null","detail":{"errorcode":"steps.javacallout.ExecutionError"}}}

in the response.

The content of my policy.xml is ::

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>textResponse</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/noTarget</BasePath>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
</ProxyEndpoint>

and of the proxies.xml is

<JavaCallout name="textResponse">
        <ClassName>com.apigee.CityLookup</ClassName>
        <ResourceURL>java://CityLookup.jar</ResourceURL>
</JavaCallout>

Can you suggest if there is any issue.

Not applicable

Checked our logs, following is the null pointer generated in your code. Please take a look

java.lang.NullPointerException: null  

at com.apigee.CityLookup.execute(CityLookup.java:37) ~[na:na]

Hi @sriki77,

Thanks a lot for checking the logs.

In the code the line number 37 belongs to

36 | catch (Exception e) {
37 |			messageContext.getErrorMessage().setContent(
					"Stack: " + ExceptionUtils.getStackTrace(e));

so i think after catching the exception, when it tries to fetch

messageContext.getErrorMessage()

I think null is returned.

Not applicable

Sorry @sarthak,

By mistake while zipping i have attached wrong source code. Attaching the correct source code , Sorry for the inconvenience caused.

Even in this source code you have additional Apigee classes. Please remove that and bundle only the CityLookup class.

You are using ExceptionUtils from apache commons. I am not sure if that is available or you have to package it along with your code. It might be the later , please check there.

Also the policy needs to be attached on the Response side and not on request side. I just used your code and it works perfectly if I put it on Response but throws the same error if used on Request side.

Hi @sarthak,

Yipeeee, Thanks a lot, yes Its working when given it as response , only one question , whihc should be better to keep it in the preflow or postflow , as i have configured api as "No-Target" proxy.

Well , I don't think there is any difference, atleast for now for you. Pre Flow and Post Flow constructs becomes important after you have multiple policies and you are trying to better manage and organize those.