com.ecwid.consul.v1.session.SessionConsulClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of consul-api Show documentation
Show all versions of consul-api Show documentation
Java client for Consul HTTP API (http://consul.io)
package com.ecwid.consul.v1.session;
import com.ecwid.consul.ConsulException;
import com.ecwid.consul.json.GsonFactory;
import com.ecwid.consul.v1.OperationException;
import com.ecwid.consul.transport.RawResponse;
import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.session.model.NewSession;
import com.ecwid.consul.v1.session.model.Session;
import com.google.gson.reflect.TypeToken;
import java.util.List;
import java.util.Map;
/**
* @author Vasily Vasilkov ([email protected])
*/
public final class SessionConsulClient implements SessionClient {
private final ConsulRawClient rawClient;
public SessionConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
public SessionConsulClient() {
this(new ConsulRawClient());
}
public SessionConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
public SessionConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
@Override
public Response sessionCreate(NewSession newSession, QueryParams queryParams) {
String json = GsonFactory.getGson().toJson(newSession);
RawResponse rawResponse = rawClient.makePutRequest("/v1/session/create", json, queryParams);
if (rawResponse.getStatusCode() == 200) {
Map value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken
© 2015 - 2024 Weber Informatics LLC | Privacy Policy