eu.unicore.services.restclient.RegistryClient Maven / Gradle / Ivy
The newest version!
package eu.unicore.services.restclient;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.json.JSONArray;
import org.json.JSONObject;
import eu.unicore.util.httpclient.IClientConfiguration;
/**
* access to the Registry
*
* @author schuller
*/
public class RegistryClient extends BaseClient {
public RegistryClient(String url, IClientConfiguration security) {
this(url, security, null);
}
public RegistryClient(String url, IClientConfiguration security, IAuthCallback authCallback) {
super(url, security, authCallback);
}
/**
* Add an entry. Reply is the "lifetime" of the entry in seconds,
* ie. the time the entry will be retained.
*
* @param content
* @return lifetime in seconds
* @throws Exception
*/
public long addEntry(Mapcontent) throws Exception {
try(ClassicHttpResponse response = post(asJSON(content))){
return Long.parseLong(response.getHeaders("X-UNICORE-Lifetime")[0].getValue());
}catch(Exception ex) {
return -1;
}
}
public List listEntries() throws Exception {
return listEntries(null);
}
public List listEntries(String serviceType) throws Exception {
JSONObject props = getJSON();
Listresult = new ArrayList<>();
JSONArray entries = props.getJSONArray("entries");
for(int i=0; i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy