Author: mibo
Date: Tue Apr 28 11:41:47 2015
New Revision: 1676498

URL: http://svn.apache.org/r1676498
Log:
CMS commit to olingo by mibo

Modified:
    olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext

Modified: 
olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext
URL: 
http://svn.apache.org/viewvc/olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext?rev=1676498&r1=1676497&r2=1676498&view=diff
==============================================================================
--- olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext 
(original)
+++ olingo/site/trunk/content/doc/odata4/tutorials/read/tutorial_read.mdtext 
Tue Apr 28 11:41:47 2015
@@ -355,21 +355,20 @@ Let’s have a closer look at the met
 
 First, we need to declare some constants, to be used in below code
 
-```java
-// Service Namespace
-public static final String NAMESPACE = "com.example.model";
-
-// EDM Container
-public static final String CONTAINER_NAME = "Container";
-public static final FullQualifiedName CONTAINER = new 
FullQualifiedName(NAMESPACE, CONTAINER_NAME);
-
-// Entity Types Names
-public static final String ET_PRODUCT_NAME = "Product";
-public static final FullQualifiedName ET_PRODUCT_FQN = new 
FullQualifiedName(NAMESPACE, ET_PRODUCT_NAME);
-
-// Entity Set Names
-public static final String ES_PRODUCTS_NAME = "Products";
-```
+    // Service Namespace
+    public static final String NAMESPACE = "com.example.model";
+
+    // EDM Container
+    public static final String CONTAINER_NAME = "Container";
+    public static final FullQualifiedName CONTAINER = new 
FullQualifiedName(NAMESPACE, CONTAINER_NAME);
+
+    // Entity Types Names
+    public static final String ET_PRODUCT_NAME = "Product";
+    public static final FullQualifiedName ET_PRODUCT_FQN = new 
FullQualifiedName(NAMESPACE, ET_PRODUCT_NAME);
+
+    // Entity Set Names
+    public static final String ES_PRODUCTS_NAME = "Products";
+
 
 
 **_getEntityType()_**
@@ -385,34 +384,32 @@ The properties: name and type and additi
 Which of the properties is the “key” property: a reference to the “ID” 
property.  
 
 
-```java
-@Override
-public EntityType getEntityType(FullQualifiedName entityTypeName) throws 
ODataException {
-
-       // this method is called for one of the EntityTypes that are configured 
in the Schema
-       if(entityTypeName.equals(ET_PRODUCT_FQN)){
-
-               //create EntityType properties
-               Property id = new 
Property().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
-               Property name = new 
Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
-               Property  description = new 
Property().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
-
-               // create PropertyRef for Key element
-               PropertyRef propertyRef = new PropertyRef();
-               propertyRef.setPropertyName("ID");
-
-               // configure EntityType
-               EntityType entityType = new EntityType();
-               entityType.setName(ET_PRODUCT_NAME);
-               entityType.setProperties(Arrays.asList(id, name , description));
-               entityType.setKey(Arrays.asList(propertyRef));
-
-               return entityType;
-       }
-
-       return null;
-}
-```
+    @Override
+    public EntityType getEntityType(FullQualifiedName entityTypeName) throws 
ODataException {
+
+       // this method is called for one of the EntityTypes that are configured 
in the Schema
+       if(entityTypeName.equals(ET_PRODUCT_FQN)){
+
+               //create EntityType properties
+               Property id = new 
Property().setName("ID").setType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName());
+               Property name = new 
Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
+               Property  description = new 
Property().setName("Description").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
+
+               // create PropertyRef for Key element
+               PropertyRef propertyRef = new PropertyRef();
+               propertyRef.setPropertyName("ID");
+
+               // configure EntityType
+               EntityType entityType = new EntityType();
+               entityType.setName(ET_PRODUCT_NAME);
+               entityType.setProperties(Arrays.asList(id, name , description));
+               entityType.setKey(Arrays.asList(propertyRef));
+
+               return entityType;
+       }
+
+       return null;
+    }
 
 
 **_getEntitySet()_**
@@ -420,29 +417,29 @@ public EntityType getEntityType(FullQual
 The procedure for declaring the _EntitySets_ is similar.
 An _EntitySet_ is a crucial resource, when an OData service is used to request 
data.
 In our example, we’ll invoke the following URL, which we expect to provide 
us a list of products:
-```html
-http://localhost:8080/DemoService/DemoServlet.svc/Products
-```
+
+    http://localhost:8080/DemoService/DemoServlet.svc/Products
+
 When declaring an _EntitySet_, we need to define the type of entries which are 
contained in the list. Such type is an _EntityType_.
 In our example, we set our previously created _EntityType_, which is referred 
by a _FullQualifiedName_.
 
-```java
-@Override
-public EntitySet getEntitySet(FullQualifiedName entityContainer, String 
entitySetName) throws ODataException {
-
-       if(entityContainer.equals(CONTAINER)){
-               if(entitySetName.equals(ES_PRODUCTS_NAME)){
-                       EntitySet entitySet = new EntitySet();
-                       entitySet.setName(ES_PRODUCTS_NAME);
-                       entitySet.setType(ET_PRODUCT_FQN);
-
-                       return entitySet;
-               }
-       }
-
-       return null;
-}
-```
+
+    @Override
+    public EntitySet getEntitySet(FullQualifiedName entityContainer, String 
entitySetName) throws ODataException {
+
+       if(entityContainer.equals(CONTAINER)){
+               if(entitySetName.equals(ES_PRODUCTS_NAME)){
+                       EntitySet entitySet = new EntitySet();
+                       entitySet.setName(ES_PRODUCTS_NAME);
+                       entitySet.setType(ET_PRODUCT_FQN);
+
+                       return entitySet;
+               }
+       }
+
+       return null;
+    }
+
 
 
 **_getEntityContainer()_**
@@ -450,22 +447,21 @@ public EntitySet getEntitySet(FullQualif
 In order to provide data, our OData service needs an _EntityContainer_ that 
carries the _EntitySets_.
 In our example, we have only one _EntitySet_, so we create one 
_EntityContainer_ and set our _EntitySet_.
 
-```java
-@Override
-public EntityContainer getEntityContainer() throws ODataException {
-
-       // create EntitySets
-       List<EntitySet> entitySets = new ArrayList<EntitySet>();
-       entitySets.add(getEntitySet(CONTAINER, ES_PRODUCTS_NAME));
-
-       // create EntityContainer
-       EntityContainer entityContainer = new EntityContainer();
-       entityContainer.setName(CONTAINER_NAME);
-       entityContainer.setEntitySets(entitySets);
-
-       return entityContainer;
-}
-```
+
+    @Override
+    public EntityContainer getEntityContainer() throws ODataException {
+
+       // create EntitySets
+       List<EntitySet> entitySets = new ArrayList<EntitySet>();
+       entitySets.add(getEntitySet(CONTAINER, ES_PRODUCTS_NAME));
+
+       // create EntityContainer
+       EntityContainer entityContainer = new EntityContainer();
+       entityContainer.setName(CONTAINER_NAME);
+       entityContainer.setEntitySets(entitySets);
+
+       return entityContainer;
+    }
 
 
 **_getSchemas()_**
@@ -477,47 +473,46 @@ So, in our example, we create a list of
 The schema is configured with a _Namespace_, which serves to uniquely identify 
all elements.  
 Then our elements are added to the Schema.
 
-```java
-@Override
-public List<Schema> getSchemas() throws ODataException {
-
-       // create Schema
-       Schema schema = new Schema();
-       schema.setNamespace(NAMESPACE);
-
-       // add EntityTypes
-       List<EntityType> entityTypes = new ArrayList<EntityType>();
-       entityTypes.add(getEntityType(ET_PRODUCT_FQN));
-       schema.setEntityTypes(entityTypes);
-
-       // add EntityContainer
-       schema.setEntityContainer(getEntityContainer());
-
-       // finally
-       List<Schema> schemas = new ArrayList<Schema>();
-       schemas.add(schema);
-
-       return schemas;
-}
-```
+
+    @Override
+    public List<Schema> getSchemas() throws ODataException {
+
+       // create Schema
+       Schema schema = new Schema();
+       schema.setNamespace(NAMESPACE);
+
+       // add EntityTypes
+       List<EntityType> entityTypes = new ArrayList<EntityType>();
+       entityTypes.add(getEntityType(ET_PRODUCT_FQN));
+       schema.setEntityTypes(entityTypes);
+
+       // add EntityContainer
+       schema.setEntityContainer(getEntityContainer());
+
+       // finally
+       List<Schema> schemas = new ArrayList<Schema>();
+       schemas.add(schema);
+
+       return schemas;
+    }
 
 
 **_getEntityContainerInfo()_**
 
-```java
-@Override
-public EntityContainerInfo getEntityContainerInfo(FullQualifiedName 
entityContainerName) throws ODataException {
-
-// This method is invoked when displaying the service document at e.g. 
http://localhost:8080/DemoService/DemoService.svc
-       if(entityContainerName == null || 
entityContainerName.equals(CONTAINER)){
-               EntityContainerInfo entityContainerInfo = new 
EntityContainerInfo();
-               entityContainerInfo.setContainerName(CONTAINER);
-               return entityContainerInfo;
-       }
-
-       return null;
-}
-```
+
+    @Override
+    public EntityContainerInfo getEntityContainerInfo(FullQualifiedName 
entityContainerName) throws ODataException {
+
+    // This method is invoked when displaying the service document at e.g. 
http://localhost:8080/DemoService/DemoService.svc
+       if(entityContainerName == null || 
entityContainerName.equals(CONTAINER)){
+               EntityContainerInfo entityContainerInfo = new 
EntityContainerInfo();
+               entityContainerInfo.setContainerName(CONTAINER);
+               return entityContainerInfo;
+       }
+
+       return null;
+    }
+
 
 **Summary:**  
 We have created a class that declares the metadata of our OData service.
@@ -526,46 +521,46 @@ We have declared the main elements of an
 At runtime of an OData service, such metadata can be viewed by invoking the 
Metadata Document.
 
 In our example:
-```
-http://localhost:8080/DemoService/DemoService.svc/$metadata
-```
-
-```xml
-<?xml version='1.0' encoding='UTF-8'?>
-<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx";>
-  <edmx:DataServices>
-    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm"; 
Namespace="com.example.model">
-      <EntityType Name="Product">
-        <Key>
-          <PropertyRef Name="ID"/>
-        </Key>
-        <Property Name="ID" Type="Edm.Int32"/>
-        <Property Name="Name" Type="Edm.String"/>
-        <Property Name="Description" Type="Edm.String"/>
-      </EntityType>
-      <EntityContainer Name="Container">
-        <EntitySet Name="Products" EntityType="com.example.model.Product"/>
-      </EntityContainer>
-    </Schema>
-  </edmx:DataServices>
-</edmx:Edmx>
-```
+
+    http://localhost:8080/DemoService/DemoService.svc/$metadata
+
+
+
+    <?xml version='1.0' encoding='UTF-8'?>
+    <edmx:Edmx Version="4.0" 
xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx";>
+      <edmx:DataServices>
+        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm"; 
Namespace="com.example.model">
+          <EntityType Name="Product">
+            <Key>
+              <PropertyRef Name="ID"/>
+            </Key>
+            <Property Name="ID" Type="Edm.Int32"/>
+            <Property Name="Name" Type="Edm.String"/>
+            <Property Name="Description" Type="Edm.String"/>
+          </EntityType>
+          <EntityContainer Name="Container">
+            <EntitySet Name="Products" EntityType="com.example.model.Product"/>
+          </EntityContainer>
+        </Schema>
+      </edmx:DataServices>
+    </edmx:Edmx>
+
 
 The Service Document can be invoked to view the Entity Sets, like in our 
example at
-```
-http://localhost:8080/DemoService/DemoService.svc/
-```
-
-```json
-{
-  "@odata.context" : 
"http://localhost:8080/DemoService/DemoService.svc/$metadata";,
-  "value" : [
-  {
-    "name" : "Products",
-    "url" : "Products"
-  } ]
-}
-```
+
+    http://localhost:8080/DemoService/DemoService.svc/
+
+
+
+    {
+      "@odata.context" : 
"http://localhost:8080/DemoService/DemoService.svc/$metadata";,
+      "value" : [
+      {
+        "name" : "Products",
+        "url" : "Products"
+      } ]
+    }
+
 
 > Note:  
 > After implementing the _EdmProvider_, we can, as an intermediate step, 
 > build/deploy the service and invoke the 2 static pages:   service document 
 > and metadata document.  
@@ -621,9 +616,10 @@ Within our package _myservice.mynamespac
 ### 4.2.3. Implement the required methods
 
 After creation of the Java class, we can see that there are 2 methods to be 
implemented:
-* _init()_  
-       This method is invoked by the _Olingo_ Framework, allowing us to store 
the context object
-* _readEntityCollection()_  
+
+  * _init()_  
+         This method is invoked by the _Olingo_ Framework, allowing us to 
store the context object
+  * _readEntityCollection()_  
     Here we have to fetch the required data and pass it back to the _Olingo_ 
FWK
 
 
@@ -637,17 +633,16 @@ The _Olingo_ framework initializes the p
 According to the Javadoc, this object is the “Root object for serving 
factory tasks…”
 We’ll need it later, so we store it as member variable.
 
-```java
-       public void init(OData odata, ServiceMetadata serviceMetadata) {
-               this.odata = odata;
-       }
-```
+
+    public void init(OData odata, ServiceMetadata serviceMetadata) {
+       this.odata = odata;
+    }
+
 
 Don’t forget to declare the member variable
 
-```java
-       private OData odata;
-```
+
+    private OData odata;
 
 **_readEntityCollection()_**
 
@@ -695,56 +690,55 @@ Because the _readEntityCollection_ metho
 
 The steps for implementating the method _readEntityCollection_ are:
 
-1. Which data is requested?  
-Usually, an OData service provides different _EntitySets_, so first it is 
required to identify which _EntitySet_ has been requested. This information can 
be retrieved from the _uriInfo_ object
-
-2. Fetch the data  
-As a developer of the OData service, you have to know how and where the data 
is stored. In many cases, this would be a database. At this point, you would 
connect to your database and fetch the requested data with an appropriate SQL 
statement. The data that is fetched from the data storage has to be put into an 
_EntitySet_ object.
-Note that this object has to be of type _EntitySet_, not _EdmEntitySet_  
-The package _org.apache.olingo.commons.api.data_ provides interfaces that 
describe the actual data, not the metadata.
+  1. Which data is requested?  
+  Usually, an OData service provides different _EntitySets_, so first it is 
required to identify which _EntitySet_ has been requested. This information can 
be retrieved from the _uriInfo_ object
+  2. Fetch the data
+  As a developer of the OData service, you have to know how and where the data 
is stored. In many cases, this would be a database. At this point, you would 
connect to your database and fetch the requested data with an appropriate SQL 
statement. The data that is fetched from the data storage has to be put into an 
_EntitySet_ object.
+  Note that this object has to be of type _EntitySet_, not _EdmEntitySet_  
+  The package _org.apache.olingo.commons.api.data_ provides interfaces that 
describe the actual data, not the metadata.
 
 ![datapackage](datapackage.png "The package containing the interfaces for 
handling runtime data")
 
-3. Transform the data  
-_Olingo_ expects from us to provide the data as low-level _InputStream_ 
object. However, _Olingo_ supports us in doing so, by providing us with a 
proper "serializer".
-So what we have to do is create the serializer based on the requested content 
type, configure it and call it.
+  3. Transform the data  
+  _Olingo_ expects from us to provide the data as low-level _InputStream_ 
object. However, _Olingo_ supports us in doing so, by providing us with a 
proper "serializer".
+  So what we have to do is create the serializer based on the requested 
content type, configure it and call it.
+
+  4. Configure the response  
+  The response object has been passed to us in the method signature. We use it 
to set the serialized data (the _InputStream_ object).  
+  Furthermore, we have to set the HTTP status code, which means that we have 
the opportunity to do proper error handling.  
+  And finally we have to set the content type.
+
+
+    public void readEntityCollection(ODataRequest request, ODataResponse 
response, UriInfo uriInfo, ContentType responseFormat)
+                         throws ODataApplicationException, SerializerException 
{
+
+       // 1st retrieve the requested EntitySet from the uriInfo 
(representation of the parsed URI)
+       List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
+       // in our example, the first segment is the EntitySet:
+       UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) 
resourcePaths.get(0);
+       EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
+
+       // 2nd: fetch the data from backend for this requested EntitySetName 
and delivere as EntitySet
+       EntitySet entitySet = getData(edmEntitySet);
+
+       // 3rd: create a serializer based on the requested format (json)
+       ODataFormat format = ODataFormat.fromContentType(responseFormat);
+       ODataSerializer serializer = odata.createSerializer(format);
+
+       // and serialize the content: transform from the EntitySet object to 
InputStream
+       EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+       ContextURL contextUrl = 
ContextURL.with().entitySet(edmEntitySet).build();
+
+        EntityCollectionSerializerOptions opts =
+                        
EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
+       InputStream serializedContent = 
serializer.entityCollection(edmEntityType, entitySet, opts);
+
+       // 4th: configure the response object: set the body, headers and status 
code
+       response.setContent(serializedContent);
+       response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+       response.setHeader(HttpHeader.CONTENT_TYPE, 
responseFormat.toContentTypeString());
+    }
 
-4. Configure the response  
-The response object has been passed to us in the method signature. We use it 
to set the serialized data (the _InputStream_ object).  
-Furthermore, we have to set the HTTP status code, which means that we have the 
opportunity to do proper error handling.  
-And finally we have to set the content type.
-
-```java
-public void readEntityCollection(ODataRequest request, ODataResponse response, 
UriInfo uriInfo, ContentType responseFormat)
-                     throws ODataApplicationException, SerializerException {
-
-       // 1st retrieve the requested EntitySet from the uriInfo 
(representation of the parsed URI)
-       List<UriResource> resourcePaths = uriInfo.getUriResourceParts();
-       // in our example, the first segment is the EntitySet:
-       UriResourceEntitySet uriResourceEntitySet = (UriResourceEntitySet) 
resourcePaths.get(0);
-       EdmEntitySet edmEntitySet = uriResourceEntitySet.getEntitySet();
-
-       // 2nd: fetch the data from backend for this requested EntitySetName 
and delivere as EntitySet
-       EntitySet entitySet = getData(edmEntitySet);
-
-       // 3rd: create a serializer based on the requested format (json)
-       ODataFormat format = ODataFormat.fromContentType(responseFormat);
-       ODataSerializer serializer = odata.createSerializer(format);
-
-       // and serialize the content: transform from the EntitySet object to 
InputStream
-       EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-       ContextURL contextUrl = 
ContextURL.with().entitySet(edmEntitySet).build();
-
-    EntityCollectionSerializerOptions opts =
-                    
EntityCollectionSerializerOptions.with().contextURL(contextUrl).build();
-       InputStream serializedContent = 
serializer.entityCollection(edmEntityType, entitySet, opts);
-
-       // 4th: configure the response object: set the body, headers and status 
code
-       response.setContent(serializedContent);
-       response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-       response.setHeader(HttpHeader.CONTENT_TYPE, 
responseFormat.toContentTypeString());
-}
-```
 
 **_getData()_**
 
@@ -753,30 +747,29 @@ In our tutorial, to keep the code as sim
 Since we’re supposed to deliver the data inside an _EntitySet_ instance, we 
create the instance, ask it for the (initially empty) list of entities and add 
some new entities to it.  
 We create the entities and their properties according to what we declared in 
our _ExampleEdmProvider_ class. So we have to take care to provide the correct 
names to the new property objects.
 
-```java
-private EntitySet getData(EdmEntitySet edmEntitySet){
 
-       EntitySet entitySet = new EntitySetImpl();
-       List<Entity> entityList = entitySet.getEntities();
+    private EntitySet getData(EdmEntitySet edmEntitySet){
+
+       EntitySet entitySet = new EntitySetImpl();
+       List<Entity> entityList = entitySet.getEntities();
 
-       // add some sample product entities
-       entityList.add(new EntityImpl()
-               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
1))
-               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "Notebook Basic 15"))
-               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 
40GB")));
-       entityList.add(new EntityImpl()
-               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
2))
-               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "1UMTS PDA"))
-               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM 
network")));
-
-       entityList.add(new EntityImpl()
-               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
3))
-               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "Ergo Screen"))
-               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "17 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 
x 960")));
-
-       return entitySet;
-}
-```
+       // add some sample product entities
+       entityList.add(new EntityImpl()
+               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
1))
+               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "Notebook Basic 15"))
+               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 
40GB")));
+       entityList.add(new EntityImpl()
+               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
2))
+               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "1UMTS PDA"))
+               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM 
network")));
+
+       entityList.add(new EntityImpl()
+               .addProperty(new PropertyImpl(null, "ID", ValueType.PRIMITIVE, 
3))
+               .addProperty(new PropertyImpl(null, "Name", 
ValueType.PRIMITIVE, "Ergo Screen"))
+               .addProperty(new PropertyImpl(null, "Description", 
ValueType.PRIMITIVE, "17 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 
x 960")));
+
+       return entitySet;
+    }
 
 
 
@@ -808,36 +801,35 @@ Furthermore, the _ODataHttpHandler_ need
 
 As such, here’s the location where our 2 implemented classes come together, 
the metadata declaration and the data provisioning.
 
-```java
-// This class represents a standard HttpServlet implementation.
-// It is used as main entry point for the web application that carries the 
OData service.
-// The implementation of this HttpServlet simply delegates the user requests 
to the ODataHttpHandler
-public class DemoServlet extends HttpServlet {
-
-       private static final long serialVersionUID = 1L;
-       private static final Logger LOG = 
LoggerFactory.getLogger(DemoServlet.class);
-
-       @Override
-       protected void service(final HttpServletRequest req, final 
HttpServletResponse resp) throws ServletException, IOException {
-
-               try {
-                       // create odata handler and configure it with 
EdmProvider and Processor
-                       OData odata = OData.newInstance();
-                       ServiceMetadata edm = odata.createServiceMetadata(new 
ExampleEdmProvider(), new ArrayList<EdmxReference>());
-                       ODataHttpHandler handler = odata.createHandler(edm);
-                       handler.register(new DemoEntityCollectionProcessor());
-
-                       // let the handler do the work
-                       handler.process(req, resp);
-
-               } catch (RuntimeException e) {
-                       LOG.error("Server Error ocurred in DemoServlet", e);
-                       throw new ServletException(e);
-               }
-       }
-}
 
-```
+    // This class represents a standard HttpServlet implementation.
+    // It is used as main entry point for the web application that carries the 
OData service.
+    // The implementation of this HttpServlet simply delegates the user 
requests to the ODataHttpHandler
+    public class DemoServlet extends HttpServlet {
+
+       private static final long serialVersionUID = 1L;
+       private static final Logger LOG = 
LoggerFactory.getLogger(DemoServlet.class);
+
+       @Override
+       protected void service(final HttpServletRequest req, final 
HttpServletResponse resp) throws ServletException, IOException {
+
+               try {
+                       // create odata handler and configure it with 
EdmProvider and Processor
+                       OData odata = OData.newInstance();
+                       ServiceMetadata edm = odata.createServiceMetadata(new 
ExampleEdmProvider(), new ArrayList<EdmxReference>());
+                       ODataHttpHandler handler = odata.createHandler(edm);
+                       handler.register(new DemoEntityCollectionProcessor());
+
+                       // let the handler do the work
+                       handler.process(req, resp);
+
+               } catch (RuntimeException e) {
+                       LOG.error("Server Error ocurred in DemoServlet", e);
+                       throw new ServletException(e);
+               }
+       }
+    }
+
 
 ### 4.3.2. Edit the web.xml
 
@@ -847,26 +839,25 @@ Furthermore, we need to specify the _url
 Open the _src/main/webapp/WEB-INF/web.xml_ file and paste the following 
content into it:
 
 
-```xml
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-    xmlns="http://java.sun.com/xml/ns/javaee";
-    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
-    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
-    id="WebApp_ID" version="2.5">
-
-<servlet>
-  <servlet-name>DemoServlet</servlet-name>
-  <servlet-class> myservice.mynamespace.web.DemoServlet</servlet-class>
-  <load-on-startup>1</load-on-startup>
-</servlet>
-
-<servlet-mapping>
-  <servlet-name>DemoServlet</servlet-name>
-  <url-pattern>/DemoService.svc/*</url-pattern>
-</servlet-mapping>
-</web-app>
 
-```
+    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xmlns="http://java.sun.com/xml/ns/javaee";
+        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
+        id="WebApp_ID" version="2.5">
+
+    <servlet>
+      <servlet-name>DemoServlet</servlet-name>
+      <servlet-class> myservice.mynamespace.web.DemoServlet</servlet-class>
+      <load-on-startup>1</load-on-startup>
+    </servlet>
+
+    <servlet-mapping>
+      <servlet-name>DemoServlet</servlet-name>
+      <url-pattern>/DemoService.svc/*</url-pattern>
+    </servlet-mapping>
+    </web-app>
+
 
 That’s it. Now we can build and run the web application.
 
@@ -905,78 +896,77 @@ Try the following URLs:
 
 **Service Document**
 
-```
-http://localhost:8080/DemoService/DemoService.svc/
-```
+    http://localhost:8080/DemoService/DemoService.svc/
+
 The expected result is the service document which displays our 
_EntityContainerInfo_:
 
-```json
-{
-  "@odata.context" : 
"http://localhost:8080/DemoService/DemoService.svc/$metadata";,
-  "value" : [
-  {
-    "name" : "Products",
-    "url" : "Products"
-  } ]
-}
-```
+
+    {
+      "@odata.context" : 
"http://localhost:8080/DemoService/DemoService.svc/$metadata";,
+      "value" : [
+      {
+        "name" : "Products",
+        "url" : "Products"
+      } ]
+    }
+
 
 **Metadata Document**
 
-```
-http://localhost:8080/ExampleService1/ExampleService1.svc/$metadata
-```
+
+    http://localhost:8080/ExampleService1/ExampleService1.svc/$metadata
+
 The expected result is the metadata document that displays our _Schema_, 
_EntityType_, _EntityContainer_ and _EntitySet_.
 
-```xml
-<?xml version='1.0' encoding='UTF-8'?>
-<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx";>
-  <edmx:DataServices>
-    <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm"; 
Namespace="com.example.model">
-      <EntityType Name="Product">
-        <Key>
-          <PropertyRef Name="ID"/>
-        </Key>
-        <Property Name="ID" Type="Edm.Int32"/>
-        <Property Name="Name" Type="Edm.String"/>
-        <Property Name="Description" Type="Edm.String"/>
-      </EntityType>
-      <EntityContainer Name="Container">
-        <EntitySet Name="Products" EntityType="com.example.model.Product"/>
-      </EntityContainer>
-    </Schema>
-  </edmx:DataServices>
-</edmx:Edmx>
-```
+
+    <?xml version='1.0' encoding='UTF-8'?>
+    <edmx:Edmx Version="4.0" 
xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx";>
+      <edmx:DataServices>
+        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm"; 
Namespace="com.example.model">
+          <EntityType Name="Product">
+            <Key>
+              <PropertyRef Name="ID"/>
+            </Key>
+            <Property Name="ID" Type="Edm.Int32"/>
+            <Property Name="Name" Type="Edm.String"/>
+            <Property Name="Description" Type="Edm.String"/>
+          </EntityType>
+          <EntityContainer Name="Container">
+            <EntitySet Name="Products" EntityType="com.example.model.Product"/>
+          </EntityContainer>
+        </Schema>
+      </edmx:DataServices>
+    </edmx:Edmx>
+
 
 **Query / EntitySet**
 
-```
-http://localhost:8080/DemoService/DemoService.svc/Products
-```
+
+    http://localhost:8080/DemoService/DemoService.svc/Products
+
 The expected result is the hardcoded list of product entries, which we have 
coded in our processor implementation:
 
-```json
-{
-  "@odata.context":"$metadata#Products","
-  value":[
-    {
-      "ID":1,
-      "Name":"Notebook Basic 15",
-      "Description":"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 
40GB"
-    },
-    {
-      "ID":2,
-      "Name":"1UMTS PDA",
-      "Description":"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM network"
-    },
+
     {
-      "ID":3,
-      "Name":"Ergo Screen",
-      "Description":"17 Optimum Resolution 1024 x 768 @ 85Hz, resolution 1280 
x 960"
-  }]
-}
-```
+      "@odata.context":"$metadata#Products","
+      value":[
+        {
+          "ID":1,
+          "Name":"Notebook Basic 15",
+          "Description":"Notebook Basic, 1.7GHz - 15 XGA - 1024MB DDR2 SDRAM - 
40GB"
+        },
+        {
+          "ID":2,
+          "Name":"1UMTS PDA",
+          "Description":"Ultrafast 3G UMTS/HSDPA Pocket PC, supports GSM 
network"
+        },
+        {
+          "ID":3,
+          "Name":"Ergo Screen",
+          "Description":"17 Optimum Resolution 1024 x 768 @ 85Hz, resolution 
1280 x 960"
+      }]
+    }
+
 
 
 ---


Reply via email to