added help as URI to ErrorReport
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@173749 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
48d51f61ac
commit
437c706cc1
|
@ -1,13 +1,78 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.datatransfer.resolver.Constants;
|
||||
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.MODE;
|
||||
import org.gcube.datatransfer.resolver.GeonetworkRequestFilterParameters.VISIBILITY;
|
||||
import org.gcube.datatransfer.resolver.services.exceptions.BadRequestException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path(Constants.SERVLET_GEONETWORK)
|
||||
public class GisResolver {
|
||||
|
||||
public void resolveGeoserver() {
|
||||
private static Logger logger = LoggerFactory.getLogger(GisResolver.class);
|
||||
|
||||
private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#GIS_Resolver";
|
||||
|
||||
@GET
|
||||
public void submitGet(@Context HttpServletRequest req, @PathParam("mode") MODE mode, @PathParam("scope") String scope, @PathParam("visibility") VISIBILITY visibility, @PathParam("owner") String owner) {
|
||||
|
||||
// MODE mode = null;
|
||||
// String theScope = null;
|
||||
// VISIBILITY visibility = null;
|
||||
// String owner = null;
|
||||
|
||||
|
||||
//Checking mandatory parameter id
|
||||
if(mode==null){
|
||||
logger.error("Path Parameter 'mode' not found");
|
||||
try {
|
||||
throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
if(scope==null || scope.isEmpty()){
|
||||
logger.error("Path Parameter 'scope' not found");
|
||||
try {
|
||||
throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(visibility==null){
|
||||
logger.error("Path Parameter 'visibility' not found");
|
||||
try {
|
||||
throw new BadRequestException(req, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter MODE", StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@POST
|
||||
public void submitPost(){
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
*/
|
||||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -45,7 +48,12 @@ public class SMPIDResolver {
|
|||
//Checking mandatory parameter smpId
|
||||
if(smpId==null || smpId.isEmpty()){
|
||||
logger.error(SMP_ID+" not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_ID, SMPIDResolver.class, new URI("https://wiki.gcube-system.org/gcube/URI_Resolver#SMP-ID_Resolver"));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
return StorageManager.resolveStorageId(httpRequest, smpId, fileName, contentType, validation);
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
*/
|
||||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -46,7 +49,12 @@ public class SMPResolver {
|
|||
//Checking mandatory parameter smpURI
|
||||
if(smpURI==null || smpURI.isEmpty()){
|
||||
logger.error(SMP_URI+" not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_URI, SMPResolver.class);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter "+SMP_URI, SMPResolver.class, new URI("https://wiki.gcube-system.org/gcube/URI_Resolver#SMP_Resolver"));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
return StorageManager.resolveStorageId(httpRequest, smpURI, fileName, contentType, validation);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -25,6 +28,8 @@ public class StorageHub {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageHub.class);
|
||||
|
||||
private String help = "https://wiki.gcube-system.org/gcube/URI_Resolver";
|
||||
|
||||
@RequestScoped
|
||||
@PathParam(STORAGE_HUB_ID)
|
||||
String id;
|
||||
|
@ -37,7 +42,12 @@ public class StorageHub {
|
|||
//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);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
StreamDescriptor descriptor = shc.open(id).asFile().download();
|
||||
|
@ -55,13 +65,23 @@ public class StorageHub {
|
|||
//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);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_HUB_ID, StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory parameter 'version'", StorageHub.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
StreamDescriptor descriptor = shc.open(id).asFile().downloadSpecificVersion(version);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.gcube.datatransfer.resolver.services;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -45,6 +47,8 @@ public class StorageManager {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageManager.class);
|
||||
|
||||
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
||||
|
||||
|
||||
/**
|
||||
* Gets the storage id.
|
||||
|
@ -63,7 +67,12 @@ public class StorageManager {
|
|||
//Checking mandatory parameter storageId
|
||||
if(storageId==null || storageId.isEmpty()){
|
||||
logger.error(STORAGE_ID+" not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
return resolveStorageId(httpRequest, storageId, fileName, contentType, validation);
|
||||
}
|
||||
|
@ -86,7 +95,12 @@ public class StorageManager {
|
|||
//Checking mandatory parameter storageId
|
||||
if (storageId == null || storageId.isEmpty()) {
|
||||
logger.warn("storageId not found");
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class);
|
||||
try {
|
||||
throw new BadRequestException(httpRequest, Status.NOT_ACCEPTABLE, "Missing mandatory path parameter "+STORAGE_ID, StorageManager.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -104,12 +118,22 @@ public class StorageManager {
|
|||
logger.info("Decoded ID"+" = "+ toSEID);
|
||||
}catch(Exception e){
|
||||
logger.error("Storage Client Exception when getting file from storage: ", e);
|
||||
throw new InternalServerException(httpRequest, Status.INTERNAL_SERVER_ERROR, "Storage Client Exception when getting file from storage with id: "+storageId, StorageManager.class);
|
||||
try {
|
||||
throw new InternalServerException(httpRequest, Status.INTERNAL_SERVER_ERROR, "Storage Client Exception when getting file from storage with id: "+storageId, StorageManager.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e1) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
if(toSEID==null || toSEID.isEmpty()){
|
||||
logger.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||
throw new WrongParameterException(httpRequest, Status.BAD_REQUEST, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageManager.class);
|
||||
try {
|
||||
throw new WrongParameterException(httpRequest, Status.BAD_REQUEST, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageManager.class, new URI(help));
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
//silent
|
||||
}
|
||||
}
|
||||
|
||||
long size = iClient.getSize().RFileById(toSEID);
|
||||
|
|
|
@ -11,6 +11,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
|
||||
@XmlRootElement(name="error")
|
||||
|
@ -18,6 +19,7 @@ import lombok.Setter;
|
|||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ErrorReport implements Serializable{
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package org.gcube.datatransfer.resolver.services.error;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
@ -11,6 +12,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Builder;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -23,6 +25,7 @@ import lombok.Setter;
|
|||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ExceptionReport implements Serializable{
|
||||
|
||||
/**
|
||||
|
@ -33,5 +36,6 @@ public class ExceptionReport implements Serializable{
|
|||
String request;
|
||||
String method;
|
||||
boolean success;
|
||||
URI help;
|
||||
ErrorReport error;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
package org.gcube.datatransfer.resolver.services.exceptions;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -29,6 +31,7 @@ public class BadParameterException extends WebApplicationException {
|
|||
*/
|
||||
private static final long serialVersionUID = -7600028435121268528L;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new bad parameter exception.
|
||||
*
|
||||
|
@ -37,8 +40,23 @@ public class BadParameterException extends WebApplicationException {
|
|||
* @param message the message
|
||||
* @param reportedBySource the reported by source
|
||||
*/
|
||||
public BadParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) {
|
||||
super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build());
|
||||
public BadParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) {
|
||||
|
||||
super(Response.status(httpReturnStatus).entity(
|
||||
ExceptionReport.builder().
|
||||
request(Util.getFullURL(request)).
|
||||
method(request.getMethod()).
|
||||
success(false).
|
||||
help(help).
|
||||
error(
|
||||
ErrorReport.builder().
|
||||
httpErrorCode(Status.BAD_REQUEST.getStatusCode()).
|
||||
name(Status.BAD_REQUEST.name())
|
||||
.message(message).
|
||||
reportedBy(reportedBySource.getName()).build())
|
||||
.build())
|
||||
.type(MediaType.APPLICATION_XML).build());
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
package org.gcube.datatransfer.resolver.services.exceptions;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -37,8 +39,21 @@ public class BadRequestException extends WebApplicationException {
|
|||
* @param message the message
|
||||
* @param reportedBySource the reported by source
|
||||
*/
|
||||
public BadRequestException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) {
|
||||
super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build());
|
||||
public BadRequestException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) {
|
||||
super(Response.status(httpReturnStatus).entity(
|
||||
ExceptionReport.builder().
|
||||
request(Util.getFullURL(request)).
|
||||
method(request.getMethod()).
|
||||
success(false).
|
||||
help(help).
|
||||
error(
|
||||
ErrorReport.builder().
|
||||
httpErrorCode(Status.BAD_REQUEST.getStatusCode()).
|
||||
name(Status.BAD_REQUEST.name())
|
||||
.message(message).
|
||||
reportedBy(reportedBySource.getName()).build())
|
||||
.build())
|
||||
.type(MediaType.APPLICATION_XML).build());
|
||||
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
package org.gcube.datatransfer.resolver.services.exceptions;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.InternalServerErrorException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -37,8 +39,21 @@ public class InternalServerException extends InternalServerErrorException {
|
|||
* @param message the message
|
||||
* @param reportedBySource the reported by source
|
||||
*/
|
||||
public InternalServerException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) {
|
||||
super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.INTERNAL_SERVER_ERROR.getStatusCode(), Status.INTERNAL_SERVER_ERROR.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build());
|
||||
public InternalServerException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) {
|
||||
super(Response.status(httpReturnStatus).entity(
|
||||
ExceptionReport.builder().
|
||||
request(Util.getFullURL(request)).
|
||||
method(request.getMethod()).
|
||||
success(false).
|
||||
help(help).
|
||||
error(
|
||||
ErrorReport.builder().
|
||||
httpErrorCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).
|
||||
name(Status.INTERNAL_SERVER_ERROR.name())
|
||||
.message(message).
|
||||
reportedBy(reportedBySource.getName()).build())
|
||||
.build())
|
||||
.type(MediaType.APPLICATION_XML).build());
|
||||
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
package org.gcube.datatransfer.resolver.services.exceptions;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -38,8 +40,21 @@ public class WrongParameterException extends WebApplicationException {
|
|||
* @param message the message
|
||||
* @param reportedBySource the reported by source
|
||||
*/
|
||||
public WrongParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource) {
|
||||
super(Response.status(httpReturnStatus).entity(new ExceptionReport(Util.getFullURL(request), request.getMethod(), false, new ErrorReport(Status.BAD_REQUEST.getStatusCode(), Status.BAD_REQUEST.name(), message, reportedBySource.getName()))).type(MediaType.APPLICATION_XML).build());
|
||||
public WrongParameterException(HttpServletRequest request, Status httpReturnStatus, String message, Class reportedBySource, URI help) {
|
||||
super(Response.status(httpReturnStatus).entity(
|
||||
ExceptionReport.builder().
|
||||
request(Util.getFullURL(request)).
|
||||
method(request.getMethod()).
|
||||
success(false).
|
||||
help(help).
|
||||
error(
|
||||
ErrorReport.builder().
|
||||
httpErrorCode(Status.BAD_REQUEST.getStatusCode()).
|
||||
name(Status.BAD_REQUEST.name())
|
||||
.message(message).
|
||||
reportedBy(reportedBySource.getName()).build())
|
||||
.build())
|
||||
.type(MediaType.APPLICATION_XML).build());
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue