Can we use JavaCallout with Spring?

Not applicable

A client provided us a java logging sdk which we must use to send log messages to their logging server. This sdk has dependencies on Spring and other jar files.

I know that:

1) we can use a Java Callout to call the log methods in the logging class.

2) we need to include all the dependent jars in the resources/java directory.

3) we need to include all the property files in this directory as well

I think that if I initialize the Spring context from the Java Callout, then this initialization will be performed for every request. Is that correct?

Can I perform a static initialization and reuse it on every request and will Apigee honor that static initialization?

public class LogUtil {

public ExecutionResult execute(MessageContext arg0, ExecutionContext arg1) {

testLogging();

}

private String testLogging() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/logging-spring-config.xml"); ServiceLoggerImpl serviceLogger= (ServiceLoggerImpl) applicationContext.getBean("serviceLogger");

...

1 5 654
5 REPLIES 5

Not applicable

i dont have an answer for you - but i just went through a similar journey at my work, and we ended up not using the java callouts because we were terrified about the initialization aspect (ad we understood that the java callout might have limited disk and network access) we ended up tossing the custom logger out too 🙂

Not applicable

Update:

I uploaded all the dependent jars with the following Management API call:

curl -v -u {user}:{password}-H "Content-Type: application/octet-stream" \-X POST --data-binary @{jar_file} \"http://{mgmt_server}:{port}/v1/organizations/{org}/environments/{envname}/resourcefiles?name={jar_file}&type=java"

I am able to see all the jars that I uploaded with the corresponding GET call.

curl --insecure -v -u "uname:pw" -X GET http://hostname/v1/organizations/{orgname}/enviro...

There are two problems:

1) I receive NoClassDefFoundError and I know the class is in the jar that I already uploaded. So it seems Apigee cannot find this jar.

2) Event though I uploaded the spring-beans 3.2 jar, Apigee is still using the 3.0.2 jar instead. I thought that if I upload a jar Apigee would use the one I uploaded instead of the existing jar.

14:24:48.731 [Apigee-Main-163] DEBUG MESSAGING.FLOW - Exception

java.lang.NoClassDefFoundError: org/apache/logging/log4j/Level

at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.7.0_71]

at java.lang.Class.privateGetDeclaredMethods(Class.java:2615) ~[na:1.7.0_71]

at java.lang.Class.getDeclaredMethods(Class.java:1860) ~[na:1.7.0_71]

at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:194) ~[spring-beans-3.0.2.RELEASE.jar:3.0.2.RELEASE]

at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:176) ~[spring-beans-3.0.2.RELEASE.jar:3.0.2.RELEASE]

at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:122) ~[spring-beans-

Why can't Apigee find my jar?

Why does it use the existing Spring 3.0.2 jars when I uploaded the spring 3.2 jars?

Dear @seanwilliams,

After you have uploaded the JAR files, you need to restart the Message Processors. This will ensure that Message Processors are able to pick up the newly uploaded dependent JAR files.

Did this work for your custom logging?

No, it did not work. We are getting class path/class loading errors. We have conflicts with the Jars that are already loaded on Apigee's class path. Here is the last error.

Unexpected exception parsing XML document from class path resource [logging-spring-config.xml]; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "javax.xml.parsers.DocumentBuilder.setEntityResolver(Lorg/xml/sax/EntityResolver;)V" the class loader (instance of com/apigee/messaging/resource/JavaResourceClassLoader) of the current class, org/springframework/beans/factory/xml/DefaultDocumentLoader, and the class loader (instance of <bootloader>) for resolved class, javax/xml/parsers/DocumentBuilder, have different Class objects for the type /EntityResolver;)V used in the signature

We removed the jar that was causing the conflict and it still generates an error, but it doesn't provide any additional info. In other words, when I trace in Apigee, it has an exclamation point on the java callout, but it does not display the error. The MP log file also does not contain any helpful errors. I also turned on debugging on the MP and that did not provide any additional info either.