You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/02/04 06:15:42 UTC
svn commit: r1564202 -
/incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext
Author: mibo
Date: Tue Feb 4 05:15:42 2014
New Revision: 1564202
URL: http://svn.apache.org/r1564202
Log:
add java highlighting
Modified:
incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext
Modified: incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext
URL: http://svn.apache.org/viewvc/incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext?rev=1564202&r1=1564201&r2=1564202&view=diff
==============================================================================
--- incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext (original)
+++ incubator/olingo/site/trunk/content/doc/tutorials/OlingoV2BasicClientSample.mdtext Tue Feb 4 05:15:42 2014
@@ -60,6 +60,7 @@ Hence the first step in this sample is t
**Code sample: Read EDM ($metadata)**
+ :::java
public Edm readEdm(String serviceUrl) throws IOException, ODataException {
InputStream content = execute(serviceUrl + "/" + METADATA, APPLICATION_XML, HTTP_METHOD_GET);
return EntityProvider.readMetadata(content, false);
@@ -85,6 +86,7 @@ Hence the code samples looks very simila
**Read complete Feed**
+ :::java
public ODataFeed readFeed(Edm edm, String serviceUri, String contentType, String entitySetName)
throws IOException, ODataException {
EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
@@ -101,6 +103,7 @@ For read of a complete `ODataFeed` the *
**Read single Entry**
+ :::java
public ODataEntry readEntry(Edm edm, String serviceUri, String contentType, String entitySetName, String keyValue)
throws IOException, ODataException {
// working with the default entity container
@@ -132,6 +135,7 @@ Additional the parts below are only code
**Part 1: POST entry**
+ :::java
HttpURLConnection connection = initializeConnection(absolutUri, contentType, httpMethod);
// prepare
EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
@@ -158,6 +162,7 @@ After this the entity is posted (created
**Part 2: Read response**
+ :::java
// if a entity is created (via POST request) the response body contains the new created entity
HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(connection.getResponseCode());
if(statusCode == HttpStatusCodes.CREATED) {
@@ -176,6 +181,7 @@ The result is a de-serialized `ODataEntr
**Part 3: Create single Entry method**
+ :::java
public ODataEntry createEntry(Edm edm, String serviceUri, String contentType,
String entitySetName, Map<String, Object> data) throws Exception {
String absolutUri = createUri(serviceUri, entitySetName, null);
@@ -205,6 +211,7 @@ For simplicity in the code sample below
**Part 1: PUT entry**
+ :::java
HttpURLConnection connection = initializeConnection(absolutUri, contentType, httpMethod);
// prepare
EdmEntityContainer entityContainer = edm.getDefaultEntityContainer();
@@ -236,6 +243,7 @@ After this the entity is update and the
**Part 2: Update Entry method**
+ :::java
public void updateEntry(Edm edm, String serviceUri, String contentType, String entitySetName,
String id, Map<String, Object> data) throws Exception {
String absolutUri = createUri(serviceUri, entitySetName, id);
@@ -248,6 +256,7 @@ The *Part 1* is copied from the shared `
For deletion of an entry just an *HTTP DELETE* 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.
+ :::java
public HttpStatusCodes deleteEntry(String serviceUri, String entityName, String id) throws IOException {
String absolutUri = createUri(serviceUri, entityName, id);
HttpURLConnection connection = connect(absolutUri, APPLICATION_XML, HTTP_METHOD_DELETE);
@@ -266,6 +275,7 @@ In this section are all methods shared a
The `writeEntity(...)` method is used for *creation* and *update* of an entry. Simplified it executes the given `httpMethod` on the given `absolutUri` for the serialized entry based on given `contentType`, `entitySetName` and `data`. Additional for the case of an successfull *create* the `ODataEntry` is returned otherwise `null` is returned.
+ :::java
private ODataEntry writeEntity(Edm edm, String absolutUri, String entitySetName,
Map<String, Object> data, String contentType, String httpMethod)
throws EdmException, MalformedURLException, IOException, EntityProviderException, URISyntaxException {
@@ -315,6 +325,7 @@ The `writeEntity(...)` method is used fo
The `createUri(...)` method is used in every convenience method (*read*, *create*, *update* and *delete*) to build the absolut uri based on the `serviceUri`, `entitySetName` and `id` for the case of a single Entry.
+ :::java
private String createUri(String serviceUri, String entitySetName, String id) {
final StringBuilder absolutUri = new StringBuilder(serviceUri).append("/").append(entitySetName);
if(id != null) {
@@ -327,6 +338,7 @@ The `createUri(...)` method is used in e
The `exectute(...)`, `connect(...)` and `initializeConnection(...)` methods are used for initialization of the connection, execute and/or connect and check basic connection success (via `checkStatus(...)` method) to the OData Service and is therefore used in every use case (*read*, *create*, *update* and *delete*).
+ :::java
private InputStream execute(String relativeUri, String contentType, String httpMethod) throws IOException {
HttpURLConnection connection = initializeConnection(relativeUri, contentType, httpMethod);
@@ -374,6 +386,7 @@ The `exectute(...)`, `connect(...)` and
The `logRawContent(...)` method is simply used for logging the content of the given `InputStream` and re-creation of an readable `InputStream` which is returned.
+ :::java
private InputStream logRawContent(String prefix, InputStream content, String postfix) throws IOException {
if(PRINT_RAW_CONTENT) {
byte[] buffer = new byte[8192];
@@ -398,6 +411,7 @@ To show a sample on how to a sample clie
**Main sample method**
+ :::java
public static void main(String[] paras) throws Exception {
OlingoSampleApp app = new OlingoSampleApp();
@@ -462,6 +476,7 @@ To show a sample on how to a sample clie
The `print` methods are only for simplified print/write logging to some output channel. In the sample it is just the `System.out` stream.
+ :::java
private static void print(String content) {
System.out.println(content);
}