From 34e04bf4863e03015d211a514ec5589e41574cfb Mon Sep 17 00:00:00 2001
From: gmantele <gmantele@ari.uni-heidelberg.de>
Date: Mon, 16 Feb 2015 10:34:23 +0100
Subject: [PATCH] [TAP] Fix exception management: do not encapsulate in a
 UWSException a TAPException whose the cause is already a UWSException ; in
 such case, the TAPException cause must be returned.

---
 src/tap/AbstractTAPFactory.java | 14 ++++++++++----
 src/tap/TAPFactory.java         | 13 ++++++++-----
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/tap/AbstractTAPFactory.java b/src/tap/AbstractTAPFactory.java
index cc364a3..7642a52 100644
--- a/src/tap/AbstractTAPFactory.java
+++ b/src/tap/AbstractTAPFactory.java
@@ -16,7 +16,7 @@ package tap;
  * You should have received a copy of the GNU Lesser General Public License
  * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
  * 
- * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
+ * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
  *                       Astronomisches Rechen Institut (ARI)
  */
 
@@ -53,7 +53,7 @@ import adql.query.ADQLQuery;
  * Only the functions related with the database connection stay abstract.
  * 
  * @author Gr&eacute;gory Mantelet (CDS;ARI)
- * @version 2.0 (12/2014)
+ * @version 2.0 (02/2015)
  */
 public abstract class AbstractTAPFactory extends TAPFactory {
 
@@ -248,7 +248,10 @@ public abstract class AbstractTAPFactory extends TAPFactory {
 			TAPParameters tapParams = createTAPParameters(request);
 			return new TAPJob(owner, tapParams);
 		}catch(TAPException te){
-			throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Can not create a TAP asynchronous job!");
+			if (te.getCause() != null && te.getCause() instanceof UWSException)
+				throw (UWSException)te.getCause();
+			else
+				throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Can not create a TAP asynchronous job!");
 		}
 	}
 
@@ -265,7 +268,10 @@ public abstract class AbstractTAPFactory extends TAPFactory {
 		try{
 			return new TAPJob(jobId, owner, params, quote, startTime, endTime, results, error);
 		}catch(TAPException te){
-			throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Can not create a TAP asynchronous job !");
+			if (te.getCause() != null && te.getCause() instanceof UWSException)
+				throw (UWSException)te.getCause();
+			else
+				throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Can not create a TAP asynchronous job !");
 		}
 	}
 
diff --git a/src/tap/TAPFactory.java b/src/tap/TAPFactory.java
index 6dbc9a8..8c632c4 100644
--- a/src/tap/TAPFactory.java
+++ b/src/tap/TAPFactory.java
@@ -16,7 +16,7 @@ package tap;
  * You should have received a copy of the GNU Lesser General Public License
  * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
  * 
- * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
+ * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
  *                       Astronomisches Rechen Institut (ARI)
  */
 
@@ -61,7 +61,7 @@ import adql.query.ADQLQuery;
  * </ul>
  * 
  * @author Gr&eacute;gory Mantelet (CDS;ARI)
- * @version 2.0 (12/2014)
+ * @version 2.0 (02/2015)
  */
 public abstract class TAPFactory implements UWSFactory {
 
@@ -364,7 +364,10 @@ public abstract class TAPFactory implements UWSFactory {
 		try{
 			return new AsyncThread((TAPJob)job, createADQLExecutor(), getErrorWriter());
 		}catch(TAPException te){
-			throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Impossible to create an AsyncThread !");
+			if (te.getCause() != null && te.getCause() instanceof UWSException)
+				throw (UWSException)te.getCause();
+			else
+				throw new UWSException(UWSException.INTERNAL_SERVER_ERROR, te, "Impossible to create an AsyncThread !");
 		}
 	}
 
@@ -385,7 +388,7 @@ public abstract class TAPFactory implements UWSFactory {
 		try{
 			return createTAPParameters(request);
 		}catch(TAPException te){
-			if (te.getCause() != null && te.getCause() instanceof UWSException && te.getMessage().equals(te.getCause().getMessage()))
+			if (te.getCause() != null && te.getCause() instanceof UWSException)
 				throw (UWSException)te.getCause();
 			else
 				throw new UWSException(te.getHttpErrorCode(), te);
@@ -423,7 +426,7 @@ public abstract class TAPFactory implements UWSFactory {
 		try{
 			return createTAPParameters(params);
 		}catch(TAPException te){
-			if (te.getCause() != null && te.getCause() instanceof UWSException && te.getMessage().equals(te.getCause().getMessage()))
+			if (te.getCause() != null && te.getCause() instanceof UWSException)
 				throw (UWSException)te.getCause();
 			else
 				throw new UWSException(te.getHttpErrorCode(), te);
-- 
GitLab