You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by bu...@apache.org on 2014/02/12 09:24:02 UTC

svn commit: r897577 - in /websites/staging/olingo/trunk/content: ./ doc/tutorials/OlingoV2BasicClientSample.html

Author: buildbot
Date: Wed Feb 12 08:24:02 2014
New Revision: 897577

Log:
Staging update by buildbot for olingo

Modified:
    websites/staging/olingo/trunk/content/   (props changed)
    websites/staging/olingo/trunk/content/doc/tutorials/OlingoV2BasicClientSample.html

Propchange: websites/staging/olingo/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Wed Feb 12 08:24:02 2014
@@ -1 +1 @@
-1567156
+1567559

Modified: websites/staging/olingo/trunk/content/doc/tutorials/OlingoV2BasicClientSample.html
==============================================================================
--- websites/staging/olingo/trunk/content/doc/tutorials/OlingoV2BasicClientSample.html (original)
+++ websites/staging/olingo/trunk/content/doc/tutorials/OlingoV2BasicClientSample.html Wed Feb 12 08:24:02 2014
@@ -76,15 +76,57 @@
 <p>This Tutorial shows how to use the Apache Olingo Library for CRUD operations on an OData Service.
 Therefore it contains the main sections:</p>
 <ul>
-<li><a href="#start">Starting the sample</a>: The actual <em>How To</em> with explanation and sample code</li>
-<li><a href="#run">Run the sample</a>: A explanation and sample how before build client can be used (Requirements at least <em>JDK 7</em> and <em>Maven 3</em>)</li>
+<li><a href="#quickstart">Client Quickstart Guide</a>: Get a running sample client and server within a few minutes (Requirements at least <em>Java 7 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:<ul>
+<li><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></li>
+</ul>
+</li>
+<li><a href="#run">Run the Client</a><ul>
+<li><a href="#together">Put the parts together</a>: A explanation and sample how before build client can be used (Requirements at least <em>Java 7 Runtime</em> and <em>Maven 3</em>)</li>
 <li><a href="#copypaste">Copy and Paste</a>: Contains the complete sample code as <em>copy/paste</em> template (to build a Maven Project)</li>
 </ul>
+</li>
+</ul>
+<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 7 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 
+               <code>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-incubating 
+                 -DarchetypeVersion=1.1.0</code></li>
+<li>Go into from archetype created folder <code>my-car-service</code> and just run <code>mvn</code> to start server.</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>. This starts a <em>Jetty Web Server</em> at <a href="http://localhost:8080">http://localhost:8080</a>.</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>
 <p><a name="start"></a></p>
-<h3 id="starting-the-sample">Starting the Sample</h3>
+<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>).
@@ -99,6 +141,7 @@ Hence the first step in this sample is t
 
 <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>.
@@ -145,6 +188,7 @@ the <code>EntityProviderReadProperties</
 
 <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). 
@@ -204,6 +248,7 @@ The result is a de-serialized <code>ODat
 
 
 <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>
@@ -261,6 +306,7 @@ In the code sample the <code>InputStream
 
 
 <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>
@@ -383,19 +429,32 @@ In the code sample the <code>InputStream
 
 
 <p><strong>Logging</strong></p>
-<p>The <code>logRawContent(...)</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>
+<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="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">size</span> <span class="o">=</span> <span class="n">content</span><span class="o">.</span><span class="na">read</span><span class="o">(</span><span class="n">buffer</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="mi">0</span><span class="o">,</span> <span class="n">size</span><span class="o">)</span> <span class="o">+</span> <span class="n">postfix</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="mi">0</span><span class="o">,</span> <span class="n">size</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>
 
 
@@ -405,27 +464,11 @@ In the code sample the <code>InputStream
 
 <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 below <code>main</code> method 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>That this sample <code>main</code> method work it is necessary that an OData Service with corresponding <em>Data Model (EDM)</em> is available at the <code>service url</code> defined in the <code>main</code> method (which is in the sample <code>http://localhost:8080/MyFormula.svc</code>).
-This can easily achieved if the Apache Olingo archetype (with id: <code>olingo-odata2-sample-cars-annotation-archetype-incubating</code>) is used. 
-To use the archtype and create this sample project Maven must be called as shown below:</p>
-<div class="codehilite"><pre><span class="n">mvn</span> <span class="n">archetype</span><span class="p">:</span><span class="n">generate</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DinteractiveMode</span><span class="p">=</span><span class="n">false</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">Dversion</span><span class="p">=</span>1<span class="p">.</span>0<span class="p">.</span>0<span class="o">-</span><span class="n">SNAPSHOT</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DgroupId</span><span class="p">=</span><span class="n">com</span><span class="p">.</span><span class="n">sample</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DartifactId</span><span class="p">=</span><span class="n">my</span><span class="o">-</span><span class="n">car</span><span class="o">-</span><span class="n">service</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DarchetypeGroupId</span><span class="p">=</span><span class="n">org</span><span class="p">.</span><span class="n">apache</span><span class="p">.</span><span class="n">olingo</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DarchetypeArtifactId</span><span class="p">=</span><span class="n">olingo</span><span class="o">-</span><span class="n">odata2</span><span class="o">-</span><span class="n">sample</span><span class="o">-</span><span class="n">cars</span><span class="o">-</span><span class="n">annotation</span><span class="o">-</span><span class="n">archetype</span><span class="o">-</span><span class="n">incubating</span> <span class="o">\</span>
-  <span class="o">-</span><span class="n">DarchetypeVersion</span><span class="p">=</span>1<span class="p">.</span>1<span class="p">.</span>0
-</pre></div>
-
-
-<p>In the generated sample project you now can simply run Maven with the default goal (run <code>mvn</code> in the shell) which compiles the sources and starts an Jetty web server at <a href="http://localhost:8080">http://localhost:8080</a>.</p>
-<p>For more detailed documentation on how to use this archetype take a look into the documentation about Archetypes in Olingo in the <a href="/doc/sample-setup">sample setup</a> section.</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 as well as a <code>pom.xml</code> to set up a maven project which all necessary build information. Only requirement is a installed <em>JDK 7</em> and <em>Maven 3</em> environment.</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 7 Runtime</em> and <em>Maven 3</em> environment.</p>
+<p><strong>Missing methods</strong></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>
@@ -529,8 +572,29 @@ To use the archtype and create this samp
 </pre></div>
 
 
-<p><a name="copypaste"></a></p>
-<h3 id="copy-and-paste">Copy and Paste</h3>
+<p><a name="sampleservice"></a></p>
+<h5 id="sample-service">Sample Service</h5>
+<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 below <code>main</code> method 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>That this sample <code>main</code> method work it is necessary that an OData Service with corresponding <em>Data Model (EDM)</em> is available at the <code>service url</code> defined in the <code>main</code> method (which is in the sample <code>http://localhost:8080/MyFormula.svc</code>).
+This can easily achieved if the Apache Olingo archetype (with id: <code>olingo-odata2-sample-cars-annotation-archetype-incubating</code>) is used. 
+To use the archtype and create this sample project Maven must be called as shown below:</p>
+<div class="codehilite"><pre><span class="n">mvn</span> <span class="n">archetype</span><span class="p">:</span><span class="n">generate</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DinteractiveMode</span><span class="p">=</span><span class="n">false</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">Dversion</span><span class="p">=</span>1<span class="p">.</span>0<span class="p">.</span>0<span class="o">-</span><span class="n">SNAPSHOT</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DgroupId</span><span class="p">=</span><span class="n">com</span><span class="p">.</span><span class="n">sample</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DartifactId</span><span class="p">=</span><span class="n">my</span><span class="o">-</span><span class="n">car</span><span class="o">-</span><span class="n">service</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DarchetypeGroupId</span><span class="p">=</span><span class="n">org</span><span class="p">.</span><span class="n">apache</span><span class="p">.</span><span class="n">olingo</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DarchetypeArtifactId</span><span class="p">=</span><span class="n">olingo</span><span class="o">-</span><span class="n">odata2</span><span class="o">-</span><span class="n">sample</span><span class="o">-</span><span class="n">cars</span><span class="o">-</span><span class="n">annotation</span><span class="o">-</span><span class="n">archetype</span><span class="o">-</span><span class="n">incubating</span> <span class="o">\</span>
+  <span class="o">-</span><span class="n">DarchetypeVersion</span><span class="p">=</span>1<span class="p">.</span>1<span class="p">.</span>0
+</pre></div>
+
+
+<p>In the generated sample project you now can simply run Maven with the default goal (run <code>mvn</code> in the shell) which compiles the sources and starts a <em>Jetty Web Server</em> at <a href="http://localhost:8080">http://localhost:8080</a>.</p>
+<p>For more detailed documentation on how to use this archetype take a look into the documentation about Archetypes in Olingo in the <a href="/doc/sample-setup">sample setup</a> section.</p>
+<p><a name="projectstructure"></a></p>
+<h5 id="project-structure">Project structure</h5>
 <p>This section contains the complete Maven Project <code>pom.xml</code> and <code>OlingoSampleApp</code> to build the project. 
 To use it just copy both blocks into files in following directory structure:</p>
 <div class="codehilite"><pre><span class="n">ProjectFolder</span>
@@ -541,13 +605,17 @@ To use it just copy both blocks into fil
 
 <p>Then run <code>mvn</code> to build the project.
 After successfull build the sample client (i.e. its <code>main</code>) can be executed via <code>java -cp target/OlingoSampleClient.jar org.apache.olingo.sample.client.OlingoSampleApp</code>.
-If the corresponding OData Service based on the <em>archetypeArtifactId=olingo-odata2-sample-cars-annotation-archetype-incubating</em> (see Olingo Annotation Archetype) is running on <code>http://localhost:8080/MyFormula.svc</code> the sample work and log some information to the console.</p>
+If the corresponding OData Service based on the <em>archetypeArtifactId=olingo-odata2-sample-cars-annotation-archetype-incubating</em> (see Olingo Annotation Archetype) is running on <a href="http://localhost:8080/MyFormula.svc">http://localhost:8080/MyFormula.svc</a> the sample work and log some information to the console.</p>
+<p><a name="runsample"></a></p>
 <h5 id="run-command">Run command</h5>
 <p>Must be run from project root directory after build with Maven (<code>mvn</code>).</p>
 <div class="codehilite"><pre><span class="n">java</span> <span class="o">-</span><span class="n">cp</span> <span class="n">target</span><span class="o">/</span><span class="n">OlingoSampleClient</span><span class="p">.</span><span class="n">jar</span> <span class="n">org</span><span class="p">.</span><span class="n">apache</span><span class="p">.</span><span class="n">olingo</span><span class="p">.</span><span class="n">sample</span><span class="p">.</span><span class="n">client</span><span class="p">.</span><span class="n">OlingoSampleApp</span>
 </pre></div>
 
 
+<p><a name="copypaste"></a></p>
+<h5 id="copy-and-paste">Copy and Paste</h5>
+<p><a name="pom"></a></p>
 <h5 id="project-pom">Project Pom</h5>
 <p>Maven project POM (<code>pom.xml</code>)</p>
 <div class="codehilite"><pre><span class="cp">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
@@ -636,6 +704,7 @@ If the corresponding OData Service based
 </pre></div>
 
 
+<p><a name="sampleclient"></a></p>
 <h5 id="client-sample">Client Sample</h5>
 <p>Complete <code>OlingoSampleApp</code> with <code>main</code> which can be <em>copy/pasted</em> into a <code>OlingoSampleApp.java</code>, then compiled and run.</p>
 <div class="codehilite"><pre><span class="cm">/*******************************************************************************</span>
@@ -839,17 +908,30 @@ If the corresponding OData Service based
 
   <span class="n">private</span> <span class="n">InputStream</span> <span class="n">logRawContent</span><span class="p">(</span><span class="n">String</span> <span class="n">prefix</span><span class="p">,</span> <span class="n">InputStream</span> <span class="n">content</span><span class="p">,</span> <span class="n">String</span> <span class="n">postfix</span><span class="p">)</span> <span class="n">throws</span> <span class="n">IOException</span> <span class="p">{</span>
     <span class="k">if</span><span class="p">(</span><span class="no">PRINT_RAW_CONTENT</span><span class="p">)</span> <span class="p">{</span>
-      <span class="k">byte</span><span class="p">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="k">new</span> <span class="k">byte</span><span class="p">[</span><span class="mh">8192</span><span class="p">];</span>
-      <span class="k">int</span> <span class="n">size</span> <span class="o">=</span> <span class="n">content</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="n">buffer</span><span class="p">);</span>
+      <span class="k">byte</span><span class="p">[]</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">streamToArray</span><span class="p">(</span><span class="n">content</span><span class="p">);</span>
       <span class="n">content</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
 
-      <span class="n">print</span><span class="p">(</span><span class="n">prefix</span> <span class="o">+</span> <span class="k">new</span> <span class="n">String</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="mh">0</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span> <span class="o">+</span> <span class="n">postfix</span><span class="p">);</span>
+      <span class="n">print</span><span class="p">(</span><span class="n">prefix</span> <span class="o">+</span> <span class="k">new</span> <span class="n">String</span><span class="p">(</span><span class="n">buffer</span><span class="p">)</span> <span class="o">+</span> <span class="n">postfix</span><span class="p">);</span>
 
-      <span class="k">return</span> <span class="k">new</span> <span class="n">ByteArrayInputStream</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="mh">0</span><span class="p">,</span> <span class="n">size</span><span class="p">);</span>
+      <span class="k">return</span> <span class="k">new</span> <span class="n">ByteArrayInputStream</span><span class="p">(</span><span class="n">buffer</span><span class="p">);</span>
     <span class="p">}</span>
     <span class="k">return</span> <span class="n">content</span><span class="p">;</span>
   <span class="p">}</span>
 
+  <span class="n">private</span> <span class="k">byte</span><span class="p">[]</span> <span class="n">streamToArray</span><span class="p">(</span><span class="n">InputStream</span> <span class="n">stream</span><span class="p">)</span> <span class="n">throws</span> <span class="n">IOException</span> <span class="p">{</span>
+    <span class="k">byte</span><span class="p">[]</span> <span class="n">result</span> <span class="o">=</span> <span class="k">new</span> <span class="k">byte</span><span class="p">[</span><span class="mh">0</span><span class="p">];</span>
+    <span class="k">byte</span><span class="p">[]</span> <span class="n">tmp</span> <span class="o">=</span> <span class="k">new</span> <span class="k">byte</span><span class="p">[</span><span class="mh">8192</span><span class="p">];</span>
+    <span class="k">int</span> <span class="n">readCount</span> <span class="o">=</span> <span class="n">stream</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="n">tmp</span><span class="p">);</span>
+    <span class="k">while</span><span class="p">(</span><span class="n">readCount</span> <span class="o">&gt;=</span> <span class="mh">0</span><span class="p">)</span> <span class="p">{</span>
+      <span class="k">byte</span><span class="p">[]</span> <span class="n">innerTmp</span> <span class="o">=</span> <span class="k">new</span> <span class="k">byte</span><span class="p">[</span><span class="n">result</span><span class="p">.</span><span class="n">length</span> <span class="o">+</span> <span class="n">readCount</span><span class="p">];</span>
+      <span class="n">System</span><span class="p">.</span><span class="n">arraycopy</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="mh">0</span><span class="p">,</span> <span class="n">innerTmp</span><span class="p">,</span> <span class="mh">0</span><span class="p">,</span> <span class="n">result</span><span class="p">.</span><span class="n">length</span><span class="p">);</span>
+      <span class="n">System</span><span class="p">.</span><span class="n">arraycopy</span><span class="p">(</span><span class="n">tmp</span><span class="p">,</span> <span class="mh">0</span><span class="p">,</span> <span class="n">innerTmp</span><span class="p">,</span> <span class="n">result</span><span class="p">.</span><span class="n">length</span><span class="p">,</span> <span class="n">readCount</span><span class="p">);</span>
+      <span class="n">result</span> <span class="o">=</span> <span class="n">innerTmp</span><span class="p">;</span>
+      <span class="n">readCount</span> <span class="o">=</span> <span class="n">stream</span><span class="p">.</span><span class="n">read</span><span class="p">(</span><span class="n">tmp</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="k">return</span> <span class="n">result</span><span class="p">;</span>
+  <span class="p">}</span>
+
   <span class="n">public</span> <span class="n">ODataEntry</span> <span class="n">createEntry</span><span class="p">(</span><span class="n">Edm</span> <span class="n">edm</span><span class="p">,</span> <span class="n">String</span> <span class="n">serviceUri</span><span class="p">,</span> <span class="n">String</span> <span class="n">contentType</span><span class="p">,</span> 
       <span class="n">String</span> <span class="n">entitySetName</span><span class="p">,</span> <span class="n">Map</span><span class="o">&lt;</span><span class="n">String</span><span class="p">,</span> <span class="n">Object</span><span class="o">&gt;</span> <span class="n">data</span><span class="p">)</span> <span class="n">throws</span> <span class="n">Exception</span> <span class="p">{</span>
     <span class="n">String</span> <span class="n">absolutUri</span> <span class="o">=</span> <span class="n">createUri</span><span class="p">(</span><span class="n">serviceUri</span><span class="p">,</span> <span class="n">entitySetName</span><span class="p">,</span> <span class="k">null</span><span class="p">);</span>