[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) {
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue