I am trying to use below etcd framework in SparkJava
https://github.com/AdoHe/etcd4j
Code looks like below:
get("/hello",(request, response) -> {
String value;
try {
EtcdClient client = new EtcdClient(URI.create("http://127.0.0.1:2379"));
String key = "/message";
value = client.get(key);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;});
However when i try to access the url as below http://localhost:4567/hello
I get following error
HTTP ERROR: 500
Problem accessing /hello. Reason:
java.lang.NoSuchFieldError: INSTANCE
Powered by Jetty:// 9.3.6.v20151106
What am i missing here? etcd working when used as standalone project with main() function, however not working with SparkJava, Is there any etcd client which works with SparkJava?
I got it to work with the following Etcd client:
<dependency>
<groupId>org.mousio</groupId>
<artifactId>etcd4j</artifactId>
<version>2.12.0</version>
</dependency>
Here's the code:
private static String etcdGet(Request request, Response response) {
EtcdClient client = new EtcdClient(URI.create("http://<ip-address>:2379"));
String key = "/message";
try {
EtcdResponsePromise<EtcdKeysResponse> value;
value = client.get(key).send();
return value.get().getNode().getValue();
} catch (Exception e) {
System.out.println(e);
throw new RuntimeException(e);
}
}