You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/09/17 09:25:31 UTC

[06/10] olingo-odata4 git commit: [OLINGO-713] Fixed all tutorials for xml

[OLINGO-713] Fixed all tutorials for xml


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

Branch: refs/heads/master
Commit: 8cfca8e5537d1c21156a982e45f6bf99079666ce
Parents: dec27a4
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Sep 17 08:54:11 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Sep 17 08:54:11 2015 +0200

----------------------------------------------------------------------
 .../service/DemoEntityCollectionProcessor.java  |  4 +-
 .../myservice/mynamespace/data/Storage.java     | 47 ++++++++++++------
 .../service/DemoEntityCollectionProcessor.java  |  4 +-
 .../myservice/mynamespace/data/Storage.java     | 39 ++++++++++-----
 .../service/DemoEntityCollectionProcessor.java  |  4 +-
 .../myservice/mynamespace/data/Storage.java     | 38 +++++++++++++++
 .../service/DemoEntityCollectionProcessor.java  |  4 +-
 .../myservice/mynamespace/data/Storage.java     | 50 +++++++++++++-------
 .../service/DemoEntityCollectionProcessor.java  |  3 +-
 .../myservice/mynamespace/data/Storage.java     | 40 ++++++++++++++++
 .../mynamespace/service/DemoEdmProvider.java    |  2 +
 .../service/DemoEntityCollectionProcessor.java  |  5 ++
 .../service/DemoEntityProcessor.java            |  3 ++
 .../myservice/mynamespace/data/Storage.java     | 47 ++++++++++++------
 .../service/DemoEntityCollectionProcessor.java  |  4 +-
 .../myservice/mynamespace/data/Storage.java     | 47 ++++++++++++------
 .../service/DemoEntityCollectionProcessor.java  |  9 ++--
 17 files changed, 269 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p1_read/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p1_read/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p1_read/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 4e4567b..6cd0cad 100755
--- a/samples/tutorials/p1_read/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p1_read/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -83,7 +83,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
     EdmEntityType edmEntityType = edmEntitySet.getEntityType();
     ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
-    EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
+    EntityCollectionSerializerOptions opts =
+        EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
     SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
 
     // Finally: configure the response object: set the body, headers and status code

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/data/Storage.java
index d5d16c2..a8374b4 100755
--- a/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.uri.UriParameter;
@@ -106,20 +109,36 @@ public class Storage {
 	private void initSampleData(){
 
 		// add some sample product entities
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
+		final Entity e1 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
+		e1.setId(createId("Products", 1));
+		productList.add(e1);
+
+		final Entity e2 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
+		e2.setId(createId("Products", 1));
+		productList.add(e2);
+
+		final Entity e3 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
+		e3.setId(createId("Products", 1));
+		productList.add(e3);
+	}
 
+	private URI createId(String entitySetName, Object id) {
+		try {
+			return new URI(entitySetName + "(" + String.valueOf(id) + ")");
+		} catch (URISyntaxException e) {
+			throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
+		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 9b6e25a..f02ebdd 100755
--- a/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p2_readep/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -76,7 +76,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
 		EdmEntityType edmEntityType = edmEntitySet.getEntityType();
 		ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
-		EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+		final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
+		EntityCollectionSerializerOptions opts =
+				EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
 		SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entityCollection, opts);
 		InputStream serializedContent = serializerResult.getContent();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/data/Storage.java
index ad5dd71..e078462 100755
--- a/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/data/Storage.java
@@ -27,11 +27,14 @@ import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.uri.UriParameter;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -235,29 +238,39 @@ public class Storage {
     return false;
   }
 
-  private void initSampleData() {
+  private void initSampleData(){
 
     // add some sample product entities
-    productList.add(new Entity()
+    final Entity e1 = new Entity()
         .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
         .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
-        .addProperty(
-            new Property(null, "Description", ValueType.PRIMITIVE,
-                "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
+        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+            "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
+    e1.setId(createId("Products", 1));
+    productList.add(e1);
 
-    productList.add(new Entity()
+    final Entity e2 = new Entity()
         .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
         .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
-        .addProperty(
-            new Property(null, "Description", ValueType.PRIMITIVE,
-                "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
+        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+            "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
+    e2.setId(createId("Products", 1));
+    productList.add(e2);
 
-    productList.add(new Entity()
+    final Entity e3 = new Entity()
         .addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
         .addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
-        .addProperty(
-            new Property(null, "Description", ValueType.PRIMITIVE,
-                "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
+        .addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+            "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
+    e3.setId(createId("Products", 1));
+    productList.add(e3);
+  }
 
+  private URI createId(String entitySetName, Object id) {
+    try {
+      return new URI(entitySetName + "(" + String.valueOf(id) + ")");
+    } catch (URISyntaxException e) {
+      throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index bae1ec5..77614e3 100755
--- a/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p3_write/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -80,7 +80,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
     EdmEntityType edmEntityType = edmEntitySet.getEntityType();
     ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
-    EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
+    EntityCollectionSerializerOptions opts =
+        EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
     SerializerResult serializedContent = serializer.entityCollection(serviceMetadata, edmEntityType, entitySet, opts);
 
     // Finally: configure the response object: set the body, headers and status code

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/data/Storage.java
index 2034fe6..9b2d342 100755
--- a/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.uri.UriParameter;
 
 public class Storage {
@@ -184,6 +187,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -192,6 +196,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Notebook Professional, 2.8GHz - 15 XGA - 8GB DDR3 RAM - 500GB"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -200,6 +205,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -208,6 +214,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "32 GB Digital Assitant with high-resolution color screen"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -216,6 +223,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -224,6 +232,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Optimum Hi-Resolution max. 1600 x 1200 @ 85Hz, Dot Pitch: 0.24mm"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
   }
 
@@ -234,19 +243,48 @@ public class Storage {
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebooks"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
 
     entity = new Entity();
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Organizers"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
 
     entity = new Entity();
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Monitors"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
   }
 
+  private URI createId(Entity entity, String idPropertyName) {
+    return createId(entity, idPropertyName, null);
+  }
+
+  private URI createId(Entity entity, String idPropertyName, String navigationName) {
+    try {
+      StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
+      final Property property = entity.getProperty(idPropertyName);
+      sb.append(property.asPrimitive()).append(")");
+      if(navigationName != null) {
+        sb.append("/").append(navigationName);
+      }
+      return new URI(sb.toString());
+    } catch (URISyntaxException e) {
+      throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
+    }
+  }
+
+  private String getEntitySetName(Entity entity) {
+    if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
+      return DemoEdmProvider.ES_CATEGORIES_NAME;
+    } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
+      return DemoEdmProvider.ES_PRODUCTS_NAME;
+    }
+    return entity.getType();
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 5a87c0d..b11d3a0 100755
--- a/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p4_navigation/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -132,7 +132,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
 
     // 3rd: create and configure a serializer
     ContextURL contextUrl = ContextURL.with().entitySet(responseEdmEntitySet).build();
-    EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+    final String id = request.getRawBaseUri() + "/" + responseEdmEntitySet.getName();
+    EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
+        .contextURL(contextUrl).setId(id).build();
     EdmEntityType edmEntityType = responseEdmEntitySet.getEntityType();
 
     ODataSerializer serializer = odata.createSerializer(responseFormat);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/data/Storage.java
index 2aa9fac..794940c 100755
--- a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.uri.UriParameter;
@@ -108,23 +111,36 @@ public class Storage {
 	private void initSampleData(){
 
 		// add some sample product entities
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
-              "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
-              "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
-              "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
+		final Entity e1 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
+		e1.setId(createId("Products", 1));
+		productList.add(e1);
+
+		final Entity e2 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
+		e2.setId(createId("Products", 1));
+		productList.add(e2);
+
+		final Entity e3 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
+		e3.setId(createId("Products", 1));
+		productList.add(e3);
+	}
 
+	private URI createId(String entitySetName, Object id) {
+		try {
+			return new URI(entitySetName + "(" + String.valueOf(id) + ")");
+		} catch (URISyntaxException e) {
+			throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
+		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index ee3558e..a33cd73 100755
--- a/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p5_queryoptions-tcs/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -133,8 +133,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
     EdmEntityType edmEntityType = edmEntitySet.getEntityType();
     ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
+    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
     EntityCollectionSerializerOptions opts =
-        EntityCollectionSerializerOptions.with().contextURL(contextUrl).count(countOption).build();
+        EntityCollectionSerializerOptions.with().contextURL(contextUrl).setId(id).count(countOption).build();
     SerializerResult serializerResult =
         serializer.entityCollection(serviceMetadata, edmEntityType, returnEntityCollection, opts);
     InputStream serializedContent = serializerResult.getContent();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/data/Storage.java
index 2034fe6..4fd1ada 100755
--- a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.uri.UriParameter;
 
 public class Storage {
@@ -101,6 +104,7 @@ public class Storage {
 
     if (sourceEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString())
         && relatedEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN)) {
+      navigationTargetEntityCollection.setId(createId(sourceEntity, "ID", DemoEdmProvider.NAV_TO_CATEGORY));
       // relation Products->Category (result all categories)
       int productID = (Integer) sourceEntity.getProperty("ID").getValue();
       if (productID == 1 || productID == 2) {
@@ -112,6 +116,7 @@ public class Storage {
       }
     } else if (sourceEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString())
         && relatedEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN)) {
+      navigationTargetEntityCollection.setId(createId(sourceEntity, "ID", DemoEdmProvider.NAV_TO_PRODUCTS));
       // relation Category->Products (result all products)
       int categoryID = (Integer) sourceEntity.getProperty("ID").getValue();
       if (categoryID == 1) {
@@ -184,6 +189,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -192,6 +198,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Notebook Professional, 2.8GHz - 15 XGA - 8GB DDR3 RAM - 500GB"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -200,6 +207,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -208,6 +216,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "32 GB Digital Assitant with high-resolution color screen"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -216,6 +225,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
 
     entity = new Entity();
@@ -224,6 +234,7 @@ public class Storage {
     entity.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
         "Optimum Hi-Resolution max. 1600 x 1200 @ 85Hz, Dot Pitch: 0.24mm"));
     entity.setType(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     productList.add(entity);
   }
 
@@ -234,19 +245,48 @@ public class Storage {
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebooks"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
 
     entity = new Entity();
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Organizers"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
 
     entity = new Entity();
     entity.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3));
     entity.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Monitors"));
     entity.setType(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString());
+    entity.setId(createId(entity, "ID"));
     categoryList.add(entity);
   }
 
+  private URI createId(Entity entity, String idPropertyName) {
+    return createId(entity, idPropertyName, null);
+  }
+
+  private URI createId(Entity entity, String idPropertyName, String navigationName) {
+    try {
+      StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
+      final Property property = entity.getProperty(idPropertyName);
+      sb.append(property.asPrimitive()).append(")");
+      if(navigationName != null) {
+        sb.append("/").append(navigationName);
+      }
+      return new URI(sb.toString());
+    } catch (URISyntaxException e) {
+      throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
+    }
+  }
+
+  private String getEntitySetName(Entity entity) {
+    if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
+      return DemoEdmProvider.ES_CATEGORIES_NAME;
+    } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
+      return DemoEdmProvider.ES_PRODUCTS_NAME;
+    }
+    return entity.getType();
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEdmProvider.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEdmProvider.java b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEdmProvider.java
index 8ce9bac..4ffd461 100755
--- a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEdmProvider.java
+++ b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEdmProvider.java
@@ -54,6 +54,8 @@ public class DemoEdmProvider extends CsdlAbstractEdmProvider {
   // Entity Set Names
   public static final String ES_PRODUCTS_NAME = "Products";
   public static final String ES_CATEGORIES_NAME = "Categories";
+  public static final String NAV_TO_CATEGORY = "Category";
+  public static final String NAV_TO_PRODUCTS = "Products";
 
   @Override
   public CsdlEntityType getEntityType(FullQualifiedName entityTypeName) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 14ac8cb..eb6f23b 100755
--- a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -138,16 +138,19 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
           Link link = new Link();
           link.setTitle(navPropName);
           link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
+          link.setRel(Constants.NS_ASSOCIATION_LINK_REL + navPropName);
 
           if (edmNavigationProperty.isCollection()) { // in case of Categories/$expand=Products
             // fetch the data for the $expand (to-many navigation) from backend
             EntityCollection expandEntityCollection = storage.getRelatedEntityCollection(entity, expandEdmEntityType);
             link.setInlineEntitySet(expandEntityCollection);
+            link.setHref(expandEntityCollection.getId().toASCIIString());
           } else { // in case of Products?$expand=Category
             // fetch the data for the $expand (to-one navigation) from backend
             // here we get the data for the expand
             Entity expandEntity = storage.getRelatedEntity(entity, expandEdmEntityType);
             link.setInlineEntity(expandEntity);
+            link.setHref(expandEntity.getId().toASCIIString());
           }
 
           // set the link - containing the expanded data - to the current entity
@@ -163,10 +166,12 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
     ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).selectList(selectList).build();
 
     // adding the selectOption to the serializerOpts will actually tell the lib to do the job
+    final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
     EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
         .contextURL(contextUrl)
         .select(selectOption)
         .expand(expandOption)
+        .setId(id)
         .build();
 
     ODataSerializer serializer = odata.createSerializer(responseFormat);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityProcessor.java b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityProcessor.java
index 6b623b0..18372aa 100755
--- a/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityProcessor.java
+++ b/samples/tutorials/p6_queryoptions-es/src/main/java/myservice/mynamespace/service/DemoEntityProcessor.java
@@ -133,17 +133,20 @@ public class DemoEntityProcessor implements EntityProcessor {
 				Link link = new Link();
 				link.setTitle(navPropName);
 				link.setType(Constants.ENTITY_NAVIGATION_LINK_TYPE);
+				link.setRel(Constants.NS_ASSOCIATION_LINK_REL + navPropName);
 
 				if(edmNavigationProperty.isCollection()){ // in case of Categories(1)/$expand=Products
 					// fetch the data for the $expand (to-many navigation) from backend
 					// here we get the data for the expand
 					EntityCollection expandEntityCollection = storage.getRelatedEntityCollection(entity, expandEdmEntityType);
 					link.setInlineEntitySet(expandEntityCollection);
+					link.setHref(expandEntityCollection.getId().toASCIIString());
 				} else {  // in case of Products(1)?$expand=Category
 					// fetch the data for the $expand (to-one navigation) from backend
 					// here we get the data for the expand
 					Entity expandEntity = storage.getRelatedEntity(entity, expandEdmEntityType);
 					link.setInlineEntity(expandEntity);
+					link.setHref(expandEntity.getId().toASCIIString());
 				}
 
 				// set the link - containing the expanded data - to the current entity

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/data/Storage.java
index d5d16c2..a8374b4 100644
--- a/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.uri.UriParameter;
@@ -106,20 +109,36 @@ public class Storage {
 	private void initSampleData(){
 
 		// add some sample product entities
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
+		final Entity e1 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
+		e1.setId(createId("Products", 1));
+		productList.add(e1);
+
+		final Entity e2 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
+		e2.setId(createId("Products", 1));
+		productList.add(e2);
+
+		final Entity e3 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
+		e3.setId(createId("Products", 1));
+		productList.add(e3);
+	}
 
+	private URI createId(String entitySetName, Object id) {
+		try {
+			return new URI(entitySetName + "(" + String.valueOf(id) + ")");
+		} catch (URISyntaxException e) {
+			throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
+		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 5b5a5eb..48f4660 100644
--- a/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p7_queryoptions-o/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -134,7 +134,9 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
 		EdmEntityType edmEntityType = edmEntitySet.getEntityType();
 		ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
-		EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+		final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
+		EntityCollectionSerializerOptions opts =
+				EntityCollectionSerializerOptions.with().setId(id).contextURL(contextUrl).build();
     SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, 
                                                                     entityCollection, opts);
 		InputStream serializedContent = serializerResult.getContent();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/data/Storage.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/data/Storage.java b/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/data/Storage.java
index d5d16c2..a8374b4 100644
--- a/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/data/Storage.java
+++ b/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/data/Storage.java
@@ -18,6 +18,8 @@
  */
 package myservice.mynamespace.data;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -31,6 +33,7 @@ import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.uri.UriParameter;
@@ -106,20 +109,36 @@ public class Storage {
 	private void initSampleData(){
 
 		// add some sample product entities
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network")));
-
-		productList.add(new Entity()
-			.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
-			.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
-			.addProperty(new Property(null, "Description", ValueType.PRIMITIVE, "19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960")));
+		final Entity e1 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 1))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Notebook Basic 15"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 40GB"));
+		e1.setId(createId("Products", 1));
+		productList.add(e1);
+
+		final Entity e2 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 2))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "1UMTS PDA"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"));
+		e2.setId(createId("Products", 1));
+		productList.add(e2);
+
+		final Entity e3 = new Entity()
+				.addProperty(new Property(null, "ID", ValueType.PRIMITIVE, 3))
+				.addProperty(new Property(null, "Name", ValueType.PRIMITIVE, "Ergo Screen"))
+				.addProperty(new Property(null, "Description", ValueType.PRIMITIVE,
+						"19 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 x 960"));
+		e3.setId(createId("Products", 1));
+		productList.add(e3);
+	}
 
+	private URI createId(String entitySetName, Object id) {
+		try {
+			return new URI(entitySetName + "(" + String.valueOf(id) + ")");
+		} catch (URISyntaxException e) {
+			throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
+		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8cfca8e5/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
----------------------------------------------------------------------
diff --git a/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java b/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
index 861b786..140d0e7 100644
--- a/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
+++ b/samples/tutorials/p8_queryoptions-f/src/main/java/myservice/mynamespace/service/DemoEntityCollectionProcessor.java
@@ -122,9 +122,12 @@ public class DemoEntityCollectionProcessor implements EntityCollectionProcessor
 		EdmEntityType edmEntityType = edmEntitySet.getEntityType();
 		ContextURL contextUrl = ContextURL.with().entitySet(edmEntitySet).build();
 
-		EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
-		SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, 
-		                                                                entityCollection, opts);
+		final String id = request.getRawBaseUri() + "/" + edmEntitySet.getName();
+		EntityCollectionSerializerOptions opts = EntityCollectionSerializerOptions.with()
+				.contextURL(contextUrl).setId(id).build();
+		SerializerResult serializerResult = serializer.entityCollection(serviceMetadata, edmEntityType, entityCollection,
+				opts);
+
 		InputStream serializedContent = serializerResult.getContent();
 
 		// 5th: configure the response object: set the body, headers and status code