From: <tho...@us...> - 2012-07-27 13:43:54
|
Revision: 6397 http://bigdata.svn.sourceforge.net/bigdata/?rev=6397&view=rev Author: thompsonbry Date: 2012-07-27 13:43:48 +0000 (Fri, 27 Jul 2012) Log Message: ----------- Modified InnerCause to examine the root causes of an ExecutionExceptions class. This class can have multiple root causes. They are now searched. Modified the test suite for TestRuleOwlFunctionalProperty to use InnerCause rather than custom code. Modified BigdataRDFServlet to use InnerCause to look for a ConstraintViolationException and report the request as a BAD_REQUEST rather than an SERVER ERROR. Modified Paths: -------------- branches/BIGDATA_RELEASE_1_2_0/bigdata/src/java/com/bigdata/util/InnerCause.java branches/BIGDATA_RELEASE_1_2_0/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleOwlFunctionalProperty.java branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/CountersServlet.java Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata/src/java/com/bigdata/util/InnerCause.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata/src/java/com/bigdata/util/InnerCause.java 2012-07-26 16:33:04 UTC (rev 6396) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata/src/java/com/bigdata/util/InnerCause.java 2012-07-27 13:43:48 UTC (rev 6397) @@ -66,6 +66,20 @@ { Class x = t.getClass(); + + // Check for Iterable<Throwable> + if(Iterable.class.isAssignableFrom(x)) { + for (Object o : (Iterable) t) { + if (!(o instanceof Throwable)) { + continue; + } + final Throwable tx = getInnerCause((Throwable) o, cls); + if (tx != null) + return tx; + } + } + + // Check the class hierarchy. while(x != null){ if( x == cls) return t; @@ -73,7 +87,8 @@ } } - + + // Check the nested cause. t = t.getCause(); if (t == null) Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleOwlFunctionalProperty.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleOwlFunctionalProperty.java 2012-07-26 16:33:04 UTC (rev 6396) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-rdf/src/test/com/bigdata/rdf/rules/TestRuleOwlFunctionalProperty.java 2012-07-27 13:43:48 UTC (rev 6397) @@ -121,16 +121,21 @@ } catch (Exception ex) { - final ExecutionExceptions ex2 = (ExecutionExceptions) - InnerCause.getInnerCause(ex, ExecutionExceptions.class); + if (!InnerCause.isInnerCause(ex, + ConstraintViolationException.class)) { + fail("Expected: " + ConstraintViolationException.class); + } + +// final ExecutionExceptions ex2 = (ExecutionExceptions) +// InnerCause.getInnerCause(ex, ExecutionExceptions.class); +// +// Throwable t = ex2.causes().get(0); +// while (t.getCause() != null) +// t = t.getCause(); +// +// if (!(t instanceof ConstraintViolationException)) +// fail("inner cause should be a ConstraintViolationException"); - Throwable t = ex2.causes().get(0); - while (t.getCause() != null) - t = t.getCause(); - - if (!(t instanceof ConstraintViolationException)) - fail("inner cause should be a ConstraintViolationException"); - } } finally { @@ -197,16 +202,20 @@ } catch (Exception ex) { - final ExecutionExceptions ex2 = (ExecutionExceptions) - InnerCause.getInnerCause(ex, ExecutionExceptions.class); + if (!InnerCause.isInnerCause(ex, + ConstraintViolationException.class)) { + fail("Expected: " + ConstraintViolationException.class); + } +// final ExecutionExceptions ex2 = (ExecutionExceptions) +// InnerCause.getInnerCause(ex, ExecutionExceptions.class); +// +// Throwable t = ex2.causes().get(0); +// while (t.getCause() != null) +// t = t.getCause(); +// +// if (!(t instanceof ConstraintViolationException)) +// fail("inner cause should be a ConstraintViolationException"); - Throwable t = ex2.causes().get(0); - while (t.getCause() != null) - t = t.getCause(); - - if (!(t instanceof ConstraintViolationException)) - fail("inner cause should be a ConstraintViolationException"); - } } finally { Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java 2012-07-26 16:33:04 UTC (rev 6396) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java 2012-07-27 13:43:48 UTC (rev 6397) @@ -52,6 +52,8 @@ import com.bigdata.rdf.properties.PropertiesFormat; import com.bigdata.rdf.properties.PropertiesWriter; import com.bigdata.rdf.properties.PropertiesWriterRegistry; +import com.bigdata.rdf.rules.ConstraintViolationException; +import com.bigdata.util.InnerCause; /** * Abstract base class for {@link Servlet}s which interact with the bigdata RDF @@ -149,10 +151,21 @@ } finally { // ignore any problems here. } - if (resp != null) { + if (resp != null) { if (!resp.isCommitted()) { - resp.setStatus(HTTP_INTERNALERROR); - resp.setContentType(MIME_TEXT_PLAIN); + if (InnerCause.isInnerCause(t, + ConstraintViolationException.class)) { + /* + * A constraint violation is a bad request (the data + * violates the rules) not a server error. + */ + resp.setStatus(HTTP_BADREQUEST); + resp.setContentType(MIME_TEXT_PLAIN); + } else { + // Internal server error. + resp.setStatus(HTTP_INTERNALERROR); + resp.setContentType(MIME_TEXT_PLAIN); + } } OutputStream os = null; try { Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/CountersServlet.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/CountersServlet.java 2012-07-26 16:33:04 UTC (rev 6396) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/CountersServlet.java 2012-07-27 13:43:48 UTC (rev 6397) @@ -50,7 +50,7 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id$ * - * FIXME The SPARQL layer needs to be separated from the core bigdata + * TODO The SPARQL layer needs to be separated from the core bigdata * layer, with the BigdataContext moving into a servlet package in the * bigdata module and the CountersServlet moving into a servlet package * in the com.bigdata.counters package namespace. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |