-
Notifications
You must be signed in to change notification settings - Fork 1
WebService
Diwischek edited this page Dec 2, 2018
·
2 revisions
An example on how to add elastic objects as a service is in the Github repository eo-springboot.
The core of elasticobject are the configurations which should be initialized only once. One could do this in a static way as used it in the tests, since there should be at least depencencies as possible.
In an application environment one can just inject the configurations as a singelton. I've started a demo application with an endpoint eo receiving serialized objects:
@Value("${elasticobjects.scope:QS}")
private String scope;
@Autowired
private EOConfigsCache cache;
....
@RequestMapping(value = "/eo", method = RequestMethod.POST)
public String adapterPost(
@RequestParam(value = "eo", required = false) String eoAsString,
@RequestParam(value = "logLevel", required = false) String logLevelAsString
) {
if (eoAsString == null) {
return "No 'eo' is set!";
}
if (eoAsString.isEmpty()) {
return "'eo' is empty!";
}
String[] roles = getRoles(); // default value {"guest"}
LogLevel logLevel = getLevel(logLevelAsString); // default WARN
try {
final EORoot eo = (EORoot) new EOBuilder(configsCache)
.setLogLevel(logLevel)
.map(eoAsString);
eo.setRoles(Arrays.asList(roles)); // roles are seet by application
eo.executeCalls();
final String result = new EOToJSON()
.setStartIndent(1)
.setSerializationType(JSONSerializationType.EO)
.toJSON(eo);
return result;
} catch (Exception e) {
return "Exception occured! " + e.getMessage();
}
}
With this we have an generic endpoint, where requests like the following would be executed.
{
"_calls": [
{
"execute": "ScsCall.read(source.csv)"
}
]
}