2017-07-05 18:42:04 +02:00
|
|
|
package org.gcube.spatial.data.sdi.rest;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
2018-05-18 17:50:51 +02:00
|
|
|
import javax.ws.rs.Consumes;
|
2017-07-05 18:42:04 +02:00
|
|
|
import javax.ws.rs.GET;
|
2017-08-03 12:43:53 +02:00
|
|
|
import javax.ws.rs.POST;
|
2017-07-05 18:42:04 +02:00
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
import javax.ws.rs.Produces;
|
2018-05-18 17:50:51 +02:00
|
|
|
import javax.ws.rs.QueryParam;
|
2017-07-05 18:42:04 +02:00
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.smartgears.annotations.ManagedBy;
|
2018-05-18 17:50:51 +02:00
|
|
|
import org.gcube.spatial.data.sdi.NetUtils;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.SDIServiceManager;
|
2017-07-05 18:42:04 +02:00
|
|
|
import org.gcube.spatial.data.sdi.engine.SDIManager;
|
|
|
|
import org.gcube.spatial.data.sdi.model.ServiceConstants;
|
|
|
|
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
|
2018-05-18 17:50:51 +02:00
|
|
|
import org.gcube.spatial.data.sdi.model.service.GeoServerDescriptor;
|
2017-08-03 12:43:53 +02:00
|
|
|
import org.gcube.spatial.data.sdi.model.services.GeoServerDefinition;
|
2018-05-18 17:50:51 +02:00
|
|
|
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition.Type;
|
2017-07-05 18:42:04 +02:00
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
|
|
import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
|
|
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
@Path(ServiceConstants.GeoServer.INTERFACE)
|
|
|
|
@Api(value=ServiceConstants.GeoServer.INTERFACE)
|
|
|
|
@Slf4j
|
2017-08-03 12:43:53 +02:00
|
|
|
@ManagedBy(SDIServiceManager.class)
|
2017-07-05 18:42:04 +02:00
|
|
|
public class GeoServer {
|
|
|
|
|
|
|
|
private final static String HOST_PATH_PARAM="host";
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
private SDIManager sdi;
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@Path("configuration/{"+HOST_PATH_PARAM+"}")
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })
|
2018-05-18 17:50:51 +02:00
|
|
|
public GeoServerDescriptor getInstanceConfiguration(@PathParam(HOST_PATH_PARAM) String host){
|
2017-07-05 18:42:04 +02:00
|
|
|
try{
|
|
|
|
log.trace("Serving credentials for host {} ",host);
|
2018-05-18 17:50:51 +02:00
|
|
|
host=NetUtils.getHost(host);
|
|
|
|
|
|
|
|
return sdi.getGeoServerManager().getDescriptorByHostname(host);
|
|
|
|
|
2017-07-05 18:42:04 +02:00
|
|
|
}catch(WebApplicationException e){
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-07-05 18:42:04 +02:00
|
|
|
throw e;
|
|
|
|
}catch(Exception e){
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-07-05 18:42:04 +02:00
|
|
|
throw new WebApplicationException("Unable to serve request", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@Path("credentials/{"+HOST_PATH_PARAM+"}")
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })
|
|
|
|
public Credentials getInstanceCredentials(@PathParam(HOST_PATH_PARAM) String host){
|
|
|
|
try{
|
|
|
|
log.trace("Serving credentials for host {} ",host);
|
2018-05-18 17:50:51 +02:00
|
|
|
host=NetUtils.getHost(host);
|
|
|
|
return sdi.getGeoServerManager().getDescriptorByHostname(host).getAccessibleCredentials().get(0);
|
2017-07-05 18:42:04 +02:00
|
|
|
}catch(WebApplicationException e){
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-07-05 18:42:04 +02:00
|
|
|
throw e;
|
|
|
|
}catch(Exception e){
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-07-05 18:42:04 +02:00
|
|
|
throw new WebApplicationException("Unable to serve request", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 12:43:53 +02:00
|
|
|
@POST
|
2018-05-18 17:50:51 +02:00
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
2017-08-03 12:43:53 +02:00
|
|
|
@Produces(MediaType.APPLICATION_XML)
|
|
|
|
public String register(GeoServerDefinition toRegister) {
|
|
|
|
try {
|
|
|
|
return sdi.registerService(toRegister);
|
|
|
|
}catch(WebApplicationException e) {
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-08-03 12:43:53 +02:00
|
|
|
throw e;
|
|
|
|
}catch(Exception e) {
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2017-08-03 12:43:53 +02:00
|
|
|
throw new WebApplicationException("Unable to serve request",e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:50:51 +02:00
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("import/{"+HOST_PATH_PARAM+"}")
|
|
|
|
@Produces(MediaType.APPLICATION_XML)
|
|
|
|
public String importFromScope(@QueryParam("sourceToken") String sourceToken,@PathParam(HOST_PATH_PARAM) String host) {
|
|
|
|
try {
|
|
|
|
return sdi.importService(sourceToken, host, Type.GEOSERVER);
|
|
|
|
}catch(WebApplicationException e) {
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2018-05-18 17:50:51 +02:00
|
|
|
throw e;
|
|
|
|
}catch(Exception e) {
|
2019-11-20 18:00:05 +01:00
|
|
|
log.warn("Unable to serve request",e);
|
2018-05-18 17:50:51 +02:00
|
|
|
throw new WebApplicationException("Unable to serve request",e);
|
2017-07-05 18:42:04 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-18 17:50:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-05 18:42:04 +02:00
|
|
|
}
|