[OLINGO-468] better error message for wrong keys in server URI parser
Change-Id: I8add3bbb0fc53670e85a86f59f1e7151214fd88c Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
parent
b5e40fdfa4
commit
357e8b654b
|
@ -282,11 +282,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
|
|
||||||
public UriResourceTypedImpl readResourcePathSegment(final PathSegmentContext ctx) {
|
public UriResourceTypedImpl readResourcePathSegment(final PathSegmentContext ctx) {
|
||||||
|
|
||||||
boolean checkFirst = false;
|
final boolean checkFirst =
|
||||||
if (context.contextUriInfo.getLastResourcePart() == null
|
context.contextUriInfo.getLastResourcePart() == null
|
||||||
|| context.contextUriInfo.getLastResourcePart() instanceof UriResourceRootImpl) {
|
|| context.contextUriInfo.getLastResourcePart() instanceof UriResourceRootImpl;
|
||||||
checkFirst = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String odi = ctx.vODI.getText();
|
String odi = ctx.vODI.getText();
|
||||||
|
|
||||||
|
@ -1375,6 +1373,10 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
|
|
||||||
UriInfoImpl uriInfoImplpath = new UriInfoImpl().setKind(UriInfoKind.resource);
|
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();
|
TypeInformation lastTypeInfo = context.contextTypes.peek();
|
||||||
|
|
||||||
if (ctx.vIt != null || ctx.vIts != null) {
|
if (ctx.vIt != null || ctx.vIts != null) {
|
||||||
|
@ -1444,8 +1446,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
ExpressionImpl expression = null;
|
ExpressionImpl expression = null;
|
||||||
try {
|
try {
|
||||||
expression = (ExpressionImpl) ctx.vVO.accept(this);
|
expression = (ExpressionImpl) ctx.vVO.accept(this);
|
||||||
} catch (Exception ex) {
|
} catch (final RuntimeException e) {
|
||||||
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText,
|
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText, e,
|
||||||
UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, valueText));
|
UriParserSemanticException.MessageKeys.INVALID_KEY_VALUE, valueText));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,11 @@ public class TestFullResourcePath {
|
||||||
.isKeyPredicate(1, "PropertyString", "'3'")
|
.isKeyPredicate(1, "PropertyString", "'3'")
|
||||||
.n()
|
.n()
|
||||||
.isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
|
.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
|
@Test
|
||||||
|
@ -1084,6 +1089,11 @@ public class TestFullResourcePath {
|
||||||
.isKeyPredicate(1, "KeyAlias1", "2")
|
.isKeyPredicate(1, "KeyAlias1", "2")
|
||||||
.isKeyPredicate(2, "KeyAlias2", "'3'")
|
.isKeyPredicate(2, "KeyAlias2", "'3'")
|
||||||
.isKeyPredicate(3, "KeyAlias3", "'4'");
|
.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
|
@Test
|
||||||
|
@ -3386,8 +3396,7 @@ public class TestFullResourcePath {
|
||||||
.isFunction("UFCRTETTwoKeyNavParamCTTwoPrim")
|
.isFunction("UFCRTETTwoKeyNavParamCTTwoPrim")
|
||||||
.isParameterAlias(0, "ParameterCTTwoPrim", "@ParamAlias");
|
.isParameterAlias(0, "ParameterCTTwoPrim", "@ParamAlias");
|
||||||
|
|
||||||
testFilter.runOnETTwoKeyNav("PropertyComp"
|
testFilter.runOnETTwoKeyNav("PropertyComp/olingo.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
|
||||||
+ "/olingo.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
|
|
||||||
+ "(ParameterString=PropertyComp/PropertyComp/PropertyString)(PropertyInt16=1,PropertyString='2')"
|
+ "(ParameterString=PropertyComp/PropertyComp/PropertyString)(PropertyInt16=1,PropertyString='2')"
|
||||||
+ "/PropertyString eq 'SomeString'")
|
+ "/PropertyString eq 'SomeString'")
|
||||||
.is("<<PropertyComp/BFCCTPrimCompRTESTwoKeyNavParam/PropertyString> eq <'SomeString'>>")
|
.is("<<PropertyComp/BFCCTPrimCompRTESTwoKeyNavParam/PropertyString> eq <'SomeString'>>")
|
||||||
|
@ -3538,7 +3547,6 @@ public class TestFullResourcePath {
|
||||||
.isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTAllPrim, false)
|
.isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTAllPrim, false)
|
||||||
.n()
|
.n()
|
||||||
.isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
|
.isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue