io.baltoro.ep.CloudServer Maven / Gradle / Ivy
package io.baltoro.ep;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Logger;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.jackson.JacksonFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.baltoro.client.Baltoro;
import io.baltoro.client.CSRequestFilter;
import io.baltoro.client.CSResponseFilter;
import io.baltoro.client.UserSession;
import io.baltoro.client.util.ObjectUtil;
import io.baltoro.client.util.StringUtil;
import io.baltoro.to.APIError;
public class CloudServer
{
static ExecutorService executor = Executors.newWorkStealingPool();
static Logger log = Logger.getLogger(CloudServer.class.getName());
static ObjectMapper mapper = new ObjectMapper();
Client client;
static Map appMap = new HashMap<>();
String appName;
boolean online = false;
public CloudServer(String appName, UserSession session)
{
this.appName = appName;
CSResponseFilter responseFilter = new CSResponseFilter(appName, session);
CSRequestFilter requestFilter = new CSRequestFilter(appName, session);
client = appMap.get(appName);
if(client == null)
{
client = ClientBuilder.newBuilder()
.register(JacksonFeature.class)
.register(requestFilter)
.register(responseFilter)
.build();
appMap.put(appName, client);
}
}
Builder getIB(WebTarget target)
{
Invocation.Builder ib = target.request(MediaType.APPLICATION_JSON_TYPE);
return ib;
}
/*
public T execute(String path, EPData data, Class returnType, Class> returnSubType)
{
WebTarget target = client.target(Baltoro.getServerUrl()).path(path);
log.info("url --> "+target);
Form form = new Form();
List