continue to manage the exceptions
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@174891 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
97312b0a47
commit
dd7102e835
|
@ -8,6 +8,7 @@ import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
@ -46,41 +47,51 @@ public class KnimeCreateResolver {
|
||||||
@Path("/create")
|
@Path("/create")
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
@Consumes(MediaType.TEXT_PLAIN)
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response createKnimeURL(@Context HttpServletRequest req) {
|
public Response createKnimeURL(@Context HttpServletRequest req) throws WebApplicationException{
|
||||||
|
|
||||||
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
logger.info(this.getClass().getSimpleName()+" POST starts...");
|
||||||
|
|
||||||
|
try{
|
||||||
|
String contextToken = SecurityTokenProvider.instance.get();
|
||||||
|
String scope = ScopeProvider.instance.get();
|
||||||
|
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
||||||
|
logger.info("ScopeProvider has scope: "+scope);
|
||||||
|
|
||||||
String contextToken = SecurityTokenProvider.instance.get();
|
String appToken = req.getServletContext().getInitParameter(TokenSetter.ROOT_APP_TOKEN);
|
||||||
String scope = ScopeProvider.instance.get();
|
|
||||||
// logger.info("SecurityTokenProvider contextToken: "+contextToken);
|
|
||||||
logger.info("ScopeProvider has scope: "+scope);
|
|
||||||
|
|
||||||
String appToken = req.getServletContext().getInitParameter(TokenSetter.ROOT_APP_TOKEN);
|
if(contextToken.compareTo(appToken)==0){
|
||||||
|
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
||||||
|
throw ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
|
||||||
if(contextToken.compareTo(appToken)==0){
|
ScopeBean scopeBean = new ScopeBean(scope);
|
||||||
logger.error("Token not passed, SecurityTokenProvider contains the root app token: "+appToken.substring(0,10)+"...");
|
|
||||||
ExceptionManager.unauthorizedException(req, "You are not authorized. You must pass a token of VRE", this.getClass(), helpURI);
|
if(scopeBean.is(Type.VRE)){
|
||||||
|
|
||||||
|
String vreName = scopeBean.name();
|
||||||
|
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
||||||
|
String queryString =req.getQueryString()==null?"":req.getQueryString();
|
||||||
|
|
||||||
|
if(req.getQueryString()!=null)
|
||||||
|
knimeGetResolverURL+="?"+queryString;
|
||||||
|
|
||||||
|
logger.info("Returning Knime Resolver URL: "+knimeGetResolverURL);
|
||||||
|
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
|
||||||
|
|
||||||
|
}else{
|
||||||
|
logger.error("The input scope "+scope+" is not a VRE");
|
||||||
|
throw ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
if(!(e instanceof WebApplicationException)){
|
||||||
|
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
String error = "Sorry, an error occurred on creating Knime URL. Please, contact the support!"+"\n Cause: "+e.getCause().getMessage();
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
//ALREADY MANAGED AS WebApplicationException
|
||||||
|
logger.error("Exception:", e);
|
||||||
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeBean scopeBean = new ScopeBean(scope);
|
|
||||||
|
|
||||||
if(scopeBean.is(Type.VRE)){
|
|
||||||
|
|
||||||
String vreName = scopeBean.name();
|
|
||||||
String knimeGetResolverURL = String.format("%s/%s/%s", Util.getServerURL(req), "knime/get", vreName);
|
|
||||||
String queryString =req.getQueryString()==null?"":req.getQueryString();
|
|
||||||
|
|
||||||
if(req.getQueryString()!=null)
|
|
||||||
knimeGetResolverURL+="?"+queryString;
|
|
||||||
|
|
||||||
logger.info("Returning Knime Resolver URL: "+knimeGetResolverURL);
|
|
||||||
return Response.ok(knimeGetResolverURL).header("Location", knimeGetResolverURL).build();
|
|
||||||
|
|
||||||
}else{
|
|
||||||
logger.error("The input scope "+scope+" is not a VRE");
|
|
||||||
ExceptionManager.badRequestException(req, "Working in the "+scope+" scope that is not a VRE. Use a token of VRE", this.getClass(), helpURI);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public class KnimeGetResolver {
|
||||||
try {
|
try {
|
||||||
if(vreName==null || vreName.isEmpty()){
|
if(vreName==null || vreName.isEmpty()){
|
||||||
logger.error("The path parameter 'vreName' not found or empty in the path");
|
logger.error("The path parameter 'vreName' not found or empty in the path");
|
||||||
ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@ -65,7 +66,7 @@ public class KnimeGetResolver {
|
||||||
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
|
reader = new ApplicationProfileReader(fullScope, APPLICATION_PROFILE, ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, false);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
|
logger.error("Error on reading the "+APPLICATION_PROFILE+" with APPID: "+ORG_GCUBE_PORTLETS_USER_KNIMEMODELSIMULATION_MANAGER_SERVICE_IMPL, e);
|
||||||
ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+KNIME_EXECUTOR_APPLICATION+". Please contact the support", this.getClass(), helpURI);
|
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "+KNIME_EXECUTOR_APPLICATION+". Please contact the support", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
//READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
//READ THE KNIME URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE fullScope
|
||||||
|
@ -78,14 +79,19 @@ public class KnimeGetResolver {
|
||||||
|
|
||||||
}catch (ExecutionException e) {
|
}catch (ExecutionException e) {
|
||||||
logger.error("The input VRE Name "+vreName+" not found", e);
|
logger.error("The input VRE Name "+vreName+" not found", e);
|
||||||
ExceptionManager.badRequestException(req, "The input 'VRE Name' "+"+vreName+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req, "The input 'VRE Name' "+"+vreName+"+ "not found on Informatiion System. Is it a valid VRE?", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
}catch (Exception e) {
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Error on resolving Knime URL",e);
|
if(!(e instanceof WebApplicationException)){
|
||||||
ExceptionManager.internalErrorException(req, "Error occurred when resolving Knime URL", this.getClass(), helpURI);
|
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
return null;
|
String error = "Sorry, an error occurred on resolving the Knime URL. Please, contact the support!"+"\n Cause: "+e.getCause().getMessage();
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
//ALREADY MANAGED AS WebApplicationException
|
||||||
|
logger.error("Exception:", e);
|
||||||
|
throw (WebApplicationException) e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,14 @@ public class PartheosRegistryResolver {
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
|
@Path("/{provider}/{path}{remainPath:(/[^?$]+)?}")
|
||||||
public Response resolveParthenosURL(@Context HttpServletRequest req,@PathParam("provider") String provider, @PathParam("path") String path, @PathParam("remainPath") String remainPath) {
|
public Response resolveParthenosURL(@Context HttpServletRequest req,
|
||||||
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
@PathParam("provider") String provider,
|
||||||
|
@PathParam("path") String path,
|
||||||
|
@PathParam("remainPath") String remainPath) throws WebApplicationException {
|
||||||
|
|
||||||
|
logger.info(this.getClass().getSimpleName()+" GET starts...");
|
||||||
String remainPathParthenosURL = null;
|
String remainPathParthenosURL = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
logger.debug("provider is: "+provider);
|
logger.debug("provider is: "+provider);
|
||||||
|
@ -76,10 +80,17 @@ public class PartheosRegistryResolver {
|
||||||
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
|
logger.info("Trying to resolve with Catalogue EntityName: "+normalizedEntityName);
|
||||||
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
|
ItemCatalogueURLs itemCatalogueURLs = CatalogueResolver.getItemCatalogueURLs(UriResolverSmartGearManagerInit.getParthenosVREName(), ResourceCatalogueCodes.CTLGD.getId(), normalizedEntityName);
|
||||||
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateCataloguePortletURL()).toURI()).build();
|
return Response.seeOther(new URL(itemCatalogueURLs.getPrivateCataloguePortletURL()).toURI()).build();
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
||||||
|
if(!(e instanceof WebApplicationException)){
|
||||||
|
//UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!"+"\n Cause: "+e.getCause().getMessage();
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
||||||
|
}
|
||||||
|
//ALREADY MANAGED AS WebApplicationException
|
||||||
logger.error("Exception:", e);
|
logger.error("Exception:", e);
|
||||||
String error = "Error occurred on resolving the path "+remainPathParthenosURL+". Please, contact the support!";
|
throw (WebApplicationException) e;
|
||||||
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,7 +116,7 @@ public class PartheosRegistryResolver {
|
||||||
|
|
||||||
if(entityName==null || entityName.isEmpty()){
|
if(entityName==null || entityName.isEmpty()){
|
||||||
logger.error("Entity Name Parameter like 'entity_name' not found or empty");
|
logger.error("Entity Name Parameter like 'entity_name' not found or empty");
|
||||||
ExceptionManager.badRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
|
throw ExceptionManager.badRequestException(req, "Mandatory body parameter 'entity_name' not found or empty", this.getClass(), helpURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
//REMOVING FIRST '/' IF EXISTS
|
//REMOVING FIRST '/' IF EXISTS
|
||||||
|
@ -145,10 +156,11 @@ public class PartheosRegistryResolver {
|
||||||
return name.toLowerCase();
|
return name.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void main(String[] args) throws UnsupportedEncodingException {
|
//TO TEST
|
||||||
//
|
// public static void main(String[] args) throws UnsupportedEncodingException {
|
||||||
// String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
|
//
|
||||||
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
|
// String remainPathParthenosURL = "Culturalitalia/unknown/Dataset/oai%3Aculturaitalia.it%3Aoai%3Aculturaitalia.it%3Amuseiditalia-mus_11953";
|
||||||
//
|
// System.out.println(URLDecoder.decode(remainPathParthenosURL, "UTF-8"));
|
||||||
// }
|
//
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue