olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r922392 [15/23] - in /websites/staging/olingo/trunk/content: ./ doc/ doc/javascript/ doc/odata2/ doc/odata2/tutorials/ doc/odata4/ doc/odata4/tutorials/ doc/tutorials/
Date Tue, 16 Sep 2014 12:34:20 GMT
Added: websites/staging/olingo/trunk/content/doc/odata4/tutorials/OlingoV2BasicClientSample.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/odata4/tutorials/OlingoV2BasicClientSample.html (added)
+++ websites/staging/olingo/trunk/content/doc/odata4/tutorials/OlingoV2BasicClientSample.html Tue Sep 16 12:34:18 2014
@@ -0,0 +1,1137 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html lang="en">
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="description" content="Apache Olingo provides libraries which enable developers to implement OData producers and OData consumers. The available OData Java library implements OData version 2.0. In future on goal is to provide an OData 4.0 compliant library once the OData standard is published at OASIS. The focus within the community is currently on the Java technology but it is up to the community to discuss if other environments find interest.">
+    <meta name="author" content="">
+    <link rel="icon" href="/favicon.ico">
+    <title>
+      Apache Olingo
+    </title><!-- Bootstrap core CSS -->
+    <link href="/css/bootstrap.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
+    <link href="/css/navbar.css" rel="stylesheet" type="text/css"><!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
+    <link href="/css/offcanvas.css" rel="stylesheet" type="text/css"><!-- Custom styles for this template -->
+    <link rel="stylesheet" href="/css/main.css">
+    <!--[if lt IE 9]><script src="/js/ie8-responsive-file-warning.js"></script><![endif]-->
+
+    <script src="/js/ie-emulation-modes-warning.js" type="text/javascript">
+</script><!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
+
+    <script src="/js/ie10-viewport-bug-workaround.js" type="text/javascript">
+</script><!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
+    <!--[if lt IE 9]>
+      <script src="/js/html5shiv.min.js"></script>
+      <script src="/js/respond.min.js"></script>
+    <![endif]-->
+  </head>
+
+  <body>
+    <div class="container">
+      <!-- Static navbar -->
+      <div class="navbar navbar-default" role="navigation">
+        <div class="container-fluid">
+          <div class="navbar-header">
+            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+              <span class="sr-only">Toggle navigation</span>
+             <span class="icon-bar"></span>
+             <span class="icon-bar"></span>
+             <span class="icon-bar"></span>
+            </button>
+              <img class="navbar-brand" src="/img/OlingoOrangeTM.png" style="width:62px;" >
+              <a class="navbar-brand" href="#">Apache Olingo™</a>
+          </div>
+          <div class="navbar-collapse collapse">
+            <ul class="nav navbar-nav">
+
+              <li><a href="/">Home</a></li>
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">ASF <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                      <li><a href="http://www.apache.org/foundation/">ASF Home</a></li>
+                      <li><a href="http://projects.apache.org/">Projects</a></li>
+                      <li><a href="http://people.apache.org/">People</a></li>
+                      <li><a href="http://www.apache.org/foundation/getinvolved.html">Get Involved</a></li>
+                      <li><a href="http://www.apache.org/dyn/closer.cgi">Download</a></li>
+                      <li><a href="http://www.apache.org/security/">Security</a></li>
+                      <li><a href="http://www.apache.org/foundation/sponsorship.html">Support Apache</a></li>
+                  </ul>
+              </li>
+
+              <li><a href="http://www.apache.org/licenses/">License</a></li>
+
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Download <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                      <li><a href="/doc/odata2/download.html">Download OData 2.0 Java</a></li>
+                      <li><a href="/doc/javascript/download.html">Download OData 4.0 JavaScript</a></li>
+                  </ul>
+              </li>
+
+              <li class="dropdown">
+                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
+                  <ul class="dropdown-menu">
+                    <li><a href="/doc/odata2/index.html">Documentation OData 2.0 Java</a></li>
+                    <li><a href="/doc/javascript/index.html">Documentation OData 4.0 JavaScript</a></li>
+                  </ul>
+              </li>
+              <li><a href="/support.html">Support</a></li>
+
+            </ul>
+
+			  <img class="navbar-right" height="50px" src="/img/asf-logo.gif">
+
+			</div><!--/.nav-collapse -->
+        </div><!--/.container-fluid -->
+      </div><!-- Main component for a primary marketing message or call to action --><h1 id="how-to-use-apache-olingo-as-client-library">How to use Apache Olingo as Client Library</h1>
+<p>This Tutorial shows how to use the Apache Olingo Library for CRUD operations on an OData Service.</p>
+<p>Therefore it contains the <a href="#start">Explaining the Client</a> section which explains how to implement the CRUD operations based on sample code and a <a href="#quickstart">Client Quickstart Guide</a> which give a step by step guide to create a sample and server to see both together in action.</p>
+<ul>
+<li><a href="#quickstart">Client Quickstart Guide</a>: Get a running sample client and server within a few minutes (Requirements at least <em>Java 6 Runtime</em> and <em>Maven 3</em>)</li>
+<li><a href="#start">Explaining the Client</a>: The actual <em>How To</em> with explanation and sample code for following use cases: <a href="#readmetadata">Read the Metadata</a>, <a href="#readdata">Read the Data</a>, <a href="#createdata">Create more Data</a>, <a href="#updatedata">Update the Data</a> and <a href="#deletedata">Delete the Data</a>. After this <em>How To</em> the sample code from all samples can be put together and be executed against a Sample Service which is shown in the <a href="#run">Run the Client</a> section.  </li>
+</ul>
+<hr />
+<p><a name="quickstart"></a></p>
+<h3 id="client-quickstart-guide">Client Quickstart Guide</h3>
+<p>With this Quickstart guide the runable sample client and an sample service is created within a few minutes.
+Therefore it just requires an installed <em>Java 6 Runtime</em>, <em>Maven 3</em> and an internet connection.</p>
+<ol>
+<li>Start in some folder (e.g. <code>Quickstart</code>) which is called our <code>$ROOT</code> in the steps below.</li>
+<li>Create sample Client project (<a href="#projectstructure">more details</a>)<ol>
+<li>Create project folder <code>ClientSample</code> (in <code>$ROOT</code>) and within create following folder structure: <code>./src/main/java/org/apache/olingo/sample/client</code> (e.g. <code>mkdir -p src/main/java/org/apache/olingo/sample/client/</code>).</li>
+<li>In project folder (<code>ClientSample</code>) create file <code>pom.xml</code> and copy <a href="#pom">this sample pom into</a>.</li>
+<li>In folder <code>./src/main/java/org/apache/olingo/sample/client</code> create file <code>OlingoSampleApp.java</code> and copy <a href="#sampleclient">the whole sample client into</a>.</li>
+<li>In project folder <code>ClientSample</code> run <code>mvn</code> to build the project.</li>
+</ol>
+</li>
+<li>Create and start sample Service (<a href="#sampleservice">more details</a>)<ol>
+<li>Go to <code>$ROOT</code> and create service project from archetype via
+<div class="codehilite">
+mvn archetype:generate
+    -DinteractiveMode=false
+    -Dversion=1.0.0-SNAPSHOT
+    -DgroupId=com.sample
+    -DartifactId=my-car-service
+    -DarchetypeGroupId=org.apache.olingo
+    -DarchetypeArtifactId=olingo-odata2-sample-cars-annotation-archetype
+    -DarchetypeVersion=2.0.0
+</div> </li>
+<li>Go into from archetype created folder <code>my-car-service</code> and just run <code>mvn</code> to start the Sample Service on a <em>Jetty Web Server</em> at <a href="http://localhost:8080">http://localhost:8080</a>.</li>
+</ol>
+</li>
+<li>Run <code>OlingoSampleApp</code> against sample Service (<a href="#runsample">more details</a>)<ol>
+<li>Go into sample project folder (<code>ClientSample</code>) and execute sample client via <code>java -cp target/OlingoSampleClient.jar org.apache.olingo.sample.client.OlingoSampleApp</code>.</li>
+<li>Now the result of the <em>read metadata</em>, <em>read/create/update/delete data</em> calls is printed as well as the corresponding <em>JSON</em> requests and response body. Within the following section <a href="#start">Explaining the Client</a> the therefore implemented client methods are shown and explained.</li>
+</ol>
+</li>
+</ol>
+<p><strong>Optional</strong>
+With running <code>mvn eclipse:eclipse</code> within the created sample client and sample server projects the necessary Eclipse project files will be generated so that both projects can easily imported into Eclipse (Eclipse -&gt; <em>File</em> -&gt; <em>Import...</em> <em>Import existing projects into workspace</em>).</p>
+<hr />
+<p><a name="start"></a></p>
+<h3 id="explaining-the-client">Explaining the Client</h3>
+<p>In this Tutorial an overview is given on how to create, read, update and delete an entity at an existing OData Service with support of the Apache Olingo Library.</p>
+<p>Each section explain how to do an operation and shows example code. For simplicity some additional not direct to Apache Olingo releated code is encapsulated in separate methods and is listed in the <em>Additional code</em> section at the end of this tutorial. After finishing this tutorial the listed code samples should compile and run against a local running Olingo Sample Service. Therefore all code samples must be <em>copy / pasted</em> into a single Java class.</p>
+<p>All listed examples (and URIs in the examples) work together with a local running Olingo Sample Service. For set up of this see the <em>Preparing</em> section.</p>
+<p><a name="readedm"></a></p>
+<h5 id="read-edm">Read EDM</h5>
+<p>For an OData Service the <em>Entity Data Model (EDM)</em> defines all <em>metadata</em> information about the provided data of the service. This includes all entities with their type, properties and relations, which entities are provided as entity sets and additional functions and operations provided by the OData Service. The <em>EDM</em> also have to be provided by the OData Service via a unique URI (e.g. <code>http://localhost:8080/MyFormula.svc/$metadata</code>) in the <em>EDMX</em> format.</p>
+<p>This fact is important because the Apache Olingo library requires the <em>metadata</em> for serialization and de-serialization of the data of an entity (e.g. the validation of the data is done against the <em>EDM</em> provided <em>metadata</em>).
+Hence the first step in this sample is to read the whole <em>EDM</em> of an OData Service.</p>
+<p><strong>Code sample: Read EDM ($metadata)</strong></p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="n">Edm</span> <span class="nf">readEdm</span><span class="o">(</span><span class="n">String</span> <span class="n">serviceUrl</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span><span class="o">,</span> <span class="n">ODataException</span> <span class="o">{</span>
+  <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="n">execute</span><span class="o">(</span><span class="n">serviceUrl</span> <span class="o">+</span> <span class="s">&quot;/&quot;</span> <span class="o">+</span> <span class="n">METADATA</span><span class="o">,</span> <span class="n">APPLICATION_XML</span><span class="o">,</span> <span class="n">HTTP_METHOD_GET</span><span class="o">);</span>
+  <span class="k">return</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">readMetadata</span><span class="o">(</span><span class="n">content</span><span class="o">,</span> <span class="kc">false</span><span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>As shown in the sample code to read the <em>EDM</em> a <em>HTTP GET</em> on the corresponding <em>$metadata</em> URI of the OData Service. The resulting conent in form of an <em>EDMX</em> is received via basic <code>HttpURLConnection</code> is pased into the <code>EntityProvider.readMetadata(InputStream content, boolean validate)</code> method which de-serialize the <em>EDMX</em> into an <em>EDM</em> object.</p>
+<p>For read and de-serialize of the <em>EDM</em> this is all what have to be done and the resulting <code>EDM</code> instance than can be used for necessary serialization and de-serialization in combination of <em>CRUD</em> operations supported by Apache Olingo library. </p>
+<p><a name="readdata"></a></p>
+<h5 id="read-entity">Read Entity</h5>
+<p>For reading entities this sample provides two methods.
+First is read of a complete <em>OData Feed</em> / <em>Entity Set</em> and second is read os a single <em>Entity</em>.
+In general both are based on <em>HTTP GET</em> requests to an URI which gets as response the content as an <code>InputStream</code> which then can be de-serialized by Apache Olingo into corresponding objects.
+For de-serialization the methods <code>EntityProvider.readFeed(...)</code> and <code>EntityProvider.readEntry(...)</code> are provided which both requires the same types of parameters.
+This is the format of the content as <em>HTTP Content-Type</em> constant (e.g. <code>application/atom+xml</code> / <code>application/json</code>),
+the <em>EdmEntitySet</em> of the to be de-serialized entity (which can be get via the <code>Edm</code>/<code>EdmEntityContainer</code> objects),
+the content as <code>InputStream</code> and
+the <code>EntityProviderReadProperties</code> to configure the read method.</p>
+<p>Hence the code samples looks very similar. The main difference is the creation of the <code>absolutUri</code> and the method called at the <code>EntityProvider</code> for de-serialization. </p>
+<p><strong>Read complete Feed</strong></p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="n">ODataFeed</span> <span class="nf">readFeed</span><span class="o">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="o">,</span> <span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">entitySetName</span><span class="o">)</span>
+      <span class="kd">throws</span> <span class="n">IOException</span><span class="o">,</span> <span class="n">ODataException</span> <span class="o">{</span>
+    <span class="n">EdmEntityContainer</span> <span class="n">entityContainer</span> <span class="o">=</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">();</span>
+    <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+
+    <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="o">(</span><span class="n">InputStream</span><span class="o">)</span> <span class="n">connect</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">HTTP_METHOD_GET</span><span class="o">).</span><span class="na">getContent</span><span class="o">();</span>
+    <span class="k">return</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">readFeed</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span>
+        <span class="n">entityContainer</span><span class="o">.</span><span class="na">getEntitySet</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">),</span>
+        <span class="n">content</span><span class="o">,</span>
+        <span class="n">EntityProviderReadProperties</span><span class="o">.</span><span class="na">init</span><span class="o">().</span><span class="na">build</span><span class="o">());</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>For read of a complete <code>ODataFeed</code> the <em>HTTP GET</em> request URI is a <em>EntitySet</em>. Via the <code>connect(...)</code> method the request is done against the created absolut uri and the responding content is returned as <code>InputStream</code>. This <code>InputStream</code> than will be de-serialized by the <code>EntitProvider.readFeed(...)</code> into an <code>ODataFeed</code> object which contains all entities provided by the OData Service as well as <code>FeedMetadata</code> like <em>inline count</em> and <em>next link</em>.</p>
+<p><strong>Read single Entry</strong></p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="n">ODataEntry</span> <span class="nf">readEntry</span><span class="o">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="o">,</span> <span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">String</span> <span class="n">keyValue</span><span class="o">)</span>
+      <span class="kd">throws</span> <span class="n">IOException</span><span class="o">,</span> <span class="n">ODataException</span> <span class="o">{</span>
+    <span class="c1">// working with the default entity container</span>
+    <span class="n">EdmEntityContainer</span> <span class="n">entityContainer</span> <span class="o">=</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">();</span>
+    <span class="c1">// create absolute uri based on service uri, entity set name and key property value</span>
+    <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">keyValue</span><span class="o">);</span>
+
+    <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="n">execute</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">HTTP_METHOD_GET</span><span class="o">);</span>
+
+    <span class="k">return</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span>
+        <span class="n">entityContainer</span><span class="o">.</span><span class="na">getEntitySet</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">),</span>
+        <span class="n">content</span><span class="o">,</span>
+        <span class="n">EntityProviderReadProperties</span><span class="o">.</span><span class="na">init</span><span class="o">().</span><span class="na">build</span><span class="o">());</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>For read of a single <code>ODataEntry</code> the <em>HTTP GET</em> request URI is an <em>Entity</em> for which a <em>key value</em> is required for creation of the absolut uri. Via the <code>connect(...)</code> method the request is done against the absolut uri and the responding content is returned as <code>InputStream</code>. 
+This <code>InputStream</code> than will be de-serialized by the <code>EntitProvider.readEntry(...)</code> into an <code>ODataEntry</code> object which contains the data / properties of the entry in form of a Map as well as <code>EntryMetadata</code> (which contains <em>etag</em>, <em>id</em>, <em>association uris</em> and <em>uri</em> information), <code>MediaMetadata</code> if the entry is a <em>media resource</em>, information about the entry <em>contains inline entries</em> and the <code>ExpandSelectTreeNode</code>.</p>
+<p><a name="createdata"></a></p>
+<h5 id="create">Create</h5>
+<p>To create an entity a <em>HTTP POST</em> on the corresponding entity set URI with the whole entity data as <em>POST Body</em> in a supported format (e.g. <code>atom-xml</code>, <code>json</code>) has to be done. With Apache Olingo the required <em>POST Body</em> can be created (serialized) with the <code>EntityProvider.writeEntry(String contentType, EdmEntitySet entitySet, Map&lt;String, Object&gt; data, EntityProviderWriteProperties properties)</code> method. This method creates an <code>ODataResponse</code> object which contains the content (i.e. the required <em>POST Body</em>) as <code>InputStream</code> which then can be send to the server. If the entry was created successfully an <em>HTTP Status: 201 created</em> will be returned as well as the complete entry.  </p>
+<p>For simplicity in the code sample below the prepare and execute of the <em>POST</em> and the read of the response is separated (see <em>Part 1: Post</em> and <em>Part 2: Read</em>). The last code sample part shows the convenience method which is used for the create entry case (i.e. absolut uri creation and call of the shared <code>writeEntry</code> method). 
+Additional the parts below are only code snippets (and no complete method which is <em>copy/paste</em> ready), because the <em>Create (HTTP POST)</em> and <em>Update (HTTP PUT)</em> are similar the whole sample contains an <code>writeEntry</code> method which is called by the <code>createEntry</code> and <code>updateEntry</code> methods. The code sample for the complete <code>writeEntry</code> method is listed in the <em>Shared code</em> section. </p>
+<p><strong>Code sample: Create single Entry</strong></p>
+<p><strong>Part 1: POST entry</strong>  </p>
+<div class="codehilite"><pre>    <span class="c1">// Map&lt;String, Object&gt; data // ...is a method parameter</span>
+
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">httpMethod</span><span class="o">);</span>
+      <span class="c1">// prepare</span>
+    <span class="n">EdmEntityContainer</span> <span class="n">entityContainer</span> <span class="o">=</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">();</span>
+    <span class="n">EdmEntitySet</span> <span class="n">entitySet</span> <span class="o">=</span> <span class="n">entityContainer</span><span class="o">.</span><span class="na">getEntitySet</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>
+    <span class="n">URI</span> <span class="n">rootUri</span> <span class="o">=</span> <span class="k">new</span> <span class="n">URI</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>    
+    <span class="n">EntityProviderWriteProperties</span> <span class="n">properties</span> <span class="o">=</span> <span class="n">EntityProviderWriteProperties</span><span class="o">.</span><span class="na">serviceRoot</span><span class="o">(</span><span class="n">rootUri</span><span class="o">).</span><span class="na">build</span><span class="o">();</span>
+    <span class="c1">// serialize data into ODataResponse object</span>
+    <span class="n">ODataResponse</span> <span class="n">response</span> <span class="o">=</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">writeEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span> <span class="n">entitySet</span><span class="o">,</span> <span class="n">data</span><span class="o">,</span> <span class="n">properties</span><span class="o">);</span>
+    <span class="c1">// get (http) entity which is for default Olingo implementation an InputStream</span>
+    <span class="kt">byte</span><span class="o">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">streamToArray</span><span class="o">((</span><span class="n">InputStream</span><span class="o">)</span> <span class="n">response</span><span class="o">.</span><span class="na">getEntity</span><span class="o">());</span>
+    <span class="c1">// do the POST   </span>
+    <span class="n">connection</span><span class="o">.</span><span class="na">getOutputStream</span><span class="o">().</span><span class="na">write</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+</pre></div>
+
+
+<p>First the <code>HttpURLConnection</code> is initialized.
+Then the Apache Olingo related objects are prepared in form of the <code>EdmEntitySet</code> and <code>EntityProviderWriteProperties</code>. With the <code>EntityProviderWriteProperties</code> is is possible to configure the serialization of the entity. But for the basic create use case it is sufficient to set the <em>rootUri</em> of the service which in the sample is the name of the entity set.
+The entity itself is provided via a <code>Map</code> which contains the data as <em>property name</em> to <em>value</em> pairs. As example with <em>Name</em> as key and <em>Max</em> as value in the Map an entity property of <em>Name</em> with the value <em>Max</em> (or as <code>XML</code>: <code>&lt;d:Name&gt;Max&lt;/d:Name&gt;</code>) will be serialized in the <code>ODataResponse</code> object.
+If all is prepared the <code>EntityProvider.writeEntry(contentType, entitySet, data, properties)</code> method creates the <code>ODataResponse</code> which contains the serialized data as entity in an <code>InputStream</code>. 
+This <code>InputStream</code> can direclty used and send to the OData Service via an <em>HTTP Post</em> as <em>HTTP Body</em>.
+In the code sample the <code>InputStream</code> is read into a buffer (for simplicity we only read once) which than is written into the <code>OutputStream</code> of the <code>HttpURLConnection</code>.
+After this the entity is posted (created) and the response can be read.</p>
+<p><strong>Part 2: Read response</strong>  </p>
+<div class="codehilite"><pre>    <span class="c1">// if a entity is created (via POST request) the response body contains the new created entity</span>
+    <span class="n">HttpStatusCodes</span> <span class="n">statusCode</span> <span class="o">=</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">fromStatusCode</span><span class="o">(</span><span class="n">connection</span><span class="o">.</span><span class="na">getResponseCode</span><span class="o">());</span>
+    <span class="k">if</span><span class="o">(</span><span class="n">statusCode</span> <span class="o">==</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">CREATED</span><span class="o">)</span> <span class="o">{</span>
+      <span class="c1">// get the content as InputStream and de-serialize it into an ODataEntry object</span>
+      <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="na">getInputStream</span><span class="o">();</span>
+      <span class="n">content</span> <span class="o">=</span> <span class="n">logRawContent</span><span class="o">(</span><span class="n">httpMethod</span> <span class="o">+</span> <span class="s">&quot; response:\n  &quot;</span><span class="o">,</span> <span class="n">content</span><span class="o">,</span> <span class="s">&quot;\n&quot;</span><span class="o">);</span>
+      <span class="n">ODataEntry</span> <span class="n">entry</span> <span class="o">=</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span>
+          <span class="n">entitySet</span><span class="o">,</span> <span class="n">content</span><span class="o">,</span> <span class="n">EntityProviderReadProperties</span><span class="o">.</span><span class="na">init</span><span class="o">().</span><span class="na">build</span><span class="o">());</span>
+    <span class="o">}</span>
+</pre></div>
+
+
+<p>When the <em>HTTP Post</em> is done the response can be read.
+Starting with the response status code to validate that the creation of the entity was successfull, which is the case if it is a <code>HttpStatusCodes.CREATED</code>.
+Then get the content as <code>InputStream</code> from the <code>HttpURLConnection</code> and pass it to the <code>EntityProvider.readEntry(...)</code> method for de-serialization.
+The necassary <code>EdmEntitySet</code> parameter is the same as for the <code>EntityProvider.writeEntry(...)</code> and for the sample the default <code>EntityProviderReadProperties</code> can be used.
+The result is a de-serialized <code>ODataEntry</code> which represents the created entity from the OData Service.</p>
+<p><strong>Part 3: Create single Entry method</strong></p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="n">ODataEntry</span> <span class="nf">createEntry</span><span class="o">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="o">,</span> <span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> 
+      <span class="n">String</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">data</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
+    <span class="k">return</span> <span class="nf">writeEntity</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">absolutUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">data</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">HTTP_METHOD_POST</span><span class="o">);</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>The <em>Part 1</em> and <em>Part 2</em> code snippets are copied from the shared <code>writeEntity(...)</code> method of the sample which is called for <em>create</em> and <em>update</em> of entities. Hence the convenience method <code>createEntry</code> only creates the <code>absolutUri</code> for the entity set and then delegates to the <code>writeEntity</code> method with correct set <code>HTTP_METHOD_POST</code>.</p>
+<p><a name="updatedata"></a></p>
+<h5 id="update">Update</h5>
+<p>Update of an entity is similar to the creation of an entity. 
+Hence the code sample is not only very similar but also <em>create</em> and <em>update</em> is based on the <code>writeEntry(...)</code> method in this tutorial and the sample. To show this of below all <em>quoted</em> text is the same as in the <em>create</em> section and only the <em>not</em> quoted text is different.</p>
+<p>To update an entity a <em>HTTP PUT</em>  on the corresponding entity URI with the <em>whole entity data</em> as <em>POST Body</em> in a supported format (e.g. <code>atom-xml</code>, <code>json</code>) has to be done. 
+With an <em>HTTP MERGE/PATCH</em> it is also possible to send only the <em>to be updated</em> data as <em>POST Body</em> and omitting the unchanged data. But this is (currently) not shown within this sample.</p>
+<blockquote>
+<p>With Apache Olingo the required <em>POST Body</em> can be created (serialized) with the <code>EntityProvider.writeEntry(String contentType, EdmEntitySet entitySet, Map&lt;String, Object&gt; data, EntityProviderWriteProperties properties)</code> method. This method creates an <code>ODataResponse</code> object which contains the content (i.e. the required <em>POST Body</em>) as <code>InputStream</code> which then can be send to the server. </p>
+</blockquote>
+<p>If the entry was updated successfully an <em>HTTP Status: 204 No content</em> will be returned.  </p>
+<p>For simplicity in the code sample below the prepare and execute of the <em>PUT/PATCH</em> and the convenience method which is used for the update entry case are separated (see <em>Part 1: Put</em> and <em>Part 2: Update Entry</em>).</p>
+<blockquote>
+<p>Additional the parts below are only code snippets (and no complete method which is <em>copy/paste</em> ready), because the <em>Create (HTTP POST)</em> and <em>Update (HTTP PUT)</em> are similar the whole sample contains an <code>writeEntry</code> method which is called by the <code>createEntry</code> and <code>updateEntry</code> methods. The code sample for the complete <code>writeEntry</code> method is listed in the <em>Shared code</em> section. </p>
+</blockquote>
+<p><strong>Code sample: Create single Entry</strong></p>
+<p><strong>Part 1: PUT entry</strong>  </p>
+<div class="codehilite"><pre>    <span class="c1">// Map&lt;String, Object&gt; data // ...is a method parameter</span>
+
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">httpMethod</span><span class="o">);</span>
+    <span class="c1">// prepare</span>
+    <span class="n">EdmEntityContainer</span> <span class="n">entityContainer</span> <span class="o">=</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">();</span>
+    <span class="n">EdmEntitySet</span> <span class="n">entitySet</span> <span class="o">=</span> <span class="n">entityContainer</span><span class="o">.</span><span class="na">getEntitySet</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>
+    <span class="n">URI</span> <span class="n">rootUri</span> <span class="o">=</span> <span class="k">new</span> <span class="n">URI</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>    
+    <span class="n">EntityProviderWriteProperties</span> <span class="n">properties</span> <span class="o">=</span> <span class="n">EntityProviderWriteProperties</span><span class="o">.</span><span class="na">serviceRoot</span><span class="o">(</span><span class="n">rootUri</span><span class="o">).</span><span class="na">build</span><span class="o">();</span>
+    <span class="c1">// serialize data into ODataResponse object</span>
+    <span class="n">ODataResponse</span> <span class="n">response</span> <span class="o">=</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">writeEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span> <span class="n">entitySet</span><span class="o">,</span> <span class="n">data</span><span class="o">,</span> <span class="n">properties</span><span class="o">);</span>
+    <span class="c1">// get (http) entity which is for default Olingo implementation an InputStream</span>
+    <span class="kt">byte</span><span class="o">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">streamToArray</span><span class="o">((</span><span class="n">InputStream</span><span class="o">)</span> <span class="n">response</span><span class="o">.</span><span class="na">getEntity</span><span class="o">());</span>
+    <span class="c1">// do the PUT   </span>
+    <span class="n">connection</span><span class="o">.</span><span class="na">getOutputStream</span><span class="o">().</span><span class="na">write</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+    <span class="c1">//</span>
+    <span class="n">HttpStatusCodes</span> <span class="n">statusCode</span> <span class="o">=</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">fromStatusCode</span><span class="o">(</span><span class="n">connection</span><span class="o">.</span><span class="na">getResponseCode</span><span class="o">());</span>
+</pre></div>
+
+
+<!-- Copy pasted from POST/create -->
+
+<blockquote>
+<p>First the <code>HttpURLConnection</code> is initialized.
+Then the Apache Olingo related objects are prepared in form of the <code>EdmEntitySet</code> and <code>EntityProviderWriteProperties</code>. With the <code>EntityProviderWriteProperties</code> is is possible to configure the serialization of the entity. But for the basic create use case it is sufficient to set the <em>rootUri</em> of the service which in the sample is the name of the entity set.
+The entity itself is provided via a <code>Map</code> which contains the data as <em>property name</em> to <em>value</em> pairs. As example with <em>Name</em> as key and <em>Max</em> as value in the Map an entity property of <em>Name</em> with the value <em>Max</em> (or as <code>XML</code>: <code>&lt;d:Name&gt;Max&lt;/d:Name&gt;</code>) will be serialized in the <code>ODataResponse</code> object.
+If all is prepared the <code>EntityProvider.writeEntry(contentType, entitySet, data, properties)</code> method creates the <code>ODataResponse</code> which contains the serialized data as entity in an <code>InputStream</code>. 
+This <code>InputStream</code> can direclty used and send to the OData Service via an <em>HTTP Post</em> as <em>HTTP Body</em>.
+In the code sample the <code>InputStream</code> is read into a buffer (for simplicity we only read once) which than is written into the <code>OutputStream</code> of the <code>HttpURLConnection</code>.
+<!-- End of Copy pasted from POST/create --></p>
+</blockquote>
+<p>After this the entity is update and the response status code can be checked.</p>
+<p><strong>Part 2: Update Entry method</strong></p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="kt">void</span> <span class="nf">updateEntry</span><span class="o">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="o">,</span> <span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">entitySetName</span><span class="o">,</span> 
+      <span class="n">String</span> <span class="n">id</span><span class="o">,</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">data</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">id</span><span class="o">);</span>
+    <span class="n">writeEntity</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">absolutUri</span><span class="o">,</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">data</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">HTTP_METHOD_PUT</span><span class="o">);</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>The <em>Part 1</em> is copied from the shared <code>writeEntity(...)</code> method of the sample which is called for <em>create</em> and <em>update</em> of entities. Hence the convenience method <code>createEntry</code> in <em>Part 2</em> only creates the <code>absolutUri</code> for the entity and then delegates to the <code>writeEntity</code> method with correct set <code>HTTP_METHOD_PUT</code>.</p>
+<p><a name="deletedata"></a></p>
+<h5 id="delete">Delete</h5>
+<p>For deletion of an entry just an <em>HTTP DELETE</em> request is necessary on the URI of the entity. Hence the Apache Olingo is not necessary to serialize or de-serialize anything for this use case.</p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="n">HttpStatusCodes</span> <span class="nf">deleteEntry</span><span class="o">(</span><span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">entityName</span><span class="o">,</span> <span class="n">String</span> <span class="n">id</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">,</span> <span class="n">entityName</span><span class="o">,</span> <span class="n">id</span><span class="o">);</span>
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">connect</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">APPLICATION_XML</span><span class="o">,</span> <span class="n">HTTP_METHOD_DELETE</span><span class="o">);</span>
+    <span class="k">return</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">fromStatusCode</span><span class="o">(</span><span class="n">connection</span><span class="o">.</span><span class="na">getResponseCode</span><span class="o">());</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p>So the code for delete of an entry the <em>HTTP DELETE</em> request URI is an <em>Entity</em> for which a <em>key value</em> is required for creation of the absolut uri. Via the <code>connect(...)</code> method the request is done against the absolut uri and the responding http status code is returned, which is, if the entry was deleted successfully, an <em>HTTP Status: 204 No content</em>.</p>
+<h5 id="shared-methods">Shared Methods</h5>
+<p>In this section are all methods shared and used from the more Apache Olingo releated methods listed as code samples in the concrete <em>read</em>, <em>create</em>, <em>update</em> and <em>delete</em> sections above.</p>
+<p><strong>Code sample: Write Entry for Create/Update</strong></p>
+<p>The <code>writeEntity(...)</code> method is used for <em>creation</em> and <em>update</em> of an entry. Simplified it executes the given <code>httpMethod</code> on the given <code>absolutUri</code> for the serialized entry based on given <code>contentType</code>, <code>entitySetName</code> and <code>data</code>. Additional for the case of an successfull <em>create</em> the <code>ODataEntry</code> is returned otherwise <code>null</code> is returned.</p>
+<div class="codehilite"><pre>  <span class="kd">private</span> <span class="n">ODataEntry</span> <span class="nf">writeEntity</span><span class="o">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="o">,</span> <span class="n">String</span> <span class="n">absolutUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">entitySetName</span><span class="o">,</span> 
+      <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">data</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">httpMethod</span><span class="o">)</span> 
+      <span class="kd">throws</span> <span class="n">EdmException</span><span class="o">,</span> <span class="n">MalformedURLException</span><span class="o">,</span> <span class="n">IOException</span><span class="o">,</span> <span class="n">EntityProviderException</span><span class="o">,</span> <span class="n">URISyntaxException</span> <span class="o">{</span>
+
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">httpMethod</span><span class="o">);</span>
+
+    <span class="n">EdmEntityContainer</span> <span class="n">entityContainer</span> <span class="o">=</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">();</span>
+    <span class="n">EdmEntitySet</span> <span class="n">entitySet</span> <span class="o">=</span> <span class="n">entityContainer</span><span class="o">.</span><span class="na">getEntitySet</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>
+    <span class="n">URI</span> <span class="n">rootUri</span> <span class="o">=</span> <span class="k">new</span> <span class="n">URI</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>
+
+    <span class="n">EntityProviderWriteProperties</span> <span class="n">properties</span> <span class="o">=</span> <span class="n">EntityProviderWriteProperties</span><span class="o">.</span><span class="na">serviceRoot</span><span class="o">(</span><span class="n">rootUri</span><span class="o">).</span><span class="na">build</span><span class="o">();</span>
+    <span class="c1">// serialize data into ODataResponse object</span>
+    <span class="n">ODataResponse</span> <span class="n">response</span> <span class="o">=</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">writeEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span> <span class="n">entitySet</span><span class="o">,</span> <span class="n">data</span><span class="o">,</span> <span class="n">properties</span><span class="o">);</span>
+    <span class="c1">// get (http) entity which is for default Olingo implementation an InputStream</span>
+    <span class="n">Object</span> <span class="n">entity</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="na">getEntity</span><span class="o">();</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">entity</span> <span class="k">instanceof</span> <span class="n">InputStream</span><span class="o">)</span> <span class="o">{</span>
+      <span class="kt">byte</span><span class="o">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">streamToArray</span><span class="o">((</span><span class="n">InputStream</span><span class="o">)</span> <span class="n">entity</span><span class="o">);</span>
+      <span class="c1">// just for logging</span>
+      <span class="n">String</span> <span class="n">content</span> <span class="o">=</span> <span class="k">new</span> <span class="n">String</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+      <span class="n">print</span><span class="o">(</span><span class="n">httpMethod</span> <span class="o">+</span> <span class="s">&quot; request:\n  &quot;</span> <span class="o">+</span> <span class="n">content</span> <span class="o">+</span> <span class="s">&quot;\n&quot;</span><span class="o">);</span>
+      <span class="c1">//</span>
+      <span class="n">connection</span><span class="o">.</span><span class="na">getOutputStream</span><span class="o">().</span><span class="na">write</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="c1">// if a entity is created (via POST request) the response body contains the new created entity</span>
+    <span class="n">ODataEntry</span> <span class="n">entry</span> <span class="o">=</span> <span class="kc">null</span><span class="o">;</span>
+    <span class="n">HttpStatusCodes</span> <span class="n">statusCode</span> <span class="o">=</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">fromStatusCode</span><span class="o">(</span><span class="n">connection</span><span class="o">.</span><span class="na">getResponseCode</span><span class="o">());</span>
+    <span class="k">if</span><span class="o">(</span><span class="n">statusCode</span> <span class="o">==</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">CREATED</span><span class="o">)</span> <span class="o">{</span>
+      <span class="c1">// get the content as InputStream and de-serialize it into an ODataEntry object</span>
+      <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="na">getInputStream</span><span class="o">();</span>
+      <span class="n">content</span> <span class="o">=</span> <span class="n">logRawContent</span><span class="o">(</span><span class="n">httpMethod</span> <span class="o">+</span> <span class="s">&quot; response:\n  &quot;</span><span class="o">,</span> <span class="n">content</span><span class="o">,</span> <span class="s">&quot;\n&quot;</span><span class="o">);</span>
+      <span class="n">entry</span> <span class="o">=</span> <span class="n">EntityProvider</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">contentType</span><span class="o">,</span>
+          <span class="n">entitySet</span><span class="o">,</span> <span class="n">content</span><span class="o">,</span> <span class="n">EntityProviderReadProperties</span><span class="o">.</span><span class="na">init</span><span class="o">().</span><span class="na">build</span><span class="o">());</span>
+    <span class="o">}</span>
+
+    <span class="c1">//</span>
+    <span class="n">connection</span><span class="o">.</span><span class="na">disconnect</span><span class="o">();</span>
+
+    <span class="k">return</span> <span class="n">entry</span><span class="o">;</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p><strong>Creation of absolut URI</strong>    </p>
+<p>The <code>createUri(...)</code> method is used in every convenience method (<em>read</em>, <em>create</em>, <em>update</em> and <em>delete</em>) to build the absolut uri based on the <code>serviceUri</code>, <code>entitySetName</code> and <code>id</code> for the case of a single Entry.</p>
+<div class="codehilite"><pre>  <span class="kd">private</span> <span class="n">String</span> <span class="nf">createUri</span><span class="o">(</span><span class="n">String</span> <span class="n">serviceUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">entitySetName</span><span class="o">,</span> <span class="n">String</span> <span class="n">id</span><span class="o">)</span> <span class="o">{</span>
+    <span class="kd">final</span> <span class="n">StringBuilder</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StringBuilder</span><span class="o">(</span><span class="n">serviceUri</span><span class="o">).</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;/&quot;</span><span class="o">).</span><span class="na">append</span><span class="o">(</span><span class="n">entitySetName</span><span class="o">);</span>
+    <span class="k">if</span><span class="o">(</span><span class="n">id</span> <span class="o">!=</span> <span class="kc">null</span><span class="o">)</span> <span class="o">{</span>
+      <span class="n">absolutUri</span><span class="o">.</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;(&quot;</span><span class="o">).</span><span class="na">append</span><span class="o">(</span><span class="n">id</span><span class="o">).</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;)&quot;</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="k">return</span> <span class="n">absolutUri</span><span class="o">.</span><span class="na">toString</span><span class="o">();</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p><strong>Basic HTTP connection initailization and validation</strong></p>
+<p>The <code>exectute(...)</code>, <code>connect(...)</code> and <code>initializeConnection(...)</code> methods are used for initialization of the connection, execute and/or connect and check basic connection success (via <code>checkStatus(...)</code> method) to the OData Service and is therefore used in every use case (<em>read</em>, <em>create</em>, <em>update</em> and <em>delete</em>).</p>
+<div class="codehilite"><pre>  <span class="kd">private</span> <span class="n">InputStream</span> <span class="nf">execute</span><span class="o">(</span><span class="n">String</span> <span class="n">relativeUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">httpMethod</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">relativeUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">httpMethod</span><span class="o">);</span>
+
+    <span class="n">connection</span><span class="o">.</span><span class="na">connect</span><span class="o">();</span>
+    <span class="n">checkStatus</span><span class="o">(</span><span class="n">connection</span><span class="o">);</span>
+
+    <span class="n">InputStream</span> <span class="n">content</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="na">getInputStream</span><span class="o">();</span>
+    <span class="n">content</span> <span class="o">=</span> <span class="n">logRawContent</span><span class="o">(</span><span class="n">httpMethod</span> <span class="o">+</span> <span class="s">&quot; request:\n  &quot;</span><span class="o">,</span> <span class="n">content</span><span class="o">,</span> <span class="s">&quot;\n&quot;</span><span class="o">);</span>
+    <span class="k">return</span> <span class="n">content</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="n">HttpURLConnection</span> <span class="nf">connect</span><span class="o">(</span><span class="n">String</span> <span class="n">relativeUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">httpMethod</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">relativeUri</span><span class="o">,</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">httpMethod</span><span class="o">);</span>
+
+    <span class="n">connection</span><span class="o">.</span><span class="na">connect</span><span class="o">();</span>
+    <span class="n">checkStatus</span><span class="o">(</span><span class="n">connection</span><span class="o">);</span>
+
+    <span class="k">return</span> <span class="n">connection</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="n">HttpURLConnection</span> <span class="nf">initializeConnection</span><span class="o">(</span><span class="n">String</span> <span class="n">absolutUri</span><span class="o">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="o">,</span> <span class="n">String</span> <span class="n">httpMethod</span><span class="o">)</span>
+      <span class="kd">throws</span> <span class="n">MalformedURLException</span><span class="o">,</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="n">URL</span> <span class="n">url</span> <span class="o">=</span> <span class="k">new</span> <span class="n">URL</span><span class="o">(</span><span class="n">absolutUri</span><span class="o">);</span>
+    <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="o">(</span><span class="n">HttpURLConnection</span><span class="o">)</span> <span class="n">url</span><span class="o">.</span><span class="na">openConnection</span><span class="o">();</span>
+
+    <span class="n">connection</span><span class="o">.</span><span class="na">setRequestMethod</span><span class="o">(</span><span class="n">httpMethod</span><span class="o">);</span>
+    <span class="n">connection</span><span class="o">.</span><span class="na">setRequestProperty</span><span class="o">(</span><span class="n">HTTP_HEADER_ACCEPT</span><span class="o">,</span> <span class="n">contentType</span><span class="o">);</span>
+    <span class="k">if</span><span class="o">(</span><span class="n">HTTP_METHOD_POST</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">httpMethod</span><span class="o">)</span> <span class="o">||</span> <span class="n">HTTP_METHOD_PUT</span><span class="o">.</span><span class="na">equals</span><span class="o">(</span><span class="n">httpMethod</span><span class="o">))</span> <span class="o">{</span>
+      <span class="n">connection</span><span class="o">.</span><span class="na">setDoOutput</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
+      <span class="n">connection</span><span class="o">.</span><span class="na">setRequestProperty</span><span class="o">(</span><span class="n">HTTP_HEADER_CONTENT_TYPE</span><span class="o">,</span> <span class="n">contentType</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="k">return</span> <span class="n">connection</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="n">HttpStatusCodes</span> <span class="nf">checkStatus</span><span class="o">(</span><span class="n">HttpURLConnection</span> <span class="n">connection</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="n">HttpStatusCodes</span> <span class="n">httpStatusCode</span> <span class="o">=</span> <span class="n">HttpStatusCodes</span><span class="o">.</span><span class="na">fromStatusCode</span><span class="o">(</span><span class="n">connection</span><span class="o">.</span><span class="na">getResponseCode</span><span class="o">());</span>
+    <span class="k">if</span> <span class="o">(</span><span class="mi">400</span> <span class="o">&lt;=</span> <span class="n">httpStatusCode</span><span class="o">.</span><span class="na">getStatusCode</span><span class="o">()</span> <span class="o">&amp;&amp;</span> <span class="n">httpStatusCode</span><span class="o">.</span><span class="na">getStatusCode</span><span class="o">()</span> <span class="o">&lt;=</span> <span class="mi">599</span><span class="o">)</span> <span class="o">{</span>
+      <span class="k">throw</span> <span class="k">new</span> <span class="nf">RuntimeException</span><span class="o">(</span><span class="s">&quot;Http Connection failed with status &quot;</span> <span class="o">+</span> <span class="n">httpStatusCode</span><span class="o">.</span><span class="na">getStatusCode</span><span class="o">()</span> <span class="o">+</span> <span class="s">&quot; &quot;</span> <span class="o">+</span> <span class="n">httpStatusCode</span><span class="o">.</span><span class="na">toString</span><span class="o">());</span>
+    <span class="o">}</span>
+    <span class="k">return</span> <span class="n">httpStatusCode</span><span class="o">;</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p><strong>Logging</strong></p>
+<p>The <code>logRawContent(...)</code> (in combination with <code>streamToArray(...)</code>) method is simply used for logging the content of the given <code>InputStream</code> and re-creation of an readable <code>InputStream</code> which is returned.</p>
+<div class="codehilite"><pre>  <span class="kd">private</span> <span class="n">InputStream</span> <span class="nf">logRawContent</span><span class="o">(</span><span class="n">String</span> <span class="n">prefix</span><span class="o">,</span> <span class="n">InputStream</span> <span class="n">content</span><span class="o">,</span> <span class="n">String</span> <span class="n">postfix</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="k">if</span><span class="o">(</span><span class="n">PRINT_RAW_CONTENT</span><span class="o">)</span> <span class="o">{</span>
+      <span class="kt">byte</span><span class="o">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">streamToArray</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>
+      <span class="n">content</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
+
+      <span class="n">print</span><span class="o">(</span><span class="n">prefix</span> <span class="o">+</span> <span class="k">new</span> <span class="n">String</span><span class="o">(</span><span class="n">buffer</span><span class="o">)</span> <span class="o">+</span> <span class="n">postfix</span><span class="o">);</span>
+
+      <span class="k">return</span> <span class="k">new</span> <span class="nf">ByteArrayInputStream</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="k">return</span> <span class="n">content</span><span class="o">;</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="kt">byte</span><span class="o">[]</span> <span class="nf">streamToArray</span><span class="o">(</span><span class="n">InputStream</span> <span class="n">stream</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="kt">byte</span><span class="o">[]</span> <span class="n">result</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">byte</span><span class="o">[</span><span class="mi">0</span><span class="o">];</span>
+    <span class="kt">byte</span><span class="o">[]</span> <span class="n">tmp</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">byte</span><span class="o">[</span><span class="mi">8192</span><span class="o">];</span>
+    <span class="kt">int</span> <span class="n">readCount</span> <span class="o">=</span> <span class="n">stream</span><span class="o">.</span><span class="na">read</span><span class="o">(</span><span class="n">tmp</span><span class="o">);</span>
+    <span class="k">while</span><span class="o">(</span><span class="n">readCount</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="o">)</span> <span class="o">{</span>
+      <span class="kt">byte</span><span class="o">[]</span> <span class="n">innerTmp</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">byte</span><span class="o">[</span><span class="n">result</span><span class="o">.</span><span class="na">length</span> <span class="o">+</span> <span class="n">readCount</span><span class="o">];</span>
+      <span class="n">System</span><span class="o">.</span><span class="na">arraycopy</span><span class="o">(</span><span class="n">result</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="n">innerTmp</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="n">result</span><span class="o">.</span><span class="na">length</span><span class="o">);</span>
+      <span class="n">System</span><span class="o">.</span><span class="na">arraycopy</span><span class="o">(</span><span class="n">tmp</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="n">innerTmp</span><span class="o">,</span> <span class="n">result</span><span class="o">.</span><span class="na">length</span><span class="o">,</span> <span class="n">readCount</span><span class="o">);</span>
+      <span class="n">result</span> <span class="o">=</span> <span class="n">innerTmp</span><span class="o">;</span>
+      <span class="n">readCount</span> <span class="o">=</span> <span class="n">stream</span><span class="o">.</span><span class="na">read</span><span class="o">(</span><span class="n">tmp</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="k">return</span> <span class="n">result</span><span class="o">;</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<!--
+### Extended Operations
+-->
+
+<p><a name="run"></a></p>
+<h3 id="run-the-sample">Run the sample</h3>
+<p>To show a sample how a client can look like and how it than can be used the code samples can be copied into an <code>OlingoSampleApp</code> class. 
+And to show an use case the <code>main</code> method below can be added which calls this <code>OlingoSampleApp</code> to <em>read</em> the <em>EDM</em>, <em>read</em> a <em>ODataFeed</em> and existing <em>ODataEntry</em>, <em>create</em> a new <em>ODataEntry</em>, <em>update</em> this <em>ODataEntry</em> and at last <em>delete</em> the <em>ODataEntry</em>. 
+Between the interaction with the <code>OlingoSampleApp</code> the results are printend via the <code>print(...)</code> and <code>prettyPrint(...)</code>' methods.</p>
+<p><a name="together"></a></p>
+<h5 id="put-the-parts-together">Put the parts together</h5>
+<p><strong>Shortcut</strong></p>
+<p>Instead of copy and paste all code samples from above and the main sample method below in section <a href="#copypaste">Copy and Paste</a> is the whole sample code as <code>OlingoSampleApp.java</code> available (<a href="#sampleclient">here</a>) as well as a <code>pom.xml</code> (<a href="#pom">here</a>) to set up a maven project which all necessary build information. Only requirements are an installed <em>Java 6 Runtime</em> and <em>Maven 3</em> environment.</p>
+<p><strong>Main sample method</strong></p>
+<div class="codehilite"><pre>  <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">paras</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">OlingoSampleApp</span> <span class="n">app</span> <span class="o">=</span> <span class="k">new</span> <span class="n">OlingoSampleApp</span><span class="o">();</span>
+
+    <span class="n">String</span> <span class="n">serviceUrl</span> <span class="o">=</span> <span class="s">&quot;http://localhost:8080/MyFormula.svc&quot;</span><span class="o">;</span>
+    <span class="n">String</span> <span class="n">usedFormat</span> <span class="o">=</span> <span class="n">APPLICATION_JSON</span><span class="o">;</span> <span class="c1">// could also be APPLICATION_ATOM_XML</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Generate sample data ------------------&quot;</span><span class="o">);</span>
+    <span class="n">app</span><span class="o">.</span><span class="na">generateSampleData</span><span class="o">(</span><span class="n">serviceUrl</span><span class="o">);</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Read Edm ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">Edm</span> <span class="n">edm</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">readEdm</span><span class="o">(</span><span class="n">serviceUrl</span><span class="o">);</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Read default EntityContainer: &quot;</span> <span class="o">+</span> <span class="n">edm</span><span class="o">.</span><span class="na">getDefaultEntityContainer</span><span class="o">().</span><span class="na">getName</span><span class="o">());</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Read Feed ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">ODataFeed</span> <span class="n">feed</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">readFeed</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">);</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Read: &quot;</span> <span class="o">+</span> <span class="n">feed</span><span class="o">.</span><span class="na">getEntries</span><span class="o">().</span><span class="na">size</span><span class="o">()</span> <span class="o">+</span> <span class="s">&quot; entries: &quot;</span><span class="o">);</span>
+    <span class="k">for</span> <span class="o">(</span><span class="n">ODataEntry</span> <span class="n">entry</span> <span class="o">:</span> <span class="n">feed</span><span class="o">.</span><span class="na">getEntries</span><span class="o">())</span> <span class="o">{</span>
+      <span class="n">print</span><span class="o">(</span><span class="s">&quot;##########&quot;</span><span class="o">);</span>
+      <span class="n">print</span><span class="o">(</span><span class="s">&quot;Entry:\n&quot;</span> <span class="o">+</span> <span class="n">prettyPrint</span><span class="o">(</span><span class="n">entry</span><span class="o">));</span>
+      <span class="n">print</span><span class="o">(</span><span class="s">&quot;##########&quot;</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Read Entry ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">ODataEntry</span> <span class="n">entry</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="s">&quot;&#39;1&#39;&quot;</span><span class="o">);</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Single Entry: &quot;</span> <span class="o">+</span> <span class="n">prettyPrint</span><span class="o">(</span><span class="n">entry</span><span class="o">));</span>
+
+    <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">data</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;();</span>
+    <span class="n">data</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Id&quot;</span><span class="o">,</span> <span class="s">&quot;123&quot;</span><span class="o">);</span>
+    <span class="n">data</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Name&quot;</span><span class="o">,</span> <span class="s">&quot;MyCarManufacturer&quot;</span><span class="o">);</span>
+    <span class="n">data</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Founded&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">Date</span><span class="o">());</span>
+    <span class="c1">//</span>
+    <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">address</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;();</span>
+    <span class="n">address</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Street&quot;</span><span class="o">,</span> <span class="s">&quot;Main&quot;</span><span class="o">);</span>
+    <span class="n">address</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;ZipCode&quot;</span><span class="o">,</span> <span class="s">&quot;42421&quot;</span><span class="o">);</span>
+    <span class="n">address</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;City&quot;</span><span class="o">,</span> <span class="s">&quot;Fairy City&quot;</span><span class="o">);</span>
+    <span class="n">address</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Country&quot;</span><span class="o">,</span> <span class="s">&quot;FarFarAway&quot;</span><span class="o">);</span>
+    <span class="n">data</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Address&quot;</span><span class="o">,</span> <span class="n">address</span><span class="o">);</span>
+    <span class="c1">//</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Create Entry ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">ODataEntry</span> <span class="n">createdEntry</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">createEntry</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="n">data</span><span class="o">);</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Created Entry:\n&quot;</span> <span class="o">+</span> <span class="n">prettyPrint</span><span class="o">(</span><span class="n">createdEntry</span><span class="o">));</span>
+
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Update Entry ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">data</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Name&quot;</span><span class="o">,</span> <span class="s">&quot;MyCarManufacturer Renamed&quot;</span><span class="o">);</span>
+    <span class="n">address</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">&quot;Street&quot;</span><span class="o">,</span> <span class="s">&quot;Main Street&quot;</span><span class="o">);</span>
+    <span class="n">app</span><span class="o">.</span><span class="na">updateEntry</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="s">&quot;&#39;123&#39;&quot;</span><span class="o">,</span> <span class="n">data</span><span class="o">);</span>
+    <span class="n">ODataEntry</span> <span class="n">updatedEntry</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="s">&quot;&#39;123&#39;&quot;</span><span class="o">);</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Updated Entry successfully:\n&quot;</span> <span class="o">+</span> <span class="n">prettyPrint</span><span class="o">(</span><span class="n">updatedEntry</span><span class="o">));</span>
+
+    <span class="c1">//</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Delete Entry ------------------------------&quot;</span><span class="o">);</span>
+    <span class="n">HttpStatusCodes</span> <span class="n">statusCode</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="na">deleteEntry</span><span class="o">(</span><span class="n">serviceUrl</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="s">&quot;&#39;123&#39;&quot;</span><span class="o">);</span>
+    <span class="n">print</span><span class="o">(</span><span class="s">&quot;Deletion of Entry was successfully: &quot;</span> <span class="o">+</span> <span class="n">statusCode</span><span class="o">.</span><span class="na">getStatusCode</span><span class="o">()</span> <span class="o">+</span> <span class="s">&quot;: &quot;</span> <span class="o">+</span> <span class="n">statusCode</span><span class="o">.</span><span class="na">getInfo</span><span class="o">());</span>
+
+    <span class="k">try</span> <span class="o">{</span>
+      <span class="n">print</span><span class="o">(</span><span class="s">&quot;\n----- Verify Delete Entry ------------------------------&quot;</span><span class="o">);</span>
+      <span class="n">app</span><span class="o">.</span><span class="na">readEntry</span><span class="o">(</span><span class="n">edm</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">,</span> <span class="n">usedFormat</span><span class="o">,</span> <span class="s">&quot;Manufacturers&quot;</span><span class="o">,</span> <span class="s">&quot;&#39;123&#39;&quot;</span><span class="o">);</span>
+    <span class="o">}</span> <span class="k">catch</span><span class="o">(</span><span class="n">Exception</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+      <span class="n">print</span><span class="o">(</span><span class="n">e</span><span class="o">.</span><span class="na">getMessage</span><span class="o">());</span>
+    <span class="o">}</span>
+  <span class="o">}</span>
+</pre></div>
+
+
+<p><strong>Genration of sample data</strong></p>
+<p>The <code>generateSampleData</code> method is used for creation of sample data at the <em>ODataService</em> based on the <a href="#sampleservice">Apache Olingo archetype sample service</a>).</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kt">void</span> <span class="nf">generateSampleData</span><span class="o">(</span><span class="n">String</span> <span class="n">serviceUrl</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">MalformedURLException</span><span class="o">,</span> <span class="n">IOException</span> <span class="o">{</span>
+  <span class="n">String</span> <span class="n">url</span> <span class="o">=</span> <span class="n">serviceUrl</span><span class="o">.</span><span class="na">substring</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">serviceUrl</span><span class="o">.</span><span class="na">lastIndexOf</span><span class="o">(</span><span class="n">SEPARATOR</span><span class="o">));</span>
+  <span class="n">HttpURLConnection</span> <span class="n">connection</span> <span class="o">=</span> <span class="n">initializeConnection</span><span class="o">(</span><span class="n">url</span> <span class="o">+</span> <span class="n">INDEX</span><span class="o">,</span> <span class="n">APPLICATION_FORM</span><span class="o">,</span> <span class="n">HTTP_METHOD_POST</span><span class="o">);</span>
+  <span class="n">String</span> <span class="n">content</span> <span class="o">=</span> <span class="s">&quot;genSampleData=true&quot;</span><span class="o">;</span>
+  <span class="n">connection</span><span class="o">.</span><span class="na">getOutputStream</span><span class="o">().</span><span class="na">write</span><span class="o">(</span><span class="n">content</span><span class="o">.</span><span class="na">getBytes</span><span class="o">());</span>
+  <span class="n">print</span><span class="o">(</span><span class="s">&quot;Generate response: &quot;</span> <span class="o">+</span> <span class="n">checkStatus</span><span class="o">(</span><span class="n">connection</span><span class="o">));</span>
+  <span class="n">connection</span><span class="o">.</span><span class="na">disconnect</span><span class="o">();</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p><strong>Print methods</strong></p>
+<p>The <code>print</code> methods are only for simplified print/write logging to some output channel. In the sample it is just the <code>System.out</code> stream.</p>
+<div class="codehilite"><pre>  <span class="kd">private</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">print</span><span class="o">(</span><span class="n">String</span> <span class="n">content</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">content</span><span class="o">);</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="kd">static</span> <span class="n">String</span> <span class="nf">prettyPrint</span><span class="o">(</span><span class="n">ODataEntry</span> <span class="n">createdEntry</span><span class="o">)</span> <span class="o">{</span>
+    <span class="k">return</span> <span class="nf">prettyPrint</span><span class="o">(</span><span class="n">createdEntry</span><span class="o">.</span><span class="na">getProperties</span><span class="o">(),</span> <span class="mi">0</span><span class="o">);</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="kd">static</span> <span class="n">String</span> <span class="nf">prettyPrint</span><span class="o">(</span><span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">properties</span><span class="o">,</span> <span class="kt">int</span> <span class="n">level</span><span class="o">)</span> <span class="o">{</span>
+    <span class="n">StringBuilder</span> <span class="n">b</span> <span class="o">=</span> <span class="k">new</span> <span class="n">StringBuilder</span><span class="o">();</span>
+    <span class="n">Set</span><span class="o">&lt;</span><span class="n">Entry</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;&gt;</span> <span class="n">entries</span> <span class="o">=</span> <span class="n">properties</span><span class="o">.</span><span class="na">entrySet</span><span class="o">();</span>
+
+    <span class="k">for</span> <span class="o">(</span><span class="n">Entry</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">entry</span> <span class="o">:</span> <span class="n">entries</span><span class="o">)</span> <span class="o">{</span>
+      <span class="n">intend</span><span class="o">(</span><span class="n">b</span><span class="o">,</span> <span class="n">level</span><span class="o">);</span>
+      <span class="n">b</span><span class="o">.</span><span class="na">append</span><span class="o">(</span><span class="n">entry</span><span class="o">.</span><span class="na">getKey</span><span class="o">()).</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;: &quot;</span><span class="o">);</span>
+      <span class="n">Object</span> <span class="n">value</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="na">getValue</span><span class="o">();</span>
+      <span class="k">if</span><span class="o">(</span><span class="n">value</span> <span class="k">instanceof</span> <span class="n">Map</span><span class="o">)</span> <span class="o">{</span>
+        <span class="n">value</span> <span class="o">=</span> <span class="n">prettyPrint</span><span class="o">((</span><span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">&gt;)</span><span class="n">value</span><span class="o">,</span> <span class="n">level</span><span class="o">+</span><span class="mi">1</span><span class="o">);</span>
+        <span class="n">b</span><span class="o">.</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;\n&quot;</span><span class="o">);</span>
+      <span class="o">}</span> <span class="k">else</span> <span class="k">if</span><span class="o">(</span><span class="n">value</span> <span class="k">instanceof</span> <span class="n">Calendar</span><span class="o">)</span> <span class="o">{</span>
+        <span class="n">Calendar</span> <span class="n">cal</span> <span class="o">=</span> <span class="o">(</span><span class="n">Calendar</span><span class="o">)</span> <span class="n">value</span><span class="o">;</span>
+        <span class="n">value</span> <span class="o">=</span> <span class="n">SimpleDateFormat</span><span class="o">.</span><span class="na">getInstance</span><span class="o">().</span><span class="na">format</span><span class="o">(</span><span class="n">cal</span><span class="o">.</span><span class="na">getTime</span><span class="o">());</span>
+      <span class="o">}</span>
+      <span class="n">b</span><span class="o">.</span><span class="na">append</span><span class="o">(</span><span class="n">value</span><span class="o">).</span><span class="na">append</span><span class="o">(</span><span class="s">&quot;\n&quot;</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="c1">// remove last line break</span>
+    <span class="n">b</span><span class="o">.</span><span class="na">deleteCharAt</span><span class="o">(</span><span class="n">b</span><span class="o">.</span><span class="na">length</span><span class="o">()-</span><span class="mi">1</span><span class="o">);</span>
+    <span class="k">return</span> <span class="n">b</span><span class="o">.</span><span class="na">toString</span><span class="o">();</span>
+  <span class="o">}</span>
+
+  <span class="kd">private</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">intend</span><span class="o">(</span><span class="n">StringBuilder</span> <span class="n">builder</span><span class="o">,</span> <span class="kt">int</span> <span class="n">intendLevel</span><span class="o">)</span> <span class="o">{</span>

[... 551 lines stripped ...]


Mime
View raw message