[OLINGO-348] Make Uri Parser exception translatable

This commit is contained in:
Christian Amend 2014-08-06 17:09:29 +02:00
parent 5c0b34a92d
commit d19afa013b
19 changed files with 353 additions and 140 deletions

View File

@ -68,7 +68,8 @@ public final class EdmDecimal extends SingletonPrimitiveType {
} }
private static boolean validateLiteral(final String value) { private static boolean validateLiteral(final String value) {
return PATTERN.matcher(value).matches(); boolean valid = PATTERN.matcher(value).matches();
return valid;
} }
private static final boolean validatePrecisionAndScale(final String value, final Integer precision, private static final boolean validatePrecisionAndScale(final String value, final Integer precision,

View File

@ -90,4 +90,10 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
expectTypeErrorInValueOfString(instance, "11:12:13"); expectTypeErrorInValueOfString(instance, "11:12:13");
} }
@Test
public void tests() throws Exception {
instance.validate("12:34:55", null, null, null, null, null);
}
} }

View File

@ -115,4 +115,10 @@ public interface UriInfoResource {
*/ */
List<UriResource> getUriResourceParts(); List<UriResource> getUriResourceParts();
/**
* @param alias
* @return the value for the given alias or null if no value is defined
*/
String getValueForAlias(String alias);
} }

View File

@ -74,7 +74,7 @@ public class ODataHandler {
processInternal(request, requestedContentType, response); processInternal(request, requestedContentType, response);
} catch (UriParserException e) { } catch (UriParserException e) {
e.printStackTrace();
} catch (ContentNegotiatorException e) { } catch (ContentNegotiatorException e) {
Locale requestedLocale = null; Locale requestedLocale = null;
ODataServerError serverError = ODataServerError serverError =

View File

@ -62,6 +62,7 @@ public class UriInfoImpl implements UriInfo {
private EdmEntityType entityTypeCast; // for $entity private EdmEntityType entityTypeCast; // for $entity
private List<CustomQueryOptionImpl> customQueryOptions = new ArrayList<CustomQueryOptionImpl>(); private List<CustomQueryOptionImpl> customQueryOptions = new ArrayList<CustomQueryOptionImpl>();
private HashMap<String, String> aliasToValue = new HashMap<String, String>();
HashMap<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions = HashMap<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions =
new HashMap<SystemQueryOptionKind, SystemQueryOption>(); new HashMap<SystemQueryOptionKind, SystemQueryOption>();
@ -134,6 +135,11 @@ public class UriInfoImpl implements UriInfo {
return retList; return retList;
} }
@Override
public String getValueForAlias(String alias) {
return aliasToValue.get(alias);
}
@Override @Override
public EdmEntityType getEntityTypeCast() { public EdmEntityType getEntityTypeCast() {
return entityTypeCast; return entityTypeCast;
@ -228,6 +234,9 @@ public class UriInfoImpl implements UriInfo {
public void addCustomQueryOption(final QueryOptionImpl item) { public void addCustomQueryOption(final QueryOptionImpl item) {
customQueryOptions.add((CustomQueryOptionImpl) item); customQueryOptions.add((CustomQueryOptionImpl) item);
if (item.getName().startsWith("@")) {
aliasToValue.put(item.getName(), item.getText());
}
} }
public UriInfoImpl setSystemQueryOption(final SystemQueryOptionImpl systemOption) { public UriInfoImpl setSystemQueryOption(final SystemQueryOptionImpl systemOption) {

View File

@ -221,7 +221,8 @@ public class Parser {
try { try {
inlineCountOption.setValue(Integer.parseInt(option.value)); inlineCountOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new UriParserSemanticException("Illegal value of $skip option!", e); throw new UriParserSemanticException("Illegal value of $skip option!", e,
UriParserSemanticException.MessageKeys.TEST);
} }
context.contextUriInfo.setSystemQueryOption(inlineCountOption); context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$skiptoken")) { } else if (option.name.equals("$skiptoken")) {
@ -237,7 +238,8 @@ public class Parser {
try { try {
inlineCountOption.setValue(Integer.parseInt(option.value)); inlineCountOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
throw new UriParserSemanticException("Illegal value of $top option!", e); throw new UriParserSemanticException("Illegal value of $top option!", e,
UriParserSemanticException.MessageKeys.TEST);
} }
context.contextUriInfo.setSystemQueryOption(inlineCountOption); context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$count")) { } else if (option.name.equals("$count")) {
@ -248,7 +250,8 @@ public class Parser {
if (option.value.equals("true") || option.value.equals("false")) { if (option.value.equals("true") || option.value.equals("false")) {
inlineCountOption.setValue(Boolean.parseBoolean(option.value)); inlineCountOption.setValue(Boolean.parseBoolean(option.value));
} else { } else {
throw new UriParserSemanticException("Illegal value of $count option!"); throw new UriParserSemanticException("Illegal value of $count option!",
UriParserSemanticException.MessageKeys.TEST);
} }
context.contextUriInfo.setSystemQueryOption(inlineCountOption); context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} }
@ -396,12 +399,12 @@ public class Parser {
} }
} catch (Exception weakException) { } catch (Exception weakException) {
throw new UriParserSyntaxException("Error in syntax", weakException); throw new UriParserSyntaxException("Error in syntax", weakException, UriParserSyntaxException.MessageKeys.TEST);
// exceptionOnStage = 2; // exceptionOnStage = 2;
} }
} catch (Exception hardException) { } catch (Exception hardException) {
throw new UriParserSyntaxException("Error in syntax", hardException); throw new UriParserSyntaxException("Error in syntax", hardException, UriParserSyntaxException.MessageKeys.TEST);
} }
return ret; return ret;

View File

@ -343,7 +343,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
tmp += (tmp.length() != 0 ? "," : "") + name; tmp += (tmp.length() != 0 ? "," : "") + name;
} }
throw wrap(new UriParserSemanticException("Function of functionimport '" + edmFunctionImport.getName() throw wrap(new UriParserSemanticException("Function of functionimport '" + edmFunctionImport.getName()
+ "' with parameters [" + tmp + "] not found")); + "' with parameters [" + tmp + "] not found", UriParserSemanticException.MessageKeys.TEST));
} }
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names)); uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
@ -358,7 +358,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastResourcePart == null) { if (lastResourcePart == null) {
if (context.contextTypes.size() == 0) { if (context.contextTypes.size() == 0) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed " throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
+ "resource parts")); + "resource parts", UriParserSemanticException.MessageKeys.TEST));
} }
source = context.contextTypes.peek(); source = context.contextTypes.peek();
} else { } else {
@ -366,7 +366,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (source.type == null) { if (source.type == null) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed " throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
+ "resource parts")); + "resource parts", UriParserSemanticException.MessageKeys.TEST));
} }
} }
@ -385,7 +385,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(source.type instanceof EdmStructuredType)) { if (!(source.type instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Can not parse'" + odi throw wrap(new UriParserSemanticException("Can not parse'" + odi
+ "'Previous path segment not a structural type.")); + "'Previous path segment not a structural type.", UriParserSemanticException.MessageKeys.TEST));
} }
EdmStructuredType structType = (EdmStructuredType) source.type; EdmStructuredType structType = (EdmStructuredType) source.type;
@ -393,7 +393,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmElement property = structType.getProperty(odi); EdmElement property = structType.getProperty(odi);
if (property == null) { if (property == null) {
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '" throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
+ structType.getNamespace() + "." + structType.getName() + "'")); + structType.getNamespace() + "." + structType.getName() + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
if (property instanceof EdmProperty) { if (property instanceof EdmProperty) {
@ -417,7 +418,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
context.contextUriInfo.addResourcePart(navigationResource); context.contextUriInfo.addResourcePart(navigationResource);
return null; return null;
} else { } else {
throw wrap(new UriParserSemanticException("Unkown type for property '" + property + "'")); throw wrap(new UriParserSemanticException("Unkown type for property '" + property + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
} else { // with namespace } else { // with namespace
@ -432,7 +434,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// is entity type cast // is entity type cast
if (!(filterEntityType.compatibleTo(source.type))) { if (!(filterEntityType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException( throw wrap(new UriParserSemanticException(
"Entity typefilter not compatible to previous path segment: " + fullFilterName.toString())); "Entity typefilter not compatible to previous path segment: " + fullFilterName.toString(),
UriParserSemanticException.MessageKeys.TEST));
} }
if (lastResourcePart == null) { if (lastResourcePart == null) {
@ -457,7 +460,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnEntry() != null) { if (lastPartWithKeys.getTypeFilterOnEntry() != null) {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '" + getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'")); + getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
lastPartWithKeys.setEntryTypeFilter(filterEntityType); lastPartWithKeys.setEntryTypeFilter(filterEntityType);
return null; return null;
@ -465,7 +469,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnCollection() != null) { if (lastPartWithKeys.getTypeFilterOnCollection() != null) {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '" + getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'")); + getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
lastPartWithKeys.setCollectionTypeFilter(filterEntityType); lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
return null; return null;
@ -475,14 +480,14 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) { if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '" + getName(filterEntityType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'")); + getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
} }
lastPartTyped.setTypeFilter(filterEntityType); lastPartTyped.setTypeFilter(filterEntityType);
return null; return null;
} else { } else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterEntityType) throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterEntityType)
+ "' not typed")); + "' not typed", UriParserSemanticException.MessageKeys.TEST));
} }
} }
} }
@ -497,7 +502,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(filterComplexType.compatibleTo(source.type))) { if (!(filterComplexType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException( throw wrap(new UriParserSemanticException(
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '" "Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
+ getName(filterComplexType) + "'")); + getName(filterComplexType) + "'", UriParserSemanticException.MessageKeys.TEST));
} }
// is simple complex type cast // is simple complex type cast
@ -523,7 +528,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnEntry() != null) { if (lastPartWithKeys.getTypeFilterOnEntry() != null) {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '" + getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'")); + getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
lastPartWithKeys.setEntryTypeFilter(filterComplexType); lastPartWithKeys.setEntryTypeFilter(filterComplexType);
return null; return null;
@ -531,7 +537,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnCollection() != null) { if (lastPartWithKeys.getTypeFilterOnCollection() != null) {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '" + getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'")); + getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TEST));
} }
lastPartWithKeys.setCollectionTypeFilter(filterComplexType); lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
return null; return null;
@ -542,14 +549,14 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) { if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '" throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '" + getName(filterComplexType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'")); + getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
} }
lastPartTyped.setTypeFilter(filterComplexType); lastPartTyped.setTypeFilter(filterComplexType);
return null; return null;
} else { } else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterComplexType) throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterComplexType)
+ "' not typed")); + "' not typed", UriParserSemanticException.MessageKeys.TEST));
} }
} }
} }
@ -569,7 +576,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// do a check for bound functions (which requires a parameter list) // do a check for bound functions (which requires a parameter list)
if (ctx.vlNVO.size() == 0) { if (ctx.vlNVO.size() == 0) {
throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString() throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString()
+ "'")); + "'", UriParserSemanticException.MessageKeys.TEST));
} }
context.contextReadingFunctionParameters = true; context.contextReadingFunctionParameters = true;
@ -610,7 +617,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return null; return null;
} }
throw wrap(new UriParserSemanticException("Unknown resource path segment:" + fullFilterName.toString())); throw wrap(new UriParserSemanticException("Unknown resource path segment:" + fullFilterName.toString(),
UriParserSemanticException.MessageKeys.TEST));
} }
} }
@ -631,7 +639,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResource obj = context.contextUriInfo.getLastResourcePart(); UriResource obj = context.contextUriInfo.getLastResourcePart();
if (!(obj instanceof UriResourcePartTyped)) { if (!(obj instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("any only allowed on typed path segments")); throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
} }
UriContext.LambdaVariables var = new UriContext.LambdaVariables(); UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@ -770,7 +779,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmEntityType type = edm.getEntityType(fullName); EdmEntityType type = edm.getEntityType(fullName);
if (type == null) { if (type == null) {
throw wrap(new UriParserSemanticException("Expected EntityTypeName")); throw wrap(new UriParserSemanticException("Expected EntityTypeName",
UriParserSemanticException.MessageKeys.TEST));
} }
context.contextUriInfo.setEntityTypeCast(type); context.contextUriInfo.setEntityTypeCast(type);
@ -855,7 +865,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (ctx.vLV != null) { if (ctx.vLV != null) {
UriResourceImpl lastResourcePart = (UriResourceImpl) context.contextUriInfo.getLastResourcePart(); UriResourceImpl lastResourcePart = (UriResourceImpl) context.contextUriInfo.getLastResourcePart();
if (!(lastResourcePart instanceof UriResourcePartTyped)) { if (!(lastResourcePart instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("any only allowed on typed path segments")); throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
} }
UriContext.LambdaVariables var = new UriContext.LambdaVariables(); UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@ -957,11 +968,13 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!((UriResourcePartTyped) pathInfo).isCollection()) { if (!((UriResourcePartTyped) pathInfo).isCollection()) {
context.contextUriInfo.addResourcePart(new UriResourceValueImpl()); context.contextUriInfo.addResourcePart(new UriResourceValueImpl());
} else { } else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments")); throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
} }
return null; return null;
} else { } else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments")); throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
} }
} else if (ctx.vC != null) { } else if (ctx.vC != null) {
@ -969,10 +982,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (((UriResourcePartTyped) pathInfo).isCollection()) { if (((UriResourcePartTyped) pathInfo).isCollection()) {
context.contextUriInfo.addResourcePart(new UriResourceCountImpl()); context.contextUriInfo.addResourcePart(new UriResourceCountImpl());
} else { } else {
throw wrap(new UriParserSemanticException("$count only allowed on collection properties")); throw wrap(new UriParserSemanticException("$count only allowed on collection properties",
UriParserSemanticException.MessageKeys.TEST));
} }
} else { } else {
throw wrap(new UriParserSemanticException("$count only allowed on typed properties")); throw wrap(new UriParserSemanticException("$count only allowed on typed properties",
UriParserSemanticException.MessageKeys.TEST));
} }
} else if (ctx.vR != null) { } else if (ctx.vR != null) {
if (pathInfo instanceof UriResourcePartTyped) { if (pathInfo instanceof UriResourcePartTyped) {
@ -980,10 +995,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (type instanceof EdmEntityType) { if (type instanceof EdmEntityType) {
context.contextUriInfo.addResourcePart(new UriResourceRefImpl()); context.contextUriInfo.addResourcePart(new UriResourceRefImpl());
} else { } else {
throw wrap(new UriParserSemanticException("$ref only allowed on endity types")); throw wrap(new UriParserSemanticException("$ref only allowed on endity types",
UriParserSemanticException.MessageKeys.TEST));
} }
} else { } else {
throw wrap(new UriParserSemanticException("$ref only allowed on typed properties")); throw wrap(new UriParserSemanticException("$ref only allowed on typed properties",
UriParserSemanticException.MessageKeys.TEST));
} }
} else if (ctx.vAll != null) { } else if (ctx.vAll != null) {
@ -1393,13 +1410,15 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
try { try {
expression = (ExpressionImpl) ctx.vVO.accept(this); expression = (ExpressionImpl) ctx.vVO.accept(this);
} catch (Exception ex) { } catch (Exception ex) {
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText)); throw wrap(new UriParserSemanticException("Invalid key value: " + valueText,
UriParserSemanticException.MessageKeys.TEST));
} }
// get type of last resource part // get type of last resource part
UriResource last = context.contextUriInfo.getLastResourcePart(); UriResource last = context.contextUriInfo.getLastResourcePart();
if (!(last instanceof UriResourcePartTyped)) { if (!(last instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Paramterslist on untyped resource path segement not allowed")); throw wrap(new UriParserSemanticException("Paramterslist on untyped resource path segement not allowed",
UriParserSemanticException.MessageKeys.TEST));
} }
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType(); EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@ -1420,14 +1439,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// key. // key.
// for using referential constrains the last resource part must be a navigation property // for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) { if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined")); throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
} }
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last; UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property // get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner(); EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) { if (partner == null) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined")); throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
} }
// create the keylist // create the keylist
@ -1445,7 +1466,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
missedKey = item; missedKey = item;
} else { } else {
// two of more keys are missing // two of more keys are missing
throw wrap(new UriParserSemanticException("Not enougth referntial contrains defined")); throw wrap(new UriParserSemanticException("Not enougth referntial contrains defined",
UriParserSemanticException.MessageKeys.TEST));
} }
} }
} }
@ -1479,7 +1501,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// get type of last resource part // get type of last resource part
if (!(last instanceof UriResourcePartTyped)) { if (!(last instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Parameterslist on untyped resource path segement not allowed")); throw wrap(new UriParserSemanticException("Parameterslist on untyped resource path segement not allowed",
UriParserSemanticException.MessageKeys.TEST));
} }
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType(); EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@ -1494,14 +1517,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// if not, check if the missing key predicates can be satisfied with help of the defined referential constrains // if not, check if the missing key predicates can be satisfied with help of the defined referential constrains
// for using referential constrains the last resource part must be a navigation property // for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) { if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined")); throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
} }
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last; UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property // get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner(); EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) { if (partner == null) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined")); throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
} }
// fill missing keys from referential constrains // fill missing keys from referential constrains
@ -1528,7 +1553,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return list; return list;
} }
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined")); throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
} }
return new ArrayList<String>(); return new ArrayList<String>();
} }
@ -1542,7 +1568,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
uriParameter.setText(ctx.vCOM.getText()); uriParameter.setText(ctx.vCOM.getText());
uriParameter.setExpression((ExpressionImpl) ctx.vCOM.accept(this)); uriParameter.setExpression((ExpressionImpl) ctx.vCOM.accept(this));
} else { } else {
uriParameter.setAlias(ctx.vALI.getText()); uriParameter.setAlias("@" + ctx.vALI.getText());
} }
return uriParameter; return uriParameter;
@ -1631,7 +1657,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
((UriResourceWithKeysImpl) pathInfoSegment) ((UriResourceWithKeysImpl) pathInfoSegment)
.setKeyPredicates(list); .setKeyPredicates(list);
} else { } else {
throw wrap(new UriParserSemanticException("Key properties not allowed")); throw wrap(new UriParserSemanticException("Key properties not allowed",
UriParserSemanticException.MessageKeys.TEST));
// throw UriSemanticError.addKrepredicatesNotAllowed(); // throw UriSemanticError.addKrepredicatesNotAllowed();
} }
} }
@ -1698,7 +1725,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResource lastResource = context.contextUriInfo.getLastResourcePart(); UriResource lastResource = context.contextUriInfo.getLastResourcePart();
if (!(lastResource instanceof UriResourcePartTyped)) { if (!(lastResource instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Resource path not typed")); throw wrap(new UriParserSemanticException("Resource path not typed",
UriParserSemanticException.MessageKeys.TEST));
} }
UriResourcePartTyped lastType = (UriResourcePartTyped) lastResource; UriResourcePartTyped lastType = (UriResourcePartTyped) lastResource;
@ -1803,18 +1831,21 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
prevType = getTypeInformation(last).type; prevType = getTypeInformation(last).type;
if (prevType == null) { if (prevType == null) {
throw wrap(new UriParserSemanticException("prev segement not typed")); throw wrap(new UriParserSemanticException("prev segement not typed",
UriParserSemanticException.MessageKeys.TEST));
} }
} }
if (!(prevType instanceof EdmStructuredType)) { if (!(prevType instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Previous select item is not a structural type")); throw wrap(new UriParserSemanticException("Previous select item is not a structural type",
UriParserSemanticException.MessageKeys.TEST));
} }
EdmStructuredType structType = (EdmStructuredType) prevType; EdmStructuredType structType = (EdmStructuredType) prevType;
EdmElement element = structType.getProperty(odi); EdmElement element = structType.getProperty(odi);
if (element == null) { if (element == null) {
throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi)); throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi,
UriParserSemanticException.MessageKeys.TEST));
} }
// create new segment // create new segment
@ -1864,7 +1895,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return this; return this;
} }
} else { } else {
throw wrap(new UriParserSemanticException("Only Simple and Complex properties within select allowed")); throw wrap(new UriParserSemanticException("Only Simple and Complex properties within select allowed",
UriParserSemanticException.MessageKeys.TEST));
} }
} else { } else {
String namespace = ctx.vNS.getText(); String namespace = ctx.vNS.getText();
@ -1916,14 +1948,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
} }
} }
} else { } else {
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type")); throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
UriParserSemanticException.MessageKeys.TEST));
} }
} else { } else {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath(); UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart(); UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) { if (!(last instanceof UriResourceTypedImpl)) {
throw wrap(new UriParserSemanticException("prev segement typed")); throw wrap(new UriParserSemanticException("prev segement typed",
UriParserSemanticException.MessageKeys.TEST));
} }
EdmType prevType = getTypeInformation(last).type; EdmType prevType = getTypeInformation(last).type;
@ -1939,7 +1973,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
} }
} }
} else if (prevType instanceof EdmEntityType) { } else if (prevType instanceof EdmEntityType) {
throw wrap(new UriParserSemanticException("Error")); throw wrap(new UriParserSemanticException("Error", UriParserSemanticException.MessageKeys.TEST));
/* /*
* EdmEntityType et = edm.getEntityType(fullName); * EdmEntityType et = edm.getEntityType(fullName);
* if (et != null) { * if (et != null) {
@ -1953,7 +1987,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
* } * }
*/ */
} else { } else {
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type")); throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
UriParserSemanticException.MessageKeys.TEST));
} }
} }
@ -1964,7 +1999,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath(); UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart(); UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) { if (!(last instanceof UriResourceTypedImpl)) {
throw wrap(new UriParserSemanticException("prev segement typed")); throw wrap(new UriParserSemanticException("prev segement typed",
UriParserSemanticException.MessageKeys.TEST));
} }
prevType = getTypeInformation(last).type; prevType = getTypeInformation(last).type;
} }

View File

@ -18,18 +18,18 @@
*/ */
package org.apache.olingo.server.core.uri.parser; package org.apache.olingo.server.core.uri.parser;
public class UriParserException extends Exception { import org.apache.olingo.server.api.ODataTranslatedException;
/**
*
*/
private static final long serialVersionUID = 1L;
public UriParserException(final String message, final Throwable cause) { public class UriParserException extends ODataTranslatedException {
super(message, cause);
private static final long serialVersionUID = -6438700016830955949L;
public UriParserException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
} }
public UriParserException(final String message) { public UriParserException(String developmentMessage, Throwable cause, MessageKey messageKey,
super(message, null); String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
} }
} }

View File

@ -20,14 +20,18 @@ package org.apache.olingo.server.core.uri.parser;
public class UriParserSemanticException extends UriParserException { public class UriParserSemanticException extends UriParserException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 3850285860949809622L;
public UriParserSemanticException(final String message, final Throwable cause) { public static enum MessageKeys implements MessageKey {
super(message, cause); TEST
} }
public UriParserSemanticException(final String message) { public UriParserSemanticException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(message, null); super(developmentMessage, messageKey, parameters);
} }
public UriParserSemanticException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
} }

View File

@ -20,17 +20,18 @@ package org.apache.olingo.server.core.uri.parser;
public class UriParserSyntaxException extends UriParserException { public class UriParserSyntaxException extends UriParserException {
/** private static final long serialVersionUID = 5887744747812478226L;
*
*/
private static final long serialVersionUID = 1L;
public UriParserSyntaxException(final String message, final Throwable cause) { public static enum MessageKeys implements MessageKey {
super(message, cause); TEST
}
public UriParserSyntaxException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
} }
public UriParserSyntaxException(final String message) { public UriParserSyntaxException(String developmentMessage, Throwable cause, MessageKey messageKey,
super(message, null); String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
} }
} }

View File

@ -18,17 +18,47 @@
*/ */
package org.apache.olingo.server.core.uri.validator; package org.apache.olingo.server.core.uri.validator;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.server.api.ODataTranslatedException;
public class UriValidationException extends Exception { public class UriValidationException extends ODataTranslatedException {
private static final long serialVersionUID = -3179078078053564742L; private static final long serialVersionUID = -3179078078053564742L;
public UriValidationException(final String msg) { public static enum MessageKeys implements MessageKey {
super(msg); /** parameter: unsupported query option */
UNSUPPORTED_QUERY_OPTION,
/** parameter: unsupported uri kind */
UNSUPPORTED_URI_KIND,
/** parameter: unsupported uri resource kind */
UNSUPPORTED_URI_RESOURCE_KIND,
/** parameter: unsupported function return type */
UNSUPPORTED_FUNCTION_RETURN_TYPE,
/** parameter: unsupported action return type */
UNSUPPORTED_ACTION_RETURN_TYPE,
/** parameter: unsupported http method */
UNSUPPORTED_HTTP_METHOD,
/** parameter: system query option */
SYSTEM_QUERY_OPTION_NOT_ALLOWED,
/** parameters: system query option, http method */
SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD,
/** parameter: invalid key property */
INVALID_KEY_PROPERTY,
/** parameter: untyped segment name */
LAST_SEGMENT_NOT_TYPED,
/** parameter: untyped segment name */
SECOND_LAST_SEGMENT_NOT_TYPED,
/** parameter: unallowed kind before $value */
UNALLOWED_KIND_BEFORE_VALUE,
/** parameter: unallowed kind before $count */
UNALLOWED_KIND_BEFORE_COUNT,
}
public UriValidationException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
} }
public UriValidationException(final EdmPrimitiveTypeException e) { public UriValidationException(String developmentMessage, Throwable cause, MessageKey messageKey,
super(e); String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
} }
} }

View File

@ -41,6 +41,7 @@ import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourceNavigation; import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped; import org.apache.olingo.server.api.uri.UriResourcePartTyped;
import org.apache.olingo.server.api.uri.UriResourceSingleton; import org.apache.olingo.server.api.uri.UriResourceSingleton;
import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
@ -219,7 +220,8 @@ public class UriValidator {
idx = ColumnIndex.top; idx = ColumnIndex.top;
break; break;
default: default:
throw new UriValidationException("Unsupported option: " + queryOptionKind); throw new UriValidationException("Unsupported option: " + queryOptionKind.toString(),
UriValidationException.MessageKeys.UNSUPPORTED_QUERY_OPTION, queryOptionKind.toString());
} }
return idx; return idx;
@ -251,7 +253,8 @@ public class UriValidator {
idx = RowIndexForUriType.service; idx = RowIndexForUriType.service;
break; break;
default: default:
throw new UriValidationException("Unsupported uriInfo kind: " + uriInfo.getKind()); throw new UriValidationException("Unsupported uriInfo kind: " + uriInfo.getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_URI_KIND, uriInfo.getKind().toString());
} }
return idx; return idx;
@ -300,7 +303,8 @@ public class UriValidator {
idx = rowIndexForValue(uriInfo); idx = rowIndexForValue(uriInfo);
break; break;
default: default:
throw new UriValidationException("Unsupported uriResource kind: " + lastPathSegment.getKind()); throw new UriValidationException("Unsupported uriResource kind: " + lastPathSegment.getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_URI_RESOURCE_KIND, lastPathSegment.getKind().toString());
} }
return idx; return idx;
@ -367,7 +371,8 @@ public class UriValidator {
break; break;
default: default:
throw new UriValidationException("Unexpected kind in path segment before $value: " throw new UriValidationException("Unexpected kind in path segment before $value: "
+ secondLastPathSegment.getKind()); + secondLastPathSegment.getKind(), UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE,
secondLastPathSegment.toString());
} }
return idx; return idx;
} }
@ -388,7 +393,8 @@ public class UriValidator {
idx = isCollection ? RowIndexForUriType.propertyPrimitiveCollection : RowIndexForUriType.propertyPrimitive; idx = isCollection ? RowIndexForUriType.propertyPrimitiveCollection : RowIndexForUriType.propertyPrimitive;
break; break;
default: default:
throw new UriValidationException("Unsupported function return type: " + functionReturnTypeKind); throw new UriValidationException("Unsupported function return type: " + functionReturnTypeKind,
UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE, functionReturnTypeKind.toString());
} }
return idx; return idx;
} }
@ -405,7 +411,8 @@ public class UriValidator {
: RowIndexForUriType.reference; : RowIndexForUriType.reference;
} else { } else {
throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
} }
return idx; return idx;
@ -420,7 +427,8 @@ public class UriValidator {
: RowIndexForUriType.propertyPrimitive; : RowIndexForUriType.propertyPrimitive;
} else { } else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
} }
return idx; return idx;
} }
@ -444,7 +452,9 @@ public class UriValidator {
idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex; idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex;
break; break;
default: default:
throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind()); throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE,
rt.getType().getKind().toString());
} }
return idx; return idx;
@ -458,7 +468,8 @@ public class UriValidator {
: RowIndexForUriType.entity; : RowIndexForUriType.entity;
} else { } else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
} }
return idx; return idx;
} }
@ -472,7 +483,8 @@ public class UriValidator {
: RowIndexForUriType.propertyComplex; : RowIndexForUriType.propertyComplex;
} else { } else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: " throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass()); + lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
} }
return idx; return idx;
} }
@ -496,7 +508,8 @@ public class UriValidator {
idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex; idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex;
break; break;
default: default:
throw new UriValidationException("Unsupported action return type: " + rt.getType().getKind()); throw new UriValidationException("Unsupported action return type: " + rt.getType().getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_ACTION_RETURN_TYPE, rt.getType().getKind().toString());
} }
return idx; return idx;
@ -535,7 +548,8 @@ public class UriValidator {
idx = determineReturnType(functionReturnTypeKind, isCollection); idx = determineReturnType(functionReturnTypeKind, isCollection);
break; break;
default: default:
throw new UriValidationException("Illegal path part kind: " + secondLastPathSegment.getKind()); throw new UriValidationException("Illegal path part kind before $count: " + secondLastPathSegment.getKind(),
UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_COUNT, secondLastPathSegment.toString());
} }
return idx; return idx;
@ -548,7 +562,8 @@ public class UriValidator {
ColumnIndex col = colIndex(option.getKind()); ColumnIndex col = colIndex(option.getKind());
if (!decisionMatrix[row.getIndex()][col.getIndex()]) { if (!decisionMatrix[row.getIndex()][col.getIndex()]) {
throw new UriValidationException("System query option not allowed: " + option.getName()); throw new UriValidationException("System query option not allowed: " + option.getName(),
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED, option.getName());
} }
} }
@ -561,7 +576,8 @@ public class UriValidator {
ColumnIndex col = colIndex(option.getKind()); ColumnIndex col = colIndex(option.getKind());
if (!decisionMatrixForHttpMethod[row.getIndex()][col.getIndex()]) { if (!decisionMatrixForHttpMethod[row.getIndex()][col.getIndex()]) {
throw new UriValidationException("System query option " + option.getName() + " not allowed for method " throw new UriValidationException("System query option " + option.getName() + " not allowed for method "
+ httpMethod); + httpMethod, UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, option
.getName(), httpMethod.toString());
} }
} }
@ -590,7 +606,8 @@ public class UriValidator {
idx = RowIndexForHttpMethod.MERGE; idx = RowIndexForHttpMethod.MERGE;
break; break;
default: default:
throw new UriValidationException("HTTP method not supported: " + httpMethod); throw new UriValidationException("HTTP method not supported: " + httpMethod,
UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, httpMethod.toString());
} }
return idx; return idx;
@ -619,26 +636,39 @@ public class UriValidator {
for (UriParameter keyPredicate : keyPredicates) { for (UriParameter keyPredicate : keyPredicates) {
String name = keyPredicate.getName(); String name = keyPredicate.getName();
String alias = keyPredicate.getAlias();
String value = keyPredicate.getText(); String value = keyPredicate.getText();
if (alias != null) {
value = uriInfo.getValueForAlias(alias);
}
EdmKeyPropertyRef edmKey = edmKeys.get(name); EdmKeyPropertyRef edmKey = edmKeys.get(name);
if (edmKey == null) { if (edmKey == null) {
throw new UriValidationException("Unknown key property: " + name); throw new UriValidationException("Unknown key property: " + name,
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, name);
} }
EdmType edmType = edmKey.getProperty().getType(); EdmType edmType = edmKey.getProperty().getType();
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType; EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
String edmLiteral = edmPrimitiveType.fromUriLiteral(value); String edmLiteral = edmPrimitiveType.fromUriLiteral(value);
edmPrimitiveType.validate(edmLiteral, edmKey.getProperty().isNullable(), edmKey.getProperty() boolean isValid =
.getMaxLength(), edmKey.getProperty().getPrecision(), edmKey.getProperty().getScale(), edmKey edmPrimitiveType.validate(edmLiteral, edmKey.getProperty().isNullable(), edmKey.getProperty()
.getProperty().isUnicode()); .getMaxLength(), edmKey.getProperty().getPrecision(), edmKey.getProperty().getScale(), edmKey
.getProperty().isUnicode());
if (!isValid) {
// TODO: Check exception here
throw new UriValidationException("PrimitiveTypeException",
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY);
}
} }
} }
} }
} }
} catch (EdmPrimitiveTypeException e) { } catch (EdmPrimitiveTypeException e) {
throw new UriValidationException(e); // TODO: Check exception here
throw new UriValidationException("PrimitiveTypeException", e,
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY);
} }
} }
} }

View File

@ -29,7 +29,9 @@ import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpContentType; import org.apache.olingo.commons.api.http.HttpContentType;
@ -40,11 +42,14 @@ import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse; import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
import org.apache.olingo.server.api.edm.provider.EntitySet;
import org.apache.olingo.server.api.processor.MetadataProcessor; import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor; import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
public class ODataHandlerTest { public class ODataHandlerTest {
@ -219,6 +224,18 @@ public class ODataHandlerTest {
assertEquals(406, response.getStatusCode()); assertEquals(406, response.getStatusCode());
} }
@Test
public void testUnregisteredProcessor() {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("ESAllPrim");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(501, response.getStatusCode());
}
@Test @Test
public void testWithApplicationExceptionInProcessor() throws Exception { public void testWithApplicationExceptionInProcessor() throws Exception {
ODataRequest request = new ODataRequest(); ODataRequest request = new ODataRequest();
@ -227,13 +244,65 @@ public class ODataHandlerTest {
request.setRawODataPath("$metadata"); request.setRawODataPath("$metadata");
MetadataProcessor metadataProcessor = mock(MetadataProcessor.class); MetadataProcessor metadataProcessor = mock(MetadataProcessor.class);
doThrow(new ODataApplicationException("msg", 412, Locale.ENGLISH)).when(metadataProcessor).readMetadata( doThrow(new ODataApplicationException("msg", 425, Locale.ENGLISH)).when(metadataProcessor).readMetadata(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class)); any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
handler.register(metadataProcessor); handler.register(metadataProcessor);
ODataResponse response = handler.process(request); ODataResponse response = handler.process(request);
assertNotNull(response); assertNotNull(response);
assertEquals(412, response.getStatusCode()); assertEquals(425, response.getStatusCode());
}
//TODO: Use this test
@Ignore
@Test
public void testUriParserExceptionResultsInRightResponseNotFound() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("NotFound");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(404, response.getStatusCode());
}
//TODO: Use this test
@Ignore
@Test
public void testUriParserExceptionResultsInRightResponseBadRequest() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("ESAllPrim()");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(404, response.getStatusCode());
}
@Test
public void testUriParserExceptionResultsInRightResponseEdmCause() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("EdmException");
OData odata = OData.newInstance();
Edm edm = odata.createEdm(new EdmProvider() {
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
throws ODataException {
throw new ODataException("msg");
}
});
ODataHandler localHandler = new ODataHandler(odata, edm);
ODataResponse response = localHandler.process(request);
assertNotNull(response);
assertEquals(500, response.getStatusCode());
// TODO: Check for message in case of EdmException
// System.out.println(IOUtils.toString(response.getContent()));
} }
} }

View File

@ -148,21 +148,21 @@ public class UriInfoImplTest {
QueryOptionImpl queryOption = new QueryOptionImpl(); QueryOptionImpl queryOption = new QueryOptionImpl();
queryOptions.add(expand); queryOptions.add(expand.setName(""));
queryOptions.add(filter); queryOptions.add(filter.setName(""));
queryOptions.add(format); queryOptions.add(format.setName(""));
queryOptions.add(id); queryOptions.add(id.setName(""));
queryOptions.add(inlinecount); queryOptions.add(inlinecount.setName(""));
queryOptions.add(orderby); queryOptions.add(orderby.setName(""));
queryOptions.add(search); queryOptions.add(search.setName(""));
queryOptions.add(select); queryOptions.add(select.setName(""));
queryOptions.add(skip); queryOptions.add(skip.setName(""));
queryOptions.add(skipToken); queryOptions.add(skipToken.setName(""));
queryOptions.add(top); queryOptions.add(top.setName(""));
queryOptions.add(customOption0); queryOptions.add(customOption0.setName(""));
queryOptions.add(customOption1); queryOptions.add(customOption1.setName(""));
queryOptions.add(levels);// not stored queryOptions.add(levels.setName(""));// not stored
queryOptions.add(queryOption);// not stored queryOptions.add(queryOption.setName(""));// not stored
uriInfo.setQueryOptions(queryOptions); uriInfo.setQueryOptions(queryOptions);
assertEquals(expand, uriInfo.getExpandOption()); assertEquals(expand, uriInfo.getExpandOption());

View File

@ -1067,21 +1067,18 @@ public class TestFullResourcePath {
.isKeyPredicate(2, "KeyAlias2", "'3'") .isKeyPredicate(2, "KeyAlias2", "'3'")
.isKeyPredicate(3, "KeyAlias3", "'4'"); .isKeyPredicate(3, "KeyAlias3", "'4'");
testUri.run("ESCollAllPrim(null)") testUri.runEx("ESCollAllPrim(null)").isExValidation("");
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESCollAllPrim");
} }
@Test @Test
public void runEsNameParaKeys() throws Exception { public void runEsNameParaKeys() throws Exception {
testUri.run(encode("ESAllKey(PropertyString='O''Neil',PropertyBoolean=true,PropertyByte=255," testUri.run(encode("ESAllKey(PropertyString='O''Neil',PropertyBoolean=true,PropertyByte=255,"
+ "PropertySByte=-128,PropertyInt16=-32768,PropertyInt32=-2147483648," + "PropertySByte=-128,PropertyInt16=-32768,PropertyInt32=-2147483648,"
+ "PropertyInt64=-9223372036854775808,PropertyDecimal=0.1,PropertyDate=2013-09-25," + "PropertyInt64=-9223372036854775808,PropertyDecimal=1,PropertyDate=2013-09-25,"
+ "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00," + "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00,"
+ "PropertyDuration=duration'P10DT5H34M21.123456789012S'," + "PropertyDuration=duration'P50903316DT2H25M4S',"
+ "PropertyGuid=12345678-1234-1234-1234-123456789012," + "PropertyGuid=12345678-1234-1234-1234-123456789012,"
+ "PropertyTimeOfDay=12:34:55.123456789012)")) + "PropertyTimeOfDay=12:34:55)"))
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.first() .first()
.isEntitySet("ESAllKey") .isEntitySet("ESAllKey")
@ -1092,12 +1089,12 @@ public class TestFullResourcePath {
.isKeyPredicate(4, "PropertyInt16", "-32768") .isKeyPredicate(4, "PropertyInt16", "-32768")
.isKeyPredicate(5, "PropertyInt32", "-2147483648") .isKeyPredicate(5, "PropertyInt32", "-2147483648")
.isKeyPredicate(6, "PropertyInt64", "-9223372036854775808") .isKeyPredicate(6, "PropertyInt64", "-9223372036854775808")
.isKeyPredicate(7, "PropertyDecimal", "0.1") .isKeyPredicate(7, "PropertyDecimal", "1")
.isKeyPredicate(8, "PropertyDate", "2013-09-25") .isKeyPredicate(8, "PropertyDate", "2013-09-25")
.isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00") .isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'") .isKeyPredicate(10, "PropertyDuration", "duration'P50903316DT2H25M4S'")
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012") .isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012"); .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55");
} }
@Test @Test
@ -3321,7 +3318,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.first() .first()
.isFunction("UFCRTETTwoKeyNavParamCTTwoPrim") .isFunction("UFCRTETTwoKeyNavParamCTTwoPrim")
.isParameterAlias(0, "ParameterCTTwoPrim", "ParamAlias"); .isParameterAlias(0, "ParameterCTTwoPrim", "@ParamAlias");
testFilter.runOnETTwoKeyNav("PropertyComp" testFilter.runOnETTwoKeyNav("PropertyComp"
+ "/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam" + "/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
@ -3446,7 +3443,7 @@ public class TestFullResourcePath {
.root().left().goPath() .root().left().goPath()
.first() .first()
.isFunction("UFCRTETTwoKeyNavParam") .isFunction("UFCRTETTwoKeyNavParam")
.isParameterAlias(0, "ParameterInt16", "Param1Alias") .isParameterAlias(0, "ParameterInt16", "@Param1Alias")
.n() .n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
@ -5091,7 +5088,8 @@ public class TestFullResourcePath {
public void testAlias() throws Exception { public void testAlias() throws Exception {
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath() testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicateAlias(1, "PropertyString", "A") .isKeyPredicateAlias(1, "PropertyString", "@A")
.isInAliasToValueMap("@A", "'2'")
.goUpUriValidator() .goUpUriValidator()
.isCustomParameter(0, "@A", "'2'"); .isCustomParameter(0, "@A", "'2'");

View File

@ -47,14 +47,14 @@ public class TestUriParserImpl {
private final String PropertyDate = "PropertyDate=2013-09-25"; private final String PropertyDate = "PropertyDate=2013-09-25";
private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00"; private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00";
private final String PropertyDecimal = "PropertyDecimal=12"; private final String PropertyDecimal = "PropertyDecimal=12";
private final String PropertyDuration = "PropertyDuration=duration'P10DT5H34M21.123456789012S'"; private final String PropertyDuration = "PropertyDuration=duration'P50903316DT2H25M4S'";
private final String PropertyGuid = "PropertyGuid=12345678-1234-1234-1234-123456789012"; private final String PropertyGuid = "PropertyGuid=12345678-1234-1234-1234-123456789012";
private final String PropertyInt16 = "PropertyInt16=1"; private final String PropertyInt16 = "PropertyInt16=1";
private final String PropertyInt32 = "PropertyInt32=12"; private final String PropertyInt32 = "PropertyInt32=12";
private final String PropertyInt64 = "PropertyInt64=64"; private final String PropertyInt64 = "PropertyInt64=64";
private final String PropertySByte = "PropertySByte=1"; private final String PropertySByte = "PropertySByte=1";
private final String PropertyString = "PropertyString='ABC'"; private final String PropertyString = "PropertyString='ABC'";
private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55.123456789012"; private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55";
private final String allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte private final String allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte
+ "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate + "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate
@ -358,9 +358,9 @@ public class TestUriParserImpl {
.isKeyPredicate(7, "PropertyDecimal", "12") .isKeyPredicate(7, "PropertyDecimal", "12")
.isKeyPredicate(8, "PropertyDate", "2013-09-25") .isKeyPredicate(8, "PropertyDate", "2013-09-25")
.isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00") .isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'") .isKeyPredicate(10, "PropertyDuration", "duration'P50903316DT2H25M4S'")
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012") .isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012"); .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55");
} }
@Test @Test

View File

@ -597,4 +597,10 @@ public class ResourceValidator implements TestValidator {
return this; return this;
} }
public ResourceValidator isInAliasToValueMap(String alias, String value) {
String valueForAlias = uriInfo.getValueForAlias(alias);
assertEquals(value, valueForAlias);
return this;
}
} }

View File

@ -71,9 +71,12 @@ public class TestUriValidator implements TestValidator {
uriInfo = null; uriInfo = null;
try { try {
uriInfo = (UriInfoImpl) parser.parseUri(uri, edm); uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET);
fail("Exception expected"); fail("Exception expected");
} catch (UriParserException e) { } catch (UriParserException e) {
exception = e; exception = e;
} catch (UriValidationException e) {
exception = e;
} }
return this; return this;
@ -252,4 +255,9 @@ public class TestUriValidator implements TestValidator {
return this; return this;
} }
public TestUriValidator isExValidation(String string) {
assertEquals(UriValidationException.class, exception.getClass());
return this;
}
} }

View File

@ -331,6 +331,12 @@ public class UriValidatorTest {
parseAndValidate(uri, HttpMethod.GET); parseAndValidate(uri, HttpMethod.GET);
} }
@Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongValueTypeForValidateMethod() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString='abc')";
parseAndValidate(uri, HttpMethod.GET);
}
@Test @Test
public void checkValidSystemQueryOption() throws Exception { public void checkValidSystemQueryOption() throws Exception {
String[] uris = constructUri(urisWithValidSystemQueryOptions); String[] uris = constructUri(urisWithValidSystemQueryOptions);