JSON string format in Java call out property

Not applicable

In my Java call out properties, I would like to build a string with also contains JSON data which will be filled at runtime from variables. If we have to include "{" in the property how can we do that.

I know we can use Assign message with payload, is there any other options. Below is the code i am looking to achive Below is the string concatenation which I would like to achieve,

POSThttps://{test.host}{test.path}+ '{ "grant_type": "password", "client_id": "' + {test.client_id} + '", "username": "' + {test.id}+ '", "password": "' + {test.password} + '" }'

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JavaCallout async="false" continueOnError="false" enabled="true" name="JC-Get-OAuth-HMAC"> <DisplayName>JC - Get OAuth HMAC</DisplayName> <Properties> <!-- name of the variable that holds the key //{verifyapikey.verify-api-key.client_secret}--> <Property name="key">{oauth_key}</Property> <Property name="algorithm">SHA-512</Property> <Property name="string-to-sign">{POSThttps://{test.host}{test.path}+ '{ "grant_type": "password", "client_id": "' + {test.client_id} + '", "username": "' + {test.id}+ '", "password": "' + {test.password} + '" }'}</Property> <Property name="debug">true</Property> </Properties> <FaultRules> <FaultRule name="rule1"> <Step> <Name>RF-invalid-hmac</Name> </Step> <Condition>hmac.error != null</Condition> </FaultRule> </FaultRules> <ClassName>com.apigee.callout.hmac.HmacCreatorCallout</ClassName> <ResourceURL>java://hmac-edge-callout1.jar</ResourceURL> </JavaCallout>

0 3 296
3 REPLIES 3

Not applicable

Hello @Pradeep Ande,

Alternatively, you can also create the request string in Javascript. Have you explored this option ?

You can use use the java script or python to prepare the request string and store the value in variable and use that variable here.

Not applicable

Thank you Deepak,

I am trying to avoid Java script just for string concatenation. I am able to concatenate the string in property for most part except for the JSON. I am getting additional $ before the JSON string. trying to get rid of it. everything else works as expected.