Closed dominik42 closed 7 months ago
Hello, The spark-java REST service was intended to provide the Api to standalone java apps too, that’s why it has jetty and other stuff included. There is currently no other implementation. As Spring Boot provides a great REST support you may implement the four required routes directly in your app to get rid of the sparkjava implementation. Please see https://github.com/microstream-one/microstream/discussions/549 for additional information.
Hi @hg-ms thank you for your fast response. In order to find my own solution later this year :-), I hope it's ok to attach it here. Maybe we find another source/place where we an include my simple but working solution for spring boot, e.g. for documentation purposes.
/**
* disable security by
* AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/microstream/**").permitAll();
*
* @see StorageRestServiceSparkJava.java
*/
@org.springframework.web.bind.annotation.RestController
@RequestMapping(value = "/microstream", produces = "application/json")
public class RestController {
private final StorageRestAdapter storageRestAdapter;
public RestController(StorageManager storageManager) {
this.storageRestAdapter = StorageRestAdapter.New(storageManager);
}
@GetMapping("/root")
public ViewerRootDescription root() {
ViewerRootDescription result = storageRestAdapter.getUserRoot();
return result;
}
@GetMapping("/dictionary")
public String dictionary() {
return storageRestAdapter.getTypeDictionary();
}
@GetMapping("/object/{objectId}")
public ViewerObjectDescription object(@PathVariable("objectId") Long objectId,
@RequestParam(value = "fixedOffset", defaultValue = "0", required = false) long fixedOffset,
@RequestParam(value = "fixedLength", defaultValue = "" + Long.MAX_VALUE, required = false) long fixedLength,
@RequestParam(value = "variableOffset", defaultValue = "0", required = false) long variableOffset,
@RequestParam(value = "variableLength", defaultValue = "" + Long.MAX_VALUE, required = false) long variableLength,
@RequestParam(value = "valueLength", required = false) Long valueLength,
@RequestParam(value = "references", defaultValue = "false", required = false) boolean references) {
// this can't be done within the method parameter declaration
if (valueLength == null) {
valueLength = this.storageRestAdapter.getDefaultValueLength();
}
ViewerObjectDescription result = storageRestAdapter.getObject(objectId, fixedOffset, fixedLength, variableOffset, variableLength, valueLength, references);
return result;
}
@GetMapping("/maintenance/filesStatistics")
public ViewerStorageFileStatistics statistics() {
return storageRestAdapter.getStorageFilesStatistics();
}
}
Thank you very much for publishing your solution here
Environment Details
Describe the bug
I want to use the REST Client GUI in order to introspect the Microstream storage within my Vaadin/SpringBoot App. Prio the necessary changes, the Vaadin App starts sucessfully aand microstream works as expected. Then I follow the docs and start setup the REST API using the default configuration:
1) add dependencies
2) enabling the REST API (BTW: please mention in the docs, that a separate thread is ncessary at least for spring boot apps; without that, the call of service.start() doesn't return)
3) start the spring boot app
Expected behavior
app started successfully, Vaadin UI is shown and the REST API is available for the Client GUI via localhost:4567/microstream
Error
Additional Context
This is the appropriate part of the pom. Please see the version mismatch for jetty components, maybe this is one of the causes of the NoClassDefFoundError: org/eclipse/jetty/server/session/SessionHandler.