Retrieving properties from Java Call out policy

Not applicable

Hi Team

I am using using a Java Call out policy ( CityLookup.jar) and i want to access properties ( key Value) from the Java Callout policy. Here is the cofig in the policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JavaCallout name="cityLookUp"> <Properties> <Property name="prop1">P1</Property> <Property name="prop2">P2</Property> </Properties> <ClassName>com.apigee.CityLookup</ClassName> <ResourceURL>java://CityLookup.jar</ResourceURL> </JavaCallout>

I want to access prop1 and prop2 values in my Java code. What methods do i use for it ? I see that i can use the Message context interface. Can you please sight an example ?

Cheers

Sumeet

0 8 787
8 REPLIES 8

Not applicable

Hi, @Sumeet Chawla . I'm not sure if Java Callout Policy supports properties as part of its declaration. I'm also looking at the XML schema and it doesn't seem to support it. I might be missing a new feature though. Are you looking at any source that indicates that this is the case?

I understand your the use case for setting up the parameters directly from the declaration. However, you can still define any parameters as context variables predefined from an Assign Message policy executed as a previous step. Not as compact as Java Callout properties, but still a workable solution.

Not applicable

Thanks Diego, seems like the version of apigee we have ( 15.0.4) adds the Properties tag by default. Wondering with that does it open the functionality to use these properties in the java code. Not sure though..as per the documentation the schema doesn't cover it.

Hi @Sumeet Chawla,

You can include properties in your java callout policy - it will be passed on to your Javacallout class, if you provide a constructor with a Map argument, for eg, like this,

public class Callout implements Execution{
   public Callout(Map<String, String> props){
	//Map containing properties configured in the policy
   }

  ...
}

you could use to pass on some configuration values to your java object, pls note - the constructor will be invoked only during the deployment

Thanks,

Thanks, @Mukundha Madhavan. This is new to me.

@Floyd Jones - Is this documented anywhere?

Hey @Diego Zuluaga. I don't think we do, so I've created a ticket for it. It'll be similar to what we've just added to the JavaScript policy: http://apigee.com/docs/api-services/reference/javascript-policy.

Thanks, @Floyd Jones.

Thanks @Mukundha Madhavan for the help. My question will be what is the method used to access those properties ? The documents provided actually doesn't cover it. Lemme know if you have the details.

Regards

Sumeet

The Map in the constructor has all the properties as key, value pairs,

you can get, value = map.get(key)