You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2016/11/22 13:21:31 UTC

[2/2] olingo-odata4 git commit: [OLINGO-917] Fix $entity request handling

[OLINGO-917] Fix $entity request handling

This is a contribution from Ramya in
https://issues.apache.org/jira/browse/OLINGO-917


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

Branch: refs/heads/master
Commit: 6a736db10c3ef9d990dda637809a6514f27cb66b
Parents: 84a052d
Author: Christian Amend <ch...@sap.com>
Authored: Tue Nov 22 14:17:59 2016 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Nov 22 14:17:59 2016 +0100

----------------------------------------------------------------------
 .../olingo/server/core/ServiceDispatcher.java   |   2 +-
 .../olingo/server/core/ServiceRequest.java      |   3 +-
 .../olingo/server/core/ODataDispatcher.java     |   1 +
 .../olingo/server/core/ODataHandlerImpl.java    |   2 +-
 .../olingo/server/core/uri/UriHelperImpl.java   |   2 +-
 .../olingo/server/core/uri/parser/Parser.java   | 117 ++++++++++++++-----
 .../server/core/uri/parser/UriDecoder.java      |   2 +-
 .../uri/parser/UriParserSemanticException.java  |   4 +-
 .../uri/parser/UriParserSyntaxException.java    |   4 +-
 .../server-core-exceptions-i18n.properties      |   2 +
 .../tecsvc/processor/TechnicalProcessor.java    |   2 +-
 .../server/core/PreconditionsValidatorTest.java |   4 +-
 .../server/core/uri/parser/ApplyParserTest.java |   2 +-
 .../core/uri/parser/ExpandParserTest.java       |   4 +-
 .../server/core/uri/parser/UriParserTest.java   |  76 +++++++++++-
 .../core/uri/testutil/FilterValidator.java      |   4 +-
 .../core/uri/testutil/ResourceValidator.java    |   2 +-
 .../core/uri/testutil/TestUriValidator.java     |  21 +++-
 .../core/uri/validator/UriValidatorTest.java    |   4 +-
 19 files changed, 203 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
index a6d39b6..877ea70 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
@@ -90,7 +90,7 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
         executeIdOption(query, odRequest, odResponse);
       } else {
         UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
-          .parseUri(path, query, null);
+          .parseUri(path, query, null, odRequest.getRawBaseUri());
         
         contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
             odRequest, this.customContentSupport, RepresentationType.ERROR);      

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
index 29c7134..c973ba6 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceRequest.java
@@ -340,7 +340,8 @@ public abstract class ServiceRequest {
       rawPath = rawPath.substring(e+path.length());
     }
 
-    UriInfo uriInfo = new Parser(serviceMetadata.getEdm(), odata).parseUri(rawPath, uri.getQuery(), null);
+    UriInfo uriInfo = new Parser(serviceMetadata.getEdm(), odata).parseUri(rawPath, uri.getQuery(), null, 
+        getODataRequest().getRawBaseUri());
     ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType);
     dispatcher.visit(uriInfo);
     dispatcher.request.setUriInfo(uriInfo);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java
index 5d48e34..d460ee7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataDispatcher.java
@@ -109,6 +109,7 @@ public class ODataDispatcher {
       break;
 
     case resource:
+    case entityId:
       handleResourceDispatching(request, response);
       break;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
index 921124c..d1a9cf2 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandlerImpl.java
@@ -136,7 +136,7 @@ public class ODataHandlerImpl implements ODataHandler {
     final int measurementUriParser = debugger.startRuntimeMeasurement("Parser", "parseUri");
     try {
       uriInfo = new Parser(serviceMetadata.getEdm(), odata)
-          .parseUri(request.getRawODataPath(), request.getRawQueryPath(), null);
+          .parseUri(request.getRawODataPath(), request.getRawQueryPath(), null, request.getRawBaseUri());
     } catch (final ODataLibraryException e) {
       debugger.stopRuntimeMeasurement(measurementUriParser);
       debugger.stopRuntimeMeasurement(measurementHandle);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
index f5d4bd0..ee4636b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
@@ -146,7 +146,7 @@ public class UriHelperImpl implements UriHelper {
 
     try {
       final List<UriResource> uriResourceParts =
-          new Parser(edm, new ODataImpl()).parseUri(oDataPath, null, null).getUriResourceParts();
+          new Parser(edm, new ODataImpl()).parseUri(oDataPath, null, null, rawServiceRoot).getUriResourceParts();
       if (uriResourceParts.size() == 1 && uriResourceParts.get(0).getKind() == UriResourceKind.entitySet) {
         final UriResourceEntitySet entityUriResource = (UriResourceEntitySet) uriResourceParts.get(0);
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
index 82e69eb..0ce8c75 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
@@ -78,6 +78,8 @@ public class Parser {
   private static final String DOLLAR = "$";
   private static final String AT = "@";
   private static final String NULL = "null";
+  private static final String ENTITY = "$entity";
+  private static final String HTTP = "http";
 
   private final Edm edm;
   private final OData odata;
@@ -87,7 +89,7 @@ public class Parser {
     this.odata = odata;
   }
 
-  public UriInfo parseUri(final String path, final String query, final String fragment)
+  public UriInfo parseUri(final String path, final String query, final String fragment, String baseUri)
       throws UriParserException, UriValidationException {
 
     UriInfoImpl contextUriInfo = new UriInfoImpl();
@@ -149,16 +151,55 @@ public class Parser {
       contextIsCollection = true;
 
     } else if (firstSegment.equals("$entity")) {
-      contextUriInfo.setKind(UriInfoKind.entityId);
-      if (numberOfSegments > 1) {
-        final String typeCastSegment = pathSegmentsDecoded.get(1);
-        ensureLastSegment(typeCastSegment, 2, numberOfSegments);
-        contextType = new ResourcePathParser(edm, contextUriInfo.getAliasMap())
-            .parseDollarEntityTypeCast(typeCastSegment);
-        contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
+      if (null != contextUriInfo.getIdOption()) {
+        String idOptionText = contextUriInfo.getIdOption().getText();
+        if (idOptionText.startsWith(HTTP)) {
+          baseUri = UriDecoder.decode(baseUri);
+          if (idOptionText.contains(baseUri)) {
+            idOptionText = idOptionText.substring(baseUri.length() + 1);
+          } else {
+            throw new UriParserSemanticException("$id cannot have an absolute path",
+                UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
+          }
+        }
+        if (numberOfSegments > 1) {
+          /**
+           * If url is of the form 
+           * http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/
+           * olingo.odata.test1.ETAllPrim?$id=ESAllPrim(32767)
+           */
+          final ResourcePathParser resourcePathParser = new ResourcePathParser
+            (edm, contextUriInfo.getAliasMap());
+          String typeCastSegment = pathSegmentsDecoded.get(1);
+          ensureLastSegment(typeCastSegment, 2, numberOfSegments);
+          contextType = resourcePathParser.parseDollarEntityTypeCast(typeCastSegment);
+          contextUriInfo = (UriInfoImpl) new Parser(edm, odata).
+              parseUri("/" + idOptionText, query, fragment, baseUri);
+          contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
+        } else if (numberOfSegments == 1) {
+          /**
+           * If url is of the form 
+           * http://localhost:8080/odata-server-tecsvc/odata.svc/$entity?$id=ESAllPrim(32527)
+           */
+          contextUriInfo = (UriInfoImpl) new Parser(edm, odata).
+                  parseUri("/" + idOptionText, query, fragment, baseUri);
+        }
+        contextType = contextUriInfo.getEntityTypeCast();
+        contextUriInfo.setKind(UriInfoKind.entityId);
+        contextIsCollection = false;
+      } else {
+        /**
+         * If url is of the form 
+         * http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/olingo.odata.test1.ETKeyNav/$ref
+         */
+        ensureLastSegment(firstSegment, 2, numberOfSegments);
+        /**
+         * If url is of the form 
+         * http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/olingo.odata.test1.ETKeyNav
+         */
+        throw new UriParserSyntaxException("The entity-id MUST be specified using the system query option $id",
+                  UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
       }
-      contextIsCollection = false;
-
     } else if (firstSegment.startsWith("$crossjoin")) {
       ensureLastSegment(firstSegment, 1, numberOfSegments);
       contextUriInfo.setKind(UriInfoKind.crossjoin);
@@ -176,35 +217,49 @@ public class Parser {
       UriResource lastSegment = null;
       for (final String pathSegment : pathSegmentsDecoded) {
         count++;
-        final UriResource segment = resourcePathParser.parsePathSegment(pathSegment, lastSegment);
-        if (segment != null) {
-          if (segment instanceof UriResourceCount
-              || segment instanceof UriResourceRef
-              || segment instanceof UriResourceValue) {
-            ensureLastSegment(pathSegment, count, numberOfSegments);
-          } else if (segment instanceof UriResourceAction
-              || segment instanceof UriResourceFunction
-              && !((UriResourceFunction) segment).getFunction().isComposable()) {
-            if (count < numberOfSegments) {
-              throw new UriValidationException(
-                  "The segment of an action or of a non-composable function must be the last resource-path segment.",
-                  UriValidationException.MessageKeys.UNALLOWED_RESOURCE_PATH,
-                  pathSegmentsDecoded.get(count));
+        if (pathSegment.startsWith(ENTITY)) {
+          /**
+           * If url is of the form 
+           * http://localhost:8080/odata-server-tecsvc/odata.svc/ESAllPrim/$entity
+           */
+          throw new UriParserSyntaxException("The entity-id MUST be specified using the system query option $id",
+                    UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
+        } else {
+          final UriResource segment = resourcePathParser.parsePathSegment(pathSegment, lastSegment);
+          if (segment != null) {
+            if (segment instanceof UriResourceCount
+                || segment instanceof UriResourceRef
+                || segment instanceof UriResourceValue) {
+              ensureLastSegment(pathSegment, count, numberOfSegments);
+            } else if (segment instanceof UriResourceAction
+                || segment instanceof UriResourceFunction
+                && !((UriResourceFunction) segment).getFunction().isComposable()) {
+              if (count < numberOfSegments) {
+                throw new UriValidationException(
+                    "The segment of an action or of a non-composable function must be the last resource-path segment.",
+                    UriValidationException.MessageKeys.UNALLOWED_RESOURCE_PATH,
+                    pathSegmentsDecoded.get(count));
+              }
+              lastSegment = segment;
+            } else if (segment instanceof UriResourceStartingTypeFilterImpl) {
+              throw new UriParserSemanticException("First resource-path segment must not be namespace-qualified.",
+                  UriParserSemanticException.MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+            } else {
+              lastSegment = segment;
             }
-            lastSegment = segment;
-          } else if (segment instanceof UriResourceStartingTypeFilterImpl) {
-            throw new UriParserSemanticException("First resource-path segment must not be namespace-qualified.",
-                UriParserSemanticException.MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
-          } else {
-            lastSegment = segment;
+            contextUriInfo.addResourcePart(segment);
           }
-          contextUriInfo.addResourcePart(segment);
         }
       }
 
       if (lastSegment instanceof UriResourcePartTyped) {
         final UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment;
         contextType = ParserHelper.getTypeInformation(typed);
+        if (contextUriInfo.getIdOption() != null && contextType != null) {
+          if (contextType instanceof EdmEntityType) {
+            contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
+          }
+        }
         contextIsCollection = typed.isCollection();
       }
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
index 4a94e85..65cbd4f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
@@ -78,7 +78,7 @@ public class UriDecoder {
     return list;
   }
 
-  private static String decode(final String encoded) throws UriParserSyntaxException {
+  public static String decode(final String encoded) throws UriParserSyntaxException {
     try {
       return Decoder.decode(encoded);
     } catch (final IllegalArgumentException e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 8260af7..ab24a4f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -75,7 +75,9 @@ public class UriParserSemanticException extends UriParserException {
     ONLY_FOR_PRIMITIVE_TYPES,
     /** parameter: function name */
     FUNCTION_MUST_USE_COLLECTIONS,
-    COLLECTION_NOT_ALLOWED;
+    COLLECTION_NOT_ALLOWED,
+    /** parameter: not implemented part for system query option $id */
+    NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION;
 
     @Override
     public String getKey() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
index 895e31e..be989ac 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
@@ -37,7 +37,9 @@ public class UriParserSyntaxException extends UriParserException {
     SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE,
     SYNTAX,
     /** parameter: alias name */
-    DUPLICATED_ALIAS;
+    DUPLICATED_ALIAS,
+    /**Entity id must be followed by system query option id */
+    ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID;
 
     @Override
     public String getKey() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 5768565..3b261ac 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -36,6 +36,7 @@ UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system q
 UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
 UriParserSyntaxException.SYNTAX=The URI is malformed.
 UriParserSyntaxException.DUPLICATED_ALIAS=Duplicated alias. An alias '%1$s' was already specified!.
+UriParserSyntaxException.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID=The entity-id must be specified using the system query option $id.
 
 SearchParserException.NO_EXPRESSION_FOUND=No expression found.
 SearchParserException.TOKENIZER_EXCEPTION=Exception during tokenizer creation with message '%1$s'.
@@ -77,6 +78,7 @@ UriParserSemanticException.IS_PROPERTY=The identifier '%1$s' is already used as
 UriParserSemanticException.ONLY_FOR_PRIMITIVE_TYPES='%1$s' is only allowed for primitive-type expressions.
 UriParserSemanticException.FUNCTION_MUST_USE_COLLECTIONS=Only bound functions with collections of structural types as binding parameter and as return type are allowed; '%1$s' is not such a function.
 UriParserSemanticException.COLLECTION_NOT_ALLOWED=A collection expression is not allowed.
+UriParserSemanticException.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION=$id with absolute url different from base url is not implemented!
 
 UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
 UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 47a9a63..fc6991f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -250,7 +250,7 @@ public abstract class TechnicalProcessor implements Processor {
   }
 
   protected void validateOptions(final UriInfoResource uriInfo) throws ODataApplicationException {
-    if (uriInfo.getIdOption() != null || uriInfo.getApplyOption() != null) {
+    if (uriInfo.getApplyOption() != null) {
       throw new ODataApplicationException("Not all of the specified options are supported.",
           HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
index 4d73a4d..154e529 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
@@ -141,7 +141,7 @@ public class PreconditionsValidatorTest {
 
   @Test
   public void simpleEntityValueValidationNotActiveForMedia() throws Exception {
-    final UriInfo uriInfo = new Parser(edm, odata).parseUri("ESMedia(1)/$value", null, null);
+    final UriInfo uriInfo = new Parser(edm, odata).parseUri("ESMedia(1)/$value", null, null, null);
 
     CustomETagSupport support = mock(CustomETagSupport.class);
     when(support.hasETag(any(EdmBindingTarget.class))).thenReturn(true);
@@ -193,7 +193,7 @@ public class PreconditionsValidatorTest {
 
   private boolean mustValidate(final String uri, final String entitySetName)
       throws UriParserException, UriValidationException, PreconditionException {
-    final UriInfo uriInfo = new Parser(edm, odata).parseUri(uri, null, null);
+    final UriInfo uriInfo = new Parser(edm, odata).parseUri(uri, null, null, null);
     final List<UriResource> parts = uriInfo.getUriResourceParts();
     final boolean isMedia = parts.size() >= 2
         && parts.get(parts.size() - 1) instanceof UriResourceValue

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java
index 4286672..c22df73 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java
@@ -498,7 +498,7 @@ public class ApplyParserTest {
 
   private ApplyValidator parse(final String path, final String apply)
       throws UriParserException, UriValidationException {
-    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, "$apply=" + apply, null);
+    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, "$apply=" + apply, null, null);
     return new ApplyValidator(uriInfo.getApplyOption());
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ExpandParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ExpandParserTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ExpandParserTest.java
index e2f129d..97504da 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ExpandParserTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ExpandParserTest.java
@@ -252,7 +252,7 @@ public class ExpandParserTest {
   @Test
   public void expandNavigationApplyOption() throws Exception {
     UriInfo uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
-        "$expand=NavPropertyETKeyNavMany($apply=identity),NavPropertyETKeyNavOne", null);
+        "$expand=NavPropertyETKeyNavMany($apply=identity),NavPropertyETKeyNavOne", null, null);
     Assert.assertEquals(ApplyItem.Kind.IDENTITY,
         uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0).getKind());
     Assert.assertEquals("NavPropertyETKeyNavOne",
@@ -260,7 +260,7 @@ public class ExpandParserTest {
             .getResourcePath().getUriResourceParts().get(0).getSegmentValue());
 
     uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
-        "$expand=NavPropertyETKeyNavMany($apply=aggregate(PropertyInt16 with sum as s))", null);
+        "$expand=NavPropertyETKeyNavMany($apply=aggregate(PropertyInt16 with sum as s))", null, null);
     final ApplyItem applyItem =
         uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0);
     Assert.assertEquals(ApplyItem.Kind.AGGREGATE, applyItem.getKind());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
index 693f5b6..e77139a 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/UriParserTest.java
@@ -71,7 +71,9 @@ public class UriParserTest {
     testUri.runEx("$all/$ref").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
     testUri.runEx("$entity/olingo.odata.test1.ETKeyNav/$ref")
         .isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
-
+    testUri.runEx("$entity/olingo.odata.test1.ETKeyNav")
+        .isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
+    
     testUri.runEx("$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
     testUri.runEx("", "$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION);
 
@@ -252,6 +254,78 @@ public class UriParserTest {
         .isEntityType(EntityTypeProvider.nameETBase)
         .isIdText("ESTwoPrim(1)")
         .goExpand().first().isSegmentStar();
+    
+    try {
+      testUri.run("$entity/olingo.odata.test1.ETAllNullable")
+      .isKind(UriInfoKind.entityId)
+      .isEntityType(EntityTypeProvider.nameETAllNullable);
+    } catch (UriParserSyntaxException e) {
+      testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
+    }
+    testUri.run("$entity/Namespace1_Alias.ETAllPrim", "$id=ESAllPrim(32767)")
+    .isKind(UriInfoKind.entityId)
+    .isEntityType(EntityTypeProvider.nameETAllPrim)
+    .isIdText("ESAllPrim(32767)");
+    try {
+      testUri.run("ESAllPrim/$entity")
+    .isKind(UriInfoKind.resource);
+    } catch (UriParserSyntaxException e) {
+      testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
+    }
+    try {
+      testUri.run("ESAllPrim(32767)/NavPropertyETTwoPrimOne/$entity")
+    .isKind(UriInfoKind.resource);
+    } catch(UriParserSyntaxException e) {
+      testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
+    }
+    testUri.run("$entity", "$id=ESAllPrim(32767)/NavPropertyETTwoPrimOne")
+      .isKind(UriInfoKind.entityId)
+      .isEntityType(EntityTypeProvider.nameETTwoPrim)
+    .isIdText("ESAllPrim(32767)/NavPropertyETTwoPrimOne");
+    testUri.run("$entity", "$id=ESAllPrim(32767)", "$select=PropertyString", null)
+    .isKind(UriInfoKind.entityId)
+    .isEntityType(EntityTypeProvider.nameETAllPrim)
+      .isIdText("ESAllPrim(32767)");
+    testUri.run("$entity", "$id=ESAllPrim(32767)", "$expand=NavPropertyETTwoPrimOne", null)
+    .isKind(UriInfoKind.entityId)
+    .isEntityType(EntityTypeProvider.nameETAllPrim)
+      .isIdText("ESAllPrim(32767)");  
+    testUri.run("$entity", "$id=http://localhost:8080/odata-server-tecsvc/odata.svc/"
+        + "ESAllPrim(32767)/NavPropertyETTwoPrimOne", null, 
+        "http://localhost:8080/odata-server-tecsvc/odata.svc")
+    .isKind(UriInfoKind.entityId)
+    .isEntityType(EntityTypeProvider.nameETTwoPrim)
+    .isIdText("http://localhost:8080/odata-server-tecsvc/odata.svc/"
+        + "ESAllPrim(32767)/NavPropertyETTwoPrimOne");
+    try {
+      testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecsvc/ESKeyNav(1)",
+            null, "http://localhost:80/tecsvc")
+          .isKind(UriInfoKind.entityId)
+          .isEntityType(EntityTypeProvider.nameETKeyNav)
+          .isIdText("http://localhost:90/tecsvc/ESKeyNav(1)");
+    } catch (UriParserSemanticException e) {
+      testUri.isExSemantic(UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
+    }
+    try {
+      testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs%27v; c/ESKeyNav(1)",
+            null, "http://localhost:80/tecs%27v; c")
+          .isKind(UriInfoKind.entityId)
+          .isEntityType(EntityTypeProvider.nameETKeyNav)
+          .isIdText("http://localhost:90/tecs%27v; c/ESKeyNav(1)");
+    } catch (UriParserSemanticException e) {
+      testUri.isExSemantic(UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
+    }
+    testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs%27v%20c/ESKeyNav(1)",
+        null, "http://localhost:90/tecs%27v%20c")
+      .isKind(UriInfoKind.entityId)
+      .isEntityType(EntityTypeProvider.nameETKeyNav);
+    String idOption = UriDecoder.decode("http://localhost:90/tecs%27v%20c/ESKeyNav(1)");
+    testUri.isIdText(idOption);
+    testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs'v c/ESKeyNav(1)",
+        null, "http://localhost:90/tecs'v c")
+      .isKind(UriInfoKind.entityId)
+      .isEntityType(EntityTypeProvider.nameETKeyNav)
+      .isIdText("http://localhost:90/tecs'v c/ESKeyNav(1)");
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
index c7e9e64..246a408 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
@@ -168,7 +168,7 @@ public class FilterValidator implements TestValidator {
 
   public FilterValidator runUri(final String path, final String query)
       throws UriParserException, UriValidationException {
-    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null);
+    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null, null);
     assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
     setFilter(uriInfo.getFilterOption());
     curExpression = filter.getExpression();
@@ -181,7 +181,7 @@ public class FilterValidator implements TestValidator {
 
   public FilterValidator runUriOrderBy(final String path, final String query)
       throws UriParserException, UriValidationException {
-    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null);
+    final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null, null);
     assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
     orderBy = uriInfo.getOrderByOption();
     return this;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
index 658f2c0..147cbd3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
@@ -83,7 +83,7 @@ public class ResourceValidator implements TestValidator {
   public ResourceValidator run(final String path) {
     UriInfo uriInfoTmp = null;
     try {
-      uriInfoTmp = new Parser(edm, odata).parseUri(path, null, null);
+      uriInfoTmp = new Parser(edm, odata).parseUri(path, null, null, null);
     } catch (final ODataLibraryException e) {
       fail("Exception occurred while parsing the URI: " + path + "\n"
           + " Message: " + e.getMessage());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
index 3f1b913..27e2cd4 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
@@ -59,17 +59,28 @@ public class TestUriValidator implements TestValidator {
 
   // Execution
   public TestUriValidator run(final String path) throws UriParserException, UriValidationException {
-    return run(path, null, null);
+    return run(path, null, null, null);
   }
 
   public TestUriValidator run(final String path, final String query)
       throws UriParserException, UriValidationException {
-    return run(path, query, null);
+    return run(path, query, null, null);
   }
-
+  public TestUriValidator run(final String path, final String query, final String fragment, final String baseUri)
+      throws UriParserException, UriValidationException {
+    try {
+      uriInfo = new Parser(edm, odata).parseUri(path, query, fragment, baseUri);
+      new UriValidator().validate(uriInfo, HttpMethod.GET);
+      return this;
+    } catch (UriParserException e) {
+      exception = e;
+      throw e;
+    } 
+  }
+  
   public TestUriValidator run(final String path, final String query, final String fragment)
       throws UriParserException, UriValidationException {
-    uriInfo = new Parser(edm, odata).parseUri(path, query, fragment);
+    uriInfo = new Parser(edm, odata).parseUri(path, query, fragment, null);
     new UriValidator().validate(uriInfo, HttpMethod.GET);
     return this;
   }
@@ -81,7 +92,7 @@ public class TestUriValidator implements TestValidator {
   public TestUriValidator runEx(final String path, final String query) {
     uriInfo = null;
     try {
-      run(path, query, null);
+      run(path, query, null, null);
       fail("Exception expected");
     } catch (UriParserException e) {
       exception = e;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/6a736db1/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
index 61cc000..3c39c41 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
@@ -467,7 +467,7 @@ public class UriValidatorTest {
 
   private void validate(final String path, final String query, final HttpMethod method) {
     try {
-      new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null), method);
+      new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null, null), method);
     } catch (final UriParserException e) {
       fail("Failed for " + method + " on URI: " + path + '?' + query);
     } catch (final UriValidationException e) {
@@ -478,7 +478,7 @@ public class UriValidatorTest {
   private void validateWrong(final String path, final String query, final HttpMethod method,
       final UriValidationException.MessageKeys expectedMessageKey) {
     try {
-      new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null), method);
+      new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null, null), method);
       fail("Validation Exception not thrown: " + method + ' ' + path + '?' + query);
     } catch (final UriParserException e) {
       fail("Wrong Exception thrown: " + method + ' ' + path + '?' + query);