Custom java callout with jar dependencies

Hi community,

We are building some java callout, and this callout have jar dependencies.

In regular java case we would put them to 'lib' folder and load them to main class.

Is this possible in Apigee platform?

Some one asked already, but we didn't undestand if this possible: https://community.apigee.com/comments/51171/view.html

What we currently did is we uploaded all dependencies to same policy shared files:

--mainjar.jar

---dep1.jar

---dep2.jar

---dep3.jar

...

But in the policy it looks not 'clean'

We want to include dep1-dep3 to mainjar.jar and have only one file in the shared resources file.

Some1 did such thing?

Thanks;

-D

0 4 1,011
4 REPLIES 4

Put all the required JARs in the /java directory (folder) of your API Proxy.

Example:

https://github.com/DinoChiesa/ApigeeEdge-Java-XMLDSIG/tree/master/bundle/apiproxy/resources/java

Specify the main Jar as the ResourceURL in the JavaCallout policy.

<JavaCallout name='Java-XMLDSIG-Sign'>
  <Properties>
    <Property name='source'>message.content</Property>
    <Property name='output-variable'>output</Property>
    <Property name='private-key'>{my_private_key}</Property>
    <Property name='private-key-password'>{my_private_key_password}</Property>
  </Properties>
  <ClassName>com.google.apigee.edgecallouts.xmldsig.Sign</ClassName>
  <ResourceURL>java://edge-xmldsig-1.0.1.jar</ResourceURL>
</JavaCallout>

https://github.com/DinoChiesa/ApigeeEdge-Java-XMLDSIG/blob/master/bundle/apiproxy/policies/Java-XMLD...

Hi Dino, this is what we don't want to achive, because it will create in the policy in the UI many jars that we don't want to see.

7429-mq-jars.png

We want only ONE jar with other JARS inside (dependencies internally in the main JAR), but not outside. Is this possible in Apigee?

OK I have two kinds of information for you.

1. regarding packaging of JARs. You have some options.

1a. You can attach JARs to the API Proxy, as a resource. You can also upload JARs to the environment or even the organization, as a resource. If you use env or org-scoped JARs, they do not show up in the API Proxy display in the UI, but the runtime will scan these JARs for dependencies. To attach them to the env or org, you must use the Administrartive API. There is no UI support for uploading a JAR as an environment or org-scoped resource.

1b. You are free to repackage all your dependencies into one giant JAR. I believe this is a bad idea but it is feasible in general.

2. I don't think the mqclient JAR will work within a Java callout hosted in Apigee Edge. There are some restrictions regarding the permissions on loaded JARs. Check the doc on Java callout and permissions. I believe this has been tried before, and it did not work.

If you want to connect to MQ, you may need to:

- use the HTTP listener

- or package your connection into a service (run it in GAE?) and call out to that service.

Good luck!

Hi Dino, thanks,

This version of MQ does not have any rest over http (8.0) and REST came out only from 9.0. I will check your suggestions. Thanks,