olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [7/9] git commit: [OLINGO-468] better error message for wrong keys in server URI parser
Date Wed, 05 Nov 2014 13:31:57 GMT
[OLINGO-468] better error message for wrong keys in server URI parser

Change-Id: I8add3bbb0fc53670e85a86f59f1e7151214fd88c

Signed-off-by: Michael Bolz <michael.bolz@sap.com>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/357e8b65
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/357e8b65
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/357e8b65

Branch: refs/heads/OLINGO-450_FunctionActionExecution
Commit: 357e8b654b992470bad64cbc85e670e39bae59e8
Parents: b5e40fd
Author: Klaus Straubinger <klaus.straubinger@sap.com>
Authored: Thu Oct 30 10:49:54 2014 +0100
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Thu Oct 30 12:50:39 2014 +0100

----------------------------------------------------------------------
 .../server/core/uri/parser/UriParseTreeVisitor.java | 16 +++++++++-------
 .../server/core/uri/antlr/TestFullResourcePath.java | 14 +++++++++++---
 2 files changed, 20 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/357e8b65/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index 4b6745a..0a582dc 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -282,11 +282,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object>
{
 
   public UriResourceTypedImpl readResourcePathSegment(final PathSegmentContext ctx) {
 
-    boolean checkFirst = false;
-    if (context.contextUriInfo.getLastResourcePart() == null
-        || context.contextUriInfo.getLastResourcePart() instanceof UriResourceRootImpl) {
-      checkFirst = true;
-    }
+    final boolean checkFirst =
+        context.contextUriInfo.getLastResourcePart() == null
+        || context.contextUriInfo.getLastResourcePart() instanceof UriResourceRootImpl;
 
     String odi = ctx.vODI.getText();
 
@@ -1375,6 +1373,10 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object>
{
 
     UriInfoImpl uriInfoImplpath = new UriInfoImpl().setKind(UriInfoKind.resource);
 
+    if (context.contextTypes.isEmpty()) {
+      throw wrap(new UriParserSemanticException("Expression '" + ctx.getText() + "' is not
allowed as key value.",
+          UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, ctx.getText()));
+    }
     TypeInformation lastTypeInfo = context.contextTypes.peek();
 
     if (ctx.vIt != null || ctx.vIts != null) {
@@ -1444,8 +1446,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object>
{
       ExpressionImpl expression = null;
       try {
         expression = (ExpressionImpl) ctx.vVO.accept(this);
-      } catch (Exception ex) {
-        throw wrap(new UriParserSemanticException("Invalid key value: " + valueText,
+      } catch (final RuntimeException e) {
+        throw wrap(new UriParserSemanticException("Invalid key value: " + valueText, e,
             UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, valueText));
       }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/357e8b65/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index d850edd..0243452 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -417,6 +417,11 @@ public class TestFullResourcePath {
         .isKeyPredicate(1, "PropertyString", "'3'")
         .n()
         .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+    testUri.runEx("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNavParam(WrongParameter='1')")
+        .isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_PART);
+    testUri.runEx("ESKeyNav/olingo.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString=wrong)")
+        .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
   }
 
   @Test
@@ -1084,6 +1089,11 @@ public class TestFullResourcePath {
         .isKeyPredicate(1, "KeyAlias1", "2")
         .isKeyPredicate(2, "KeyAlias2", "'3'")
         .isKeyPredicate(3, "KeyAlias3", "'4'");
+
+    testUri.runEx("ESTwoPrim(wrong)")
+        .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
+    testUri.runEx("ESTwoPrim(PropertyInt16=wrong)")
+        .isExSemantic(UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE);
   }
 
   @Test
@@ -3386,8 +3396,7 @@ public class TestFullResourcePath {
         .isFunction("UFCRTETTwoKeyNavParamCTTwoPrim")
         .isParameterAlias(0, "ParameterCTTwoPrim", "@ParamAlias");
 
-    testFilter.runOnETTwoKeyNav("PropertyComp"
-        + "/olingo.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
+    testFilter.runOnETTwoKeyNav("PropertyComp/olingo.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
         + "(ParameterString=PropertyComp/PropertyComp/PropertyString)(PropertyInt16=1,PropertyString='2')"
         + "/PropertyString eq 'SomeString'")
         .is("<<PropertyComp/BFCCTPrimCompRTESTwoKeyNavParam/PropertyString> eq <'SomeString'>>")
@@ -3538,7 +3547,6 @@ public class TestFullResourcePath {
         .isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTAllPrim, false)
         .n()
         .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
-
   }
 
   @Test


Mime
View raw message