Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Java Callout access to File Resources

Hello dear comunity,

I would like to have access to a Resource File from Java (using the JavaCallout).

The basic idea is to be able to read the JSON File that is saved as part of the proxy.

{ 
"node1": "value1",
"node2": "value2"
}

This file is provided by the clients, and we should use some of the information included on it, for example read the "node1" value, in case the Call Path in the url contains "node1".

Some other idea I had, was to pass the content of the file (maybe JSON Stringify?) as a Property to the Java Callout, but I haven´t been able to use the "ressourceURL" syntax here:

<Properties>
	<Property name="nodeValue">jsc://my-javascript.js</Property>
</Properties>

But sadly, this just passes the value string "jsc://my-javascript.js"

Does anybody knows how can we achieve this?

Thank you very much.

Oscar

Solved Solved
3 7 761
1 ACCEPTED SOLUTION

How complicated is the JSON? How large? If it is 3 or 4 properties, why not just use what you described?

<Properties>
	<Property name="nodeValue">{ 
  "node1": "value1",
  "node2": "value2"
}</Property>
</Properties>

And then in the Java callout, use Gson or Jackson or whatever to deserialize the JSON string.

String jsonString = properties.get("nodeValue");
// deserialize json here

And if that's not appropriate, thebn you could just reference it in a variable

<Properties>
	<Property name="variable">context-variable</Property>
</Properties>

And in this case the Java callout would perform

String jsonString = messageContext.getVariable(properties.get("variable"));
// deserialize json here

View solution in original post

7 REPLIES 7