added exceptions

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@100685 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-10-14 16:36:13 +00:00
parent 1e961a0593
commit 64b7d28a27
5 changed files with 97 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package org.gcube.datatransfer.resolver.gis; package org.gcube.datatransfer.resolver.gis;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters; import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -38,17 +39,17 @@ public class GeonetowrkAccessParameter implements GeonetworkServiceInterface{
* @param geonetworkInstance * @param geonetworkInstance
* @return * @return
*/ */
public GeonetworkInstance getGeonetworkInstance(boolean authenticate) throws Exception { public GeonetworkInstance getGeonetworkInstance(boolean authenticate) throws GeonetworkInstanceException {
return instanceGeonetwork(authenticate); return instanceGeonetwork(authenticate);
} }
private GeonetworkInstance instanceGeonetwork(boolean authenticate) throws Exception{ private GeonetworkInstance instanceGeonetwork(boolean authenticate) throws GeonetworkInstanceException{
if(scope == null || scope.isEmpty()) if(scope == null || scope.isEmpty())
throw new Exception("Scope is null"); throw new GeonetworkInstanceException("Scope is null");
if(serverParam.getUrl() == null || serverParam.getUrl().isEmpty()) if(serverParam.getUrl() == null || serverParam.getUrl().isEmpty())
throw new Exception("Geonetwork url is null or empty"); throw new GeonetworkInstanceException("Geonetwork url is null or empty");
if(geonetworkInstance==null) if(geonetworkInstance==null)
geonetworkInstance = new GeonetworkInstance(scope, serverParam.getUrl(), serverParam.getUser(), serverParam.getPassword(), authenticate); geonetworkInstance = new GeonetworkInstance(scope, serverParam.getUrl(), serverParam.getUser(), serverParam.getPassword(), authenticate);

View File

@ -3,9 +3,11 @@ package org.gcube.datatransfer.resolver.gis;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.spatial.data.geonetwork.GeoNetwork; import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher; import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
import org.gcube.spatial.data.geonetwork.LoginLevel; import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.AuthorizationException;
import org.gcube.spatial.data.geonetwork.configuration.Configuration; import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -50,7 +52,7 @@ public class GeonetworkInstance {
* @param httpSession * @param httpSession
* @throws Exception * @throws Exception
*/ */
public GeonetworkInstance(String scope, String geoNetworkUrl, String user, String pwd, boolean authenticate) throws Exception { public GeonetworkInstance(String scope, String geoNetworkUrl, String user, String pwd, boolean authenticate) throws GeonetworkInstanceException {
logger.trace("Instancing GeonetworkInstance with specific parameters"); logger.trace("Instancing GeonetworkInstance with specific parameters");
this.geoNetworkUser = user; this.geoNetworkUser = user;
this.geoNetworkPwd = pwd; this.geoNetworkPwd = pwd;
@ -61,7 +63,7 @@ public class GeonetworkInstance {
} catch (Exception e) { } catch (Exception e) {
String message = "Sorry, an error occurred in instancing geonetwork"; String message = "Sorry, an error occurred in instancing geonetwork";
logger.warn(message, e); logger.warn(message, e);
throw new Exception(message); throw new GeonetworkInstanceException(message);
} }
} }
@ -70,7 +72,7 @@ public class GeonetworkInstance {
* @param authenticate * @param authenticate
* @throws Exception * @throws Exception
*/ */
private void createInstance(boolean authenticate) throws Exception { private void createInstance(boolean authenticate) throws GeonetworkInstanceException {
this.geonetworkPublisher = GeoNetwork.get(new GeonetworkConfiguration()); this.geonetworkPublisher = GeoNetwork.get(new GeonetworkConfiguration());
authenticateOnGeoenetwork(authenticate); authenticateOnGeoenetwork(authenticate);
} }
@ -80,7 +82,7 @@ public class GeonetworkInstance {
* @param authenticate * @param authenticate
* @throws Exception * @throws Exception
*/ */
public void authenticateOnGeoenetwork(boolean authenticate) throws Exception { public void authenticateOnGeoenetwork(boolean authenticate) throws GeonetworkInstanceException {
logger.trace("authenticating.. geonetworkPublisher is null? "+(this.geonetworkPublisher==null)); logger.trace("authenticating.. geonetworkPublisher is null? "+(this.geonetworkPublisher==null));
if(geonetworkPublisher==null){ if(geonetworkPublisher==null){
@ -89,7 +91,11 @@ public class GeonetworkInstance {
} }
if (authenticate){ if (authenticate){
try {
this.geonetworkPublisher.login(LoginLevel.DEFAULT); this.geonetworkPublisher.login(LoginLevel.DEFAULT);
} catch (AuthorizationException e) {
throw new GeonetworkInstanceException(e);
}
logger.trace("authentication on geonetwork completed"); logger.trace("authentication on geonetwork completed");
} }
} }

View File

@ -22,6 +22,8 @@ import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileRead
import org.gcube.datatransfer.resolver.applicationprofile.ScopeUtil; import org.gcube.datatransfer.resolver.applicationprofile.ScopeUtil;
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE; import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters; import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
import org.gcube.datatransfer.resolver.gis.property.GisViewerAppGenericResourcePropertyReader; import org.gcube.datatransfer.resolver.gis.property.GisViewerAppGenericResourcePropertyReader;
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException; import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -201,6 +203,12 @@ public class GisResolver extends HttpServlet{
logger.info("returning link: " + gisPortletUrl); logger.info("returning link: " + gisPortletUrl);
out.close();*/ out.close();*/
urlRedirect(req, resp, gisPortletUrl); urlRedirect(req, resp, gisPortletUrl);
} catch (IllegalArgumentException e){
logger.error("IllegalArgumentException:", e);
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, SCOPE+" illegal argument to carry out the request!");
return;
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception:", e); logger.error("Exception:", e);
String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!"; String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
@ -250,9 +258,12 @@ public class GisResolver extends HttpServlet{
try { try {
GeonetworkServiceInterface gntwAccess = new GeonetowrkAccessParameter(scope, geonetworkParams); GeonetworkServiceInterface gntwAccess = new GeonetowrkAccessParameter(scope, geonetworkParams);
return MetadataConverter.getWMSOnLineResource(gntwAccess.getGeonetworkInstance(true), gisUUID); return MetadataConverter.getWMSOnLineResource(gntwAccess.getGeonetworkInstance(true), gisUUID);
}catch (GeonetworkInstanceException e){
logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);
} catch (Exception e) { } catch (Exception e) {
logger.error("An error occurred when retrieving gis layer with UUID "+gisUUID, e); logger.error("An error occurred when retrieving gis layer with UUID "+gisUUID, e);
throw new Exception("Sorry, An error occurred when retrieving gis layer with UUID "+gisUUID); throw new IllegalArgumentException("Sorry, An error occurred when retrieving gis layer with UUID "+gisUUID);
} }
} }

View File

@ -0,0 +1,39 @@
/**
*
*/
package org.gcube.datatransfer.resolver.gis.exception;
import org.gcube.spatial.data.geonetwork.configuration.AuthorizationException;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Oct 14, 2014
*
*/
public class GeonetworkInstanceException extends Exception {
/**
*
*/
private static final long serialVersionUID = 8589705350737964325L;
/**
*
*/
public GeonetworkInstanceException() {
super();
}
public GeonetworkInstanceException(String message) {
super(message);
}
/**
* @param e
*/
public GeonetworkInstanceException(AuthorizationException e) {
super(e);
}
}

View File

@ -0,0 +1,30 @@
/**
*
*/
package org.gcube.datatransfer.resolver.gis.exception;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Oct 14, 2014
*
*/
public class IllegalArgumentException extends Exception {
/**
*
*/
private static final long serialVersionUID = 8589705350737964325L;
/**
*
*/
public IllegalArgumentException() {
super();
}
public IllegalArgumentException(String message) {
super(message);
}
}