I am using Java Callout policy where i am intending to populate the Java POJO objects using Jackson databinding based on the JSON service callout response.
I have noticed that as soon as i import Jackson ObjectMapper dependency as follows :
import com.fasterxml.jackson.databind.ObjectMapper
I start getting following error while deployment :
The revision is deployed, but traffic cannot flow. Failed to instantiate the JavaCallout Class apigee.test.TestJavaProject
I have added the required jackson dependency jars & the Java code works perfectly fine in Eclipse in standalone mode.
Following are my dependency jars :
The ObjectMapper class is part of jackson-databind-2.6.3.jar.
Can you please help me fix this issue ?
We are using OPDK. In system.log i am seeing following exception :
Caused by: java.lang.Error: Unresolved compilation problem: The import com.fasterxml cannot be resolved at apigee.test.TestJavaProject.<init>(TestJavaProject.java:15) ~[na:na] ... 38 common frames omitted
But as you can see above all jackson related Jars are added.
@Dino, @Mukundha Madhavan, @Floyd Jones Can you please help here ?
@Swapnil Raverkar can you pls add all jackson-* dependencies to your TestJavaCallout jar. Alternatively you should consider Resource files. Without this Edge will always fail to resolve jackson classes.
I tried both ways. Adding Resource files was my first try. You can see the screenshot in the post.
I also tried to add all jackson-* jars into main jar. And then use only the main jar.
Now i am getting this error :
Caused by: java.lang.ClassCastException: apigee.test.TestJavaProject cannot be cast to com.apigee.flow.execution.spi.Execution at com.apigee.steps.javacallout.JavaCalloutStepDefinition.createNewInstance(JavaCalloutStepDefinition.java:96) ~[javacallout-1.0.0.jar:na] at com.apigee.steps.javacallout.JavaCalloutStepDefinition.newInstance(JavaCalloutStepDefinition.java:67) ~[javacallout-1.0.0.jar:na] ... 32 common frames omitted
Is there any issue with using jackson libraries in Java callout ?
@Swapnil Raverkar this exception suggests your class, TestJavaProject, does not implement com.apigee.flow.execution.spi.Execution. pls check guidelines to execute your Java code through a JavaCallout policy.
Here is the snippet :
package apigee.test; import java.io.IOException; import java.lang.reflect.Method; import java.util.List; import com.test.api.claims.pojos.Claim; import com.test.api.claims.pojos.Claims; import com.test.api.claims.pojos.Metadata; import com.test.api.claims.pojos.Page; 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; import com.fasterxml.jackson.databind.ObjectMapper; public class TestJavaProject implements Execution { @Override public ExecutionResult execute(MessageContext messageContext, ExecutionContext arg1) { // String wgsResponse = messageContext.getVariable("WGSCalloutResponse.content"); // Populate ClaimsSummary object from JSON response // Read JSON and populate java objects /*ObjectMapper mapper = new ObjectMapper(); try { Claims claimsSummary = ((Claims) mapper.readValue(wgsResponse, Claims.class)); } catch (JsonParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ messageContext.setVariable("respString", "Test Response String"); return ExecutionResult.SUCCESS; }
I see you're not using jackson libraries in your code so I'm guesing this is most likely resource file issue. Can you please confirm that both expression-1.0.0.jar & message-flow-1.0.0.jar are not part of your JAR/resource folder. Have a look here too
@Swapnil Raverkar is everything working out for you?
Can you please help here?
Hi All
I am getting Exception when when trying to deserialize and object.
{"code":"ExecutionError","message":"Failed to execute JavaCallout. com/auth0/jwt/internal/com/fasterxml/jackson/databind/ObjectMapper {\"errorcode\":\"steps.javacallout.ExecutionError\"}","source":"apigeePolicy","sourceName":"apigeePolicy"}
My Code Snippet is following:-
import com.auth0.jwt.internal.com.fasterxml.jackson.databind.DeserializationFeature;import com.auth0.jwt.internal.com.fasterxml.jackson.databind.ObjectMapper;
System.out.println("*****************************************************************************");System.out.println("Input Base64 Data:: \n" + data);System.out.println("*****************************************************************************");byte[] dataArray = Base64.decodeBase64(data);String s = new String(dataArray);s = s.replace("\n", "").replace("\\", "");System.out.println("*****************************************************************************");System.out.println("Data to be signed:: \n" + s);System.out.println("*****************************************************************************");String singedData = SigningUtil.signData(s,"11");ObjectMapper mapper = new ObjectMapper();mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);Response res = mapper.readValue(s, Response.class);
Is it fine to use Object mapper inside Apigee Jar, Above code works fine when run locally on mac.
Regards,
Nishant
User | Count |
---|---|
7 | |
2 | |
2 | |
1 | |
1 |