added exception to StorageHub Resolver and refactor
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173745 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e1f9cfb330
commit
6a6045dd2b
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datatransfer.resolver.services;
|
||||
package org.gcube.datatransfer.resolver;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
@ -5,7 +5,7 @@ import javax.ws.rs.Path;
|
|||
import org.gcube.datatransfer.resolver.Constants;
|
||||
|
||||
@Path(Constants.SERVLET_GEONETWORK)
|
||||
public class GeoServer {
|
||||
public class GisResolver {
|
||||
|
||||
public void resolveGeoserver() {
|
||||
|
|
@ -1,36 +1,69 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path("shub/{id}")
|
||||
public class StorageHub {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String STORAGE_HUB_ID = "id";
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageHub.class);
|
||||
|
||||
@RequestScoped
|
||||
@PathParam("id")
|
||||
@PathParam(STORAGE_HUB_ID)
|
||||
String id;
|
||||
|
||||
@GET
|
||||
@Path("")
|
||||
public Response download() {
|
||||
public Response download(@Context HttpServletRequest httpRequest) {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
//Checking mandatory parameter id
|
||||
if(id==null || id.isEmpty()){
|
||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class);
|
||||
}
|
||||
|
||||
StreamDescriptor descriptor = shc.open(id).asFile().download();
|
||||
|
||||
|
||||
return Response
|
||||
.ok(descriptor.getStream())
|
||||
.header("content-disposition","attachment; filename = \""+descriptor.getFileName()+"\"").build();
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{version}")
|
||||
public Response downloadVersion(@PathParam("version") String version) {
|
||||
public Response downloadVersion(@Context HttpServletRequest httpRequest, @PathParam("version") String version) {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
//Checking mandatory parameter id
|
||||
if(id==null || id.isEmpty()){
|
||||
logger.error("Path Parameter "+STORAGE_HUB_ID+" not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class);
|
||||
}
|
||||
|
||||
//Checking mandatory parameter id
|
||||
if(version==null || version.isEmpty()){
|
||||
logger.error("Parameter 'version' not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter 'version'", StorageHub.class);
|
||||
}
|
||||
|
||||
StreamDescriptor descriptor = shc.open(id).asFile().downloadSpecificVersion(version);
|
||||
return Response
|
||||
.ok(descriptor.getStream())
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.Util;
|
||||
import org.gcube.datatransfer.resolver.Util;
|
||||
import org.gcube.datatransfer.resolver.services.error.ErrorReport;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionReport;
|
||||
;
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.Util;
|
||||
import org.gcube.datatransfer.resolver.Util;
|
||||
import org.gcube.datatransfer.resolver.services.error.ErrorReport;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionReport;
|
||||
;
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.Util;
|
||||
import org.gcube.datatransfer.resolver.Util;
|
||||
import org.gcube.datatransfer.resolver.services.error.ErrorReport;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionReport;
|
||||
;
|
||||
|
|
|
@ -10,7 +10,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.Util;
|
||||
import org.gcube.datatransfer.resolver.Util;
|
||||
import org.gcube.datatransfer.resolver.services.error.ErrorReport;
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionReport;
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue