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 2016/02/22 08:54:25 UTC

[01/21] olingo-odata4 git commit: [OLINGO-832] First idea of PoC

Repository: olingo-odata4
Updated Branches:
  refs/heads/master c86009a24 -> 0879bfbe5


[OLINGO-832] First idea of PoC


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

Branch: refs/heads/master
Commit: f4ad8892adf11a91e99b7bc555f6c765140d5bc9
Parents: d88913f
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Dec 8 14:49:26 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Dec 14 09:12:03 2015 +0100

----------------------------------------------------------------------
 .../api/data/EntityStreamCollection.java        |  28 +++
 .../apache/olingo/server/core/ODataImpl.java    |   4 +-
 .../core/serializer/StreamSerializerResult.java | 166 +++++++++++++++++
 .../serializer/json/ODataJsonSerializer.java    |  10 +-
 .../json/ODataJsonStreamSerializer.java         | 183 +++++++++++++++++++
 .../processor/TechnicalEntityProcessor.java     | 116 +++++++++++-
 6 files changed, 500 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
new file mode 100644
index 0000000..9eae442
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.data;
+
+/**
+ * Data representation for a collection of single entities.
+ */
+public abstract class EntityStreamCollection extends EntityCollection {
+
+  public abstract boolean hasNext();
+  public abstract Entity nextEntity();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index ad7d410..df6c7df 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -49,6 +49,7 @@ import org.apache.olingo.server.core.etag.ETagHelperImpl;
 import org.apache.olingo.server.core.prefer.PreferencesImpl;
 import org.apache.olingo.server.core.serializer.FixedFormatSerializerImpl;
 import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
+import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
 import org.apache.olingo.server.core.uri.UriHelperImpl;
 
@@ -63,7 +64,8 @@ public class ODataImpl extends OData {
       if (metadata == null
           || ContentType.VALUE_ODATA_METADATA_MINIMAL.equals(metadata)
           || ContentType.VALUE_ODATA_METADATA_NONE.equals(metadata)) {
-        serializer = new ODataJsonSerializer(contentType);
+//        serializer = new ODataJsonSerializer(contentType);
+        serializer = new ODataJsonStreamSerializer(contentType);
       }
     } else if (contentType.isCompatible(ContentType.APPLICATION_XML)
         || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
new file mode 100644
index 0000000..d45c594
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class StreamSerializerResult implements SerializerResult {
+  private InputStream content;
+
+  private static class StreamInputStream extends InputStream {
+    private String head;
+    private String tail;
+    private int tailCount = 0;
+    private int headCount = 0;
+    private int entityCount = 0;
+    private InputStream inputStream = null;
+    private ODataJsonStreamSerializer jsonSerializer;
+    private EntityStreamCollection coll;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+
+    public StreamInputStream(EntityStreamCollection coll, EdmEntityType entityType, String head,
+        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
+        EntitySerializerOptions options, String tail) {
+      this.coll = coll;
+      this.entityType = entityType;
+      this.head = head;
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+      this.tail = tail;
+    }
+
+    @Override
+    public int read() throws IOException {
+      if (headCount < head.length()) {
+        return head.charAt(headCount++);
+      }
+      if (inputStream == null && coll.hasNext()) {
+        try {
+          inputStream = serEntity(coll.nextEntity());
+          entityCount++;
+          if (entityCount > 1) {
+            return (int) ',';
+          }
+        } catch (SerializerException e) {
+          inputStream = null;
+          return read();
+        }
+      }
+      if (inputStream != null) {
+        int read = inputStream.read();
+        if (read == -1) {
+          inputStream = null;
+          return read();
+        }
+        return read;
+      }
+      if (tailCount < tail.length()) {
+        return tail.charAt(tailCount++);
+      }
+      return -1;
+    }
+
+    private InputStream serEntity(Entity entity) throws SerializerException {
+      try {
+        CircleStreamBuffer buffer = new CircleStreamBuffer();
+        OutputStream outputStream = buffer.getOutputStream();
+        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+        jsonSerializer.writeEntity(metadata, entityType, entity, null,
+            options == null ? null : options.getExpand(),
+            options == null ? null : options.getSelect(),
+            options != null && options.getWriteOnlyReferences(),
+            json);
+
+        json.close();
+        outputStream.close();
+        return buffer.getInputStream();
+      } catch (final IOException e) {
+        return new ByteArrayInputStream(("ERROR" + e.getMessage()).getBytes());
+//      } catch (SerializerException e) {
+//        return new ByteArrayInputStream(("ERROR" + e.getMessage()).getBytes());
+      }
+    }
+  }
+
+  @Override
+  public InputStream getContent() {
+    return content;
+  }
+
+  private StreamSerializerResult(InputStream content) {
+    this.content = content;
+  }
+
+  public static SerializerResultBuilder with(EntityStreamCollection coll, EdmEntityType entityType,
+      ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+    return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
+  }
+
+  public static class SerializerResultBuilder {
+    private ODataJsonStreamSerializer jsonSerializer;
+    private EntityStreamCollection coll;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+    private String head;
+    private String tail;
+
+    public SerializerResultBuilder(EntityStreamCollection coll, EdmEntityType entityType,
+        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+      this.coll = coll;
+      this.entityType = entityType;
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+    }
+
+    public SerializerResultBuilder addHead(String head) {
+      this.head = head;
+      return this;
+    }
+
+    public SerializerResultBuilder addTail(String tail) {
+      this.tail = tail;
+      return this;
+    }
+
+    public SerializerResult build() {
+      InputStream input = new StreamInputStream(coll, entityType, head, jsonSerializer, metadata, options, tail);
+      return new StreamSerializerResult(input);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index b5a2c6a..4a1a528 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -203,7 +203,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     }
   }
 
-  private ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException {
+  ContextURL checkContextURL(final ContextURL contextURL) throws SerializerException {
     if (isODataMetadataNone) {
       return null;
     } else if (contextURL == null) {
@@ -767,13 +767,13 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
 
   }
 
-  private void writeContextURL(final ContextURL contextURL, JsonGenerator json) throws IOException {
+  void writeContextURL(final ContextURL contextURL, JsonGenerator json) throws IOException {
     if (!isODataMetadataNone && contextURL != null) {
       json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
     }
   }
 
-  private void writeMetadataETag(final ServiceMetadata metadata, JsonGenerator json) throws IOException {
+  void writeMetadataETag(final ServiceMetadata metadata, JsonGenerator json) throws IOException {
     if (!isODataMetadataNone
         && metadata != null
         && metadata.getServiceMetadataETagSupport() != null
@@ -783,7 +783,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     }
   }
 
-  private void writeCount(final EntityCollection entityCollection, JsonGenerator json) throws IOException {
+  void writeCount(final EntityCollection entityCollection, JsonGenerator json) throws IOException {
     if (entityCollection.getCount() != null) {
       if (isIEEE754Compatible) {
         json.writeStringField(Constants.JSON_COUNT, entityCollection.getCount().toString());
@@ -793,7 +793,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     }
   }
 
-  private void writeNextLink(final EntityCollection entitySet, JsonGenerator json) throws IOException {
+  void writeNextLink(final EntityCollection entitySet, JsonGenerator json) throws IOException {
     if (entitySet.getNext() != null) {
       json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
new file mode 100644
index 0000000..08a30c6
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer.json;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.data.ComplexValue;
+import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.data.Link;
+import org.apache.olingo.commons.api.data.Linked;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.edm.EdmComplexType;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.server.api.ODataServerError;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
+import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.uri.UriHelper;
+import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
+import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.core.serializer.AbstractODataSerializer;
+import org.apache.olingo.server.core.serializer.SerializerResultImpl;
+import org.apache.olingo.server.core.serializer.StreamSerializerResult;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+import org.apache.olingo.server.core.serializer.utils.ContentTypeHelper;
+import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
+import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
+import org.apache.olingo.server.core.uri.UriHelperImpl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ODataJsonStreamSerializer extends ODataJsonSerializer {
+
+  private final ODataJsonSerializer serializer;
+
+  public ODataJsonStreamSerializer(final ContentType contentType) {
+    super(contentType);
+    this.serializer = new ODataJsonSerializer(contentType);
+  }
+
+  @Override
+  public SerializerResult entityCollection(final ServiceMetadata metadata,
+      final EdmEntityType entityType, final EntityCollection entitySet,
+      final EntityCollectionSerializerOptions options) throws SerializerException {
+
+    EntityStreamCollection coll;
+    if(entitySet instanceof EntityStreamCollection) {
+      coll = (EntityStreamCollection) entitySet;
+    } else {
+      return serializer.entityCollection(metadata, entityType, entitySet, options);
+    }
+
+    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+    SerializerException cachedException = null;
+    try {
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+      json.writeStartObject();
+
+      final ContextURL contextURL = serializer.checkContextURL(options == null ? null : options.getContextURL());
+      serializer.writeContextURL(contextURL, json);
+
+      serializer.writeMetadataETag(metadata, json);
+
+      if (options != null && options.getCount() != null && options.getCount().getValue()) {
+        serializer.writeCount(entitySet, json);
+      }
+      json.writeFieldName(Constants.VALUE);
+      json.writeStartArray();
+      json.close();
+      outputStream.close();
+      String temp = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
+      String head = temp.substring(0, temp.length()-2);
+      //      if (options == null) {
+//        writeEntitySet(metadata, entityType, entitySet, null, null, false, json);
+//      } else {
+//        writeEntitySet(metadata, entityType, entitySet,
+//            options.getExpand(), options.getSelect(), options.getWriteOnlyReferences(), json);
+//      }
+
+      outputStream = new ByteArrayOutputStream();
+      outputStream.write(']');
+      outputStream.write('}');
+      outputStream.close();
+      String tail = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
+
+      EntitySerializerOptions.Builder opt = EntitySerializerOptions.with();
+      if(options != null) {
+        opt.expand(options.getExpand()).select(options
+            .getSelect()).writeOnlyReferences(options.getWriteOnlyReferences());
+      }
+      return StreamSerializerResult.with(coll, entityType, this, metadata, opt.build())
+          .addHead(head).addTail(tail).build();
+    } catch (final IOException e) {
+      cachedException =
+          new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
+      throw cachedException;
+    } finally {
+      closeCircleStreamBufferOutput(outputStream, cachedException);
+    }
+  }
+
+  @Override
+  public void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
+      final Entity entity, final ContextURL contextURL, final ExpandOption expand,
+      final SelectOption select, final boolean onlyReference, final JsonGenerator json)
+      throws IOException, SerializerException {
+    serializer.writeEntity(metadata, entityType, entity, contextURL, expand, select, onlyReference, json);
+  }
+
+//  @Override
+//  public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
+//      final Entity entity, final EntitySerializerOptions options) throws SerializerException {
+//    return serializer.entity(metadata, entityType, entity, options);
+//  }
+
+//  protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
+//      final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
+//      final boolean onlyReference, final JsonGenerator json) throws IOException,
+//      SerializerException {
+//
+//        json.writeStartArray();
+//        json.writeEndArray();
+//
+    //    json.writeStartArray();
+//    for (final Entity entity : entitySet.getEntities()) {
+//      if (onlyReference) {
+//        json.writeStartObject();
+//        json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
+//        json.writeEndObject();
+//      } else {
+//        serializer.writeEntity(metadata, entityType, entity, null, expand, select, false, json);
+//      }
+//    }
+//    json.writeEndArray();
+//  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f4ad8892/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 6d7c41e..6644f1e 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -18,13 +18,20 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
+import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.ContextURL.Builder;
 import org.apache.olingo.commons.api.data.ContextURL.Suffix;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.format.ContentType;
@@ -520,11 +527,17 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     }
 
     // Serialize
+//    final SerializerResult serializerResult = (isReference) ?
+//        serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption) :
+//        serializeEntityCollection(request, entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
+//            expand, select, countOption, id);
     final SerializerResult serializerResult = (isReference) ?
         serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption) :
-        serializeEntityCollection(request, entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
+        serializeEntityStreamCollectionFixed(request,
+            entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
             expand, select, countOption, id);
     response.setContent(serializerResult.getContent());
+
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
     if (pageSize != null) {
@@ -533,6 +546,107 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     }
   }
 
+  // just for demonstration
+  private SerializerResult serializeEntityStreamCollectionFixed(final ODataRequest request,
+      final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
+      final EdmEntityType edmEntityType,
+      final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
+      final CountOption countOption, final String id) throws ODataLibraryException {
+
+    EntityStreamCollection streamCollection = new EntityStreamCollection() {
+      Iterator<Entity> entityIterator = entityCollection.getEntities().iterator();
+
+      @Override
+      public boolean hasNext() {
+        return entityIterator.hasNext();
+      }
+
+      @Override
+      public Entity nextEntity() {
+        Entity next = entityIterator.next();
+        replacePrimitiveProperty(next, "PropertyString", generateData(28192));
+//        next.getProperties().remove(1);
+//        next.addProperty(new Property(null, "PropertyString", ValueType.PRIMITIVE, generateData(28192)));
+        try {
+          TimeUnit.MILLISECONDS.sleep(2500);
+        } catch (InterruptedException e) { }
+        return next;
+      }
+
+      @Override
+      public List<Entity> getEntities() {
+        return entityCollection.getEntities();
+      }
+
+      private void replacePrimitiveProperty(Entity entity, String name, Object data) {
+        List<Property> properties = entity.getProperties();
+        int pos = 0;
+        for (Property property : properties) {
+          if(name.equals(property.getName())) {
+            properties.remove(pos);
+            entity.addProperty(new Property(null, name, ValueType.PRIMITIVE, data));
+            break;
+          }
+          pos++;
+        }
+      }
+
+      private String generateData(final int len) {
+        Random random = new Random();
+        StringBuilder b = new StringBuilder(len);
+        for (int j = 0; j < len; j++) {
+          final char c = (char) ('A' + random.nextInt('Z' - 'A' + 1));
+          b.append(c);
+        }
+        return b.toString();
+      }
+
+    };
+
+    return odata.createSerializer(requestedFormat).entityCollection(
+        serviceMetadata,
+        edmEntityType,
+        streamCollection,
+        EntityCollectionSerializerOptions.with()
+            .contextURL(isODataMetadataNone(requestedFormat) ? null :
+                getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select))
+            .count(countOption)
+            .expand(expand).select(select)
+            .id(id)
+            .build());
+  }
+
+  private SerializerResult serializeEntityStreamCollection(final ODataRequest request,
+      final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
+      final EdmEntityType edmEntityType,
+      final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
+      final CountOption countOption, final String id) throws ODataLibraryException {
+
+    EntityStreamCollection streamCollection = new EntityStreamCollection() {
+      Iterator<Entity> test = entityCollection.getEntities().iterator();
+      @Override
+      public boolean hasNext() {
+        return test.hasNext();
+      }
+
+      @Override
+      public Entity nextEntity() {
+        return test.next();
+      }
+    };
+    return odata.createSerializer(requestedFormat).entityCollection(
+        serviceMetadata,
+        edmEntityType,
+        streamCollection,
+        EntityCollectionSerializerOptions.with()
+            .contextURL(isODataMetadataNone(requestedFormat) ? null :
+                getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select))
+            .count(countOption)
+            .expand(expand).select(select)
+            .id(id)
+            .build());
+  }
+
   private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
       entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,


[16/21] olingo-odata4 git commit: [OLINGO-832] Added WriteContentErrorContext and first tests

Posted by mi...@apache.org.
[OLINGO-832] Added WriteContentErrorContext and first tests


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

Branch: refs/heads/master
Commit: 5b6cccfa9cd38262b57409bdc6204b16406afd0e
Parents: 67494a7
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Feb 16 15:46:42 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Feb 16 15:46:42 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataContent.java  |   1 -
 .../server/api/WriteContentErrorCallback.java   |   2 +-
 .../server/api/WriteContentErrorContext.java    |  25 +++++
 .../server/core/ODataWritableContent.java       |  50 +++++++--
 .../serializer/json/ODataJsonSerializer.java    |   7 +-
 .../json/ODataJsonSerializerTest.java           | 104 ++++++++++++++++++-
 6 files changed, 173 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
index d7e7ec3..e237bf3 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
@@ -19,7 +19,6 @@
 package org.apache.olingo.server.api;
 
 import java.io.OutputStream;
-import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 
 public interface ODataContent {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
index 4219b8f..abc500a 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
@@ -21,5 +21,5 @@ package org.apache.olingo.server.api;
 import java.nio.channels.WritableByteChannel;
 
 public interface WriteContentErrorCallback {
-  void handleError(ODataContent content, WritableByteChannel channel);
+  void handleError(WriteContentErrorContext context, WritableByteChannel channel);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
new file mode 100644
index 0000000..d773df1
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+public interface WriteContentErrorContext {
+  Exception getException();
+  ODataLibraryException getODataLibraryException();
+//  Object getParameter(String name);
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index ba7025c..1b9cb30 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -25,14 +25,19 @@ import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.ODataContent;
+import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
+import org.apache.olingo.server.api.WriteContentErrorContext;
+import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
@@ -53,11 +58,11 @@ public class ODataWritableContent implements ODataContent {
     private EntityIterator coll;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
-    private EntitySerializerOptions options;
+    private EntityCollectionSerializerOptions options;
 
     public StreamChannel(EntityIterator coll, EdmEntityType entityType, String head,
                          ODataJsonSerializer jsonSerializer, ServiceMetadata metadata,
-                         EntitySerializerOptions options, String tail) {
+                         EntityCollectionSerializerOptions options, String tail) {
       this.coll = coll;
       this.entityType = entityType;
       this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
@@ -81,6 +86,11 @@ public class ODataWritableContent implements ODataContent {
           }
           return true;
         } catch (SerializerException e) {
+          final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
+          if(errorCallback != null) {
+            final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
+            errorCallback.handleError(errorContext, Channels.newChannel(out));
+          }
         }
       } else if(tail.hasRemaining()) {
         out.write(tail.array());
@@ -215,22 +225,50 @@ public class ODataWritableContent implements ODataContent {
 
   public static ODataWritableContentBuilder with(EntityIterator coll, EdmEntityType entityType,
                                              ODataJsonSerializer jsonSerializer,
-                                             ServiceMetadata metadata, EntitySerializerOptions options) {
+                                             ServiceMetadata metadata, EntityCollectionSerializerOptions options) {
     return new ODataWritableContentBuilder(coll, entityType, jsonSerializer, metadata, options);
   }
 
+  public static class ErrorContext implements WriteContentErrorContext {
+    private ODataLibraryException exception;
+    final private Map<String, Object> parameters = new HashMap<String, Object>();
+
+    public ErrorContext(ODataLibraryException exception) {
+      this.exception = exception;
+    }
+
+    @Override
+    public Exception getException() {
+      return exception;
+    }
+    @Override
+    public ODataLibraryException getODataLibraryException() {
+      return exception;
+    }
+
+    public ErrorContext setParameter(String name, Object value) {
+      parameters.put(name, value);
+      return this;
+    }
+
+//    @Override
+    public Object getParameter(String name) {
+      return parameters.get(name);
+    }
+  }
+
   public static class ODataWritableContentBuilder {
     private ODataJsonSerializer jsonSerializer;
     private EntityIterator entities;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
-    private EntitySerializerOptions options;
+    private EntityCollectionSerializerOptions options;
     private String head;
     private String tail;
 
     public ODataWritableContentBuilder(EntityIterator entities, EdmEntityType entityType,
                                    ODataJsonSerializer jsonSerializer,
-                                   ServiceMetadata metadata, EntitySerializerOptions options) {
+                                   ServiceMetadata metadata, EntityCollectionSerializerOptions options) {
       this.entities = entities;
       this.entityType = entityType;
       this.jsonSerializer = jsonSerializer;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index ba32ab6..df2ee84 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -211,12 +211,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       outputStream.close();
       String tail = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
 
-      EntitySerializerOptions.Builder opt = EntitySerializerOptions.with();
-      if(options != null) {
-        opt.expand(options.getExpand()).select(options
-            .getSelect()).writeOnlyReferences(options.getWriteOnlyReferences());
-      }
-      return ODataWritableContent.with(entities, entityType, this, metadata, opt.build())
+      return ODataWritableContent.with(entities, entityType, this, metadata, options)
           .addHead(head).addTail(tail).build();
     } catch (final IOException e) {
       cachedException =

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5b6cccfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index df6e472..4211819 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -18,18 +18,25 @@
  */
 package org.apache.olingo.server.core.serializer.json;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.nio.ByteBuffer;
+import java.nio.channels.WritableByteChannel;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Iterator;
+import java.util.Locale;
 import java.util.TimeZone;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.ContextURL.Suffix;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmComplexType;
@@ -40,7 +47,10 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmProperty;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
+import org.apache.olingo.server.api.WriteContentErrorContext;
 import org.apache.olingo.server.api.edmx.EdmxReference;
 import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
 import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
@@ -85,12 +95,12 @@ public class ODataJsonSerializerTest {
   public void setup() {
     TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
   }
-  
+
   @After
   public void teardown() {
     TimeZone.setDefault(TimeZone.getDefault());
   }
-  
+
   @Test
   public void entitySimple() throws Exception {
     final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
@@ -208,6 +218,96 @@ public class ODataJsonSerializerTest {
   }
 
   @Test
+  public void entityCollectionStreamed() throws Exception {
+    final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+    final EntityIterator entityIterator = new EntityIterator() {
+      Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator();
+      @Override
+      public boolean hasNext() {
+        return innerIterator.hasNext();
+      }
+      @Override
+      public Entity next() {
+        return innerIterator.next();
+      }
+    };
+    CountOption countOption = Mockito.mock(CountOption.class);
+    Mockito.when(countOption.getValue()).thenReturn(true);
+
+    ODataContent result = serializer.entityCollectionStreamed(
+        metadata, edmEntitySet.getEntityType(), entityIterator,
+        EntityCollectionSerializerOptions.with()
+            .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+            .build()).getODataContent();
+    ByteArrayOutputStream bout = new ByteArrayOutputStream();
+    result.write(bout);
+    final String resultString = new String(bout.toByteArray(), "UTF-8");
+
+    Assert.assertThat(resultString, CoreMatchers.startsWith("{"
+        + "\"@odata.context\":\"$metadata#ESAllPrim\","
+        + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+        + "\"value\":[{\"PropertyInt16\":32767,\"PropertyString\""));
+    Assert.assertThat(resultString, CoreMatchers.endsWith(
+        "\"PropertyTimeOfDay\":\"00:01:01\"}]}"));
+
+    int count = 0;
+    int index = -1;
+    while ((index = resultString.indexOf("PropertyInt16\":", ++index)) > 0) {
+      count++;
+    }
+    Assert.assertEquals(3, count);
+  }
+
+  @Test
+  public void entityCollectionStreamedWithError() throws Exception {
+    final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+    final EntityIterator entityIterator = new EntityIterator() {
+      Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator();
+      @Override
+      public boolean hasNext() {
+        return innerIterator.hasNext();
+      }
+      @Override
+      public Entity next() {
+        return new Entity();
+      }
+    };
+    CountOption countOption = Mockito.mock(CountOption.class);
+    Mockito.when(countOption.getValue()).thenReturn(true);
+
+    WriteContentErrorCallback errorCallback = new WriteContentErrorCallback() {
+      @Override
+      public void handleError(WriteContentErrorContext context, WritableByteChannel channel) {
+        try {
+          String msgKey = context.getODataLibraryException().getMessageKey().getKey();
+          String toChannel = "ERROR: " + msgKey;
+          channel.write(ByteBuffer.wrap(toChannel.getBytes("UTF-8")));
+        } catch (IOException e) {
+          throw new RuntimeException("Error in error.");
+        }
+      }
+    };
+
+    ODataContent result = serializer.entityCollectionStreamed(
+        metadata, edmEntitySet.getEntityType(), entityIterator,
+        EntityCollectionSerializerOptions.with()
+            .writeContentErrorCallback(errorCallback)
+            .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+            .build()).getODataContent();
+    ByteArrayOutputStream bout = new ByteArrayOutputStream();
+    result.write(bout);
+    final String resultString = new String(bout.toByteArray(), "UTF-8");
+
+    Assert.assertThat(resultString, CoreMatchers.startsWith("{"
+        + "\"@odata.context\":\"$metadata#ESAllPrim\","
+        + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+        + "\"value\":"));
+    Assert.assertThat(resultString, CoreMatchers.endsWith(
+        "[ERROR: MISSING_PROPERTY"));
+  }
+
+
+  @Test
   public void entityCollAllPrim() throws Exception {
     final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
     final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);


[11/21] olingo-odata4 git commit: [OLINGO-832] Removed 'write' from ODataResponse

Posted by mi...@apache.org.
[OLINGO-832] Removed 'write' from ODataResponse


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

Branch: refs/heads/master
Commit: 18a78981fb590628f40bc1c36ade38dd0f135235
Parents: a6e0fb1
Author: mibo <mi...@apache.org>
Authored: Mon Feb 8 11:30:11 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Mon Feb 8 11:30:11 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataResponse.java | 37 ++++----------------
 .../server/api/serializer/SerializerResult.java |  2 +-
 .../server/core/ODataHttpHandlerImpl.java       | 22 +++++++-----
 .../serializer/ChannelSerializerResult.java     |  2 +-
 .../core/serializer/SerializerResultImpl.java   |  2 +-
 .../core/serializer/StreamSerializerResult.java |  2 +-
 .../processor/TechnicalEntityProcessor.java     |  4 +--
 7 files changed, 26 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
index 2063c65..5e2bad6 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
@@ -18,21 +18,13 @@
  */
 package org.apache.olingo.server.api;
 
-import java.io.IOException;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channel;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.olingo.commons.api.ex.ODataRuntimeException;
-import org.apache.olingo.commons.api.http.HttpStatusCode;
-import org.apache.olingo.server.api.serializer.SerializerResult;
-
 /**
  * Response object to carry OData-relevant HTTP information (status code, response headers, and content).
  */
@@ -41,7 +33,6 @@ public class ODataResponse {
   private int statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode();
   private final HttpHeaders headers = new HttpHeaders();
   private InputStream content;
-  private ReadableByteChannel channel;
 
   /**
    * Sets the status code.
@@ -141,29 +132,13 @@ public class ODataResponse {
     return content;
   }
 
-//  public void setChannel(final ReadableByteChannel channel) {
-//    this.channel = channel;
-//  }
-//
-//  public ReadableByteChannel getChannel() {
-//    return channel;
-//  }
-//
-//  public boolean isChannelAvailable() {
-//    return channel != null;
-//  }
-
   private SerializerResult serializerResult;
 
-  public void setResult(SerializerResult result) {
+  public void setSerializerResult(SerializerResult result) {
     serializerResult = result;
   }
 
-  public boolean isResultAvailable() {
-    return serializerResult != null;
-  }
-
-  public void write(WritableByteChannel output) {
-    serializerResult.writeContent(output);
+  public SerializerResult getSerializerResult() {
+    return serializerResult;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
index e380b97..d1e76e4 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -36,5 +36,5 @@ public interface SerializerResult {
 
   void writeContent(WritableByteChannel channel);
 
-  boolean isNioSupported();
+  boolean isWriteSupported();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index d3275e4..418234f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -19,6 +19,8 @@
 package org.apache.olingo.server.core;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channel;
 import java.nio.channels.Channels;
@@ -49,6 +51,7 @@ import org.apache.olingo.server.api.deserializer.DeserializerException;
 import org.apache.olingo.server.api.etag.CustomETagSupport;
 import org.apache.olingo.server.api.processor.Processor;
 import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
+import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.debug.ServerCoreDebugger;
 
 public class ODataHttpHandlerImpl implements ODataHttpHandler {
@@ -149,30 +152,33 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
       }
     }
 
-    if(odResponse.isResultAvailable()) {
+    if (odResponse.getContent() != null ) {
+      copyContent(odResponse.getContent(), response);
+    } else if(odResponse.getSerializerResult() != null) {
       writeContent(odResponse, response);
-    } else if (odResponse.getContent() != null ) {
-      copyContent(odResponse, response);
     }
   }
 
   static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
     try {
-    if(odataResponse.isResultAvailable()) {
-      odataResponse.write(Channels.newChannel(servletResponse.getOutputStream()));
-    }
+      SerializerResult res = odataResponse.getSerializerResult();
+      if(res.isWriteSupported()) {
+        res.writeContent(Channels.newChannel(servletResponse.getOutputStream()));
+      } else {
+        copyContent(res.getContent(), servletResponse);
+      }
     } catch (IOException e) {
       throw new ODataRuntimeException("Error on reading request content", e);
     }
   }
 
-  static void copyContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
+  static void copyContent(final InputStream inputStream, final HttpServletResponse servletResponse) {
     ReadableByteChannel input = null;
     WritableByteChannel output = null;
     try {
       ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
       output = Channels.newChannel(servletResponse.getOutputStream());
-      input = Channels.newChannel(odataResponse.getContent());
+      input = Channels.newChannel(inputStream);
       while (input.read(inBuffer) > 0) {
         inBuffer.flip();
         output.write(inBuffer);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index 60b62f0..1b48814 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -193,7 +193,7 @@ public class ChannelSerializerResult implements SerializerResult {
   }
 
   @Override
-  public boolean isNioSupported() {
+  public boolean isWriteSupported() {
     return true;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index f314017..4adc142 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -45,7 +45,7 @@ public class SerializerResultImpl implements SerializerResult {
   }
 
   @Override
-  public boolean isNioSupported() {
+  public boolean isWriteSupported() {
     return false;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
index c7cbce4..9a9283f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
@@ -136,7 +136,7 @@ public class StreamSerializerResult implements SerializerResult {
   }
 
   @Override
-  public boolean isNioSupported() {
+  public boolean isWriteSupported() {
     return true;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/18a78981/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index baacebb..4987ba3 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -536,12 +536,12 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         serializeEntityStreamCollectionFixed(request,
             entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
             expand, select, countOption, id);
-//    if(serializerResult.isNioSupported()) {
+//    if(serializerResult.isWriteSupported()) {
 //      response.setChannel(serializerResult.getChannel());
 //    } else {
 //      response.setContent(serializerResult.getContent());
 //    }
-    response.setResult(serializerResult);
+    response.setSerializerResult(serializerResult);
     //
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());


[02/21] olingo-odata4 git commit: [OLINGO-832] Added additional methods for Java NIO Channels

Posted by mi...@apache.org.
[OLINGO-832] Added additional methods for Java NIO Channels


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

Branch: refs/heads/master
Commit: 885ec27ef2411697c9e8b82e12c77e54e4c2710d
Parents: f4ad889
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Jan 8 09:45:09 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Jan 22 13:14:06 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataResponse.java |  13 ++
 .../server/api/serializer/SerializerResult.java |   5 +
 .../server/core/ODataHttpHandlerImpl.java       |   8 +-
 .../serializer/ChannelSerializerResult.java     | 201 +++++++++++++++++++
 .../core/serializer/SerializerResultImpl.java   |  13 ++
 .../core/serializer/StreamSerializerResult.java |  14 ++
 .../json/ODataJsonStreamSerializer.java         |   5 +-
 .../serializer/utils/CircleStreamBuffer.java    |  20 ++
 .../processor/TechnicalEntityProcessor.java     |  11 +-
 9 files changed, 285 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
index 3b63af7..a4dc7e0 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.api;
 
 import java.io.InputStream;
+import java.nio.channels.ReadableByteChannel;
 import java.util.List;
 import java.util.Map;
 
@@ -32,6 +33,7 @@ public class ODataResponse {
   private int statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode();
   private final HttpHeaders headers = new HttpHeaders();
   private InputStream content;
+  private ReadableByteChannel channel;
 
   /**
    * Sets the status code.
@@ -132,4 +134,15 @@ public class ODataResponse {
     return content;
   }
 
+  public void setChannel(final ReadableByteChannel channel) {
+    this.channel = channel;
+  }
+
+  public ReadableByteChannel getChannel() {
+    return channel;
+  }
+
+  public boolean isChannelAvailable() {
+    return channel != null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
index edf3ac8..fe23502 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.api.serializer;
 
 import java.io.InputStream;
+import java.nio.channels.ReadableByteChannel;
 
 /**
  * Result type for {@link ODataSerializer} methods
@@ -29,4 +30,8 @@ public interface SerializerResult {
    * @return serialized content
    */
   InputStream getContent();
+
+  ReadableByteChannel getChannel();
+
+  boolean isNioSupported();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index 1624943..59d7972 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -149,7 +149,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
       }
     }
 
-    if (odResponse.getContent() != null) {
+    if (odResponse.getContent() != null || odResponse.isChannelAvailable()) {
       copyContent(odResponse, response);
     }
   }
@@ -160,7 +160,11 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
     try {
       ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
       output = Channels.newChannel(servletResponse.getOutputStream());
-      input = Channels.newChannel(odataResponse.getContent());
+      if(odataResponse.isChannelAvailable()) {
+        input = odataResponse.getChannel();
+      } else {
+        input = Channels.newChannel(odataResponse.getContent());
+      }
       while (input.read(inBuffer) > 0) {
         inBuffer.flip();
         output.write(inBuffer);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
new file mode 100644
index 0000000..1d4c32f
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.charset.Charset;
+
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+
+public class ChannelSerializerResult implements SerializerResult {
+  private ReadableByteChannel channel;
+
+  private static class StreamChannel implements ReadableByteChannel {
+    private static final Charset DEFAULT = Charset.forName("UTF-8");
+    private ByteBuffer head;
+    private ByteBuffer tail;
+    private ODataJsonStreamSerializer jsonSerializer;
+    private EntityStreamCollection coll;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+
+    public StreamChannel(EntityStreamCollection coll, EdmEntityType entityType, String head,
+        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
+        EntitySerializerOptions options, String tail) {
+      this.coll = coll;
+      this.entityType = entityType;
+      this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+      this.tail = ByteBuffer.wrap(tail.getBytes(DEFAULT));
+    }
+
+    @Override
+    public int read(ByteBuffer dest) throws IOException {
+      ByteBuffer buffer = getCurrentBuffer();
+      if (buffer != null && buffer.hasRemaining()) {
+        int r = buffer.remaining();
+        if(r <= dest.remaining()) {
+          dest.put(buffer);
+        } else {
+          byte[] buf = new byte[dest.remaining()];
+          buffer.get(buf);
+          dest.put(buf);
+        }
+        return r;
+      }
+      return -1;
+    }
+
+    ByteBuffer currentBuffer;
+
+    private ByteBuffer getCurrentBuffer() {
+      if(currentBuffer == null) {
+        currentBuffer = head;
+      } if(!currentBuffer.hasRemaining()) {
+        if (coll.hasNext()) {
+          try {
+            // FIXME: mibo_160108: Inefficient buffer handling, replace
+            currentBuffer = serEntity(coll.nextEntity());
+            if(coll.hasNext()) {
+              ByteBuffer b = ByteBuffer.allocate(currentBuffer.position() + 1);
+              currentBuffer.flip();
+              b.put(currentBuffer).put(",".getBytes(DEFAULT));
+              currentBuffer = b;
+            }
+            currentBuffer.flip();
+          } catch (SerializerException e) {
+            return getCurrentBuffer();
+          }
+        } else if(tail.hasRemaining()) {
+          currentBuffer = tail;
+        } else {
+          return null;
+        }
+      }
+      return currentBuffer;
+    }
+
+    private ByteBuffer serEntity(Entity entity) throws SerializerException {
+      try {
+        CircleStreamBuffer buffer = new CircleStreamBuffer();
+        OutputStream outputStream = buffer.getOutputStream();
+        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+        jsonSerializer.writeEntity(metadata, entityType, entity, null,
+            options == null ? null : options.getExpand(),
+            options == null ? null : options.getSelect(),
+            options != null && options.getWriteOnlyReferences(),
+            json);
+
+        json.close();
+        outputStream.close();
+        return buffer.getBuffer();
+      } catch (final IOException e) {
+        return ByteBuffer.wrap(("ERROR" + e.getMessage()).getBytes());
+      }
+    }
+
+
+    @Override
+    public boolean isOpen() {
+      return false;
+    }
+
+    @Override
+    public void close() throws IOException {
+
+    }
+  }
+
+  @Override
+  public InputStream getContent() {
+    return Channels.newInputStream(this.channel);
+  }
+
+  @Override
+  public ReadableByteChannel getChannel() {
+    return this.channel;
+  }
+
+  @Override
+  public boolean isNioSupported() {
+    return true;
+  }
+
+  private ChannelSerializerResult(ReadableByteChannel channel) {
+    this.channel = channel;
+  }
+
+  public static SerializerResultBuilder with(EntityStreamCollection coll, EdmEntityType entityType,
+      ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+    return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
+  }
+
+  public static class SerializerResultBuilder {
+    private ODataJsonStreamSerializer jsonSerializer;
+    private EntityStreamCollection coll;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+    private String head;
+    private String tail;
+
+    public SerializerResultBuilder(EntityStreamCollection coll, EdmEntityType entityType,
+        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+      this.coll = coll;
+      this.entityType = entityType;
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+    }
+
+    public SerializerResultBuilder addHead(String head) {
+      this.head = head;
+      return this;
+    }
+
+    public SerializerResultBuilder addTail(String tail) {
+      this.tail = tail;
+      return this;
+    }
+
+    public SerializerResult build() {
+      ReadableByteChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
+      return new ChannelSerializerResult(input);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 53dca19..5a5364a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -19,6 +19,9 @@
 package org.apache.olingo.server.core.serializer;
 
 import java.io.InputStream;
+import java.nio.channels.Channel;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
 
 import org.apache.olingo.server.api.serializer.SerializerResult;
 
@@ -30,6 +33,16 @@ public class SerializerResultImpl implements SerializerResult {
     return content;
   }
 
+  @Override
+  public ReadableByteChannel getChannel() {
+    return Channels.newChannel(getContent());
+  }
+
+  @Override
+  public boolean isNioSupported() {
+    return false;
+  }
+
   public static SerializerResultBuilder with() {
     return new SerializerResultBuilder();
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
index d45c594..e4c8051 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
@@ -34,6 +34,10 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.channels.Channel;
+import java.nio.channels.Channels;
+import java.nio.channels.FileChannel;
+import java.nio.channels.ReadableByteChannel;
 
 public class StreamSerializerResult implements SerializerResult {
   private InputStream content;
@@ -121,6 +125,16 @@ public class StreamSerializerResult implements SerializerResult {
     return content;
   }
 
+  @Override
+  public ReadableByteChannel getChannel() {
+    return Channels.newChannel(getContent());
+  }
+
+  @Override
+  public boolean isNioSupported() {
+    return true;
+  }
+
   private StreamSerializerResult(InputStream content) {
     this.content = content;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
index 08a30c6..110d416 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
@@ -58,6 +58,7 @@ import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
 import org.apache.olingo.server.core.serializer.AbstractODataSerializer;
+import org.apache.olingo.server.core.serializer.ChannelSerializerResult;
 import org.apache.olingo.server.core.serializer.SerializerResultImpl;
 import org.apache.olingo.server.core.serializer.StreamSerializerResult;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
@@ -134,7 +135,9 @@ public class ODataJsonStreamSerializer extends ODataJsonSerializer {
         opt.expand(options.getExpand()).select(options
             .getSelect()).writeOnlyReferences(options.getWriteOnlyReferences());
       }
-      return StreamSerializerResult.with(coll, entityType, this, metadata, opt.build())
+//      return StreamSerializerResult.with(coll, entityType, this, metadata, opt.build())
+//          .addHead(head).addTail(tail).build();
+      return ChannelSerializerResult.with(coll, entityType, this, metadata, opt.build())
           .addHead(head).addTail(tail).build();
     } catch (final IOException e) {
       cachedException =

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
index 20d9ca5..b7ba2f2 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
 import java.util.Queue;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -193,6 +194,25 @@ public class CircleStreamBuffer {
     return readBuffer.get();
   }
 
+  public ByteBuffer getBuffer() throws IOException {
+    if (readClosed) {
+      throw new IOException("Tried to read from closed stream.");
+    }
+    writeMode = false;
+
+    // FIXME: mibo_160108: This is not efficient and only for test/poc reasons
+    int reqSize = 0;
+    for (ByteBuffer byteBuffer : bufferQueue) {
+      reqSize += byteBuffer.position();
+    }
+    ByteBuffer tmp = ByteBuffer.allocateDirect(reqSize);
+    for (ByteBuffer byteBuffer : bufferQueue) {
+      byteBuffer.flip();
+      tmp.put(byteBuffer);
+    }
+    return tmp;
+  }
+
   // #############################################
   // #
   // # Writing parts

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/885ec27e/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 6644f1e..f8fa7c8 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -536,8 +536,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         serializeEntityStreamCollectionFixed(request,
             entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
             expand, select, countOption, id);
-    response.setContent(serializerResult.getContent());
-
+    if(serializerResult.isNioSupported()) {
+      response.setChannel(serializerResult.getChannel());
+    } else {
+      response.setContent(serializerResult.getContent());
+    }
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
     if (pageSize != null) {
@@ -631,6 +634,9 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
       @Override
       public Entity nextEntity() {
+        try {
+          TimeUnit.MILLISECONDS.sleep(1000);
+        } catch (InterruptedException e) { }
         return test.next();
       }
     };
@@ -647,6 +653,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
             .build());
   }
 
+
   private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
       entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,


[06/21] olingo-odata4 git commit: [OLINGO-832] Minor change for PoC demo

Posted by mi...@apache.org.
[OLINGO-832] Minor change for PoC demo


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

Branch: refs/heads/master
Commit: 44e1b02633380e7262ab8985de5c455ee615073c
Parents: c02215e
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Jan 25 14:43:24 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Jan 25 14:43:24 2016 +0100

----------------------------------------------------------------------
 .../processor/TechnicalEntityProcessor.java     | 32 +++++++++++++++++---
 1 file changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44e1b026/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index f4c81c1..dc7f0b7 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -567,12 +567,11 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       @Override
       public Entity next() {
         Entity next = entityIterator.next();
-        replacePrimitiveProperty(next, "PropertyString", generateData(28192));
-//        next.getProperties().remove(1);
+//        replacePrimitiveProperty(next, "PropertyString", generateData(28192));
+        replacePrimitiveProperty(next, "PropertyString", generateData(request));
 //        next.addProperty(new Property(null, "PropertyString", ValueType.PRIMITIVE, generateData(28192)));
-        try {
-          TimeUnit.MILLISECONDS.sleep(2500);
-        } catch (InterruptedException e) { }
+
+        sleep(request, 2500);
         return next;
       }
 
@@ -594,6 +593,29 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         }
       }
 
+      private void sleep(ODataRequest request, int defaultTimeMs) {
+        String sleepTimeMs = request.getHeader("StreamSleep");
+        if(sleepTimeMs != null) {
+          try {
+            defaultTimeMs = Integer.parseInt(sleepTimeMs);
+          } catch (NumberFormatException e) { }
+        }
+        try {
+          TimeUnit.MILLISECONDS.sleep(defaultTimeMs);
+        } catch (InterruptedException e) { }
+
+      }
+
+      private String generateData(ODataRequest request) {
+        String streamHeader = request.getHeader("StreamData");
+        if(streamHeader != null) {
+          try {
+            return generateData(Integer.parseInt(streamHeader));
+          } catch (NumberFormatException e) { }
+        }
+        return generateData(28192);
+      }
+
       private String generateData(final int len) {
         Random random = new Random();
         StringBuilder b = new StringBuilder(len);


[04/21] olingo-odata4 git commit: [OLINGO-832] Fixed channel copy

Posted by mi...@apache.org.
[OLINGO-832] Fixed channel copy


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

Branch: refs/heads/master
Commit: 0cc2199437060e3db9be02c75a912ae9d80bd398
Parents: 69f58e8
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Jan 25 13:29:52 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Jan 25 14:14:02 2016 +0100

----------------------------------------------------------------------
 .../java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java   | 2 +-
 .../olingo/server/core/serializer/ChannelSerializerResult.java     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0cc21994/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index 59d7972..9aff6a2 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -168,7 +168,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
       while (input.read(inBuffer) > 0) {
         inBuffer.flip();
         output.write(inBuffer);
-        inBuffer.rewind();
+        inBuffer.clear();
       }
     } catch (IOException e) {
       throw new ODataRuntimeException("Error on reading request content", e);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0cc21994/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index 7768783..d692986 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -71,6 +71,7 @@ public class ChannelSerializerResult implements SerializerResult {
         if(r <= dest.remaining()) {
           dest.put(buffer);
         } else {
+          r = dest.remaining();
           byte[] buf = new byte[dest.remaining()];
           buffer.get(buf);
           dest.put(buf);


[12/21] olingo-odata4 git commit: [OLINGO-832] New ODataContent for streamed and basic content

Posted by mi...@apache.org.
[OLINGO-832] New ODataContent for streamed and basic content


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

Branch: refs/heads/master
Commit: 31dea712ef703672a20e650b8185855f1af8b4a2
Parents: 18a7898
Author: mibo <mi...@apache.org>
Authored: Mon Feb 8 15:25:45 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Mon Feb 8 16:06:01 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataContent.java  |  32 ++++
 .../apache/olingo/server/api/ODataResponse.java |  11 +-
 .../server/api/WriteContentErrorCallback.java   |  25 +++
 .../server/api/serializer/SerializerResult.java |   8 +-
 .../server/core/ODataHttpHandlerImpl.java       |  17 +-
 .../serializer/ChannelSerializerResult.java     |  26 ++-
 .../core/serializer/SerializerResultImpl.java   |  40 ++--
 .../core/serializer/StreamSerializerResult.java | 187 -------------------
 .../processor/TechnicalEntityProcessor.java     |   2 +-
 9 files changed, 118 insertions(+), 230 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
new file mode 100644
index 0000000..a3147f6
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+public interface ODataContent {
+  ReadableByteChannel getChannel();
+
+  void write(WritableByteChannel channel);
+
+  void write(WritableByteChannel channel, WriteContentErrorCallback callback);
+
+  boolean isWriteSupported();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
index 5e2bad6..39c9452 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
@@ -19,7 +19,6 @@
 package org.apache.olingo.server.api;
 
 import org.apache.olingo.commons.api.http.HttpStatusCode;
-import org.apache.olingo.server.api.serializer.SerializerResult;
 
 import java.io.InputStream;
 import java.util.List;
@@ -132,13 +131,13 @@ public class ODataResponse {
     return content;
   }
 
-  private SerializerResult serializerResult;
+  private ODataContent odataContent;
 
-  public void setSerializerResult(SerializerResult result) {
-    serializerResult = result;
+  public void setODataContent(ODataContent result) {
+    odataContent = result;
   }
 
-  public SerializerResult getSerializerResult() {
-    return serializerResult;
+  public ODataContent getODataContent() {
+    return odataContent;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
new file mode 100644
index 0000000..4219b8f
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+import java.nio.channels.WritableByteChannel;
+
+public interface WriteContentErrorCallback {
+  void handleError(ODataContent content, WritableByteChannel channel);
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
index d1e76e4..c3206d6 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -18,6 +18,8 @@
  */
 package org.apache.olingo.server.api.serializer;
 
+import org.apache.olingo.server.api.ODataContent;
+
 import java.io.InputStream;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
@@ -32,9 +34,5 @@ public interface SerializerResult {
    */
   InputStream getContent();
 
-  ReadableByteChannel getChannel();
-
-  void writeContent(WritableByteChannel channel);
-
-  boolean isWriteSupported();
+  ODataContent getODataContent();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index 418234f..dfd4a75 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -20,7 +20,6 @@ package org.apache.olingo.server.core;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channel;
 import java.nio.channels.Channels;
@@ -40,6 +39,7 @@ import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ODataHttpHandler;
 import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ODataRequest;
@@ -51,7 +51,6 @@ import org.apache.olingo.server.api.deserializer.DeserializerException;
 import org.apache.olingo.server.api.etag.CustomETagSupport;
 import org.apache.olingo.server.api.processor.Processor;
 import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
-import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.debug.ServerCoreDebugger;
 
 public class ODataHttpHandlerImpl implements ODataHttpHandler {
@@ -154,18 +153,18 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
 
     if (odResponse.getContent() != null ) {
       copyContent(odResponse.getContent(), response);
-    } else if(odResponse.getSerializerResult() != null) {
+    } else if(odResponse.getODataContent() != null) {
       writeContent(odResponse, response);
     }
   }
 
   static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
     try {
-      SerializerResult res = odataResponse.getSerializerResult();
+      ODataContent res = odataResponse.getODataContent();
       if(res.isWriteSupported()) {
-        res.writeContent(Channels.newChannel(servletResponse.getOutputStream()));
+        res.write(Channels.newChannel(servletResponse.getOutputStream()));
       } else {
-        copyContent(res.getContent(), servletResponse);
+        copyContent(res.getChannel(), servletResponse);
       }
     } catch (IOException e) {
       throw new ODataRuntimeException("Error on reading request content", e);
@@ -173,12 +172,14 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
   }
 
   static void copyContent(final InputStream inputStream, final HttpServletResponse servletResponse) {
-    ReadableByteChannel input = null;
+    copyContent(Channels.newChannel(inputStream), servletResponse);
+  }
+
+  static void copyContent(final ReadableByteChannel input, final HttpServletResponse servletResponse) {
     WritableByteChannel output = null;
     try {
       ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
       output = Channels.newChannel(servletResponse.getOutputStream());
-      input = Channels.newChannel(inputStream);
       while (input.read(inBuffer) > 0) {
         inBuffer.flip();
         output.write(inBuffer);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index 1b48814..1e97731 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -24,7 +24,9 @@ import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
+import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
@@ -40,7 +42,7 @@ import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 
-public class ChannelSerializerResult implements SerializerResult {
+public class ChannelSerializerResult implements ODataContent {
   private StreamChannel channel;
 
   private static class StreamChannel implements ReadableByteChannel {
@@ -182,10 +184,10 @@ public class ChannelSerializerResult implements SerializerResult {
     }
   }
 
-  @Override
-  public InputStream getContent() {
-    return Channels.newInputStream(this.channel);
-  }
+//  @Override
+//  public InputStream getContent() {
+//    return Channels.newInputStream(this.channel);
+//  }
 
   @Override
   public ReadableByteChannel getChannel() {
@@ -198,7 +200,7 @@ public class ChannelSerializerResult implements SerializerResult {
   }
 
   @Override
-  public void writeContent(WritableByteChannel writeChannel) {
+  public void write(WritableByteChannel writeChannel) {
     try {
       boolean contentAvailable = true;
       while(contentAvailable) {
@@ -209,6 +211,12 @@ public class ChannelSerializerResult implements SerializerResult {
     }
   }
 
+  @Override
+  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
+    // TODO: implement error handling
+    throw new ODataRuntimeException("error handling not yet supported");
+  }
+
   private ChannelSerializerResult(StreamChannel channel) {
     this.channel = channel;
   }
@@ -248,9 +256,13 @@ public class ChannelSerializerResult implements SerializerResult {
       return this;
     }
 
-    public SerializerResult build() {
+    public ODataContent buildContent() {
       StreamChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
       return new ChannelSerializerResult(input);
     }
+    public SerializerResult build() {
+      StreamChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
+      return SerializerResultImpl.with().content(new ChannelSerializerResult(input)).build();
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 4adc142..310cc5d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -18,6 +18,7 @@
  */
 package org.apache.olingo.server.core.serializer;
 
+import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
@@ -28,6 +29,7 @@ import java.nio.channels.WritableByteChannel;
 
 public class SerializerResultImpl implements SerializerResult {
   private InputStream content;
+  private ODataContent oDataContent;
 
   @Override
   public InputStream getContent() {
@@ -35,37 +37,43 @@ public class SerializerResultImpl implements SerializerResult {
   }
 
   @Override
-  public ReadableByteChannel getChannel() {
-    return Channels.newChannel(getContent());
+  public ODataContent getODataContent() {
+    return oDataContent;
   }
 
-  @Override
-  public void writeContent(WritableByteChannel channel) {
-    ResultHelper.copy(Channels.newChannel(content), channel);
-  }
-
-  @Override
-  public boolean isWriteSupported() {
-    return false;
-  }
+  //  @Override
+//  public ReadableByteChannel getChannel() {
+//    return Channels.newChannel(getContent());
+//  }
+//
+//  @Override
+//  public void write(WritableByteChannel channel) {
+//    ResultHelper.copy(Channels.newChannel(content), channel);
+//  }
+//
+//  @Override
+//  public boolean isWriteSupported() {
+//    return false;
+//  }
 
   public static SerializerResultBuilder with() {
     return new SerializerResultBuilder();
   }
 
   public static class SerializerResultBuilder {
-    private InputStream content;
+    private SerializerResultImpl result = new SerializerResultImpl();
 
     public SerializerResultBuilder content(final InputStream input) {
-      content = input;
+      result.content = input;
+      return this;
+    }
 
+    public SerializerResultBuilder content(final ODataContent input) {
+      result.oDataContent = input;
       return this;
     }
 
     public SerializerResult build() {
-      SerializerResultImpl result = new SerializerResultImpl();
-      result.content = content;
-
       return result;
     }
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
deleted file mode 100644
index 9a9283f..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.serializer;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityIterator;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
-import org.apache.olingo.server.api.serializer.SerializerException;
-import org.apache.olingo.server.api.serializer.SerializerResult;
-import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
-import org.apache.olingo.server.core.serializer.utils.ResultHelper;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-public class StreamSerializerResult implements SerializerResult {
-  private InputStream content;
-
-  private static class StreamInputStream extends InputStream {
-    private String head;
-    private String tail;
-    private int tailCount = 0;
-    private int headCount = 0;
-    private int entityCount = 0;
-    private InputStream inputStream = null;
-    private ODataJsonStreamSerializer jsonSerializer;
-    private EntityIterator coll;
-    private ServiceMetadata metadata;
-    private EdmEntityType entityType;
-    private EntitySerializerOptions options;
-
-    public StreamInputStream(EntityIterator coll, EdmEntityType entityType, String head,
-                             ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
-                             EntitySerializerOptions options, String tail) {
-      this.coll = coll;
-      this.entityType = entityType;
-      this.head = head;
-      this.jsonSerializer = jsonSerializer;
-      this.metadata = metadata;
-      this.options = options;
-      this.tail = tail;
-    }
-
-    @Override
-    public int read() throws IOException {
-      if (headCount < head.length()) {
-        return head.charAt(headCount++);
-      }
-      if (inputStream == null && coll.hasNext()) {
-        try {
-          inputStream = serEntity(coll.next());
-          entityCount++;
-          if (entityCount > 1) {
-            return (int) ',';
-          }
-        } catch (SerializerException e) {
-          inputStream = null;
-          return read();
-        }
-      }
-      if (inputStream != null) {
-        int read = inputStream.read();
-        if (read == -1) {
-          inputStream = null;
-          return read();
-        }
-        return read;
-      }
-      if (tailCount < tail.length()) {
-        return tail.charAt(tailCount++);
-      }
-      return -1;
-    }
-
-    private InputStream serEntity(Entity entity) throws SerializerException {
-      try {
-        CircleStreamBuffer buffer = new CircleStreamBuffer();
-        OutputStream outputStream = buffer.getOutputStream();
-        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-        jsonSerializer.writeEntity(metadata, entityType, entity, null,
-            options == null ? null : options.getExpand(),
-            options == null ? null : options.getSelect(),
-            options != null && options.getWriteOnlyReferences(),
-            json);
-
-        json.close();
-        outputStream.close();
-        return buffer.getInputStream();
-      } catch (final IOException e) {
-        return new ByteArrayInputStream(("ERROR" + e.getMessage()).getBytes());
-//      } catch (SerializerException e) {
-//        return new ByteArrayInputStream(("ERROR" + e.getMessage()).getBytes());
-      }
-    }
-  }
-
-  @Override
-  public InputStream getContent() {
-    return content;
-  }
-
-  @Override
-  public ReadableByteChannel getChannel() {
-    return Channels.newChannel(getContent());
-  }
-
-  @Override
-  public void writeContent(WritableByteChannel channel) {
-    ResultHelper.copy(getChannel(), channel);
-  }
-
-  @Override
-  public boolean isWriteSupported() {
-    return true;
-  }
-
-  private StreamSerializerResult(InputStream content) {
-    this.content = content;
-  }
-
-  public static SerializerResultBuilder with(EntityIterator coll, EdmEntityType entityType,
-                                             ODataJsonStreamSerializer jsonSerializer,
-                                             ServiceMetadata metadata, EntitySerializerOptions options) {
-    return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
-  }
-
-  public static class SerializerResultBuilder {
-    private ODataJsonStreamSerializer jsonSerializer;
-    private EntityIterator coll;
-    private ServiceMetadata metadata;
-    private EdmEntityType entityType;
-    private EntitySerializerOptions options;
-    private String head;
-    private String tail;
-
-    public SerializerResultBuilder(EntityIterator coll, EdmEntityType entityType,
-                                   ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
-                                   EntitySerializerOptions options) {
-      this.coll = coll;
-      this.entityType = entityType;
-      this.jsonSerializer = jsonSerializer;
-      this.metadata = metadata;
-      this.options = options;
-    }
-
-    public SerializerResultBuilder addHead(String head) {
-      this.head = head;
-      return this;
-    }
-
-    public SerializerResultBuilder addTail(String tail) {
-      this.tail = tail;
-      return this;
-    }
-
-    public SerializerResult build() {
-      InputStream input = new StreamInputStream(coll, entityType, head, jsonSerializer, metadata, options, tail);
-      return new StreamSerializerResult(input);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/31dea712/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 4987ba3..2c3c766 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -541,7 +541,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 //    } else {
 //      response.setContent(serializerResult.getContent());
 //    }
-    response.setSerializerResult(serializerResult);
+    response.setODataContent(serializerResult.getODataContent());
     //
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());


[13/21] olingo-odata4 git commit: [OLINGO-832] Added new SerializerStreamResult

Posted by mi...@apache.org.
[OLINGO-832] Added new SerializerStreamResult


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

Branch: refs/heads/master
Commit: dc2c972c464adb230c394d9529f2ce5d91f6fe21
Parents: 31dea71
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Feb 9 11:00:34 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Feb 9 11:00:34 2016 +0100

----------------------------------------------------------------------
 .../server/api/serializer/ODataSerializer.java  |  11 +
 .../api/serializer/SerializerStreamResult.java  |  32 +++
 .../olingo/server/core/ODataBasicContent.java   |  59 ++++
 .../apache/olingo/server/core/ODataImpl.java    |  11 +-
 .../server/core/ODataWritableContent.java       | 267 ++++++++++++++++++
 .../serializer/ChannelSerializerResult.java     | 268 -------------------
 .../core/serializer/SerializerResultImpl.java   |   5 +
 .../serializer/SerializerStreamResultImpl.java  |  67 +++++
 .../serializer/json/ODataJsonSerializer.java    |  58 +++-
 .../json/ODataJsonStreamSerializer.java         | 150 -----------
 .../core/serializer/xml/ODataXmlSerializer.java |   9 +
 .../processor/TechnicalEntityProcessor.java     |  34 ++-
 12 files changed, 526 insertions(+), 445 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 57370ba..432e1de 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.api.serializer;
 
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.AbstractEntityCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.edm.EdmComplexType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
@@ -64,6 +65,16 @@ public interface ODataSerializer {
       AbstractEntityCollection entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
 
   /**
+   * Writes entity-collection data into an InputStream.
+   * @param metadata metadata for the service
+   * @param entityType the {@link EdmEntityType}
+   * @param entities the data of the entity set
+   * @param options options for the serializer
+   */
+  SerializerStreamResult entityCollectionStreamed(ServiceMetadata metadata, EdmEntityType entityType,
+      EntityIterator entities, EntityCollectionSerializerOptions options) throws SerializerException;
+
+  /**
    * Writes entity data into an InputStream.
    * @param metadata metadata for the service
    * @param entityType the {@link EdmEntityType}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
new file mode 100644
index 0000000..c0dbafa
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api.serializer;
+
+import org.apache.olingo.server.api.ODataContent;
+
+/**
+ * Result type for {@link ODataSerializer} methods
+ */
+public interface SerializerStreamResult {
+  /**
+   * Returns the content as ODataContent
+   * @return content
+   */
+  ODataContent getODataContent();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
new file mode 100644
index 0000000..03328f4
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import org.apache.olingo.server.api.ODataContent;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
+
+import java.io.InputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+public class ODataBasicContent implements ODataContent {
+  private final ReadableByteChannel channel;
+
+  public ODataBasicContent(ReadableByteChannel channel) {
+    this.channel = channel;
+  }
+
+  public ODataBasicContent(InputStream stream) {
+    this(Channels.newChannel(stream));
+  }
+
+  @Override
+  public ReadableByteChannel getChannel() {
+    return channel;
+  }
+
+  @Override
+  public void write(WritableByteChannel channel) {
+
+  }
+
+  @Override
+  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
+
+  }
+
+  @Override
+  public boolean isWriteSupported() {
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index c056b45..4c2642c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -18,6 +18,9 @@
  */
 package org.apache.olingo.server.core;
 
+import java.util.Collection;
+import java.util.List;
+
 import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
@@ -45,13 +48,10 @@ import org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer;
 import org.apache.olingo.server.core.etag.ETagHelperImpl;
 import org.apache.olingo.server.core.prefer.PreferencesImpl;
 import org.apache.olingo.server.core.serializer.FixedFormatSerializerImpl;
-import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
+import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
 import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
 import org.apache.olingo.server.core.uri.UriHelperImpl;
 
-import java.util.Collection;
-import java.util.List;
-
 public class ODataImpl extends OData {
 
   @Override
@@ -63,8 +63,7 @@ public class ODataImpl extends OData {
       if (metadata == null
           || ContentType.VALUE_ODATA_METADATA_MINIMAL.equals(metadata)
           || ContentType.VALUE_ODATA_METADATA_NONE.equals(metadata)) {
-//        serializer = new ODataJsonSerializer(contentType);
-        serializer = new ODataJsonStreamSerializer(contentType);
+        serializer = new ODataJsonSerializer(contentType);
       }
     } else if (contentType.isCompatible(ContentType.APPLICATION_XML)
         || contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
new file mode 100644
index 0000000..fc45639
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntityIterator;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
+import org.apache.olingo.server.api.ODataContent;
+import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
+import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
+import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
+import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
+public class ODataWritableContent implements ODataContent {
+  private StreamChannel channel;
+
+  private static class StreamChannel implements ReadableByteChannel {
+    private static final Charset DEFAULT = Charset.forName("UTF-8");
+    private ByteBuffer head;
+    private ByteBuffer tail;
+    private ODataJsonSerializer jsonSerializer;
+    private EntityIterator coll;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+
+    public StreamChannel(EntityIterator coll, EdmEntityType entityType, String head,
+                         ODataJsonSerializer jsonSerializer, ServiceMetadata metadata,
+                         EntitySerializerOptions options, String tail) {
+      this.coll = coll;
+      this.entityType = entityType;
+      this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+      this.tail = ByteBuffer.wrap(tail.getBytes(DEFAULT));
+    }
+
+    public boolean write(OutputStream out) throws IOException {
+      if(head.hasRemaining()) {
+        out.write(head.array());
+        head.flip();
+        return true;
+      }
+      if (coll.hasNext()) {
+        try {
+          writeEntity(coll.next(), out);
+          if(coll.hasNext()) {
+            out.write(",".getBytes(DEFAULT));
+          }
+          return true;
+        } catch (SerializerException e) {
+        }
+      } else if(tail.hasRemaining()) {
+        out.write(tail.array());
+        tail.flip();
+        return true;
+      }
+      return false;
+    }
+
+
+    private void writeEntity(Entity entity, OutputStream outputStream) throws SerializerException {
+      try {
+        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+        jsonSerializer.writeEntity(metadata, entityType, entity, null,
+            options == null ? null : options.getExpand(),
+            options == null ? null : options.getSelect(),
+            options != null && options.getWriteOnlyReferences(),
+            json);
+        json.flush();
+      } catch (final IOException e) {
+        throw new ODataRuntimeException("Failed entity serialization");
+      }
+    }
+
+    @Override
+    public int read(ByteBuffer dest) throws IOException {
+      ByteBuffer buffer = getCurrentBuffer();
+      if (buffer != null && buffer.hasRemaining()) {
+        int r = buffer.remaining();
+        if(r <= dest.remaining()) {
+          dest.put(buffer);
+        } else {
+          r = dest.remaining();
+          byte[] buf = new byte[dest.remaining()];
+          buffer.get(buf);
+          dest.put(buf);
+        }
+        return r;
+      }
+      return -1;
+    }
+
+    ByteBuffer currentBuffer;
+
+    private ByteBuffer getCurrentBuffer() {
+      if(currentBuffer == null) {
+        currentBuffer = head;
+      }
+      if(!currentBuffer.hasRemaining()) {
+        if (coll.hasNext()) {
+          try {
+            // FIXME: mibo_160108: Inefficient buffer handling, replace
+            currentBuffer = serEntity(coll.next());
+            if(coll.hasNext()) {
+              ByteBuffer b = ByteBuffer.allocate(currentBuffer.position() + 1);
+              currentBuffer.flip();
+              b.put(currentBuffer).put(",".getBytes(DEFAULT));
+              currentBuffer = b;
+            }
+            currentBuffer.flip();
+          } catch (SerializerException e) {
+            return getCurrentBuffer();
+          }
+        } else if(tail.hasRemaining()) {
+          currentBuffer = tail;
+        } else {
+          return null;
+        }
+      }
+      return currentBuffer;
+    }
+
+    private ByteBuffer serEntity(Entity entity) throws SerializerException {
+      try {
+        CircleStreamBuffer buffer = new CircleStreamBuffer();
+        OutputStream outputStream = buffer.getOutputStream();
+        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+        jsonSerializer.writeEntity(metadata, entityType, entity, null,
+            options == null ? null : options.getExpand(),
+            options == null ? null : options.getSelect(),
+            options != null && options.getWriteOnlyReferences(),
+            json);
+
+        json.close();
+        outputStream.close();
+        return buffer.getBuffer();
+      } catch (final IOException e) {
+        return ByteBuffer.wrap(("ERROR" + e.getMessage()).getBytes());
+      }
+    }
+
+
+    @Override
+    public boolean isOpen() {
+      return false;
+    }
+
+    @Override
+    public void close() throws IOException {
+
+    }
+  }
+
+//  @Override
+//  public InputStream getContent() {
+//    return Channels.newInputStream(this.channel);
+//  }
+
+  @Override
+  public ReadableByteChannel getChannel() {
+    return this.channel;
+  }
+
+  @Override
+  public boolean isWriteSupported() {
+    return true;
+  }
+
+  @Override
+  public void write(WritableByteChannel writeChannel) {
+    try {
+      boolean contentAvailable = true;
+      while(contentAvailable) {
+        contentAvailable = this.channel.write(Channels.newOutputStream(writeChannel));
+      }
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
+    // TODO: implement error handling
+    throw new ODataRuntimeException("error handling not yet supported");
+  }
+
+  private ODataWritableContent(StreamChannel channel) {
+    this.channel = channel;
+  }
+
+  public static ODataWritableContentBuilder with(EntityIterator coll, EdmEntityType entityType,
+                                             ODataJsonSerializer jsonSerializer,
+                                             ServiceMetadata metadata, EntitySerializerOptions options) {
+    return new ODataWritableContentBuilder(coll, entityType, jsonSerializer, metadata, options);
+  }
+
+  public static class ODataWritableContentBuilder {
+    private ODataJsonSerializer jsonSerializer;
+    private EntityIterator entities;
+    private ServiceMetadata metadata;
+    private EdmEntityType entityType;
+    private EntitySerializerOptions options;
+    private String head;
+    private String tail;
+
+    public ODataWritableContentBuilder(EntityIterator entities, EdmEntityType entityType,
+                                   ODataJsonSerializer jsonSerializer,
+                                   ServiceMetadata metadata, EntitySerializerOptions options) {
+      this.entities = entities;
+      this.entityType = entityType;
+      this.jsonSerializer = jsonSerializer;
+      this.metadata = metadata;
+      this.options = options;
+    }
+
+    public ODataWritableContentBuilder addHead(String head) {
+      this.head = head;
+      return this;
+    }
+
+    public ODataWritableContentBuilder addTail(String tail) {
+      this.tail = tail;
+      return this;
+    }
+
+    public ODataContent buildContent() {
+      StreamChannel input = new StreamChannel(entities, entityType, head, jsonSerializer, metadata, options, tail);
+      return new ODataWritableContent(input);
+    }
+    public SerializerStreamResult build() {
+      return SerializerStreamResultImpl.with().content(buildContent()).build();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
deleted file mode 100644
index 1e97731..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.serializer;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityIterator;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.ex.ODataRuntimeException;
-import org.apache.olingo.server.api.ODataContent;
-import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
-import org.apache.olingo.server.api.serializer.SerializerException;
-import org.apache.olingo.server.api.serializer.SerializerResult;
-import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
-
-public class ChannelSerializerResult implements ODataContent {
-  private StreamChannel channel;
-
-  private static class StreamChannel implements ReadableByteChannel {
-    private static final Charset DEFAULT = Charset.forName("UTF-8");
-    private ByteBuffer head;
-    private ByteBuffer tail;
-    private ODataJsonStreamSerializer jsonSerializer;
-    private EntityIterator coll;
-    private ServiceMetadata metadata;
-    private EdmEntityType entityType;
-    private EntitySerializerOptions options;
-
-    public StreamChannel(EntityIterator coll, EdmEntityType entityType, String head,
-                         ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
-                         EntitySerializerOptions options, String tail) {
-      this.coll = coll;
-      this.entityType = entityType;
-      this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
-      this.jsonSerializer = jsonSerializer;
-      this.metadata = metadata;
-      this.options = options;
-      this.tail = ByteBuffer.wrap(tail.getBytes(DEFAULT));
-    }
-
-    public boolean write(OutputStream out) throws IOException {
-      if(head.hasRemaining()) {
-        out.write(head.array());
-        head.flip();
-        return true;
-      }
-      if (coll.hasNext()) {
-        try {
-          writeEntity(coll.next(), out);
-          if(coll.hasNext()) {
-            out.write(",".getBytes(DEFAULT));
-          }
-          return true;
-        } catch (SerializerException e) {
-        }
-      } else if(tail.hasRemaining()) {
-        out.write(tail.array());
-        tail.flip();
-        return true;
-      }
-      return false;
-    }
-
-
-    private void writeEntity(Entity entity, OutputStream outputStream) throws SerializerException {
-      try {
-        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-        jsonSerializer.writeEntity(metadata, entityType, entity, null,
-            options == null ? null : options.getExpand(),
-            options == null ? null : options.getSelect(),
-            options != null && options.getWriteOnlyReferences(),
-            json);
-        json.flush();
-      } catch (final IOException e) {
-        throw new ODataRuntimeException("Failed entity serialization");
-      }
-    }
-
-    @Override
-    public int read(ByteBuffer dest) throws IOException {
-      ByteBuffer buffer = getCurrentBuffer();
-      if (buffer != null && buffer.hasRemaining()) {
-        int r = buffer.remaining();
-        if(r <= dest.remaining()) {
-          dest.put(buffer);
-        } else {
-          r = dest.remaining();
-          byte[] buf = new byte[dest.remaining()];
-          buffer.get(buf);
-          dest.put(buf);
-        }
-        return r;
-      }
-      return -1;
-    }
-
-    ByteBuffer currentBuffer;
-
-    private ByteBuffer getCurrentBuffer() {
-      if(currentBuffer == null) {
-        currentBuffer = head;
-      }
-      if(!currentBuffer.hasRemaining()) {
-        if (coll.hasNext()) {
-          try {
-            // FIXME: mibo_160108: Inefficient buffer handling, replace
-            currentBuffer = serEntity(coll.next());
-            if(coll.hasNext()) {
-              ByteBuffer b = ByteBuffer.allocate(currentBuffer.position() + 1);
-              currentBuffer.flip();
-              b.put(currentBuffer).put(",".getBytes(DEFAULT));
-              currentBuffer = b;
-            }
-            currentBuffer.flip();
-          } catch (SerializerException e) {
-            return getCurrentBuffer();
-          }
-        } else if(tail.hasRemaining()) {
-          currentBuffer = tail;
-        } else {
-          return null;
-        }
-      }
-      return currentBuffer;
-    }
-
-    private ByteBuffer serEntity(Entity entity) throws SerializerException {
-      try {
-        CircleStreamBuffer buffer = new CircleStreamBuffer();
-        OutputStream outputStream = buffer.getOutputStream();
-        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-        jsonSerializer.writeEntity(metadata, entityType, entity, null,
-            options == null ? null : options.getExpand(),
-            options == null ? null : options.getSelect(),
-            options != null && options.getWriteOnlyReferences(),
-            json);
-
-        json.close();
-        outputStream.close();
-        return buffer.getBuffer();
-      } catch (final IOException e) {
-        return ByteBuffer.wrap(("ERROR" + e.getMessage()).getBytes());
-      }
-    }
-
-
-    @Override
-    public boolean isOpen() {
-      return false;
-    }
-
-    @Override
-    public void close() throws IOException {
-
-    }
-  }
-
-//  @Override
-//  public InputStream getContent() {
-//    return Channels.newInputStream(this.channel);
-//  }
-
-  @Override
-  public ReadableByteChannel getChannel() {
-    return this.channel;
-  }
-
-  @Override
-  public boolean isWriteSupported() {
-    return true;
-  }
-
-  @Override
-  public void write(WritableByteChannel writeChannel) {
-    try {
-      boolean contentAvailable = true;
-      while(contentAvailable) {
-        contentAvailable = this.channel.write(Channels.newOutputStream(writeChannel));
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-  }
-
-  @Override
-  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
-    // TODO: implement error handling
-    throw new ODataRuntimeException("error handling not yet supported");
-  }
-
-  private ChannelSerializerResult(StreamChannel channel) {
-    this.channel = channel;
-  }
-
-  public static SerializerResultBuilder with(EntityIterator coll, EdmEntityType entityType,
-                                             ODataJsonStreamSerializer jsonSerializer,
-                                             ServiceMetadata metadata, EntitySerializerOptions options) {
-    return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
-  }
-
-  public static class SerializerResultBuilder {
-    private ODataJsonStreamSerializer jsonSerializer;
-    private EntityIterator coll;
-    private ServiceMetadata metadata;
-    private EdmEntityType entityType;
-    private EntitySerializerOptions options;
-    private String head;
-    private String tail;
-
-    public SerializerResultBuilder(EntityIterator coll, EdmEntityType entityType,
-                                   ODataJsonStreamSerializer jsonSerializer,
-                                   ServiceMetadata metadata, EntitySerializerOptions options) {
-      this.coll = coll;
-      this.entityType = entityType;
-      this.jsonSerializer = jsonSerializer;
-      this.metadata = metadata;
-      this.options = options;
-    }
-
-    public SerializerResultBuilder addHead(String head) {
-      this.head = head;
-      return this;
-    }
-
-    public SerializerResultBuilder addTail(String tail) {
-      this.tail = tail;
-      return this;
-    }
-
-    public ODataContent buildContent() {
-      StreamChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
-      return new ChannelSerializerResult(input);
-    }
-    public SerializerResult build() {
-      StreamChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
-      return SerializerResultImpl.with().content(new ChannelSerializerResult(input)).build();
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 310cc5d..8c69f18 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -20,6 +20,8 @@ package org.apache.olingo.server.core.serializer;
 
 import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
+import org.apache.olingo.server.core.ODataBasicContent;
 import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
 import java.io.InputStream;
@@ -38,6 +40,9 @@ public class SerializerResultImpl implements SerializerResult {
 
   @Override
   public ODataContent getODataContent() {
+    if(oDataContent == null && content != null) {
+      return new ODataBasicContent(content);
+    }
     return oDataContent;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
new file mode 100644
index 0000000..14fab97
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer;
+
+import java.io.InputStream;
+
+import org.apache.olingo.server.api.ODataContent;
+import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
+
+public class SerializerStreamResultImpl implements SerializerStreamResult {
+  private InputStream content;
+  private ODataContent oDataContent;
+
+  @Override
+  public ODataContent getODataContent() {
+    return oDataContent;
+  }
+
+  //  @Override
+//  public ReadableByteChannel getChannel() {
+//    return Channels.newChannel(getContent());
+//  }
+//
+//  @Override
+//  public void write(WritableByteChannel channel) {
+//    ResultHelper.copy(Channels.newChannel(content), channel);
+//  }
+//
+//  @Override
+//  public boolean isWriteSupported() {
+//    return false;
+//  }
+
+  public static SerializerResultBuilder with() {
+    return new SerializerResultBuilder();
+  }
+
+  public static class SerializerResultBuilder {
+    private SerializerStreamResultImpl result = new SerializerStreamResultImpl();
+
+    public SerializerResultBuilder content(final ODataContent content) {
+      result.oDataContent = content;
+      return this;
+    }
+
+    public SerializerStreamResult build() {
+      return result;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index c381760..42e0025 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -18,8 +18,10 @@
  */
 package org.apache.olingo.server.core.serializer.json;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -30,6 +32,7 @@ import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.AbstractEntityCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Linked;
 import org.apache.olingo.commons.api.data.Property;
@@ -57,11 +60,13 @@ import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOpti
 import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.api.uri.UriHelper;
 import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
 import org.apache.olingo.server.core.serializer.AbstractODataSerializer;
+import org.apache.olingo.server.core.ODataWritableContent;
 import org.apache.olingo.server.core.serializer.SerializerResultImpl;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
 import org.apache.olingo.server.core.serializer.utils.ContentTypeHelper;
@@ -176,6 +181,53 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   }
 
   @Override
+  public SerializerStreamResult entityCollectionStreamed(ServiceMetadata metadata, EdmEntityType entityType,
+      EntityIterator entities, EntityCollectionSerializerOptions options) throws SerializerException {
+
+    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+    SerializerException cachedException = null;
+    try {
+      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+      json.writeStartObject();
+
+      final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
+      writeContextURL(contextURL, json);
+
+      writeMetadataETag(metadata, json);
+
+      if (options != null && options.getCount() != null && options.getCount().getValue()) {
+        writeCount(entities, json);
+      }
+      json.writeFieldName(Constants.VALUE);
+      json.writeStartArray();
+      json.close();
+      outputStream.close();
+      String temp = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
+      String head = temp.substring(0, temp.length()-2);
+
+      outputStream = new ByteArrayOutputStream();
+      outputStream.write(']');
+      outputStream.write('}');
+      outputStream.close();
+      String tail = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
+
+      EntitySerializerOptions.Builder opt = EntitySerializerOptions.with();
+      if(options != null) {
+        opt.expand(options.getExpand()).select(options
+            .getSelect()).writeOnlyReferences(options.getWriteOnlyReferences());
+      }
+      return ODataWritableContent.with(entities, entityType, this, metadata, opt.build())
+          .addHead(head).addTail(tail).build();
+    } catch (final IOException e) {
+      cachedException =
+          new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
+      throw cachedException;
+    } finally {
+      closeCircleStreamBufferOutput(outputStream, cachedException);
+    }
+  }
+
+  @Override
   public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
       final Entity entity, final EntitySerializerOptions options) throws SerializerException {
     OutputStream outputStream = null;
@@ -229,9 +281,9 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     json.writeEndArray();
   }
 
-  protected void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
-      final Entity entity, final ContextURL contextURL, final ExpandOption expand,
-      final SelectOption select, final boolean onlyReference, final JsonGenerator json)
+  public void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType, final Entity entity,
+      final ContextURL contextURL, final ExpandOption expand, final SelectOption select, final boolean onlyReference,
+      final JsonGenerator json)
           throws IOException, SerializerException {
     json.writeStartObject();
     if (!isODataMetadataNone) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
deleted file mode 100644
index 4cced29..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.serializer.json;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
-import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.AbstractEntityCollection;
-import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityIterator;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
-import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
-import org.apache.olingo.server.api.serializer.SerializerException;
-import org.apache.olingo.server.api.serializer.SerializerResult;
-import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
-import org.apache.olingo.server.api.uri.queryoption.SelectOption;
-import org.apache.olingo.server.core.serializer.ChannelSerializerResult;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-public class ODataJsonStreamSerializer extends ODataJsonSerializer {
-
-  private final ODataJsonSerializer serializer;
-
-  public ODataJsonStreamSerializer(final ContentType contentType) {
-    super(contentType);
-    this.serializer = new ODataJsonSerializer(contentType);
-  }
-
-  @Override
-  public SerializerResult entityCollection(final ServiceMetadata metadata,
-      final EdmEntityType entityType, final AbstractEntityCollection entitySet,
-      final EntityCollectionSerializerOptions options) throws SerializerException {
-
-    EntityIterator coll;
-    if(entitySet instanceof EntityIterator) {
-      coll = (EntityIterator) entitySet;
-    } else {
-      return serializer.entityCollection(metadata, entityType, entitySet, options);
-    }
-
-    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-    SerializerException cachedException = null;
-    try {
-      JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-      json.writeStartObject();
-
-      final ContextURL contextURL = serializer.checkContextURL(options == null ? null : options.getContextURL());
-      serializer.writeContextURL(contextURL, json);
-
-      serializer.writeMetadataETag(metadata, json);
-
-      if (options != null && options.getCount() != null && options.getCount().getValue()) {
-        serializer.writeCount(entitySet, json);
-      }
-      json.writeFieldName(Constants.VALUE);
-      json.writeStartArray();
-      json.close();
-      outputStream.close();
-      String temp = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
-      String head = temp.substring(0, temp.length()-2);
-      //      if (options == null) {
-//        writeEntitySet(metadata, entityType, entitySet, null, null, false, json);
-//      } else {
-//        writeEntitySet(metadata, entityType, entitySet,
-//            options.getExpand(), options.getSelect(), options.getWriteOnlyReferences(), json);
-//      }
-
-      outputStream = new ByteArrayOutputStream();
-      outputStream.write(']');
-      outputStream.write('}');
-      outputStream.close();
-      String tail = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
-
-      EntitySerializerOptions.Builder opt = EntitySerializerOptions.with();
-      if(options != null) {
-        opt.expand(options.getExpand()).select(options
-            .getSelect()).writeOnlyReferences(options.getWriteOnlyReferences());
-      }
-//      return StreamSerializerResult.with(coll, entityType, this, metadata, opt.build())
-//          .addHead(head).addTail(tail).build();
-      return ChannelSerializerResult.with(coll, entityType, this, metadata, opt.build())
-          .addHead(head).addTail(tail).build();
-    } catch (final IOException e) {
-      cachedException =
-          new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
-      throw cachedException;
-    } finally {
-      closeCircleStreamBufferOutput(outputStream, cachedException);
-    }
-  }
-
-  @Override
-  public void writeEntity(final ServiceMetadata metadata, final EdmEntityType entityType,
-      final Entity entity, final ContextURL contextURL, final ExpandOption expand,
-      final SelectOption select, final boolean onlyReference, final JsonGenerator json)
-      throws IOException, SerializerException {
-    serializer.writeEntity(metadata, entityType, entity, contextURL, expand, select, onlyReference, json);
-  }
-
-//  @Override
-//  public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
-//      final Entity entity, final EntitySerializerOptions options) throws SerializerException {
-//    return serializer.entity(metadata, entityType, entity, options);
-//  }
-
-//  protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
-//      final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
-//      final boolean onlyReference, final JsonGenerator json) throws IOException,
-//      SerializerException {
-//
-//        json.writeStartArray();
-//        json.writeEndArray();
-//
-    //    json.writeStartArray();
-//    for (final Entity entity : entitySet.getEntities()) {
-//      if (onlyReference) {
-//        json.writeStartObject();
-//        json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
-//        json.writeEndObject();
-//      } else {
-//        serializer.writeEntity(metadata, entityType, entity, null, expand, select, false, json);
-//      }
-//    }
-//    json.writeEndArray();
-//  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index b3d9d5d..5454007 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -36,6 +36,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.data.AbstractEntityCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Linked;
 import org.apache.olingo.commons.api.data.Property;
@@ -52,6 +53,7 @@ import org.apache.olingo.commons.api.edm.EdmType;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
 import org.apache.olingo.commons.api.ex.ODataErrorDetail;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
 import org.apache.olingo.server.api.ODataServerError;
 import org.apache.olingo.server.api.ServiceMetadata;
@@ -63,6 +65,7 @@ import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOpti
 import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
@@ -279,6 +282,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
   }
 
   @Override
+  public SerializerStreamResult entityCollectionStreamed(ServiceMetadata metadata, EdmEntityType entityType,
+      EntityIterator entities, EntityCollectionSerializerOptions options) throws SerializerException {
+    throw new ODataRuntimeException("entityCollectionStreamed for XML not supported (yet)");
+  }
+
+  @Override
   public SerializerResult entity(final ServiceMetadata metadata, final EdmEntityType entityType,
       final Entity entity, final EntitySerializerOptions options) throws SerializerException {
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dc2c972c/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 2c3c766..9241860 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -39,6 +39,7 @@ import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
+import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
@@ -58,6 +59,7 @@ import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
 import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOptions;
 import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.api.uri.UriInfo;
 import org.apache.olingo.server.api.uri.UriResourceEntitySet;
 import org.apache.olingo.server.api.uri.UriResourceNavigation;
@@ -526,22 +528,18 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       id = request.getRawBaseUri() + edmEntitySet.getName();
     }
 
-    // Serialize
-//    final SerializerResult serializerResult = (isReference) ?
-//        serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption) :
-//        serializeEntityCollection(request, entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
-//            expand, select, countOption, id);
-    final SerializerResult serializerResult = (isReference) ?
-        serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption) :
-        serializeEntityStreamCollectionFixed(request,
-            entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
-            expand, select, countOption, id);
-//    if(serializerResult.isWriteSupported()) {
-//      response.setChannel(serializerResult.getChannel());
-//    } else {
-//      response.setContent(serializerResult.getContent());
-//    }
-    response.setODataContent(serializerResult.getODataContent());
+    if(isReference) {
+      final SerializerResult serializerResult =
+          serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption);
+      response.setODataContent(serializerResult.getODataContent());
+    } else {
+      final SerializerStreamResult serializerResult =
+          serializeEntityStreamCollectionFixed(request,
+              entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
+              expand, select, countOption, id);
+
+      response.setODataContent(serializerResult.getODataContent());
+    }
     //
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
@@ -552,7 +550,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
   }
 
   // just for demonstration
-  private SerializerResult serializeEntityStreamCollectionFixed(final ODataRequest request,
+  private SerializerStreamResult serializeEntityStreamCollectionFixed(final ODataRequest request,
       final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
       final EdmEntityType edmEntityType,
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
@@ -630,7 +628,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
     };
 
-    return odata.createSerializer(requestedFormat).entityCollection(
+    return odata.createSerializer(requestedFormat).entityCollectionStreamed(
         serviceMetadata,
         edmEntityType,
         streamCollection,


[21/21] olingo-odata4 git commit: [OLINGO-832] Clean up after merge

Posted by mi...@apache.org.
[OLINGO-832] Clean up after merge


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

Branch: refs/heads/master
Commit: 0879bfbe5ed0401872168b3c4478612f42eb75b4
Parents: 47bc730
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Feb 22 08:42:38 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Feb 22 08:42:38 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataContent.java  | 24 +++++++++++
 .../api/ODataContentWriteErrorCallback.java     | 41 ++++++++++++++++++
 .../api/ODataContentWriteErrorContext.java      | 45 ++++++++++++++++++++
 .../server/api/WriteContentErrorCallback.java   | 30 -------------
 .../server/api/WriteContentErrorContext.java    | 27 ------------
 .../EntityCollectionSerializerOptions.java      | 14 +++---
 .../api/serializer/SerializerStreamResult.java  |  7 +--
 .../server/core/ODataWritableContent.java       | 20 ++++++---
 .../core/serializer/SerializerResultImpl.java   | 16 -------
 .../core/serializer/xml/ODataXmlSerializer.java |  1 -
 .../json/ODataJsonSerializerTest.java           |  9 ++--
 11 files changed, 139 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
index e237bf3..7f971df 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
@@ -21,8 +21,32 @@ package org.apache.olingo.server.api;
 import java.io.OutputStream;
 import java.nio.channels.WritableByteChannel;
 
+/**
+ * Contains the response content for the OData request.
+ * <p/>
+ * Because the content is potential streamable an error can occur when the
+ * <code>write</code> methods are used.
+ * If this happens <b>NO</b> exception will be thrown but if registered the
+ * org.apache.olingo.server.api.ODataContentWriteErrorCallback is called.
+ */
 public interface ODataContent {
+  /**
+   * Write the available content into the given <code>WritableByteChannel</code>.
+   *
+   * If during write of the content an exception is thrown this exception will be catched
+   * and the org.apache.olingo.server.api.ODataContentWriteErrorCallback is called (if registered).
+   *
+   * @param channel channel in which the content is written.
+   */
   void write(WritableByteChannel channel);
 
+  /**
+   * Write the available content into the given <code>OutputStream</code>.
+   *
+   * If during write of the content an exception is thrown this exception will be catched
+   * and the org.apache.olingo.server.api.ODataContentWriteErrorCallback is called (if registered).
+   *
+   * @param stream stream in which the content is written.
+   */
   void write(OutputStream stream);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java
new file mode 100644
index 0000000..643d676
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorCallback.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+import java.io.OutputStream;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * The ODataContentWriteErrorCallback is called when during the {@link ODataContent#write(OutputStream)}
+ * or the {@link ODataContent#write(WritableByteChannel)} an error occurs.
+ */
+public interface ODataContentWriteErrorCallback {
+  /**
+   * Is called when during <i>write</i> in the ODataContent an error occurs.
+   * The <code>context:ODataContentWriteErrorContext</code> contains all relevant information
+   * and the <code>channel</code> is the channel (stream) in which before was written.
+   * This channel is at this point not closed and can be used to write additional information.
+   * <b>ATTENTION:</b> This channel MUST NOT be closed by the callback. It will be closed by the
+   * layer responsible for the environment / data transfer (e.g. application server).
+   *
+   * @param context contains all relevant error information
+   * @param channel is the channel (stream) in which before was written
+   */
+  void handleError(ODataContentWriteErrorContext context, WritableByteChannel channel);
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java
new file mode 100644
index 0000000..5c72b57
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContentWriteErrorContext.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.api;
+
+/**
+ * The WriteContentErrorErrorContext is the parameter for the WriteContentErrorCallback.
+ * and contains all relevant error information
+ */
+public interface ODataContentWriteErrorContext {
+  /**
+   * Get the exception which caused this error (as Java exception).
+   * If the cause exception is a ODataLibraryException this method will
+   * return the same exception as the {@link #getODataLibraryException()} method.
+   *
+   * @return the exception which caused this error (as Java exception).
+   */
+  Exception getException();
+  /**
+   * Get the exception which caused this error (as ODataLibraryException exception).
+   * If the cause exception is an ODataLibraryException this method will
+   * return the same exception as the {@link #getException()} method.
+   * If the cause exception is <b>NOT</b> an ODataLibraryException this method will
+   * return <code>NULL</code>.
+   *
+   * @return the cause exception if it is an ODataLibraryException otherwise
+   *          this method will return <code>NULL</code>.
+   */
+  ODataLibraryException getODataLibraryException();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
deleted file mode 100644
index 3132876..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.api;
-
-import java.io.OutputStream;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * The WriteContentErrorCallback is called when during the {@link ODataContent#write(OutputStream)}
- * or the {@link ODataContent#write(WritableByteChannel)} an error occurs.
- */
-public interface WriteContentErrorCallback {
-  void handleError(WriteContentErrorContext context, WritableByteChannel channel);
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
deleted file mode 100644
index 837c184..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.api;
-
-/**
- * The WriteContentErrorErrorContext is the parameter for the WriteContentErrorCallback.
- */
-public interface WriteContentErrorContext {
-  Exception getException();
-  ODataLibraryException getODataLibraryException();
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 9335829..9578ba7 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@ -19,7 +19,7 @@
 package org.apache.olingo.server.api.serializer;
 
 import org.apache.olingo.commons.api.data.ContextURL;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
 import org.apache.olingo.server.api.uri.queryoption.CountOption;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
@@ -33,7 +33,7 @@ public class EntityCollectionSerializerOptions {
   private SelectOption select;
   private boolean writeOnlyReferences;
   private String id;
-  private WriteContentErrorCallback writeContentErrorCallback;
+  private ODataContentWriteErrorCallback ODataContentWriteErrorCallback;
   private String xml10InvalidCharReplacement;
 
   /** Gets the {@link ContextURL}. */
@@ -74,8 +74,8 @@ public class EntityCollectionSerializerOptions {
    * write of the content
    *
    */
-  public WriteContentErrorCallback getWriteContentErrorCallback() {
-    return writeContentErrorCallback;
+  public ODataContentWriteErrorCallback getODataContentWriteErrorCallback() {
+    return ODataContentWriteErrorCallback;
   }
   /** Gets the replacement string for unicode characters, that is not allowed in XML 1.0 */
   public String xml10InvalidCharReplacement() {
@@ -136,11 +136,11 @@ public class EntityCollectionSerializerOptions {
      * Set the callback which is used in case of an exception during
      * write of the content.
      *
-     * @param writeContentErrorCallback the callback
+     * @param ODataContentWriteErrorCallback the callback
      * @return the builder
      */
-    public Builder writeContentErrorCallback(WriteContentErrorCallback writeContentErrorCallback) {
-      options.writeContentErrorCallback = writeContentErrorCallback;
+    public Builder writeContentErrorCallback(ODataContentWriteErrorCallback ODataContentWriteErrorCallback) {
+      options.ODataContentWriteErrorCallback = ODataContentWriteErrorCallback;
       return this;
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
index c19c270..54e928d 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
@@ -22,12 +22,13 @@ import org.apache.olingo.server.api.ODataContent;
 
 /**
  * Result type for {@link ODataSerializer} methods
- * which supports stream/write in the future
+ * which supports streaming (write in the future).
  */
 public interface SerializerStreamResult {
   /**
-   * Returns the content as ODataContent
-   * @return content
+   * Returns the content as ODataContent instance.
+   * 
+   * @return OData response content
    */
   ODataContent getODataContent();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index 7a7c142..f315734 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -29,8 +29,8 @@ import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-import org.apache.olingo.server.api.WriteContentErrorContext;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorContext;
 import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
 import org.apache.olingo.server.api.serializer.ODataSerializer;
 import org.apache.olingo.server.api.serializer.SerializerException;
@@ -39,6 +39,14 @@ import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
 import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
 import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
 
+/**
+ * Stream supporting implementation of the ODataContent
+ * and contains the response content for the OData request.
+ * <p/>
+ * If an error occur during a <code>write</code> method <b>NO</b> exception
+ * will be thrown but if registered the
+ * org.apache.olingo.server.api.ODataContentWriteErrorCallback is called.
+ */
 public class ODataWritableContent implements ODataContent {
   private StreamContent streamContent;
 
@@ -65,9 +73,9 @@ public class ODataWritableContent implements ODataContent {
       try {
         writeEntity(iterator, out);
       } catch (SerializerException e) {
-        final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
+        final ODataContentWriteErrorCallback errorCallback = options.getODataContentWriteErrorCallback();
         if(errorCallback != null) {
-          final ErrorContext errorContext = new ErrorContext(e);
+          final WriteErrorContext errorContext = new WriteErrorContext(e);
           errorCallback.handleError(errorContext, Channels.newChannel(out));
         }
       }
@@ -136,9 +144,9 @@ public class ODataWritableContent implements ODataContent {
     return new ODataWritableContentBuilder(iterator, entityType, serializer, metadata, options);
   }
 
-  public static class ErrorContext implements WriteContentErrorContext {
+  public static class WriteErrorContext implements ODataContentWriteErrorContext {
     private ODataLibraryException exception;
-    public ErrorContext(ODataLibraryException exception) {
+    public WriteErrorContext(ODataLibraryException exception) {
       this.exception = exception;
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 7c7de2f..69287af 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -20,7 +20,6 @@ package org.apache.olingo.server.core.serializer;
 
 import java.io.InputStream;
 
-import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.serializer.SerializerResult;
 
 public class SerializerResultImpl implements SerializerResult {
@@ -31,21 +30,6 @@ public class SerializerResultImpl implements SerializerResult {
     return content;
   }
 
-  //  @Override
-//  public ReadableByteChannel getChannel() {
-//    return Channels.newChannel(getContent());
-//  }
-//
-//  @Override
-//  public void write(WritableByteChannel channel) {
-//    ResultHelper.copy(Channels.newChannel(content), channel);
-//  }
-//
-//  @Override
-//  public boolean isWriteSupported() {
-//    return false;
-//  }
-
   public static SerializerResultBuilder with() {
     return new SerializerResultBuilder();
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 2fa16ea..399df3d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -53,7 +53,6 @@ import org.apache.olingo.commons.api.edm.EdmType;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
 import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
 import org.apache.olingo.commons.api.ex.ODataErrorDetail;
-import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
 import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
 import org.apache.olingo.server.api.ODataServerError;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0879bfbe/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index a7cf057..bc3ac19 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -26,7 +26,6 @@ import java.nio.channels.WritableByteChannel;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.Locale;
 import java.util.TimeZone;
 
 import org.apache.commons.io.IOUtils;
@@ -49,8 +48,8 @@ import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-import org.apache.olingo.server.api.WriteContentErrorContext;
+import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
+import org.apache.olingo.server.api.ODataContentWriteErrorContext;
 import org.apache.olingo.server.api.edmx.EdmxReference;
 import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
 import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
@@ -275,9 +274,9 @@ public class ODataJsonSerializerTest {
     CountOption countOption = Mockito.mock(CountOption.class);
     Mockito.when(countOption.getValue()).thenReturn(true);
 
-    WriteContentErrorCallback errorCallback = new WriteContentErrorCallback() {
+    ODataContentWriteErrorCallback errorCallback = new ODataContentWriteErrorCallback() {
       @Override
-      public void handleError(WriteContentErrorContext context, WritableByteChannel channel) {
+      public void handleError(ODataContentWriteErrorContext context, WritableByteChannel channel) {
         try {
           String msgKey = context.getODataLibraryException().getMessageKey().getKey();
           String toChannel = "ERROR: " + msgKey;


[09/21] olingo-odata4 git commit: [OLINGO-832] New approach with ODataResponse change

Posted by mi...@apache.org.
[OLINGO-832] New approach with ODataResponse change


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

Branch: refs/heads/master
Commit: 2a80ca3391f51325d82b4c87ec21f55295aabe02
Parents: 1a7c28a
Author: mibo <mi...@apache.org>
Authored: Sun Feb 7 19:27:55 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Sun Feb 7 19:27:55 2016 +0100

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataResponse.java | 34 ++++++++--
 .../server/api/serializer/SerializerResult.java |  3 +
 .../server/core/ODataHttpHandlerImpl.java       | 20 ++++--
 .../serializer/ChannelSerializerResult.java     |  9 +++
 .../core/serializer/SerializerResultImpl.java   |  7 +++
 .../core/serializer/StreamSerializerResult.java |  7 +++
 .../json/ODataJsonStreamSerializer.java         |  1 -
 .../core/serializer/utils/ResultHelper.java     | 65 ++++++++++++++++++++
 .../processor/TechnicalEntityProcessor.java     | 12 ++--
 9 files changed, 140 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
index a80d1cc..2063c65 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
@@ -18,12 +18,20 @@
  */
 package org.apache.olingo.server.api;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.serializer.SerializerResult;
 
 /**
  * Response object to carry OData-relevant HTTP information (status code, response headers, and content).
@@ -133,15 +141,29 @@ public class ODataResponse {
     return content;
   }
 
-  public void setChannel(final ReadableByteChannel channel) {
-    this.channel = channel;
+//  public void setChannel(final ReadableByteChannel channel) {
+//    this.channel = channel;
+//  }
+//
+//  public ReadableByteChannel getChannel() {
+//    return channel;
+//  }
+//
+//  public boolean isChannelAvailable() {
+//    return channel != null;
+//  }
+
+  private SerializerResult serializerResult;
+
+  public void setResult(SerializerResult result) {
+    serializerResult = result;
   }
 
-  public ReadableByteChannel getChannel() {
-    return channel;
+  public boolean isResultAvailable() {
+    return serializerResult != null;
   }
 
-  public boolean isChannelAvailable() {
-    return channel != null;
+  public void write(WritableByteChannel output) {
+    serializerResult.writeContent(output);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
index 0e3f97c..e380b97 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.api.serializer;
 
 import java.io.InputStream;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 /**
  * Result type for {@link ODataSerializer} methods
@@ -33,5 +34,7 @@ public interface SerializerResult {
 
   ReadableByteChannel getChannel();
 
+  void writeContent(WritableByteChannel channel);
+
   boolean isNioSupported();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index fd480dd..d3275e4 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -149,22 +149,30 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
       }
     }
 
-    if (odResponse.getContent() != null || odResponse.isChannelAvailable()) {
+    if(odResponse.isResultAvailable()) {
+      writeContent(odResponse, response);
+    } else if (odResponse.getContent() != null ) {
       copyContent(odResponse, response);
     }
   }
 
+  static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
+    try {
+    if(odataResponse.isResultAvailable()) {
+      odataResponse.write(Channels.newChannel(servletResponse.getOutputStream()));
+    }
+    } catch (IOException e) {
+      throw new ODataRuntimeException("Error on reading request content", e);
+    }
+  }
+
   static void copyContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
     ReadableByteChannel input = null;
     WritableByteChannel output = null;
     try {
       ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
       output = Channels.newChannel(servletResponse.getOutputStream());
-      if(odataResponse.isChannelAvailable()) {
-        input = odataResponse.getChannel();
-      } else {
-        input = Channels.newChannel(odataResponse.getContent());
-      }
+      input = Channels.newChannel(odataResponse.getContent());
       while (input.read(inBuffer) > 0) {
         inBuffer.flip();
         output.write(inBuffer);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index d692986..a3b6b0c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -29,6 +29,7 @@ import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -36,6 +37,7 @@ import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 
 public class ChannelSerializerResult implements SerializerResult {
@@ -157,6 +159,13 @@ public class ChannelSerializerResult implements SerializerResult {
     return true;
   }
 
+  @Override
+  public void writeContent(WritableByteChannel writeChannel) {
+    // TODO: mibo: replace with passing 'writeChannel' to json serializer
+    ResultHelper.copy(this.channel, writeChannel);
+  }
+
+
   private ChannelSerializerResult(ReadableByteChannel channel) {
     this.channel = channel;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index d58315d..f314017 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -19,10 +19,12 @@
 package org.apache.olingo.server.core.serializer;
 
 import org.apache.olingo.server.api.serializer.SerializerResult;
+import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
 import java.io.InputStream;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 public class SerializerResultImpl implements SerializerResult {
   private InputStream content;
@@ -38,6 +40,11 @@ public class SerializerResultImpl implements SerializerResult {
   }
 
   @Override
+  public void writeContent(WritableByteChannel channel) {
+    ResultHelper.copy(Channels.newChannel(content), channel);
+  }
+
+  @Override
   public boolean isNioSupported() {
     return false;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
index 19b9f5d..c7cbce4 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
@@ -29,6 +29,7 @@ import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -36,6 +37,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 public class StreamSerializerResult implements SerializerResult {
   private InputStream content;
@@ -129,6 +131,11 @@ public class StreamSerializerResult implements SerializerResult {
   }
 
   @Override
+  public void writeContent(WritableByteChannel channel) {
+    ResultHelper.copy(getChannel(), channel);
+  }
+
+  @Override
   public boolean isNioSupported() {
     return true;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
index 406fbe7..4cced29 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
@@ -24,7 +24,6 @@ import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.format.ContentType;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ResultHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ResultHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ResultHelper.java
new file mode 100644
index 0000000..fd57593
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ResultHelper.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer.utils;
+
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+public class ResultHelper {
+
+  public static final int COPY_BUFFER_SIZE = 8192;
+
+  public static void copy(InputStream input, OutputStream output) {
+    copy(Channels.newChannel(input), Channels.newChannel(output));
+  }
+
+  public static void copy(ReadableByteChannel input, WritableByteChannel output) {
+    try {
+      ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
+      while (input.read(inBuffer) > 0) {
+        inBuffer.flip();
+        output.write(inBuffer);
+        inBuffer.clear();
+      }
+    } catch (IOException e) {
+      throw new ODataRuntimeException("Error on reading request content", e);
+    } finally {
+      closeStream(input);
+      closeStream(output);
+    }
+  }
+
+  private static void closeStream(final Channel closeable) {
+    if (closeable != null) {
+      try {
+        closeable.close();
+      } catch (IOException e) {
+        // ignore
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2a80ca33/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index dc7f0b7..baacebb 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -536,11 +536,13 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         serializeEntityStreamCollectionFixed(request,
             entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
             expand, select, countOption, id);
-    if(serializerResult.isNioSupported()) {
-      response.setChannel(serializerResult.getChannel());
-    } else {
-      response.setContent(serializerResult.getContent());
-    }
+//    if(serializerResult.isNioSupported()) {
+//      response.setChannel(serializerResult.getChannel());
+//    } else {
+//      response.setContent(serializerResult.getContent());
+//    }
+    response.setResult(serializerResult);
+    //
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
     if (pageSize != null) {


[19/21] olingo-odata4 git commit: [OlINGO-832] Clean up and basic IT test

Posted by mi...@apache.org.
[OlINGO-832] Clean up and basic IT test


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

Branch: refs/heads/master
Commit: 09fd6d9b48dd0b833176dbe0b2864c5065b99ee0
Parents: 4aa1277
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Feb 19 21:57:31 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Feb 19 21:57:31 2016 +0100

----------------------------------------------------------------------
 .../fit/tecsvc/http/BasicStreamITCase.java      |  66 ++++++
 .../server/api/WriteContentErrorCallback.java   |   5 +
 .../server/api/WriteContentErrorContext.java    |   4 +-
 .../server/core/ODataWritableContent.java       | 235 +++++--------------
 .../serializer/SerializerStreamResultImpl.java  |  19 --
 .../core/serializer/xml/ODataXmlSerializer.java |  62 ++++-
 .../processor/TechnicalEntityProcessor.java     |  52 +++-
 7 files changed, 247 insertions(+), 196 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
new file mode 100644
index 0000000..1903d13
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.fit.tecsvc.http;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.ODataClient;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.fit.AbstractBaseTestITCase;
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Test;
+
+public class BasicStreamITCase extends AbstractBaseTestITCase {
+
+  private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
+
+  @Test
+  public void streamAllPrim() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESAllPrim?$format=json");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.setRequestProperty("odata.streaming", "true");
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());
+    assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+
+    assertTrue(content.contains("\"PropertyString\":\"First Resource - positive values->streamed\""));
+    assertTrue(content.contains("\"PropertyString\":\"Second Resource - negative values->streamed\""));
+    assertTrue(content.contains("\"PropertyString\":\"->streamed\""));
+  }
+
+
+  @Override
+  protected ODataClient getClient() {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
index abc500a..3132876 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorCallback.java
@@ -18,8 +18,13 @@
  */
 package org.apache.olingo.server.api;
 
+import java.io.OutputStream;
 import java.nio.channels.WritableByteChannel;
 
+/**
+ * The WriteContentErrorCallback is called when during the {@link ODataContent#write(OutputStream)}
+ * or the {@link ODataContent#write(WritableByteChannel)} an error occurs.
+ */
 public interface WriteContentErrorCallback {
   void handleError(WriteContentErrorContext context, WritableByteChannel channel);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
index d773df1..837c184 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/WriteContentErrorContext.java
@@ -18,8 +18,10 @@
  */
 package org.apache.olingo.server.api;
 
+/**
+ * The WriteContentErrorErrorContext is the parameter for the WriteContentErrorCallback.
+ */
 public interface WriteContentErrorContext {
   Exception getException();
   ODataLibraryException getODataLibraryException();
-//  Object getParameter(String name);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index 904a6d0..7a7c142 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -20,15 +20,9 @@ package org.apache.olingo.server.core;
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
-import java.util.HashMap;
-import java.util.Map;
 
-import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
@@ -38,82 +32,60 @@ import org.apache.olingo.server.api.ServiceMetadata;
 import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.WriteContentErrorContext;
 import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
 import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
+import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
 
 public class ODataWritableContent implements ODataContent {
-  private StreamChannel channel;
-
-  private static class StreamChannel implements ReadableByteChannel {
-    private static final Charset DEFAULT = Charset.forName("UTF-8");
-    private ByteBuffer head;
-    private ByteBuffer tail;
-    private ODataJsonSerializer jsonSerializer;
-    private EntityIterator coll;
-    private ServiceMetadata metadata;
-    private EdmEntityType entityType;
-    private EntityCollectionSerializerOptions options;
-
-    public StreamChannel(EntityIterator coll, EdmEntityType entityType, String head,
-                         ODataJsonSerializer jsonSerializer, ServiceMetadata metadata,
-                         EntityCollectionSerializerOptions options, String tail) {
-      this.coll = coll;
+  private StreamContent streamContent;
+
+  private static abstract class StreamContent {
+    protected ODataSerializer serializer;
+    protected EntityIterator iterator;
+    protected ServiceMetadata metadata;
+    protected EdmEntityType entityType;
+    protected EntityCollectionSerializerOptions options;
+
+    public StreamContent(EntityIterator iterator, EdmEntityType entityType,
+                         ODataSerializer serializer, ServiceMetadata metadata,
+                         EntityCollectionSerializerOptions options) {
+      this.iterator = iterator;
       this.entityType = entityType;
-      this.head = head == null ? ByteBuffer.allocate(0) : ByteBuffer.wrap(head.getBytes(DEFAULT));
-      this.jsonSerializer = jsonSerializer;
+      this.serializer = serializer;
       this.metadata = metadata;
       this.options = options;
-      this.tail = tail == null ? ByteBuffer.allocate(0) : ByteBuffer.wrap(tail.getBytes(DEFAULT));
     }
 
-//    public boolean write(OutputStream out) throws IOException {
-//      if(head.hasRemaining()) {
-//        out.write(head.array());
-//        head.flip();
-//        return true;
-//      }
-//      if (coll.hasNext()) {
-//        try {
-//          writeEntity(coll.next(), out);
-//          if(coll.hasNext()) {
-//            out.write(",".getBytes(DEFAULT));
-//          }
-//          return true;
-//        } catch (SerializerException e) {
-//          final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
-//          if(errorCallback != null) {
-//            final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
-//            errorCallback.handleError(errorContext, Channels.newChannel(out));
-//          }
-//        }
-//      } else if(tail.hasRemaining()) {
-//        out.write(tail.array());
-//        tail.flip();
-//        return true;
-//      }
-//      return false;
-//    }
+    protected abstract void writeEntity(EntityIterator entity, OutputStream outputStream) throws SerializerException;
 
     public void write(OutputStream out) {
       try {
-        writeEntity(coll, out);
+        writeEntity(iterator, out);
       } catch (SerializerException e) {
         final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
         if(errorCallback != null) {
-          final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
+          final ErrorContext errorContext = new ErrorContext(e);
           errorCallback.handleError(errorContext, Channels.newChannel(out));
         }
       }
     }
+  }
+
+  private static class StreamContentForJson extends StreamContent {
+    private ODataJsonSerializer jsonSerializer;
 
+    public StreamContentForJson(EntityIterator iterator, EdmEntityType entityType,
+        ODataJsonSerializer jsonSerializer, ServiceMetadata metadata,
+        EntityCollectionSerializerOptions options) {
+      super(iterator, entityType, jsonSerializer, metadata, options);
 
-    private void writeEntity(EntityIterator entity, OutputStream outputStream) throws SerializerException {
+      this.jsonSerializer = jsonSerializer;
+    }
+
+    protected void writeEntity(EntityIterator entity, OutputStream outputStream) throws SerializerException {
       try {
         jsonSerializer.entityCollectionIntoStream(metadata, entityType, entity, options, outputStream);
         outputStream.flush();
@@ -121,97 +93,32 @@ public class ODataWritableContent implements ODataContent {
         throw new ODataRuntimeException("Failed entity serialization");
       }
     }
+  }
 
-    @Override
-    public int read(ByteBuffer dest) throws IOException {
-      ByteBuffer buffer = getCurrentBuffer();
-      if (buffer != null && buffer.hasRemaining()) {
-        int r = buffer.remaining();
-        if(r <= dest.remaining()) {
-          dest.put(buffer);
-        } else {
-          r = dest.remaining();
-          byte[] buf = new byte[dest.remaining()];
-          buffer.get(buf);
-          dest.put(buf);
-        }
-        return r;
-      }
-      return -1;
-    }
+  private static class StreamContentForXml extends StreamContent {
+    private ODataXmlSerializer xmlSerializer;
 
-    ByteBuffer currentBuffer;
+    public StreamContentForXml(EntityIterator iterator, EdmEntityType entityType,
+        ODataXmlSerializer xmlSerializer, ServiceMetadata metadata,
+        EntityCollectionSerializerOptions options) {
+      super(iterator, entityType, xmlSerializer, metadata, options);
 
-    private ByteBuffer getCurrentBuffer() {
-      if(currentBuffer == null) {
-        currentBuffer = head;
-      }
-      if(!currentBuffer.hasRemaining()) {
-        if (coll.hasNext()) {
-          try {
-            // FIXME: mibo_160108: Inefficient buffer handling, replace
-            currentBuffer = serEntity(coll.next());
-            if(coll.hasNext()) {
-              ByteBuffer b = ByteBuffer.allocate(currentBuffer.position() + 1);
-              currentBuffer.flip();
-              b.put(currentBuffer).put(",".getBytes(DEFAULT));
-              currentBuffer = b;
-            }
-            currentBuffer.flip();
-          } catch (SerializerException e) {
-            return getCurrentBuffer();
-          }
-        } else if(tail.hasRemaining()) {
-          currentBuffer = tail;
-        } else {
-          return null;
-        }
-      }
-      return currentBuffer;
+      this.xmlSerializer = xmlSerializer;
     }
 
-    private ByteBuffer serEntity(Entity entity) throws SerializerException {
+    protected void writeEntity(EntityIterator entity, OutputStream outputStream) throws SerializerException {
       try {
-        CircleStreamBuffer buffer = new CircleStreamBuffer();
-        OutputStream outputStream = buffer.getOutputStream();
-        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-        jsonSerializer.writeEntity(metadata, entityType, entity, null,
-            options == null ? null : options.getExpand(),
-            options == null ? null : options.getSelect(),
-            options != null && options.getWriteOnlyReferences(),
-            json);
-
-        json.close();
-        outputStream.close();
-        return buffer.getBuffer();
+        xmlSerializer.entityCollectionIntoStream(metadata, entityType, entity, options, outputStream);
+        outputStream.flush();
       } catch (final IOException e) {
-        return ByteBuffer.wrap(("ERROR" + e.getMessage()).getBytes());
+        throw new ODataRuntimeException("Failed entity serialization");
       }
     }
-
-
-    @Override
-    public boolean isOpen() {
-      return false;
-    }
-
-    @Override
-    public void close() throws IOException {
-
-    }
-  }
-
-  public ReadableByteChannel getChannel() {
-    return this.channel;
-  }
-
-  public boolean isWriteSupported() {
-    return true;
   }
 
   @Override
   public void write(WritableByteChannel writeChannel) {
-    this.channel.write(Channels.newOutputStream(writeChannel));
+    this.streamContent.write(Channels.newOutputStream(writeChannel));
   }
 
   @Override
@@ -219,20 +126,18 @@ public class ODataWritableContent implements ODataContent {
     write(Channels.newChannel(stream));
   }
 
-  private ODataWritableContent(StreamChannel channel) {
-    this.channel = channel;
+  private ODataWritableContent(StreamContent streamContent) {
+    this.streamContent = streamContent;
   }
 
-  public static ODataWritableContentBuilder with(EntityIterator coll, EdmEntityType entityType,
-                                             ODataJsonSerializer jsonSerializer,
-                                             ServiceMetadata metadata, EntityCollectionSerializerOptions options) {
-    return new ODataWritableContentBuilder(coll, entityType, jsonSerializer, metadata, options);
+  public static ODataWritableContentBuilder with(EntityIterator iterator, EdmEntityType entityType,
+                                             ODataSerializer serializer, ServiceMetadata metadata,
+      EntityCollectionSerializerOptions options) {
+    return new ODataWritableContentBuilder(iterator, entityType, serializer, metadata, options);
   }
 
   public static class ErrorContext implements WriteContentErrorContext {
     private ODataLibraryException exception;
-    final private Map<String, Object> parameters = new HashMap<String, Object>();
-
     public ErrorContext(ODataLibraryException exception) {
       this.exception = exception;
     }
@@ -245,50 +150,36 @@ public class ODataWritableContent implements ODataContent {
     public ODataLibraryException getODataLibraryException() {
       return exception;
     }
-
-    public ErrorContext setParameter(String name, Object value) {
-      parameters.put(name, value);
-      return this;
-    }
-
-//    @Override
-    public Object getParameter(String name) {
-      return parameters.get(name);
-    }
   }
 
   public static class ODataWritableContentBuilder {
-    private ODataJsonSerializer jsonSerializer;
+    private ODataSerializer serializer;
     private EntityIterator entities;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
     private EntityCollectionSerializerOptions options;
-    private String head;
-    private String tail;
 
     public ODataWritableContentBuilder(EntityIterator entities, EdmEntityType entityType,
-                                   ODataJsonSerializer jsonSerializer,
+                                    ODataSerializer serializer,
                                    ServiceMetadata metadata, EntityCollectionSerializerOptions options) {
       this.entities = entities;
       this.entityType = entityType;
-      this.jsonSerializer = jsonSerializer;
+      this.serializer = serializer;
       this.metadata = metadata;
       this.options = options;
     }
 
-    public ODataWritableContentBuilder addHead(String head) {
-      this.head = head;
-      return this;
-    }
-
-    public ODataWritableContentBuilder addTail(String tail) {
-      this.tail = tail;
-      return this;
-    }
-
     public ODataContent buildContent() {
-      StreamChannel input = new StreamChannel(entities, entityType, head, jsonSerializer, metadata, options, tail);
-      return new ODataWritableContent(input);
+      if(serializer instanceof ODataJsonSerializer) {
+        StreamContent input = new StreamContentForJson(entities, entityType,
+            (ODataJsonSerializer) serializer, metadata, options);
+        return new ODataWritableContent(input);
+      } else if(serializer instanceof ODataXmlSerializer) {
+        StreamContentForXml input = new StreamContentForXml(entities, entityType,
+            (ODataXmlSerializer) serializer, metadata, options);
+        return new ODataWritableContent(input);
+      }
+      throw new ODataRuntimeException("No suitable serializer found");
     }
     public SerializerStreamResult build() {
       return SerializerStreamResultImpl.with().content(buildContent()).build();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
index 14fab97..a7c0efc 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerStreamResultImpl.java
@@ -18,14 +18,10 @@
  */
 package org.apache.olingo.server.core.serializer;
 
-import java.io.InputStream;
-
 import org.apache.olingo.server.api.ODataContent;
-import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 
 public class SerializerStreamResultImpl implements SerializerStreamResult {
-  private InputStream content;
   private ODataContent oDataContent;
 
   @Override
@@ -33,21 +29,6 @@ public class SerializerStreamResultImpl implements SerializerStreamResult {
     return oDataContent;
   }
 
-  //  @Override
-//  public ReadableByteChannel getChannel() {
-//    return Channels.newChannel(getContent());
-//  }
-//
-//  @Override
-//  public void write(WritableByteChannel channel) {
-//    ResultHelper.copy(Channels.newChannel(content), channel);
-//  }
-//
-//  @Override
-//  public boolean isWriteSupported() {
-//    return false;
-//  }
-
   public static SerializerResultBuilder with() {
     return new SerializerResultBuilder();
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index a42e3df..2fa16ea 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -70,6 +70,7 @@ import org.apache.olingo.server.api.serializer.SerializerStreamResult;
 import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
+import org.apache.olingo.server.core.ODataWritableContent;
 import org.apache.olingo.server.core.serializer.AbstractODataSerializer;
 import org.apache.olingo.server.core.serializer.SerializerResultImpl;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
@@ -282,10 +283,67 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
     }
   }
 
+  public void entityCollectionIntoStream(ServiceMetadata metadata, EdmEntityType entityType, EntityIterator entitySet,
+      EntityCollectionSerializerOptions options, OutputStream outputStream) throws SerializerException {
+
+    final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
+//    if (options != null && options.getWriteOnlyReferences()) {
+//      ReferenceCollectionSerializerOptions rso = ReferenceCollectionSerializerOptions.with()
+//          .contextURL(contextURL).build();
+//      return entityReferenceCollection(entitySet, rso);
+//    }
+
+    SerializerException cachedException = null;
+    try {
+      CircleStreamBuffer buffer = new CircleStreamBuffer();
+      outputStream = buffer.getOutputStream();
+      XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
+      writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+      writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
+      writer.writeNamespace(ATOM, NS_ATOM);
+      writer.writeNamespace(METADATA, NS_METADATA);
+      writer.writeNamespace(DATA, NS_DATA);
+
+      writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
+          ContextURLBuilder.create(contextURL).toASCIIString());
+      writeMetadataETag(metadata, writer);
+
+      if (options != null && options.getId() != null) {
+        writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ID, NS_ATOM);
+        writer.writeCharacters(options.getId());
+        writer.writeEndElement();
+      }
+
+      if (options != null && options.getCount() != null && options.getCount().getValue()
+          && entitySet.getCount() != null) {
+        writeCount(entitySet, writer);
+      }
+      if (entitySet.getNext() != null) {
+        writeNextLink(entitySet, writer);
+      }
+
+      if (options == null) {
+        writeEntitySet(metadata, entityType, entitySet, null, null, null, writer);
+      } else {
+        writeEntitySet(metadata, entityType, entitySet,
+            options.getExpand(), options.getSelect(), options.xml10InvalidCharReplacement(), writer);
+      }
+
+      writer.writeEndElement();
+      writer.writeEndDocument();
+
+      writer.flush();
+    } catch (final XMLStreamException e) {
+      cachedException =
+          new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
+      throw cachedException;
+    }
+  }
+
   @Override
   public SerializerStreamResult entityCollectionStreamed(ServiceMetadata metadata, EdmEntityType entityType,
       EntityIterator entities, EntityCollectionSerializerOptions options) throws SerializerException {
-    throw new ODataRuntimeException("entityCollectionStreamed for XML not supported (yet)");
+      return ODataWritableContent.with(entities, entityType, this, metadata, options).build();
   }
 
   @Override
@@ -1163,5 +1221,5 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       return value;
     }
     return result.toString();
-  }  
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/09fd6d9b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 28989d6..850867e 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.tecsvc.processor;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Locale;
 
 import org.apache.olingo.commons.api.data.ContextURL;
@@ -27,6 +28,8 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.data.EntityIterator;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.format.ContentType;
@@ -526,13 +529,19 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       final SerializerResult serializerResult =
           serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption);
       response.setContent(serializerResult.getContent());
-    } else {
+    } else if(isOdataStreaming(request)) {
       final SerializerStreamResult serializerResult =
           serializeEntityCollectionStreamed(request,
               entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
               expand, select, countOption, id);
 
       response.setODataContent(serializerResult.getODataContent());
+    } else {
+      final SerializerResult serializerResult =
+          serializeEntityCollection(request,
+              entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
+              expand, select, countOption, id);
+      response.setContent(serializerResult.getContent());
     }
 
     //
@@ -544,6 +553,29 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     }
   }
 
+  private boolean isOdataStreaming(ODataRequest request) {
+    String odataStreaming = request.getHeader("odata.streaming");
+    return Boolean.parseBoolean(odataStreaming);
+  }
+
+  private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
+      entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
+      final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
+      final CountOption countOption, String id) throws ODataLibraryException {
+
+    return odata.createSerializer(requestedFormat).entityCollection(
+        serviceMetadata,
+        edmEntityType,
+        entityCollection,
+        EntityCollectionSerializerOptions.with()
+            .contextURL(isODataMetadataNone(requestedFormat) ? null :
+                getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select))
+            .count(countOption)
+            .expand(expand).select(select)
+            .id(id)
+            .build());
+  }
+
   // serialise as streamed collection
   private SerializerStreamResult serializeEntityCollectionStreamed(final ODataRequest request,
       final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
@@ -561,7 +593,23 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
       @Override
       public Entity next() {
-        return entityIterator.next();
+        return addToPrimitiveProperty(entityIterator.next(), "PropertyString", "->streamed");
+      }
+
+      private Entity addToPrimitiveProperty(Entity entity, String name, Object data) {
+        List<Property> properties = entity.getProperties();
+        int pos = 0;
+        for (Property property : properties) {
+          if(name.equals(property.getName())) {
+            properties.remove(pos);
+            final String old = property.getValue().toString();
+            String newValue = (old == null ? "": old) + data.toString();
+            entity.addProperty(new Property(null, name, ValueType.PRIMITIVE, newValue));
+            break;
+          }
+          pos++;
+        }
+        return entity;
       }
     };
 


[08/21] olingo-odata4 git commit: [OLINGO-832] Reverted change for inline entities

Posted by mi...@apache.org.
[OLINGO-832] Reverted change for inline entities


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

Branch: refs/heads/master
Commit: 1a7c28a7438efcfdeeb66a545d47e591010997bb
Parents: c6d45d9
Author: mibo <mi...@apache.org>
Authored: Sun Jan 31 17:43:55 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Sun Jan 31 17:43:55 2016 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/olingo/commons/api/data/Link.java | 6 +++---
 .../apache/olingo/server/api/serializer/ODataSerializer.java   | 5 +++--
 .../server/core/serializer/json/ODataJsonStreamSerializer.java | 3 ++-
 .../olingo/server/core/serializer/xml/ODataXmlSerializer.java  | 2 +-
 4 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1a7c28a7/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
index 996e378..0bf8237 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
@@ -32,7 +32,7 @@ public class Link extends Annotatable {
   private String type;
   private String mediaETag;
   private Entity entity;
-  private AbstractEntityCollection entitySet;
+  private EntityCollection entitySet;
   private String bindingLink;
   private List<String> bindingLinks = new ArrayList<String>();
 
@@ -149,7 +149,7 @@ public class Link extends Annotatable {
    *
    * @return in-line entity set.
    */
-  public AbstractEntityCollection getInlineEntitySet() {
+  public EntityCollection getInlineEntitySet() {
     return entitySet;
   }
 
@@ -158,7 +158,7 @@ public class Link extends Annotatable {
    *
    * @param entitySet entity set.
    */
-  public void setInlineEntitySet(final AbstractEntityCollection entitySet) {
+  public void setInlineEntitySet(final EntityCollection entitySet) {
     this.entitySet = entitySet;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1a7c28a7/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 3deb396..57370ba 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -128,8 +128,9 @@ public interface ODataSerializer {
    * @param metadata metadata for the service
    * @param edmEntitySet {@link EdmEntitySet}
    * @param entityCollection data of the entity collection
-   * @param ReferenceCollectionSerializerOptions {@link ReferenceCollectionSerializerOptions}
+   * @param options {@link ReferenceCollectionSerializerOptions}
    */
   SerializerResult referenceCollection(ServiceMetadata metadata, EdmEntitySet edmEntitySet,
-      AbstractEntityCollection entityCollection, ReferenceCollectionSerializerOptions options) throws SerializerException;
+      AbstractEntityCollection entityCollection, ReferenceCollectionSerializerOptions options)
+      throws SerializerException;
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1a7c28a7/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
index a7bd4f4..406fbe7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
@@ -21,6 +21,7 @@ package org.apache.olingo.server.core.serializer.json;
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 import org.apache.olingo.commons.api.Constants;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
@@ -51,7 +52,7 @@ public class ODataJsonStreamSerializer extends ODataJsonSerializer {
 
   @Override
   public SerializerResult entityCollection(final ServiceMetadata metadata,
-      final EdmEntityType entityType, final EntityCollection entitySet,
+      final EdmEntityType entityType, final AbstractEntityCollection entitySet,
       final EntityCollectionSerializerOptions options) throws SerializerException {
 
     EntityIterator coll;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/1a7c28a7/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 70d797f..b3d9d5d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -556,7 +556,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
       link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
       link.setTitle(navigationPropertyName);
-      AbstractEntityCollection target = new EntityCollection();
+      EntityCollection target = new EntityCollection();
       link.setInlineEntitySet(target);
       if (linked.getId() != null) {
         link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);


[10/21] olingo-odata4 git commit: [OLINGO-832] Pass out stream to json generator

Posted by mi...@apache.org.
[OLINGO-832] Pass out stream to json generator


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

Branch: refs/heads/master
Commit: a6e0fb1a562b7a3801c79fd0d3dcb19a5a323f3c
Parents: 2a80ca3
Author: mibo <mi...@apache.org>
Authored: Sun Feb 7 20:01:15 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Sun Feb 7 20:01:15 2016 +0100

----------------------------------------------------------------------
 .../serializer/ChannelSerializerResult.java     | 57 +++++++++++++++++---
 1 file changed, 50 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a6e0fb1a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index a3b6b0c..60b62f0 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -23,13 +23,13 @@ import com.fasterxml.jackson.core.JsonGenerator;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.ServiceMetadata;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
-import org.apache.olingo.server.core.serializer.utils.ResultHelper;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -41,7 +41,7 @@ import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 
 public class ChannelSerializerResult implements SerializerResult {
-  private ReadableByteChannel channel;
+  private StreamChannel channel;
 
   private static class StreamChannel implements ReadableByteChannel {
     private static final Charset DEFAULT = Charset.forName("UTF-8");
@@ -65,6 +65,44 @@ public class ChannelSerializerResult implements SerializerResult {
       this.tail = ByteBuffer.wrap(tail.getBytes(DEFAULT));
     }
 
+    public boolean write(OutputStream out) throws IOException {
+      if(head.hasRemaining()) {
+        out.write(head.array());
+        head.flip();
+        return true;
+      }
+      if (coll.hasNext()) {
+        try {
+          writeEntity(coll.next(), out);
+          if(coll.hasNext()) {
+            out.write(",".getBytes(DEFAULT));
+          }
+          return true;
+        } catch (SerializerException e) {
+        }
+      } else if(tail.hasRemaining()) {
+        out.write(tail.array());
+        tail.flip();
+        return true;
+      }
+      return false;
+    }
+
+
+    private void writeEntity(Entity entity, OutputStream outputStream) throws SerializerException {
+      try {
+        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
+        jsonSerializer.writeEntity(metadata, entityType, entity, null,
+            options == null ? null : options.getExpand(),
+            options == null ? null : options.getSelect(),
+            options != null && options.getWriteOnlyReferences(),
+            json);
+        json.flush();
+      } catch (final IOException e) {
+        throw new ODataRuntimeException("Failed entity serialization");
+      }
+    }
+
     @Override
     public int read(ByteBuffer dest) throws IOException {
       ByteBuffer buffer = getCurrentBuffer();
@@ -161,12 +199,17 @@ public class ChannelSerializerResult implements SerializerResult {
 
   @Override
   public void writeContent(WritableByteChannel writeChannel) {
-    // TODO: mibo: replace with passing 'writeChannel' to json serializer
-    ResultHelper.copy(this.channel, writeChannel);
+    try {
+      boolean contentAvailable = true;
+      while(contentAvailable) {
+        contentAvailable = this.channel.write(Channels.newOutputStream(writeChannel));
+      }
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
   }
 
-
-  private ChannelSerializerResult(ReadableByteChannel channel) {
+  private ChannelSerializerResult(StreamChannel channel) {
     this.channel = channel;
   }
 
@@ -206,7 +249,7 @@ public class ChannelSerializerResult implements SerializerResult {
     }
 
     public SerializerResult build() {
-      ReadableByteChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
+      StreamChannel input = new StreamChannel(coll, entityType, head, jsonSerializer, metadata, options, tail);
       return new ChannelSerializerResult(input);
     }
   }


[15/21] olingo-odata4 git commit: [OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC

Posted by mi...@apache.org.
[OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC


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

Branch: refs/heads/master
Commit: 67494a789798911fee97388e204952ff4c357723
Parents: 5174f70 3c205f9
Author: mibo <mi...@apache.org>
Authored: Sat Feb 13 07:28:32 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Sat Feb 13 07:28:32 2016 +0100

----------------------------------------------------------------------
 .../commons/AbstractInvocationHandler.java      |   17 +-
 .../AbstractStructuredInvocationHandler.java    |    2 +-
 .../commons/AnnotatationsInvocationHandler.java |    2 +-
 .../ComplexCollectionInvocationHandler.java     |    2 +-
 .../proxy/commons/ComplexInvocationHandler.java |    6 +-
 .../proxy/commons/EdmStreamValueHandler.java    |    2 +-
 .../EntityCollectionInvocationHandler.java      |    2 +-
 .../EntityContainerInvocationHandler.java       |    4 +-
 .../proxy/commons/EntityInvocationHandler.java  |    6 +-
 .../commons/EntitySetInvocationHandler.java     |    2 +-
 .../proxy/commons/InvokerInvocationHandler.java |    2 +-
 .../commons/OperationInvocationHandler.java     |    2 +-
 .../PrimitiveCollectionInvocationHandler.java   |    2 +-
 ...turedComposableInvokerInvocationHandler.java |    2 +-
 .../olingo/ext/proxy/utils/CoreUtils.java       |    5 +-
 .../org/apache/olingo/fit/AbstractServices.java | 1947 --------------
 .../main/java/org/apache/olingo/fit/Demo.java   |    6 +-
 .../java/org/apache/olingo/fit/OpenType.java    |    5 +-
 .../java/org/apache/olingo/fit/Services.java    | 2511 +++++++++++++++---
 .../org/apache/olingo/fit/Vocabularies.java     |   10 +-
 .../apache/olingo/fit/metadata/EntitySet.java   |    8 -
 .../olingo/fit/rest/OAuth2RequestFilter.java    |    3 +-
 .../fit/serializer/FITAtomDeserializer.java     |   13 +-
 .../olingo/fit/utils/AbstractUtilities.java     |   22 +-
 .../org/apache/olingo/fit/utils/Accept.java     |   31 +-
 .../org/apache/olingo/fit/utils/Commons.java    |   24 +-
 .../apache/olingo/fit/utils/ConstantKey.java    |   10 +-
 .../org/apache/olingo/fit/utils/Constants.java  |    7 -
 .../org/apache/olingo/fit/utils/FSManager.java  |   25 +-
 .../fit/utils/InjectableSerializerProvider.java |   42 -
 .../apache/olingo/fit/utils/JSONUtilities.java  |   14 +-
 .../olingo/fit/utils/MetadataLinkInfo.java      |  182 --
 .../apache/olingo/fit/utils/XMLUtilities.java   |    3 +
 .../proxy/demo/odatademo/types/Customer.java    |    6 +-
 .../proxy/demo/odatademo/types/Employee.java    |    6 +-
 .../demo/odatademo/types/FeaturedProduct.java   |    6 +-
 .../opentypesservice/types/IndexedRow.java      |    8 +-
 .../odatawcfservice/types/CreditCardPI.java     |    6 +-
 .../odatawcfservice/types/Customer.java         |    6 +-
 .../odatawcfservice/types/Employee.java         |    6 +-
 .../odatawcfservice/types/PublicCompany.java    |    8 +-
 .../client/AbstractParamTecSvcITCase.java       |   14 +
 .../olingo/fit/tecsvc/client/BasicITCase.java   |   34 +-
 .../fit/tecsvc/client/BatchClientITCase.java    |    8 +-
 .../olingo/fit/tecsvc/client/BindingITCase.java |   10 +-
 .../fit/tecsvc/client/DeepInsertITCase.java     |   31 +-
 .../tecsvc/client/EntityReferencesITCase.java   |   13 +-
 .../ExpandWithSystemQueryOptionsITCase.java     |   74 +-
 .../tecsvc/client/FilterSystemQueryITCase.java  |    4 +-
 .../core/domain/AbstractClientEntitySet.java    |  114 -
 .../core/domain/ClientCollectionValueImpl.java  |    2 +-
 .../client/core/domain/ClientEntitySetImpl.java |   74 +-
 .../core/domain/ClientPrimitiveValueImpl.java   |    5 +-
 .../client/core/domain/ClientPropertyImpl.java  |  135 +-
 .../client/core/domain/ClientValuableImpl.java  |   22 +-
 .../core/serialization/ODataBinderImpl.java     |    2 +-
 .../apache/olingo/client/core/AbstractTest.java |    9 +-
 .../org/apache/olingo/client/core/AtomTest.java |    6 -
 .../olingo/client/core/EntitySetTest.java       |   22 +-
 .../apache/olingo/client/core/EntityTest.java   |   73 +-
 .../apache/olingo/client/core/ErrorTest.java    |    8 +-
 .../org/apache/olingo/client/core/JSONTest.java |   46 +-
 .../apache/olingo/client/core/MetadataTest.java |   33 +-
 .../olingo/client/core/PrimitiveValueTest.java  |   22 +-
 .../apache/olingo/client/core/PropertyTest.java |   38 +-
 .../olingo/client/core/ServiceDocumentTest.java |   16 +-
 .../client/core/uri/FilterFactoryTest.java      |    8 +-
 .../olingo/client/core/uri/URIBuilderTest.java  |   71 +-
 .../olingo/commons/api/edm/geo/Geospatial.java  |    7 +-
 .../commons/api/edm/provider/CsdlOnDelete.java  |   23 +-
 .../api/edm/provider/CsdlReturnType.java        |   23 +-
 .../olingo/commons/api/http/HttpHeader.java     |    2 +
 .../olingo/server/api/edmx/EdmxReference.java   |   24 +-
 .../commons/core/edm/EdmEntityTypeImpl.java     |    7 +-
 .../core/edm/EdmNavigationPropertyImpl.java     |    3 +-
 .../commons/core/edm/EdmParameterImpl.java      |    3 +-
 .../commons/core/edm/EdmPropertyImpl.java       |    5 +-
 .../commons/core/edm/primitivetype/EdmDate.java |    5 +-
 .../edm/primitivetype/EdmDateTimeOffset.java    |   62 +-
 .../core/edm/primitivetype/EdmTimeOfDay.java    |   20 +-
 .../core/edm/primitivetype/EdmDateTest.java     |    1 -
 .../primitivetype/EdmDateTimeOffsetTest.java    |    9 +-
 .../edm/primitivetype/EdmTimeOfDayTest.java     |   23 +-
 .../edm/provider/EdmEntityTypeImplTest.java     |   19 +
 .../org/apache/olingo/server/api/OData.java     |   10 +
 .../uri/queryoption/SystemQueryOptionKind.java  |   22 +-
 .../apache/olingo/server/core/ErrorHandler.java |   47 +-
 .../olingo/server/core/MetadataParser.java      |  582 +++-
 .../olingo/server/core/OData4HttpHandler.java   |   10 +-
 .../olingo/server/core/ReferenceResolver.java   |   33 +
 .../server/core/SchemaBasedEdmProvider.java     |  137 +-
 .../olingo/server/core/ServiceDispatcher.java   |   48 +-
 .../olingo/server/core/ServiceHandler.java      |   27 +-
 .../core/legacy/ProcessorServiceHandler.java    |   12 +
 .../server/core/requests/ActionRequest.java     |    2 +-
 .../server/core/requests/BatchRequest.java      |   11 +-
 .../server/core/requests/DataRequest.java       |    6 +-
 .../server/core/responses/EntityResponse.java   |    1 +
 .../core/responses/EntitySetResponse.java       |    2 +
 .../server/core/responses/ErrorResponse.java    |   58 +
 .../server/core/responses/MetadataResponse.java |    2 +
 .../server/core/responses/PropertyResponse.java |    2 +
 .../core/responses/ServiceDocumentResponse.java |    2 +
 .../core/responses/ServiceResponseVisior.java   |    4 +
 .../resources/Org.OData.Capabilities.V1.xml     |  388 +++
 .../src/main/resources/Org.OData.Core.V1.xml    |  187 ++
 .../main/resources/Org.OData.Measures.V1.xml    |  110 +
 .../core/MetadataParserAnnotationsTest.java     |  215 ++
 .../olingo/server/core/MetadataParserTest.java  |    3 +-
 .../server/core/ServiceDispatcherTest.java      |   17 +-
 .../olingo/server/example/TripPinDataModel.java |    2 +-
 .../olingo/server/example/TripPinHandler.java   |   14 +-
 .../server/example/TripPinServiceTest.java      |   10 +
 .../olingo/server/example/TripPinServlet.java   |   11 +-
 .../src/test/resources/annotations.xml          |  153 ++
 .../src/test/resources/trippin.xml              |  808 +++---
 .../apache/olingo/server/core/ODataHandler.java |    4 +-
 .../server/core/ODataHttpHandlerImpl.java       |   19 +-
 .../apache/olingo/server/core/ODataImpl.java    |   13 +
 .../core/batchhandler/BatchFacadeImpl.java      |   18 +-
 .../server/core/batchhandler/BatchHandler.java  |    2 +-
 .../json/ODataJsonDeserializer.java             |   77 +-
 .../deserializer/xml/ODataXmlDeserializer.java  |   84 +-
 .../serializer/json/ODataJsonSerializer.java    |   42 +-
 .../core/serializer/xml/ODataXmlSerializer.java |   18 +-
 .../olingo/server/core/uri/UriInfoImpl.java     |   37 +-
 .../server/core/uri/parser/ExpandParser.java    |   30 +-
 .../core/uri/parser/ExpressionParser.java       |   85 +-
 .../server/core/uri/parser/FilterParser.java    |    6 +-
 .../server/core/uri/parser/OrderByParser.java   |    6 +-
 .../olingo/server/core/uri/parser/Parser.java   |  354 +--
 .../server/core/uri/parser/ParserHelper.java    |  168 +-
 .../core/uri/parser/ResourcePathParser.java     |   38 +-
 .../server/core/uri/parser/SelectParser.java    |   12 +-
 .../server/core/uri/parser/UriTokenizer.java    |   12 +-
 .../uri/queryoption/expression/AliasImpl.java   |    9 +-
 .../uri/validator/UriValidationException.java   |    4 +-
 .../server/core/uri/validator/UriValidator.java |  513 +---
 .../server-core-exceptions-i18n.properties      |    1 +
 .../olingo/server/core/uri/UriInfoImplTest.java |   50 +-
 .../core/uri/parser/ExpressionParserTest.java   |    2 +-
 .../core/uri/parser/UriTokenizerTest.java       |    3 +
 .../olingo/server/tecsvc/data/DataCreator.java  |   27 +-
 .../olingo/server/tecsvc/data/DataProvider.java |   12 +-
 .../SystemQueryOptionsRuntimeException.java     |    3 +-
 .../tecsvc/provider/ComplexTypeProvider.java    |    8 +
 .../tecsvc/provider/ContainerProvider.java      |    6 +-
 .../server/tecsvc/data/DataProviderTest.java    |   14 +
 .../AbstractODataDeserializerTest.java          |    5 +-
 .../ODataDeserializerEntityCollectionTest.java  |    4 +-
 ...ataJsonDeserializerActionParametersTest.java |    2 +-
 .../json/ODataJsonDeserializerEntityTest.java   |   46 +-
 ...DataXMLDeserializerActionParametersTest.java |    2 +-
 .../xml/ODataXmlDeserializerTest.java           |   43 +-
 .../json/ODataJsonSerializerTest.java           |   47 +-
 .../serializer/xml/ODataXmlSerializerTest.java  |   77 +-
 .../core/uri/parser/TestFullResourcePath.java   |  112 +-
 .../core/uri/queryoption/QueryOptionTest.java   |    4 +-
 .../queryoption/expression/ExpressionTest.java  |    6 +-
 .../core/uri/testutil/FilterValidator.java      |   51 +-
 .../core/uri/validator/UriValidatorTest.java    |   68 +-
 161 files changed, 6352 insertions(+), 4831 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/67494a78/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/67494a78/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/67494a78/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------


[18/21] olingo-odata4 git commit: [OLINGO-832] ODataJsonSerializer changes for streaming

Posted by mi...@apache.org.
[OLINGO-832] ODataJsonSerializer changes for streaming


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

Branch: refs/heads/master
Commit: 4aa1277a1284aa7a61c6e86a6685ff1a942d0e3b
Parents: 396a39b
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Feb 19 15:11:40 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Feb 19 15:11:40 2016 +0100

----------------------------------------------------------------------
 .../api/data/AbstractEntityCollection.java      |   3 -
 .../server/core/ODataWritableContent.java       |  84 ++++++------
 .../serializer/json/ODataJsonSerializer.java    |  40 +++---
 .../processor/TechnicalEntityProcessor.java     | 131 +------------------
 .../json/ODataJsonSerializerTest.java           |   8 +-
 5 files changed, 67 insertions(+), 199 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4aa1277a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
index 9b4f9ff..a3222c7 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
@@ -27,7 +27,4 @@ public abstract class AbstractEntityCollection extends AbstractODataObject imple
   public abstract URI getNext();
 
   public abstract URI getDeltaLink();
-//
-//  @Override
-//  Iterator<Entity> iterator();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4aa1277a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index 1b9cb30..904a6d0 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -65,51 +65,58 @@ public class ODataWritableContent implements ODataContent {
                          EntityCollectionSerializerOptions options, String tail) {
       this.coll = coll;
       this.entityType = entityType;
-      this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
+      this.head = head == null ? ByteBuffer.allocate(0) : ByteBuffer.wrap(head.getBytes(DEFAULT));
       this.jsonSerializer = jsonSerializer;
       this.metadata = metadata;
       this.options = options;
-      this.tail = ByteBuffer.wrap(tail.getBytes(DEFAULT));
+      this.tail = tail == null ? ByteBuffer.allocate(0) : ByteBuffer.wrap(tail.getBytes(DEFAULT));
     }
 
-    public boolean write(OutputStream out) throws IOException {
-      if(head.hasRemaining()) {
-        out.write(head.array());
-        head.flip();
-        return true;
-      }
-      if (coll.hasNext()) {
-        try {
-          writeEntity(coll.next(), out);
-          if(coll.hasNext()) {
-            out.write(",".getBytes(DEFAULT));
-          }
-          return true;
-        } catch (SerializerException e) {
-          final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
-          if(errorCallback != null) {
-            final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
-            errorCallback.handleError(errorContext, Channels.newChannel(out));
-          }
+//    public boolean write(OutputStream out) throws IOException {
+//      if(head.hasRemaining()) {
+//        out.write(head.array());
+//        head.flip();
+//        return true;
+//      }
+//      if (coll.hasNext()) {
+//        try {
+//          writeEntity(coll.next(), out);
+//          if(coll.hasNext()) {
+//            out.write(",".getBytes(DEFAULT));
+//          }
+//          return true;
+//        } catch (SerializerException e) {
+//          final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
+//          if(errorCallback != null) {
+//            final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
+//            errorCallback.handleError(errorContext, Channels.newChannel(out));
+//          }
+//        }
+//      } else if(tail.hasRemaining()) {
+//        out.write(tail.array());
+//        tail.flip();
+//        return true;
+//      }
+//      return false;
+//    }
+
+    public void write(OutputStream out) {
+      try {
+        writeEntity(coll, out);
+      } catch (SerializerException e) {
+        final WriteContentErrorCallback errorCallback = options.getWriteContentErrorCallback();
+        if(errorCallback != null) {
+          final ErrorContext errorContext = new ErrorContext(e).setParameter("Sample", "Some exception happened.");
+          errorCallback.handleError(errorContext, Channels.newChannel(out));
         }
-      } else if(tail.hasRemaining()) {
-        out.write(tail.array());
-        tail.flip();
-        return true;
       }
-      return false;
     }
 
 
-    private void writeEntity(Entity entity, OutputStream outputStream) throws SerializerException {
+    private void writeEntity(EntityIterator entity, OutputStream outputStream) throws SerializerException {
       try {
-        JsonGenerator json = new JsonFactory().createGenerator(outputStream);
-        jsonSerializer.writeEntity(metadata, entityType, entity, null,
-            options == null ? null : options.getExpand(),
-            options == null ? null : options.getSelect(),
-            options != null && options.getWriteOnlyReferences(),
-            json);
-        json.flush();
+        jsonSerializer.entityCollectionIntoStream(metadata, entityType, entity, options, outputStream);
+        outputStream.flush();
       } catch (final IOException e) {
         throw new ODataRuntimeException("Failed entity serialization");
       }
@@ -204,14 +211,7 @@ public class ODataWritableContent implements ODataContent {
 
   @Override
   public void write(WritableByteChannel writeChannel) {
-    try {
-      boolean contentAvailable = true;
-      while(contentAvailable) {
-        contentAvailable = this.channel.write(Channels.newOutputStream(writeChannel));
-      }
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
+    this.channel.write(Channels.newOutputStream(writeChannel));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4aa1277a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index df2ee84..cb60b4e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -18,10 +18,8 @@
  */
 package org.apache.olingo.server.core.serializer.json;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -184,8 +182,16 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   public SerializerStreamResult entityCollectionStreamed(ServiceMetadata metadata, EdmEntityType entityType,
       EntityIterator entities, EntityCollectionSerializerOptions options) throws SerializerException {
 
-    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-    SerializerException cachedException = null;
+    return ODataWritableContent.with(entities, entityType, this, metadata, options).build();
+  }
+
+
+  public void entityCollectionIntoStream(final ServiceMetadata metadata,
+      final EdmEntityType entityType, final EntityIterator entitySet,
+      final EntityCollectionSerializerOptions options, final OutputStream outputStream)
+        throws SerializerException {
+
+    SerializerException cachedException;
     try {
       JsonGenerator json = new JsonFactory().createGenerator(outputStream);
       json.writeStartObject();
@@ -196,29 +202,23 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       writeMetadataETag(metadata, json);
 
       if (options != null && options.getCount() != null && options.getCount().getValue()) {
-        writeCount(entities, json);
+        writeCount(entitySet, json);
       }
       json.writeFieldName(Constants.VALUE);
-      json.writeStartArray();
-      json.close();
-      outputStream.close();
-      String temp = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
-      String head = temp.substring(0, temp.length()-2);
-
-      outputStream = new ByteArrayOutputStream();
-      outputStream.write(']');
-      outputStream.write('}');
-      outputStream.close();
-      String tail = new String(outputStream.toByteArray(), Charset.forName("UTF-8"));
+      if (options == null) {
+        writeEntitySet(metadata, entityType, entitySet, null, null, false, json);
+      } else {
+        writeEntitySet(metadata, entityType, entitySet,
+            options.getExpand(), options.getSelect(), options.getWriteOnlyReferences(), json);
+      }
+      // next link not supported by default for streaming results
+//      writeNextLink(entitySet, json);
 
-      return ODataWritableContent.with(entities, entityType, this, metadata, options)
-          .addHead(head).addTail(tail).build();
+      json.close();
     } catch (final IOException e) {
       cachedException =
           new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION);
       throw cachedException;
-    } finally {
-      closeCircleStreamBufferOutput(outputStream, cachedException);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4aa1277a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 1afc288..28989d6 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -18,16 +18,8 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.ContextURL.Builder;
@@ -35,8 +27,6 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.data.EntityIterator;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.format.ContentType;
@@ -44,12 +34,10 @@ import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataApplicationException;
-import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.deserializer.DeserializerResult;
 import org.apache.olingo.server.api.deserializer.ODataDeserializer;
 import org.apache.olingo.server.api.prefer.Preferences.Return;
@@ -540,7 +528,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       response.setContent(serializerResult.getContent());
     } else {
       final SerializerStreamResult serializerResult =
-          serializeEntityStreamCollectionFixed(request,
+          serializeEntityCollectionStreamed(request,
               entitySetSerialization, edmEntitySet, edmEntityType, requestedContentType,
               expand, select, countOption, id);
 
@@ -556,8 +544,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     }
   }
 
-  // just for demonstration
-  private SerializerStreamResult serializeEntityStreamCollectionFixed(final ODataRequest request,
+  // serialise as streamed collection
+  private SerializerStreamResult serializeEntityCollectionStreamed(final ODataRequest request,
       final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
       final EdmEntityType edmEntityType,
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
@@ -573,66 +561,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
       @Override
       public Entity next() {
-        Entity next = entityIterator.next();
-//        replacePrimitiveProperty(next, "PropertyString", generateData(28192));
-        replacePrimitiveProperty(next, "PropertyString", generateData(request));
-//        next.addProperty(new Property(null, "PropertyString", ValueType.PRIMITIVE, generateData(28192)));
-
-        sleep(request, 2500);
-        return next;
-      }
-
-//      @Override
-//      public List<Entity> getEntities() {
-//        return entityCollection.getEntities();
-//      }
-
-      private void replacePrimitiveProperty(Entity entity, String name, Object data) {
-        List<Property> properties = entity.getProperties();
-        int pos = 0;
-        for (Property property : properties) {
-          if(name.equals(property.getName())) {
-            properties.remove(pos);
-            entity.addProperty(new Property(null, name, ValueType.PRIMITIVE, data));
-            break;
-          }
-          pos++;
-        }
+        return entityIterator.next();
       }
-
-      private void sleep(ODataRequest request, int defaultTimeMs) {
-        String sleepTimeMs = request.getHeader("StreamSleep");
-        if(sleepTimeMs != null) {
-          try {
-            defaultTimeMs = Integer.parseInt(sleepTimeMs);
-          } catch (NumberFormatException e) { }
-        }
-        try {
-          TimeUnit.MILLISECONDS.sleep(defaultTimeMs);
-        } catch (InterruptedException e) { }
-
-      }
-
-      private String generateData(ODataRequest request) {
-        String streamHeader = request.getHeader("StreamData");
-        if(streamHeader != null) {
-          try {
-            return generateData(Integer.parseInt(streamHeader));
-          } catch (NumberFormatException e) { }
-        }
-        return generateData(28192);
-      }
-
-      private String generateData(final int len) {
-        Random random = new Random();
-        StringBuilder b = new StringBuilder(len);
-        for (int j = 0; j < len; j++) {
-          final char c = (char) ('A' + random.nextInt('Z' - 'A' + 1));
-          b.append(c);
-        }
-        return b.toString();
-      }
-
     };
 
     return odata.createSerializer(requestedFormat).entityCollectionStreamed(
@@ -648,59 +578,6 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
             .build());
   }
 
-  private SerializerResult serializeEntityStreamCollection(final ODataRequest request,
-      final EntityCollection entityCollection, final EdmEntitySet edmEntitySet,
-      final EdmEntityType edmEntityType,
-      final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
-      final CountOption countOption, final String id) throws ODataLibraryException {
-
-    EntityIterator streamCollection = new EntityIterator() {
-      Iterator<Entity> test = entityCollection.getEntities().iterator();
-      @Override
-      public boolean hasNext() {
-        return test.hasNext();
-      }
-
-      @Override
-      public Entity next() {
-        try {
-          TimeUnit.MILLISECONDS.sleep(1000);
-        } catch (InterruptedException e) { }
-        return test.next();
-      }
-    };
-    return odata.createSerializer(requestedFormat).entityCollection(
-        serviceMetadata,
-        edmEntityType,
-        streamCollection,
-        EntityCollectionSerializerOptions.with()
-            .contextURL(isODataMetadataNone(requestedFormat) ? null :
-                getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select))
-            .count(countOption)
-            .expand(expand).select(select)
-            .id(id)
-            .build());
-  }
-
-
-  private SerializerResult serializeEntityCollection(final ODataRequest request, final EntityCollection
-      entityCollection, final EdmEntitySet edmEntitySet, final EdmEntityType edmEntityType,
-      final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
-      final CountOption countOption, String id) throws ODataLibraryException {
-
-    return odata.createSerializer(requestedFormat).entityCollection(
-        serviceMetadata,
-        edmEntityType,
-        entityCollection,
-        EntityCollectionSerializerOptions.with()
-            .contextURL(isODataMetadataNone(requestedFormat) ? null :
-                getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, false, expand, select))
-            .count(countOption)
-            .expand(expand).select(select)
-            .id(id)
-            .build());
-  }
-
   private SerializerResult serializeReferenceCollection(final EntityCollection entityCollection,
       final EdmEntitySet edmEntitySet, final ContentType requestedFormat, final CountOption countOption)
       throws ODataLibraryException {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/4aa1277a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 4211819..a7cf057 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -297,13 +297,7 @@ public class ODataJsonSerializerTest {
     ByteArrayOutputStream bout = new ByteArrayOutputStream();
     result.write(bout);
     final String resultString = new String(bout.toByteArray(), "UTF-8");
-
-    Assert.assertThat(resultString, CoreMatchers.startsWith("{"
-        + "\"@odata.context\":\"$metadata#ESAllPrim\","
-        + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
-        + "\"value\":"));
-    Assert.assertThat(resultString, CoreMatchers.endsWith(
-        "[ERROR: MISSING_PROPERTY"));
+    Assert.assertEquals(resultString, "ERROR: MISSING_PROPERTY");
   }
 
 


[07/21] olingo-odata4 git commit: [OLINGO-832] Introduced AbstractEntityCollection

Posted by mi...@apache.org.
[OLINGO-832] Introduced AbstractEntityCollection


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

Branch: refs/heads/master
Commit: c6d45d9f51e47c97f083076bfe37620630a8d03d
Parents: 44e1b02
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Jan 26 14:41:49 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Jan 26 14:41:49 2016 +0100

----------------------------------------------------------------------
 .../api/data/AbstractEntityCollection.java      | 33 ++++++++++++++++++++
 .../commons/api/data/EntityCollection.java      |  5 ++-
 .../olingo/commons/api/data/EntityIterator.java | 17 +++++++++-
 .../apache/olingo/commons/api/data/Link.java    |  6 ++--
 .../server/api/serializer/ODataSerializer.java  |  6 ++--
 .../serializer/json/ODataJsonSerializer.java    | 14 ++++-----
 .../core/serializer/xml/ODataXmlSerializer.java | 15 ++++-----
 7 files changed, 74 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
new file mode 100644
index 0000000..9b4f9ff
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/AbstractEntityCollection.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.data;
+
+import java.net.URI;
+import java.util.Iterator;
+
+public abstract class AbstractEntityCollection extends AbstractODataObject implements Iterable<Entity> {
+  public abstract Integer getCount();
+
+  public abstract URI getNext();
+
+  public abstract URI getDeltaLink();
+//
+//  @Override
+//  Iterator<Entity> iterator();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
index d3ec8e8..86d8747 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
@@ -26,7 +26,7 @@ import java.util.List;
 /**
  * Data representation for a collection of single entities.
  */
-public class EntityCollection extends AbstractODataObject implements Iterable<Entity> {
+public class EntityCollection extends AbstractEntityCollection {
 
   private final List<Entity> entities = new ArrayList<Entity>();
   private Integer count;
@@ -47,6 +47,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
    *
    * @return number of entries into the entity set.
    */
+  @Override
   public Integer getCount() {
     return count;
   }
@@ -74,6 +75,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
    *
    * @return next link if exists; null otherwise.
    */
+  @Override
   public URI getNext() {
     return next;
   }
@@ -83,6 +85,7 @@ public class EntityCollection extends AbstractODataObject implements Iterable<En
    *
    * @return delta link if exists; null otherwise.
    */
+  @Override
   public URI getDeltaLink() {
     return deltaLink;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
index 18f1019..697676e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
@@ -18,14 +18,16 @@
  */
 package org.apache.olingo.commons.api.data;
 
+import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
+import java.net.URI;
 import java.util.Iterator;
 
 /**
  * Data representation for a collection of single entities.
  */
-public abstract class EntityIterator extends EntityCollection implements Iterator<Entity> {
+public abstract class EntityIterator extends AbstractEntityCollection implements Iterator<Entity> {
 
   public abstract boolean hasNext();
   public abstract Entity next();
@@ -40,4 +42,17 @@ public abstract class EntityIterator extends EntityCollection implements Iterato
   public Iterator<Entity> iterator() {
     return this;
   }
+
+  public Integer getCount() {
+    throw new ODataRuntimeException("getCount() not supported for " + getClass().getSimpleName());
+  }
+
+  public URI getNext() {
+    throw new ODataRuntimeException("getNext() not supported for " + getClass().getSimpleName());
+
+  }
+
+  public URI getDeltaLink() {
+    throw new ODataRuntimeException("getDeltaLink() not supported for " + getClass().getSimpleName());
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
index 0bf8237..996e378 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/Link.java
@@ -32,7 +32,7 @@ public class Link extends Annotatable {
   private String type;
   private String mediaETag;
   private Entity entity;
-  private EntityCollection entitySet;
+  private AbstractEntityCollection entitySet;
   private String bindingLink;
   private List<String> bindingLinks = new ArrayList<String>();
 
@@ -149,7 +149,7 @@ public class Link extends Annotatable {
    *
    * @return in-line entity set.
    */
-  public EntityCollection getInlineEntitySet() {
+  public AbstractEntityCollection getInlineEntitySet() {
     return entitySet;
   }
 
@@ -158,7 +158,7 @@ public class Link extends Annotatable {
    *
    * @param entitySet entity set.
    */
-  public void setInlineEntitySet(final EntityCollection entitySet) {
+  public void setInlineEntitySet(final AbstractEntityCollection entitySet) {
     this.entitySet = entitySet;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
index 5dd5187..3deb396 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/ODataSerializer.java
@@ -19,7 +19,7 @@
 package org.apache.olingo.server.api.serializer;
 
 import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.edm.EdmComplexType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
@@ -61,7 +61,7 @@ public interface ODataSerializer {
    * @param options options for the serializer
    */
   SerializerResult entityCollection(ServiceMetadata metadata, EdmEntityType entityType,
-      EntityCollection entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
+      AbstractEntityCollection entitySet, EntityCollectionSerializerOptions options) throws SerializerException;
 
   /**
    * Writes entity data into an InputStream.
@@ -131,5 +131,5 @@ public interface ODataSerializer {
    * @param ReferenceCollectionSerializerOptions {@link ReferenceCollectionSerializerOptions}
    */
   SerializerResult referenceCollection(ServiceMetadata metadata, EdmEntitySet edmEntitySet,
-      EntityCollection entityCollection, ReferenceCollectionSerializerOptions options) throws SerializerException;
+      AbstractEntityCollection entityCollection, ReferenceCollectionSerializerOptions options) throws SerializerException;
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 7f84319..c381760 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Linked;
 import org.apache.olingo.commons.api.data.Property;
@@ -136,7 +136,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
 
   @Override
   public SerializerResult entityCollection(final ServiceMetadata metadata,
-      final EdmEntityType entityType, final EntityCollection entitySet,
+      final EdmEntityType entityType, final AbstractEntityCollection entitySet,
       final EntityCollectionSerializerOptions options) throws SerializerException {
     OutputStream outputStream = null;
     SerializerException cachedException = null;
@@ -213,7 +213,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
   }
 
   protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
-      final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
+      final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select,
       final boolean onlyReference, final JsonGenerator json) throws IOException,
       SerializerException {
     json.writeStartArray();
@@ -724,7 +724,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
 
   @Override
   public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
-      final EntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
+      final AbstractEntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
           throws SerializerException {
     OutputStream outputStream = null;
     SerializerException cachedException = null;
@@ -743,7 +743,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       }
 
       json.writeArrayFieldStart(Constants.VALUE);
-      for (final Entity entity : entityCollection.getEntities()) {
+      for (final Entity entity : entityCollection) {
         json.writeStartObject();
         json.writeStringField(Constants.JSON_ID, uriHelper.buildCanonicalURL(edmEntitySet, entity));
         json.writeEndObject();
@@ -783,7 +783,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     }
   }
 
-  void writeCount(final EntityCollection entityCollection, final JsonGenerator json) throws IOException {
+  void writeCount(final AbstractEntityCollection entityCollection, final JsonGenerator json) throws IOException {
     if (entityCollection.getCount() != null) {
       if (isIEEE754Compatible) {
         json.writeStringField(Constants.JSON_COUNT, entityCollection.getCount().toString());
@@ -793,7 +793,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
     }
   }
 
-  void writeNextLink(final EntityCollection entitySet, final JsonGenerator json) throws IOException {
+  void writeNextLink(final AbstractEntityCollection entitySet, final JsonGenerator json) throws IOException {
     if (entitySet.getNext() != null) {
       json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c6d45d9f/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 7e56976..70d797f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -35,6 +35,7 @@ import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
+import org.apache.olingo.commons.api.data.AbstractEntityCollection;
 import org.apache.olingo.commons.api.data.Link;
 import org.apache.olingo.commons.api.data.Linked;
 import org.apache.olingo.commons.api.data.Property;
@@ -209,7 +210,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
   @Override
   public SerializerResult entityCollection(final ServiceMetadata metadata,
-      final EdmEntityType entityType, final EntityCollection entitySet,
+      final EdmEntityType entityType, final AbstractEntityCollection entitySet,
       final EntityCollectionSerializerOptions options) throws SerializerException {
 
     final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL());
@@ -335,7 +336,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
   }
 
   protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
-      final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
+      final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select,
       final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
     for (final Entity entity : entitySet) {
       writeEntity(metadata, entityType, entity, null, expand, select, writer, false);
@@ -555,7 +556,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
       link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
       link.setTitle(navigationPropertyName);
-      EntityCollection target = new EntityCollection();
+      AbstractEntityCollection target = new EntityCollection();
       link.setInlineEntitySet(target);
       if (linked.getId() != null) {
         link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
@@ -1035,12 +1036,12 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
 
   @Override
   public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
-      final EntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
+      final AbstractEntityCollection entityCollection, final ReferenceCollectionSerializerOptions options)
       throws SerializerException {
     return entityReferenceCollection(entityCollection, options);
   }
 
-  protected SerializerResult entityReferenceCollection(final EntityCollection entitySet,
+  protected SerializerResult entityReferenceCollection(final AbstractEntityCollection entitySet,
       final ReferenceCollectionSerializerOptions options) throws SerializerException {
     OutputStream outputStream = null;
     SerializerException cachedException = null;
@@ -1086,14 +1087,14 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
     }
   }
 
-  private void writeCount(final EntityCollection entitySet, final XMLStreamWriter writer)
+  private void writeCount(final AbstractEntityCollection entitySet, final XMLStreamWriter writer)
       throws XMLStreamException {
     writer.writeStartElement(METADATA, Constants.ATOM_ELEM_COUNT, NS_METADATA);
     writer.writeCharacters(String.valueOf(entitySet.getCount()));
     writer.writeEndElement();
   }
 
-  private void writeNextLink(final EntityCollection entitySet, final XMLStreamWriter writer)
+  private void writeNextLink(final AbstractEntityCollection entitySet, final XMLStreamWriter writer)
       throws XMLStreamException {
     writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
     writer.writeAttribute(Constants.ATTR_REL, Constants.NEXT_LINK_REL);


[17/21] olingo-odata4 git commit: [OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC

Posted by mi...@apache.org.
[OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC


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

Branch: refs/heads/master
Commit: 396a39baec9539249dcfa4b111e87c037cb6fb64
Parents: 5b6cccf d040afe
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Feb 19 09:39:49 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Feb 19 09:39:49 2016 +0100

----------------------------------------------------------------------
 .../core/edm/annotation/EdmRecordImpl.java      |  16 +-
 .../core/edm/annotations/EdmRecordImplTest.java |   6 -
 .../core/edm/primitivetype/EdmDateTest.java     |  16 +-
 .../serializer/ComplexSerializerOptions.java    |  14 +-
 .../EntityCollectionSerializerOptions.java      |  11 +
 .../api/serializer/EntitySerializerOptions.java |  14 +-
 .../serializer/PrimitiveSerializerOptions.java  |  13 +
 .../PrimitiveValueSerializerOptions.java        |  14 +-
 .../olingo/server/core/MetadataParser.java      | 262 ++++++++++++++-----
 .../server/core/SchemaBasedEdmProvider.java     | 117 ++++-----
 .../olingo/server/core/ServiceRequest.java      |  50 +++-
 .../server/core/requests/DataRequest.java       |  13 +-
 .../src/main/resources/org.apache.olingo.v1.xml |  40 +++
 .../core/MetadataParserAnnotationsTest.java     |  10 +-
 .../olingo/server/core/MetadataParserTest.java  |   1 -
 .../server/core/ServiceDispatcherTest.java      |   3 +
 .../olingo/server/example/TripPinHandler.java   |   1 +
 .../server/example/TripPinServiceTest.java      |  30 ++-
 .../olingo/server/example/TripPinServlet.java   |   3 +-
 .../src/test/resources/airlines.json            |   2 +-
 .../src/test/resources/annotations.xml          |  17 ++
 .../src/test/resources/trippin.xml              |   6 +-
 .../xml/MetadataDocumentXmlSerializer.java      |   5 +-
 .../core/serializer/xml/ODataXmlSerializer.java | 138 ++++++----
 .../serializer/xml/ODataXmlSerializerTest.java  |  27 +-
 25 files changed, 606 insertions(+), 223 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/396a39ba/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --cc lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 6f4ed2d,9ee7d24..9335829
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@@ -33,7 -32,7 +33,8 @@@ public class EntityCollectionSerializer
    private SelectOption select;
    private boolean writeOnlyReferences;
    private String id;
 +  private WriteContentErrorCallback writeContentErrorCallback;
+   private String xml10InvalidCharReplacement;
  
    /** Gets the {@link ContextURL}. */
    public ContextURL getContextURL() {
@@@ -65,17 -64,10 +66,21 @@@
      return id;
    }
  
 +  /**
 +   * Gets the callback which is used in case of an exception during
 +   * write of the content (in case the content will be written/streamed
 +   * in the future)
 +   * @return callback which is used in case of an exception during
 +   * write of the content
 +   *
 +   */
 +  public WriteContentErrorCallback getWriteContentErrorCallback() {
 +    return writeContentErrorCallback;
 +  }
+   /** Gets the replacement string for unicode characters, that is not allowed in XML 1.0 */
+   public String xml10InvalidCharReplacement() {
+     return xml10InvalidCharReplacement;
+   }  
  
    /** Initializes the options builder. */
    public static Builder with() {
@@@ -126,19 -118,13 +131,25 @@@
        options.id = id;
        return this;
      }
 -    
 +
 +    /**
 +     * Set the callback which is used in case of an exception during
 +     * write of the content.
 +     *
 +     * @param writeContentErrorCallback the callback
 +     * @return the builder
 +     */
 +    public Builder writeContentErrorCallback(WriteContentErrorCallback writeContentErrorCallback) {
 +      options.writeContentErrorCallback = writeContentErrorCallback;
 +      return this;
 +    }
 +
+     /** set the replacement String for xml 1.0 unicode controlled characters that are not allowed */
+     public Builder xml10InvalidCharReplacement(final String replacement) {
+       options.xml10InvalidCharReplacement = replacement;
+       return this;
+     } 
+     
      /** Builds the OData serializer options. */
      public EntityCollectionSerializerOptions build() {
        return options;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/396a39ba/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --cc lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 1a07faa,a72e096..a42e3df
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@@ -53,8 -51,8 +53,9 @@@ import org.apache.olingo.commons.api.ed
  import org.apache.olingo.commons.api.edm.FullQualifiedName;
  import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
  import org.apache.olingo.commons.api.ex.ODataErrorDetail;
 +import org.apache.olingo.commons.api.ex.ODataRuntimeException;
  import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+ import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
  import org.apache.olingo.server.api.ODataServerError;
  import org.apache.olingo.server.api.ServiceMetadata;
  import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
@@@ -345,10 -338,11 +348,11 @@@ public class ODataXmlSerializer extend
    }
  
    protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
 -      final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
 +      final AbstractEntityCollection entitySet, final ExpandOption expand, final SelectOption select,
-       final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
+       final String xml10InvalidCharReplacement,final XMLStreamWriter writer) 
+           throws XMLStreamException, SerializerException {
 -    for (final Entity entity : entitySet.getEntities()) {
 +    for (final Entity entity : entitySet) {
-       writeEntity(metadata, entityType, entity, null, expand, select, writer, false);
+       writeEntity(metadata, entityType, entity, null, expand, select, xml10InvalidCharReplacement, writer, false);
      }
    }
  


[03/21] olingo-odata4 git commit: [OLINGO-832] Added iterable

Posted by mi...@apache.org.
[OLINGO-832] Added iterable


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

Branch: refs/heads/master
Commit: 69f58e84bf057239f50273031e7617641fbcc41f
Parents: 885ec27
Author: mibo <mi...@apache.org>
Authored: Sun Jan 24 07:22:57 2016 +0100
Committer: mibo <mi...@apache.org>
Committed: Sun Jan 24 12:31:02 2016 +0100

----------------------------------------------------------------------
 .../core/serialization/AtomSerializer.java      |  2 +-
 .../commons/api/data/EntityCollection.java      |  8 +++-
 .../olingo/commons/api/data/EntityIterator.java | 43 ++++++++++++++++++
 .../api/data/EntityStreamCollection.java        | 28 ------------
 .../apache/olingo/server/core/ODataImpl.java    |  7 ++-
 .../serializer/ChannelSerializerResult.java     | 46 ++++++++++----------
 .../core/serializer/SerializerResultImpl.java   |  5 +--
 .../core/serializer/StreamSerializerResult.java | 26 +++++------
 .../serializer/json/ODataJsonSerializer.java    |  2 +-
 .../json/ODataJsonStreamSerializer.java         | 44 ++-----------------
 .../serializer/utils/CircleStreamBuffer.java    |  1 -
 .../core/serializer/xml/ODataXmlSerializer.java |  4 +-
 .../uri/parser/search/SearchTokenizerTest.java  | 15 +++----
 .../processor/TechnicalEntityProcessor.java     | 20 ++++-----
 14 files changed, 117 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AtomSerializer.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AtomSerializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AtomSerializer.java
index b43605f..3c5fa1f 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AtomSerializer.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/AtomSerializer.java
@@ -525,7 +525,7 @@ public class AtomSerializer extends AbstractAtomDealer implements ODataSerialize
 
     common(writer, entitySet);
 
-    for (Entity entity : entitySet.getEntities()) {
+    for (Entity entity : entitySet) {
       if (entity.getType() == null && entity.getProperties().isEmpty()) {
         entityRef(writer, entity);
       } else {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
index adb43dc..e2aee4e 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
@@ -20,12 +20,13 @@ package org.apache.olingo.commons.api.data;
 
 import java.net.URI;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 /**
  * Data representation for a collection of single entities.
  */
-public class EntityCollection extends AbstractODataObject {
+public class EntityCollection extends AbstractODataObject implements Iterable<Entity> {
 
   private Integer count;
 
@@ -97,4 +98,9 @@ public class EntityCollection extends AbstractODataObject {
   public void setDeltaLink(final URI deltaLink) {
     this.deltaLink = deltaLink;
   }
+
+  @Override
+  public Iterator<Entity> iterator() {
+    return this.entities.iterator();
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
new file mode 100644
index 0000000..18f1019
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.data;
+
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
+import java.util.Iterator;
+
+/**
+ * Data representation for a collection of single entities.
+ */
+public abstract class EntityIterator extends EntityCollection implements Iterator<Entity> {
+
+  public abstract boolean hasNext();
+  public abstract Entity next();
+
+  @Override
+  public void remove() {
+    //"Remove is not supported for iteration over Entities."
+    throw new NotImplementedException();
+  }
+
+  @Override
+  public Iterator<Entity> iterator() {
+    return this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
deleted file mode 100644
index 9eae442..0000000
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityStreamCollection.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.commons.api.data;
-
-/**
- * Data representation for a collection of single entities.
- */
-public abstract class EntityStreamCollection extends EntityCollection {
-
-  public abstract boolean hasNext();
-  public abstract Entity nextEntity();
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index df6c7df..b063233 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -18,9 +18,6 @@
  */
 package org.apache.olingo.server.core;
 
-import java.util.Collection;
-import java.util.List;
-
 import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
 import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
@@ -48,11 +45,13 @@ import org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer;
 import org.apache.olingo.server.core.etag.ETagHelperImpl;
 import org.apache.olingo.server.core.prefer.PreferencesImpl;
 import org.apache.olingo.server.core.serializer.FixedFormatSerializerImpl;
-import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
 import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.xml.ODataXmlSerializer;
 import org.apache.olingo.server.core.uri.UriHelperImpl;
 
+import java.util.Collection;
+import java.util.List;
+
 public class ODataImpl extends OData {
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
index 1d4c32f..7768783 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/ChannelSerializerResult.java
@@ -18,16 +18,10 @@
  */
 package org.apache.olingo.server.core.serializer;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.charset.Charset;
-
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
 import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.server.api.ServiceMetadata;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
@@ -36,8 +30,13 @@ import org.apache.olingo.server.api.serializer.SerializerResult;
 import org.apache.olingo.server.core.serializer.json.ODataJsonStreamSerializer;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
 
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.charset.Charset;
 
 public class ChannelSerializerResult implements SerializerResult {
   private ReadableByteChannel channel;
@@ -47,14 +46,14 @@ public class ChannelSerializerResult implements SerializerResult {
     private ByteBuffer head;
     private ByteBuffer tail;
     private ODataJsonStreamSerializer jsonSerializer;
-    private EntityStreamCollection coll;
+    private EntityIterator coll;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
     private EntitySerializerOptions options;
 
-    public StreamChannel(EntityStreamCollection coll, EdmEntityType entityType, String head,
-        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
-        EntitySerializerOptions options, String tail) {
+    public StreamChannel(EntityIterator coll, EdmEntityType entityType, String head,
+                         ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
+                         EntitySerializerOptions options, String tail) {
       this.coll = coll;
       this.entityType = entityType;
       this.head = ByteBuffer.wrap(head.getBytes(DEFAULT));
@@ -86,11 +85,12 @@ public class ChannelSerializerResult implements SerializerResult {
     private ByteBuffer getCurrentBuffer() {
       if(currentBuffer == null) {
         currentBuffer = head;
-      } if(!currentBuffer.hasRemaining()) {
+      }
+      if(!currentBuffer.hasRemaining()) {
         if (coll.hasNext()) {
           try {
             // FIXME: mibo_160108: Inefficient buffer handling, replace
-            currentBuffer = serEntity(coll.nextEntity());
+            currentBuffer = serEntity(coll.next());
             if(coll.hasNext()) {
               ByteBuffer b = ByteBuffer.allocate(currentBuffer.position() + 1);
               currentBuffer.flip();
@@ -160,22 +160,24 @@ public class ChannelSerializerResult implements SerializerResult {
     this.channel = channel;
   }
 
-  public static SerializerResultBuilder with(EntityStreamCollection coll, EdmEntityType entityType,
-      ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+  public static SerializerResultBuilder with(EntityIterator coll, EdmEntityType entityType,
+                                             ODataJsonStreamSerializer jsonSerializer,
+                                             ServiceMetadata metadata, EntitySerializerOptions options) {
     return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
   }
 
   public static class SerializerResultBuilder {
     private ODataJsonStreamSerializer jsonSerializer;
-    private EntityStreamCollection coll;
+    private EntityIterator coll;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
     private EntitySerializerOptions options;
     private String head;
     private String tail;
 
-    public SerializerResultBuilder(EntityStreamCollection coll, EdmEntityType entityType,
-        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+    public SerializerResultBuilder(EntityIterator coll, EdmEntityType entityType,
+                                   ODataJsonStreamSerializer jsonSerializer,
+                                   ServiceMetadata metadata, EntitySerializerOptions options) {
       this.coll = coll;
       this.entityType = entityType;
       this.jsonSerializer = jsonSerializer;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 5a5364a..c039a71 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -18,13 +18,12 @@
  */
 package org.apache.olingo.server.core.serializer;
 
+import org.apache.olingo.server.api.serializer.SerializerResult;
+
 import java.io.InputStream;
-import java.nio.channels.Channel;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;
 
-import org.apache.olingo.server.api.serializer.SerializerResult;
-
 public class SerializerResultImpl implements SerializerResult {
   private InputStream content;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
index e4c8051..19b9f5d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/StreamSerializerResult.java
@@ -21,7 +21,7 @@ package org.apache.olingo.server.core.serializer;
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.server.api.ServiceMetadata;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
@@ -34,9 +34,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.nio.channels.Channel;
 import java.nio.channels.Channels;
-import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
 
 public class StreamSerializerResult implements SerializerResult {
@@ -50,14 +48,14 @@ public class StreamSerializerResult implements SerializerResult {
     private int entityCount = 0;
     private InputStream inputStream = null;
     private ODataJsonStreamSerializer jsonSerializer;
-    private EntityStreamCollection coll;
+    private EntityIterator coll;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
     private EntitySerializerOptions options;
 
-    public StreamInputStream(EntityStreamCollection coll, EdmEntityType entityType, String head,
-        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
-        EntitySerializerOptions options, String tail) {
+    public StreamInputStream(EntityIterator coll, EdmEntityType entityType, String head,
+                             ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
+                             EntitySerializerOptions options, String tail) {
       this.coll = coll;
       this.entityType = entityType;
       this.head = head;
@@ -74,7 +72,7 @@ public class StreamSerializerResult implements SerializerResult {
       }
       if (inputStream == null && coll.hasNext()) {
         try {
-          inputStream = serEntity(coll.nextEntity());
+          inputStream = serEntity(coll.next());
           entityCount++;
           if (entityCount > 1) {
             return (int) ',';
@@ -139,22 +137,24 @@ public class StreamSerializerResult implements SerializerResult {
     this.content = content;
   }
 
-  public static SerializerResultBuilder with(EntityStreamCollection coll, EdmEntityType entityType,
-      ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+  public static SerializerResultBuilder with(EntityIterator coll, EdmEntityType entityType,
+                                             ODataJsonStreamSerializer jsonSerializer,
+                                             ServiceMetadata metadata, EntitySerializerOptions options) {
     return new SerializerResultBuilder(coll, entityType, jsonSerializer, metadata, options);
   }
 
   public static class SerializerResultBuilder {
     private ODataJsonStreamSerializer jsonSerializer;
-    private EntityStreamCollection coll;
+    private EntityIterator coll;
     private ServiceMetadata metadata;
     private EdmEntityType entityType;
     private EntitySerializerOptions options;
     private String head;
     private String tail;
 
-    public SerializerResultBuilder(EntityStreamCollection coll, EdmEntityType entityType,
-        ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata, EntitySerializerOptions options) {
+    public SerializerResultBuilder(EntityIterator coll, EdmEntityType entityType,
+                                   ODataJsonStreamSerializer jsonSerializer, ServiceMetadata metadata,
+                                   EntitySerializerOptions options) {
       this.coll = coll;
       this.entityType = entityType;
       this.jsonSerializer = jsonSerializer;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 4a1a528..ce0258c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -217,7 +217,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
       final boolean onlyReference, final JsonGenerator json) throws IOException,
       SerializerException {
     json.writeStartArray();
-    for (final Entity entity : entitySet.getEntities()) {
+    for (final Entity entity : entitySet) {
       if (onlyReference) {
         json.writeStartObject();
         json.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
index 110d416..a7bd4f4 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonStreamSerializer.java
@@ -21,60 +21,24 @@ package org.apache.olingo.server.core.serializer.json;
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonGenerator;
 import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
-import org.apache.olingo.commons.api.data.EntityStreamCollection;
-import org.apache.olingo.commons.api.data.Link;
-import org.apache.olingo.commons.api.data.Linked;
-import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.EdmStructuredType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
 import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.apache.olingo.server.api.ODataServerError;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
 import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
-import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
-import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOptions;
-import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerResult;
-import org.apache.olingo.server.api.uri.UriHelper;
-import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
-import org.apache.olingo.server.core.serializer.AbstractODataSerializer;
 import org.apache.olingo.server.core.serializer.ChannelSerializerResult;
-import org.apache.olingo.server.core.serializer.SerializerResultImpl;
-import org.apache.olingo.server.core.serializer.StreamSerializerResult;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
-import org.apache.olingo.server.core.serializer.utils.ContentTypeHelper;
-import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
-import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
-import org.apache.olingo.server.core.uri.UriHelperImpl;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.nio.charset.Charset;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
 
 public class ODataJsonStreamSerializer extends ODataJsonSerializer {
 
@@ -90,9 +54,9 @@ public class ODataJsonStreamSerializer extends ODataJsonSerializer {
       final EdmEntityType entityType, final EntityCollection entitySet,
       final EntityCollectionSerializerOptions options) throws SerializerException {
 
-    EntityStreamCollection coll;
-    if(entitySet instanceof EntityStreamCollection) {
-      coll = (EntityStreamCollection) entitySet;
+    EntityIterator coll;
+    if(entitySet instanceof EntityIterator) {
+      coll = (EntityIterator) entitySet;
     } else {
       return serializer.entityCollection(metadata, entityType, entitySet, options);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
index b7ba2f2..7586339 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
@@ -22,7 +22,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
-import java.nio.channels.ReadableByteChannel;
 import java.util.Queue;
 import java.util.concurrent.LinkedBlockingQueue;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 2af8ede..a97d322 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -336,7 +336,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
   protected void writeEntitySet(final ServiceMetadata metadata, final EdmEntityType entityType,
       final EntityCollection entitySet, final ExpandOption expand, final SelectOption select,
       final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
-    for (final Entity entity : entitySet.getEntities()) {
+    for (final Entity entity : entitySet) {
       writeEntity(metadata, entityType, entity, null, expand, select, writer, false);
     }
   }
@@ -1060,7 +1060,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
       if (entitySet.getNext() != null) {
         writeNextLink(entitySet, writer);
       }
-      for (final Entity entity : entitySet.getEntities()) {
+      for (final Entity entity : entitySet) {
         writeReference(entity, options == null ? null : options.getContextURL(), writer, false);
       }
       writer.writeEndElement();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
index c2a390a..20a1c0d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
@@ -18,6 +18,13 @@
  */
 package org.apache.olingo.server.core.uri.parser.search;
 
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.Token.AND;
 import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.Token.CLOSE;
 import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.Token.NOT;
@@ -26,14 +33,6 @@ import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.T
 import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.Token.PHRASE;
 import static org.apache.olingo.server.core.uri.parser.search.SearchQueryToken.Token.WORD;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
 public class SearchTokenizerTest {
 
   @Test

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/69f58e84/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index f8fa7c8..f4c81c1 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.data.ContextURL.Builder;
 import org.apache.olingo.commons.api.data.ContextURL.Suffix;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
-import org.apache.olingo.commons.api.data.EntityStreamCollection;
+import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.data.Property;
 import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.EdmEntitySet;
@@ -556,8 +556,8 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
       final CountOption countOption, final String id) throws ODataLibraryException {
 
-    EntityStreamCollection streamCollection = new EntityStreamCollection() {
-      Iterator<Entity> entityIterator = entityCollection.getEntities().iterator();
+    EntityIterator streamCollection = new EntityIterator() {
+      Iterator<Entity> entityIterator = entityCollection.iterator();
 
       @Override
       public boolean hasNext() {
@@ -565,7 +565,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       }
 
       @Override
-      public Entity nextEntity() {
+      public Entity next() {
         Entity next = entityIterator.next();
         replacePrimitiveProperty(next, "PropertyString", generateData(28192));
 //        next.getProperties().remove(1);
@@ -576,10 +576,10 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
         return next;
       }
 
-      @Override
-      public List<Entity> getEntities() {
-        return entityCollection.getEntities();
-      }
+//      @Override
+//      public List<Entity> getEntities() {
+//        return entityCollection.getEntities();
+//      }
 
       private void replacePrimitiveProperty(Entity entity, String name, Object data) {
         List<Property> properties = entity.getProperties();
@@ -625,7 +625,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       final ContentType requestedFormat, final ExpandOption expand, final SelectOption select,
       final CountOption countOption, final String id) throws ODataLibraryException {
 
-    EntityStreamCollection streamCollection = new EntityStreamCollection() {
+    EntityIterator streamCollection = new EntityIterator() {
       Iterator<Entity> test = entityCollection.getEntities().iterator();
       @Override
       public boolean hasNext() {
@@ -633,7 +633,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
       }
 
       @Override
-      public Entity nextEntity() {
+      public Entity next() {
         try {
           TimeUnit.MILLISECONDS.sleep(1000);
         } catch (InterruptedException e) { }


[14/21] olingo-odata4 git commit: [OLINGO-832] Removed actual not supported/wanted methods

Posted by mi...@apache.org.
[OLINGO-832] Removed actual not supported/wanted methods


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

Branch: refs/heads/master
Commit: 5174f708973e9c296db3867d03ea7f731f0a93d7
Parents: dc2c972
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Feb 10 06:29:38 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Feb 10 06:38:25 2016 +0100

----------------------------------------------------------------------
 .../olingo/commons/api/data/EntityIterator.java | 10 ++--
 .../api/ex/ODataNotSupportedException.java      | 56 +++++++++++++++++++
 .../apache/olingo/server/api/ODataContent.java  |  7 +--
 .../EntityCollectionSerializerOptions.java      | 26 +++++++++
 .../server/api/serializer/SerializerResult.java |  6 --
 .../api/serializer/SerializerStreamResult.java  |  1 +
 .../olingo/server/core/ODataBasicContent.java   | 59 --------------------
 .../server/core/ODataHttpHandlerImpl.java       |  6 +-
 .../server/core/ODataWritableContent.java       | 32 ++++-------
 .../core/serializer/SerializerResultImpl.java   | 24 +-------
 .../processor/TechnicalEntityProcessor.java     |  9 ++-
 11 files changed, 113 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
index 697676e..8afd1fe 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityIterator.java
@@ -18,6 +18,7 @@
  */
 package org.apache.olingo.commons.api.data;
 
+import org.apache.olingo.commons.api.ex.ODataNotSupportedException;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
@@ -35,7 +36,7 @@ public abstract class EntityIterator extends AbstractEntityCollection implements
   @Override
   public void remove() {
     //"Remove is not supported for iteration over Entities."
-    throw new NotImplementedException();
+    throw new ODataNotSupportedException("Entity Iterator does not support remove()");
   }
 
   @Override
@@ -44,15 +45,14 @@ public abstract class EntityIterator extends AbstractEntityCollection implements
   }
 
   public Integer getCount() {
-    throw new ODataRuntimeException("getCount() not supported for " + getClass().getSimpleName());
+    throw new ODataNotSupportedException("Entity Iterator does not support getCount()");
   }
 
   public URI getNext() {
-    throw new ODataRuntimeException("getNext() not supported for " + getClass().getSimpleName());
-
+    throw new ODataNotSupportedException("Entity Iterator does not support getNext()");
   }
 
   public URI getDeltaLink() {
-    throw new ODataRuntimeException("getDeltaLink() not supported for " + getClass().getSimpleName());
+    throw new ODataNotSupportedException("Entity Iterator does not support getDeltaLink()");
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ex/ODataNotSupportedException.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ex/ODataNotSupportedException.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ex/ODataNotSupportedException.java
new file mode 100644
index 0000000..714c523
--- /dev/null
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/ex/ODataNotSupportedException.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.commons.api.ex;
+
+/**
+ * Core runtime exception for OData.
+ */
+public class ODataNotSupportedException extends ODataRuntimeException {
+
+  private static final long serialVersionUID = 42L;
+
+  /**
+   * Create with <code>message</code>.
+   *
+   * @param msg message text for exception
+   */
+  public ODataNotSupportedException(final String msg) {
+    super(msg);
+  }
+
+  /**
+   * Create with <code>message</code> for and <code>cause</code> of exception.
+   *
+   * @param msg message text for exception
+   * @param cause cause of exception
+   */
+  public ODataNotSupportedException(final String msg, final Exception cause) {
+    super(msg, cause);
+  }
+
+  /**
+   * Create with <code>cause</code> of exception.
+   *
+   * @param cause cause of exception
+   */
+  public ODataNotSupportedException(final Exception cause) {
+    super(cause);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
index a3147f6..d7e7ec3 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataContent.java
@@ -18,15 +18,12 @@
  */
 package org.apache.olingo.server.api;
 
+import java.io.OutputStream;
 import java.nio.channels.ReadableByteChannel;
 import java.nio.channels.WritableByteChannel;
 
 public interface ODataContent {
-  ReadableByteChannel getChannel();
-
   void write(WritableByteChannel channel);
 
-  void write(WritableByteChannel channel, WriteContentErrorCallback callback);
-
-  boolean isWriteSupported();
+  void write(OutputStream stream);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
index 611485f..6f4ed2d 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/EntityCollectionSerializerOptions.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.api.serializer;
 
 import org.apache.olingo.commons.api.data.ContextURL;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.uri.queryoption.CountOption;
 import org.apache.olingo.server.api.uri.queryoption.ExpandOption;
 import org.apache.olingo.server.api.uri.queryoption.SelectOption;
@@ -32,6 +33,7 @@ public class EntityCollectionSerializerOptions {
   private SelectOption select;
   private boolean writeOnlyReferences;
   private String id;
+  private WriteContentErrorCallback writeContentErrorCallback;
 
   /** Gets the {@link ContextURL}. */
   public ContextURL getContextURL() {
@@ -63,6 +65,18 @@ public class EntityCollectionSerializerOptions {
     return id;
   }
 
+  /**
+   * Gets the callback which is used in case of an exception during
+   * write of the content (in case the content will be written/streamed
+   * in the future)
+   * @return callback which is used in case of an exception during
+   * write of the content
+   *
+   */
+  public WriteContentErrorCallback getWriteContentErrorCallback() {
+    return writeContentErrorCallback;
+  }
+
   /** Initializes the options builder. */
   public static Builder with() {
     return new Builder();
@@ -113,6 +127,18 @@ public class EntityCollectionSerializerOptions {
       return this;
     }
 
+    /**
+     * Set the callback which is used in case of an exception during
+     * write of the content.
+     *
+     * @param writeContentErrorCallback the callback
+     * @return the builder
+     */
+    public Builder writeContentErrorCallback(WriteContentErrorCallback writeContentErrorCallback) {
+      options.writeContentErrorCallback = writeContentErrorCallback;
+      return this;
+    }
+
     /** Builds the OData serializer options. */
     public EntityCollectionSerializerOptions build() {
       return options;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
index c3206d6..85c625d 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
@@ -18,11 +18,7 @@
  */
 package org.apache.olingo.server.api.serializer;
 
-import org.apache.olingo.server.api.ODataContent;
-
 import java.io.InputStream;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
 
 /**
  * Result type for {@link ODataSerializer} methods
@@ -33,6 +29,4 @@ public interface SerializerResult {
    * @return serialized content
    */
   InputStream getContent();
-
-  ODataContent getODataContent();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
index c0dbafa..c19c270 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerStreamResult.java
@@ -22,6 +22,7 @@ import org.apache.olingo.server.api.ODataContent;
 
 /**
  * Result type for {@link ODataSerializer} methods
+ * which supports stream/write in the future
  */
 public interface SerializerStreamResult {
   /**

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
deleted file mode 100644
index 03328f4..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataBasicContent.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core;
-
-import org.apache.olingo.server.api.ODataContent;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
-
-import java.io.InputStream;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-public class ODataBasicContent implements ODataContent {
-  private final ReadableByteChannel channel;
-
-  public ODataBasicContent(ReadableByteChannel channel) {
-    this.channel = channel;
-  }
-
-  public ODataBasicContent(InputStream stream) {
-    this(Channels.newChannel(stream));
-  }
-
-  @Override
-  public ReadableByteChannel getChannel() {
-    return channel;
-  }
-
-  @Override
-  public void write(WritableByteChannel channel) {
-
-  }
-
-  @Override
-  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
-
-  }
-
-  @Override
-  public boolean isWriteSupported() {
-    return false;
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index dfd4a75..1e8947a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -161,11 +161,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
   static void writeContent(final ODataResponse odataResponse, final HttpServletResponse servletResponse) {
     try {
       ODataContent res = odataResponse.getODataContent();
-      if(res.isWriteSupported()) {
-        res.write(Channels.newChannel(servletResponse.getOutputStream()));
-      } else {
-        copyContent(res.getChannel(), servletResponse);
-      }
+      res.write(Channels.newChannel(servletResponse.getOutputStream()));
     } catch (IOException e) {
       throw new ODataRuntimeException("Error on reading request content", e);
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
index fc45639..ba7025c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataWritableContent.java
@@ -18,15 +18,20 @@
  */
 package org.apache.olingo.server.core;
 
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerator;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityIterator;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
 import org.apache.olingo.commons.api.ex.ODataRuntimeException;
 import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
 import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.api.serializer.SerializerStreamResult;
@@ -34,13 +39,8 @@ import org.apache.olingo.server.core.serializer.SerializerStreamResultImpl;
 import org.apache.olingo.server.core.serializer.json.ODataJsonSerializer;
 import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
 
 public class ODataWritableContent implements ODataContent {
   private StreamChannel channel;
@@ -184,17 +184,10 @@ public class ODataWritableContent implements ODataContent {
     }
   }
 
-//  @Override
-//  public InputStream getContent() {
-//    return Channels.newInputStream(this.channel);
-//  }
-
-  @Override
   public ReadableByteChannel getChannel() {
     return this.channel;
   }
 
-  @Override
   public boolean isWriteSupported() {
     return true;
   }
@@ -212,9 +205,8 @@ public class ODataWritableContent implements ODataContent {
   }
 
   @Override
-  public void write(WritableByteChannel channel, WriteContentErrorCallback callback) {
-    // TODO: implement error handling
-    throw new ODataRuntimeException("error handling not yet supported");
+  public void write(OutputStream stream) {
+    write(Channels.newChannel(stream));
   }
 
   private ODataWritableContent(StreamChannel channel) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
index 8c69f18..7c7de2f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
@@ -18,34 +18,19 @@
  */
 package org.apache.olingo.server.core.serializer;
 
+import java.io.InputStream;
+
 import org.apache.olingo.server.api.ODataContent;
 import org.apache.olingo.server.api.serializer.SerializerResult;
-import org.apache.olingo.server.api.serializer.SerializerStreamResult;
-import org.apache.olingo.server.core.ODataBasicContent;
-import org.apache.olingo.server.core.serializer.utils.ResultHelper;
-
-import java.io.InputStream;
-import java.nio.channels.Channels;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
 
 public class SerializerResultImpl implements SerializerResult {
   private InputStream content;
-  private ODataContent oDataContent;
 
   @Override
   public InputStream getContent() {
     return content;
   }
 
-  @Override
-  public ODataContent getODataContent() {
-    if(oDataContent == null && content != null) {
-      return new ODataBasicContent(content);
-    }
-    return oDataContent;
-  }
-
   //  @Override
 //  public ReadableByteChannel getChannel() {
 //    return Channels.newChannel(getContent());
@@ -73,11 +58,6 @@ public class SerializerResultImpl implements SerializerResult {
       return this;
     }
 
-    public SerializerResultBuilder content(final ODataContent input) {
-      result.oDataContent = input;
-      return this;
-    }
-
     public SerializerResult build() {
       return result;
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5174f708/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 9241860..1afc288 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -18,6 +18,11 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -44,6 +49,7 @@ import org.apache.olingo.server.api.ODataLibraryException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
 import org.apache.olingo.server.api.ServiceMetadata;
+import org.apache.olingo.server.api.WriteContentErrorCallback;
 import org.apache.olingo.server.api.deserializer.DeserializerResult;
 import org.apache.olingo.server.api.deserializer.ODataDeserializer;
 import org.apache.olingo.server.api.prefer.Preferences.Return;
@@ -531,7 +537,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
     if(isReference) {
       final SerializerResult serializerResult =
           serializeReferenceCollection(entitySetSerialization, edmEntitySet, requestedContentType, countOption);
-      response.setODataContent(serializerResult.getODataContent());
+      response.setContent(serializerResult.getContent());
     } else {
       final SerializerStreamResult serializerResult =
           serializeEntityStreamCollectionFixed(request,
@@ -540,6 +546,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor
 
       response.setODataContent(serializerResult.getODataContent());
     }
+
     //
     response.setStatusCode(HttpStatusCode.OK.getStatusCode());
     response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());


[05/21] olingo-odata4 git commit: [OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC

Posted by mi...@apache.org.
[OLINGO-832] Merge branch 'master' into OLINGO-832_StreamSerializerPoC


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

Branch: refs/heads/master
Commit: c02215e2ef1eaec9cecc8ab9f188a4538d8164e3
Parents: 0cc2199 b9512ed
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Jan 25 14:18:13 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Jan 25 14:18:13 2016 +0100

----------------------------------------------------------------------
 dist/android-lib/pom.xml                        |    2 +-
 dist/client-lib/pom.xml                         |    2 +-
 dist/javadoc/pom.xml                            |    2 +-
 dist/pom.xml                                    |    2 +-
 dist/server-lib/pom.xml                         |    2 +-
 dist/server-lib/src/main/resources/LICENSE      |   67 -
 dist/server-lib/src/main/resources/NOTICE       |   31 +-
 ext/client-android/pom.xml                      |    2 +-
 ext/client-proxy/pom.xml                        |    2 +-
 ext/karaf/karaf-features/pom.xml                |    2 +-
 .../src/main/resources/features.xml             |    1 -
 ext/karaf/karaf-fit/pom.xml                     |    2 +-
 .../osgi/itests/server/CarServiceTest.java      |    2 +-
 ext/karaf/pom.xml                               |    2 +-
 ext/pojogen-maven-plugin/pom.xml                |    2 +-
 ext/pom.xml                                     |    2 +-
 fit/pom.xml                                     |   10 +-
 .../org/apache/olingo/fit/AbstractServices.java |   46 -
 .../apache/olingo/fit/metadata/Association.java |   70 -
 .../olingo/fit/metadata/AssociationSet.java     |   74 -
 .../apache/olingo/fit/metadata/Container.java   |   13 -
 .../apache/olingo/fit/metadata/Metadata.java    |  110 +-
 .../olingo/fit/metadata/NavigationProperty.java |   27 -
 .../org/apache/olingo/fit/metadata/Schema.java  |   14 -
 .../org/apache/olingo/fit/methods/MERGE.java    |   33 -
 .../org/apache/olingo/fit/utils/Constants.java  |   60 +-
 .../olingo/fit/base/EntityUpdateTestITCase.java |    2 +-
 .../olingo/fit/tecsvc/client/BasicITCase.java   |    2 +-
 .../tecsvc/client/FilterSystemQueryITCase.java  |   34 +-
 .../tecsvc/client/OrderBySystemQueryITCase.java |    4 +-
 .../tecsvc/client/SystemQueryOptionITCase.java  |    2 +-
 .../olingo/fit/tecsvc/http/BasicHttpITCase.java |    4 +-
 lib/client-api/pom.xml                          |    6 +-
 .../ODataClientErrorException.java              |    9 +-
 .../api/domain/ClientEntitySetIterator.java     |    7 +-
 .../client/api/domain/ClientLinkType.java       |    6 +-
 .../olingo/client/api/uri/SegmentType.java      |    6 +-
 lib/client-core/pom.xml                         |   23 +-
 .../retrieve/RetrieveRequestFactoryImpl.java    |    9 +-
 .../client/core/edm/ClientCsdlXMLMetadata.java  |    3 +-
 .../client/core/edm/xml/ClientCsdlAction.java   |    4 +-
 .../core/edm/xml/ClientCsdlActionImport.java    |    4 +-
 .../core/edm/xml/ClientCsdlAnnotation.java      |    3 +-
 .../core/edm/xml/ClientCsdlAnnotations.java     |    4 +-
 .../core/edm/xml/ClientCsdlComplexType.java     |    4 +-
 .../core/edm/xml/ClientCsdlDataServices.java    |    4 +-
 .../client/core/edm/xml/ClientCsdlEdmx.java     |    4 +-
 .../core/edm/xml/ClientCsdlEntityContainer.java |    4 +-
 .../core/edm/xml/ClientCsdlEntityKey.java       |    4 +-
 .../core/edm/xml/ClientCsdlEntitySet.java       |    4 +-
 .../core/edm/xml/ClientCsdlEntityType.java      |    4 +-
 .../core/edm/xml/ClientCsdlEnumMember.java      |    4 +-
 .../client/core/edm/xml/ClientCsdlEnumType.java |    4 +-
 .../client/core/edm/xml/ClientCsdlFunction.java |    4 +-
 .../core/edm/xml/ClientCsdlFunctionImport.java  |    4 +-
 .../client/core/edm/xml/ClientCsdlInclude.java  |    4 +-
 .../edm/xml/ClientCsdlIncludeAnnotations.java   |    4 +-
 .../edm/xml/ClientCsdlNavigationProperty.java   |    4 +-
 .../ClientCsdlNavigationPropertyBinding.java    |    4 +-
 .../client/core/edm/xml/ClientCsdlOnDelete.java |    4 +-
 .../core/edm/xml/ClientCsdlParameter.java       |    4 +-
 .../client/core/edm/xml/ClientCsdlProperty.java |    4 +-
 .../core/edm/xml/ClientCsdlPropertyRef.java     |    4 +-
 .../core/edm/xml/ClientCsdlReference.java       |    4 +-
 .../xml/ClientCsdlReferentialConstraint.java    |    4 +-
 .../core/edm/xml/ClientCsdlReturnType.java      |    4 +-
 .../client/core/edm/xml/ClientCsdlSchema.java   |    4 +-
 .../core/edm/xml/ClientCsdlSingleton.java       |    4 +-
 .../client/core/edm/xml/ClientCsdlTerm.java     |    4 +-
 .../core/edm/xml/ClientCsdlTypeDefinition.java  |    4 +-
 .../edm/xml/annotation/ClientCsdlApply.java     |    3 +-
 .../core/edm/xml/annotation/ClientCsdlCast.java |    3 +-
 .../xml/annotation/ClientCsdlCollection.java    |    3 +-
 .../annotation/ClientCsdlDynamicExpression.java |    3 +-
 .../core/edm/xml/annotation/ClientCsdlIsOf.java |    3 +-
 .../annotation/ClientCsdlLabeledElement.java    |    3 +-
 .../core/edm/xml/annotation/ClientCsdlNull.java |    3 +-
 .../xml/annotation/ClientCsdlPropertyValue.java |    3 +-
 .../edm/xml/annotation/ClientCsdlRecord.java    |    3 +-
 .../edm/xml/annotation/ClientCsdlUrlRef.java    |    3 +-
 .../core/serialization/AbstractAtomDealer.java  |    3 +-
 .../olingo/client/core/uri/URIBuilderImpl.java  |    4 +-
 .../olingo/client/core/uri/URIBuilderTest.java  |   15 +-
 lib/commons-api/pom.xml                         |    7 +-
 .../commons/api/data/AbstractODataObject.java   |   25 +
 .../olingo/commons/api/data/Annotatable.java    |   30 -
 .../olingo/commons/api/data/Annotation.java     |   18 +
 .../olingo/commons/api/data/ComplexValue.java   |   17 +
 .../apache/olingo/commons/api/data/Delta.java   |   17 +
 .../olingo/commons/api/data/DeltaLink.java      |   25 +
 .../apache/olingo/commons/api/data/Entity.java  |   40 +
 .../commons/api/data/EntityCollection.java      |   27 +-
 .../apache/olingo/commons/api/data/Link.java    |   37 +
 .../apache/olingo/commons/api/data/Linked.java  |   17 +
 .../olingo/commons/api/data/Parameter.java      |   18 +
 .../olingo/commons/api/data/Property.java       |   18 +
 .../olingo/commons/api/data/Valuable.java       |   27 +-
 .../commons/api/edm/EdmBindingTarget.java       |    2 +-
 .../olingo/commons/api/edm/EdmMapping.java      |    7 +
 .../commons/api/edm/FullQualifiedName.java      |   19 +-
 .../edm/annotation/EdmConstantExpression.java   |    8 +-
 .../commons/api/edm/geo/ComposedGeospatial.java |   32 +-
 .../olingo/commons/api/edm/geo/Geospatial.java  |   37 +-
 .../api/edm/geo/GeospatialCollection.java       |   10 +-
 .../olingo/commons/api/edm/geo/LineString.java  |    8 +-
 .../commons/api/edm/geo/MultiLineString.java    |    8 +-
 .../olingo/commons/api/edm/geo/MultiPoint.java  |    8 +-
 .../commons/api/edm/geo/MultiPolygon.java       |    8 +-
 .../olingo/commons/api/edm/geo/Point.java       |   72 +-
 .../olingo/commons/api/edm/geo/Polygon.java     |   38 +-
 .../apache/olingo/commons/api/edm/geo/SRID.java |   49 +-
 .../api/edm/provider/CsdlAbstractEdmItem.java   |   25 +-
 .../commons/api/edm/provider/CsdlAction.java    |    2 -
 .../api/edm/provider/CsdlActionImport.java      |    2 -
 .../api/edm/provider/CsdlAnnotation.java        |    2 -
 .../api/edm/provider/CsdlAnnotations.java       |    2 -
 .../api/edm/provider/CsdlBindingTarget.java     |   27 +-
 .../api/edm/provider/CsdlComplexType.java       |    2 -
 .../api/edm/provider/CsdlEntityContainer.java   |    2 -
 .../commons/api/edm/provider/CsdlEntitySet.java |    8 +-
 .../api/edm/provider/CsdlEntityType.java        |    2 -
 .../api/edm/provider/CsdlEnumMember.java        |    2 -
 .../commons/api/edm/provider/CsdlEnumType.java  |    2 -
 .../commons/api/edm/provider/CsdlFunction.java  |    2 -
 .../api/edm/provider/CsdlFunctionImport.java    |    2 -
 .../commons/api/edm/provider/CsdlMapping.java   |   21 +
 .../edm/provider/CsdlNavigationProperty.java    |    2 -
 .../provider/CsdlNavigationPropertyBinding.java |    2 -
 .../commons/api/edm/provider/CsdlOnDelete.java  |    2 -
 .../commons/api/edm/provider/CsdlOperation.java |    2 -
 .../api/edm/provider/CsdlOperationImport.java   |    2 -
 .../commons/api/edm/provider/CsdlParameter.java |    2 -
 .../commons/api/edm/provider/CsdlProperty.java  |    2 -
 .../api/edm/provider/CsdlPropertyRef.java       |    2 -
 .../edm/provider/CsdlReferentialConstraint.java |    2 -
 .../api/edm/provider/CsdlReturnType.java        |    2 -
 .../commons/api/edm/provider/CsdlSchema.java    |    2 -
 .../commons/api/edm/provider/CsdlSingleton.java |   16 +-
 .../api/edm/provider/CsdlStructuralType.java    |    2 -
 .../commons/api/edm/provider/CsdlTerm.java      |    2 -
 .../api/edm/provider/CsdlTypeDefinition.java    |    2 -
 .../provider/annotation/CsdlAnnotationPath.java |    1 -
 .../api/edm/provider/annotation/CsdlApply.java  |    3 +-
 .../api/edm/provider/annotation/CsdlCast.java   |    1 -
 .../edm/provider/annotation/CsdlCollection.java |    1 -
 .../annotation/CsdlConstantExpression.java      |    3 -
 .../annotation/CsdlDynamicExpression.java       |    2 -
 .../edm/provider/annotation/CsdlExpression.java |    2 -
 .../api/edm/provider/annotation/CsdlIf.java     |    2 -
 .../api/edm/provider/annotation/CsdlIsOf.java   |    2 -
 .../provider/annotation/CsdlLabeledElement.java |    4 +-
 .../annotation/CsdlLabeledElementReference.java |    1 -
 .../CsdlLogicalOrComparisonExpression.java      |    2 -
 .../annotation/CsdlNavigationPropertyPath.java  |    1 -
 .../api/edm/provider/annotation/CsdlNull.java   |    2 -
 .../api/edm/provider/annotation/CsdlPath.java   |    1 -
 .../provider/annotation/CsdlPropertyPath.java   |    1 -
 .../provider/annotation/CsdlPropertyValue.java  |    5 +-
 .../api/edm/provider/annotation/CsdlRecord.java |    1 -
 .../api/edm/provider/annotation/CsdlUrlRef.java |    3 +-
 lib/commons-core/pom.xml                        |   24 +-
 .../core/edm/AbstractEdmBindingTarget.java      |   12 +-
 .../olingo/commons/core/edm/EdmTypeInfo.java    |   10 +-
 .../primitivetype/AbstractGeospatialType.java   |   49 +-
 .../core/edm/primitivetype/EdmBinary.java       |   12 +-
 .../edm/primitivetype/EdmDateTimeOffset.java    |    8 +-
 .../commons/core/edm/EdmImplCachingTest.java    |    3 +-
 .../primitivetype/EdmDateTimeOffsetTest.java    |   16 +-
 .../edm/primitivetype/EdmTimeOfDayTest.java     |   26 +-
 .../edm/provider/EdmActionImportImplTest.java   |    2 +-
 .../core/edm/provider/EdmMappingTest.java       |   42 +-
 .../core/edm/provider/EdmProviderImplTest.java  |    4 +-
 .../core/edm/provider/EdmSchemaImplTest.java    |    1 +
 lib/pom.xml                                     |    2 +-
 lib/server-api/pom.xml                          |    2 +-
 .../apache/olingo/server/api/HttpHeaders.java   |    4 +-
 .../org/apache/olingo/server/api/OData.java     |    6 +-
 .../server/api/ODataApplicationException.java   |    4 +-
 .../olingo/server/api/ODataHttpHandler.java     |    4 +-
 .../server/api/ODataLibraryException.java       |    4 +-
 .../apache/olingo/server/api/ODataRequest.java  |    6 +-
 .../apache/olingo/server/api/ODataResponse.java |    5 +-
 .../olingo/server/api/ODataServerError.java     |    4 +-
 .../olingo/server/api/ServiceMetadata.java      |    4 +-
 .../olingo/server/api/batch/BatchFacade.java    |  106 +-
 .../olingo/server/api/batch/package-info.java   |    4 +-
 .../server/api/debug/DebugInformation.java      |   16 +-
 .../server/api/debug/DebugResponseHelper.java   |    4 +-
 .../olingo/server/api/debug/DebugSupport.java   |    9 +-
 .../server/api/debug/DefaultDebugSupport.java   |    8 +-
 .../server/api/debug/RuntimeMeasurement.java    |   12 +-
 .../olingo/server/api/debug/package-info.java   |    4 +-
 .../api/deserializer/DeserializerException.java |    4 +-
 .../api/deserializer/DeserializerResult.java    |    4 +-
 .../deserializer/FixedFormatDeserializer.java   |   12 +-
 .../api/deserializer/ODataDeserializer.java     |   10 +-
 .../batch/BatchDeserializerException.java       |   14 +-
 .../api/deserializer/batch/BatchOptions.java    |    8 +-
 .../deserializer/batch/BatchRequestPart.java    |    4 +-
 .../deserializer/batch/ODataResponsePart.java   |    8 +-
 .../api/deserializer/batch/package-info.java    |    4 +-
 .../server/api/deserializer/package-info.java   |    4 +-
 .../server/api/etag/CustomETagSupport.java      |    4 +-
 .../olingo/server/api/etag/ETagHelper.java      |   22 +-
 .../server/api/etag/PreconditionException.java  |    4 +-
 .../api/etag/ServiceMetadataETagSupport.java    |    6 +-
 .../olingo/server/api/etag/package-info.java    |    4 +-
 .../apache/olingo/server/api/package-info.java  |    4 +-
 .../olingo/server/api/prefer/Preferences.java   |   13 +-
 .../server/api/prefer/PreferencesApplied.java   |   16 +-
 .../olingo/server/api/prefer/package-info.java  |    4 +-
 .../ActionComplexCollectionProcessor.java       |    4 +-
 .../api/processor/ActionComplexProcessor.java   |    4 +-
 .../ActionEntityCollectionProcessor.java        |    4 +-
 .../api/processor/ActionEntityProcessor.java    |    4 +-
 .../ActionPrimitiveCollectionProcessor.java     |    4 +-
 .../api/processor/ActionPrimitiveProcessor.java |    4 +-
 .../api/processor/ActionVoidProcessor.java      |    4 +-
 .../server/api/processor/BatchProcessor.java    |    4 +-
 .../processor/ComplexCollectionProcessor.java   |    4 +-
 .../server/api/processor/ComplexProcessor.java  |    4 +-
 .../CountComplexCollectionProcessor.java        |    4 +-
 .../CountEntityCollectionProcessor.java         |    4 +-
 .../CountPrimitiveCollectionProcessor.java      |    4 +-
 .../server/api/processor/DefaultProcessor.java  |    4 +-
 .../server/api/processor/DeltaProcessor.java    |   30 +-
 .../processor/EntityCollectionProcessor.java    |    4 +-
 .../server/api/processor/EntityProcessor.java   |    6 +-
 .../server/api/processor/ErrorProcessor.java    |    6 +-
 .../api/processor/MediaEntityProcessor.java     |    4 +-
 .../server/api/processor/MetadataProcessor.java |    4 +-
 .../processor/PrimitiveCollectionProcessor.java |    4 +-
 .../api/processor/PrimitiveProcessor.java       |    6 +-
 .../api/processor/PrimitiveValueProcessor.java  |    6 +-
 .../olingo/server/api/processor/Processor.java  |    4 +-
 .../processor/ReferenceCollectionProcessor.java |    4 +-
 .../api/processor/ReferenceProcessor.java       |    4 +-
 .../api/processor/ServiceDocumentProcessor.java |    4 +-
 .../server/api/processor/package-info.java      |    5 +-
 .../serializer/BatchSerializerException.java    |    7 +-
 .../serializer/ComplexSerializerOptions.java    |   10 +-
 .../serializer/CustomContentTypeSupport.java    |    4 +-
 .../EntityCollectionSerializerOptions.java      |    8 +-
 .../api/serializer/EntitySerializerOptions.java |    8 +-
 .../api/serializer/FixedFormatSerializer.java   |    6 +-
 .../server/api/serializer/ODataSerializer.java  |   52 +-
 .../serializer/PrimitiveSerializerOptions.java  |   10 +-
 .../PrimitiveValueSerializerOptions.java        |    4 +-
 .../ReferenceCollectionSerializerOptions.java   |   12 +-
 .../serializer/ReferenceSerializerOptions.java  |    4 +-
 .../api/serializer/RepresentationType.java      |    4 +-
 .../api/serializer/SerializerException.java     |    4 +-
 .../server/api/serializer/SerializerResult.java |    4 +-
 .../server/api/serializer/package-info.java     |    4 +-
 .../apache/olingo/server/api/uri/UriHelper.java |   10 +-
 .../apache/olingo/server/api/uri/UriInfo.java   |    6 +-
 .../olingo/server/api/uri/UriInfoAll.java       |    6 +-
 .../olingo/server/api/uri/UriInfoBatch.java     |    6 +-
 .../olingo/server/api/uri/UriInfoCrossjoin.java |    8 +-
 .../olingo/server/api/uri/UriInfoEntityId.java  |    4 +-
 .../olingo/server/api/uri/UriInfoKind.java      |    4 +-
 .../olingo/server/api/uri/UriInfoMetadata.java  |    4 +-
 .../olingo/server/api/uri/UriInfoResource.java  |    4 +-
 .../olingo/server/api/uri/UriInfoService.java   |    6 +-
 .../olingo/server/api/uri/UriParameter.java     |    4 +-
 .../olingo/server/api/uri/UriResource.java      |    4 +-
 .../server/api/uri/UriResourceAction.java       |    4 +-
 .../api/uri/UriResourceComplexProperty.java     |    4 +-
 .../olingo/server/api/uri/UriResourceCount.java |    6 +-
 .../server/api/uri/UriResourceEntitySet.java    |    4 +-
 .../server/api/uri/UriResourceFunction.java     |    4 +-
 .../olingo/server/api/uri/UriResourceIt.java    |    4 +-
 .../olingo/server/api/uri/UriResourceKind.java  |    4 +-
 .../server/api/uri/UriResourceLambdaAll.java    |    4 +-
 .../server/api/uri/UriResourceLambdaAny.java    |    4 +-
 .../api/uri/UriResourceLambdaVariable.java      |    4 +-
 .../server/api/uri/UriResourceNavigation.java   |    4 +-
 .../server/api/uri/UriResourcePartTyped.java    |    6 +-
 .../api/uri/UriResourcePrimitiveProperty.java   |    6 +-
 .../server/api/uri/UriResourceProperty.java     |    4 +-
 .../olingo/server/api/uri/UriResourceRef.java   |    6 +-
 .../olingo/server/api/uri/UriResourceRoot.java  |    6 +-
 .../server/api/uri/UriResourceSingleton.java    |    4 +-
 .../olingo/server/api/uri/UriResourceValue.java |    6 +-
 .../olingo/server/api/uri/package-info.java     |    6 +-
 .../api/uri/queryoption/AliasQueryOption.java   |    4 +-
 .../server/api/uri/queryoption/CountOption.java |    4 +-
 .../api/uri/queryoption/CustomQueryOption.java  |    6 +-
 .../server/api/uri/queryoption/ExpandItem.java  |    5 +-
 .../api/uri/queryoption/ExpandOption.java       |    4 +-
 .../api/uri/queryoption/FilterOption.java       |    4 +-
 .../api/uri/queryoption/FormatOption.java       |    4 +-
 .../server/api/uri/queryoption/IdOption.java    |    4 +-
 .../api/uri/queryoption/LevelsExpandOption.java |    4 +-
 .../server/api/uri/queryoption/OrderByItem.java |    4 +-
 .../api/uri/queryoption/OrderByOption.java      |    4 +-
 .../server/api/uri/queryoption/QueryOption.java |    4 +-
 .../api/uri/queryoption/SearchOption.java       |    4 +-
 .../server/api/uri/queryoption/SelectItem.java  |    4 +-
 .../api/uri/queryoption/SelectOption.java       |    4 +-
 .../server/api/uri/queryoption/SkipOption.java  |    4 +-
 .../api/uri/queryoption/SkipTokenOption.java    |    4 +-
 .../api/uri/queryoption/SystemQueryOption.java  |    4 +-
 .../uri/queryoption/SystemQueryOptionKind.java  |    4 +-
 .../server/api/uri/queryoption/TopOption.java   |    4 +-
 .../api/uri/queryoption/expression/Alias.java   |    4 +-
 .../api/uri/queryoption/expression/Binary.java  |    4 +-
 .../expression/BinaryOperatorKind.java          |    4 +-
 .../uri/queryoption/expression/Enumeration.java |    4 +-
 .../uri/queryoption/expression/Expression.java  |    6 +-
 .../expression/ExpressionVisitException.java    |    4 +-
 .../expression/ExpressionVisitor.java           |    4 +-
 .../uri/queryoption/expression/LambdaRef.java   |    4 +-
 .../api/uri/queryoption/expression/Literal.java |   10 +-
 .../api/uri/queryoption/expression/Member.java  |    4 +-
 .../api/uri/queryoption/expression/Method.java  |    4 +-
 .../uri/queryoption/expression/MethodKind.java  |    4 +-
 .../uri/queryoption/expression/TypeLiteral.java |    4 +-
 .../api/uri/queryoption/expression/Unary.java   |    4 +-
 .../expression/UnaryOperatorKind.java           |    4 +-
 .../expression/VisitableExpression.java         |    4 +-
 .../queryoption/expression/package-info.java    |    4 +-
 .../api/uri/queryoption/package-info.java       |    4 +-
 .../uri/queryoption/search/SearchBinary.java    |    4 +-
 .../search/SearchBinaryOperatorKind.java        |   31 +-
 .../queryoption/search/SearchExpression.java    |   18 +-
 .../api/uri/queryoption/search/SearchTerm.java  |    4 +-
 .../api/uri/queryoption/search/SearchUnary.java |    5 +-
 .../search/SearchUnaryOperatorKind.java         |   24 +-
 .../uri/queryoption/search/package-info.java    |    4 +-
 .../olingo/server/api/ODataRequestTest.java     |    4 +-
 .../server/api/TranslatedExceptionsTest.java    |    4 +-
 .../api/prefer/PreferencesAppliedTest.java      |   22 +-
 lib/server-core-ext/pom.xml                     |   10 +-
 .../apache/olingo/server/core/ErrorHandler.java |    8 +-
 .../olingo/server/core/ServiceDispatcher.java   |    4 +-
 .../olingo/server/core/ServiceRequest.java      |    6 +-
 .../server/core/responses/EntityResponse.java   |   39 +-
 .../olingo/server/example/TripPinDataModel.java |    4 +-
 lib/server-core/pom.xml                         |   60 +-
 .../olingo/server/core/uri/antlr/UriLexer.g4    |  424 --
 .../olingo/server/core/uri/antlr/UriParser.g4   |  447 --
 .../olingo/server/core/ContentNegotiator.java   |   18 +-
 .../server/core/ContentNegotiatorException.java |    4 +-
 .../server/core/DefaultRedirectProcessor.java   |    4 +-
 .../olingo/server/core/ODataDispatcher.java     |  132 +-
 .../server/core/ODataExceptionHelper.java       |   14 +-
 .../apache/olingo/server/core/ODataHandler.java |   22 +-
 .../server/core/ODataHandlerException.java      |    6 +-
 .../server/core/ODataHttpHandlerImpl.java       |    8 +-
 .../apache/olingo/server/core/ODataImpl.java    |   10 +-
 .../olingo/server/core/RedirectProcessor.java   |    4 +-
 .../olingo/server/core/ServiceMetadataImpl.java |    8 +-
 .../core/batchhandler/BatchFacadeImpl.java      |    8 +-
 .../server/core/batchhandler/BatchHandler.java  |    4 +-
 .../core/batchhandler/BatchPartHandler.java     |    6 +-
 .../BatchReferenceRewriter.java                 |    4 +-
 .../core/debug/DebugResponseHelperImpl.java     |  118 +-
 .../olingo/server/core/debug/DebugTab.java      |    5 +-
 .../olingo/server/core/debug/DebugTabBody.java  |   12 +-
 .../server/core/debug/DebugTabRequest.java      |   28 +-
 .../server/core/debug/DebugTabResponse.java     |   14 +-
 .../server/core/debug/DebugTabRuntime.java      |   34 +-
 .../server/core/debug/DebugTabServer.java       |   14 +-
 .../server/core/debug/DebugTabStacktrace.java   |   24 +-
 .../olingo/server/core/debug/DebugTabUri.java   |   74 +-
 .../core/debug/ExpressionJsonVisitor.java       |   12 +-
 .../server/core/debug/ServerCoreDebugger.java   |   12 +-
 .../deserializer/DeserializerResultImpl.java    |    4 +-
 .../FixedFormatDeserializerImpl.java            |   10 +-
 .../core/deserializer/batch/BatchBodyPart.java  |    8 +-
 .../deserializer/batch/BatchChangeSetPart.java  |    4 +-
 .../deserializer/batch/BatchLineReader.java     |   44 +-
 .../core/deserializer/batch/BatchParser.java    |   10 +-
 .../deserializer/batch/BatchParserCommon.java   |   14 +-
 .../core/deserializer/batch/BatchPart.java      |    4 +-
 .../deserializer/batch/BatchQueryOperation.java |    4 +-
 .../batch/BatchRequestTransformator.java        |   20 +-
 .../batch/BatchTransformatorCommon.java         |    8 +-
 .../server/core/deserializer/batch/Header.java  |    4 +-
 .../core/deserializer/batch/HeaderField.java    |    4 +-
 .../batch/HttpRequestStatusLine.java            |    6 +-
 .../server/core/deserializer/batch/Line.java    |    4 +-
 .../deserializer/helper/ExpandTreeBuilder.java  |   18 +-
 .../helper/ExpandTreeBuilderImpl.java           |    4 +-
 .../json/ODataJsonDeserializer.java             |  113 +-
 .../deserializer/xml/ODataXmlDeserializer.java  |   40 +-
 .../olingo/server/core/etag/ETagHelperImpl.java |    8 +-
 .../server/core/etag/ETagInformation.java       |    4 +-
 .../olingo/server/core/etag/ETagParser.java     |   22 +-
 .../core/etag/PreconditionsValidator.java       |   14 +-
 .../olingo/server/core/prefer/PreferParser.java |   40 +-
 .../server/core/prefer/PreferencesImpl.java     |   13 +-
 .../serializer/AbstractODataSerializer.java     |    7 +-
 .../serializer/AsyncResponseSerializer.java     |   18 +-
 .../serializer/BatchResponseSerializer.java     |   45 +-
 .../serializer/FixedFormatSerializerImpl.java   |    6 +-
 .../core/serializer/SerializerResultImpl.java   |    4 +-
 .../serializer/json/ODataErrorSerializer.java   |    4 +-
 .../serializer/json/ODataJsonSerializer.java    |   94 +-
 .../json/ServiceDocumentJsonSerializer.java     |   12 +-
 .../serializer/utils/CircleStreamBuffer.java    |    4 +-
 .../serializer/utils/ContentTypeHelper.java     |   16 +-
 .../serializer/utils/ContextURLBuilder.java     |   22 +-
 .../core/serializer/utils/ContextURLHelper.java |   17 +-
 .../serializer/utils/ExpandSelectHelper.java    |    4 +-
 .../xml/MetadataDocumentXmlSerializer.java      |   38 +-
 .../core/serializer/xml/ODataXmlSerializer.java |   27 +-
 .../xml/ServiceDocumentXmlSerializer.java       |   12 +-
 .../olingo/server/core/uri/UriHelperImpl.java   |   17 +-
 .../olingo/server/core/uri/UriInfoImpl.java     |    4 +-
 .../server/core/uri/UriParameterImpl.java       |    4 +-
 .../server/core/uri/UriResourceActionImpl.java  |   52 +-
 .../uri/UriResourceComplexPropertyImpl.java     |   22 +-
 .../server/core/uri/UriResourceCountImpl.java   |   14 +-
 .../core/uri/UriResourceEntitySetImpl.java      |   25 +-
 .../core/uri/UriResourceFunctionImpl.java       |   54 +-
 .../olingo/server/core/uri/UriResourceImpl.java |   10 +-
 .../server/core/uri/UriResourceItImpl.java      |   35 +-
 .../core/uri/UriResourceLambdaAllImpl.java      |   35 +-
 .../core/uri/UriResourceLambdaAnyImpl.java      |   34 +-
 .../core/uri/UriResourceLambdaVarImpl.java      |   38 +-
 .../uri/UriResourceNavigationPropertyImpl.java  |   30 +-
 .../uri/UriResourcePrimitivePropertyImpl.java   |   24 +-
 .../server/core/uri/UriResourceRefImpl.java     |   14 +-
 .../server/core/uri/UriResourceRootImpl.java    |   35 +-
 .../core/uri/UriResourceSingletonImpl.java      |   25 +-
 .../uri/UriResourceStartingTypeFilterImpl.java  |   37 +-
 .../server/core/uri/UriResourceTypedImpl.java   |   16 +-
 .../server/core/uri/UriResourceValueImpl.java   |   13 +-
 .../core/uri/UriResourceWithKeysImpl.java       |    7 +-
 .../uri/parser/CheckFullContextListener.java    |   60 -
 .../server/core/uri/parser/ExpandParser.java    |  282 +
 .../core/uri/parser/ExpressionParser.java       | 1245 ++++
 .../server/core/uri/parser/FilterParser.java    |   56 +
 .../server/core/uri/parser/OrderByParser.java   |   61 +
 .../olingo/server/core/uri/parser/Parser.java   |  680 +-
 .../server/core/uri/parser/ParserHelper.java    |  477 ++
 .../olingo/server/core/uri/parser/RawUri.java   |   46 -
 .../core/uri/parser/ResourcePathParser.java     |  397 ++
 .../server/core/uri/parser/SearchParser.java    |  108 +
 .../server/core/uri/parser/SelectParser.java    |  234 +
 .../server/core/uri/parser/UriContext.java      |  113 -
 .../server/core/uri/parser/UriDecoder.java      |  101 +-
 .../core/uri/parser/UriParseTreeVisitor.java    | 2545 --------
 .../core/uri/parser/UriParserException.java     |    4 +-
 .../uri/parser/UriParserSemanticException.java  |   31 +-
 .../uri/parser/UriParserSyntaxException.java    |    6 +-
 .../server/core/uri/parser/UriTokenizer.java    | 1406 ++++
 .../uri/parser/search/SearchBinaryImpl.java     |    7 +-
 .../uri/parser/search/SearchExpressionImpl.java |    4 +-
 .../core/uri/parser/search/SearchParser.java    |   62 +-
 .../parser/search/SearchParserException.java    |    6 +-
 .../uri/parser/search/SearchQueryToken.java     |    9 +-
 .../core/uri/parser/search/SearchTermImpl.java  |    6 +-
 .../core/uri/parser/search/SearchTokenizer.java |  174 +-
 .../parser/search/SearchTokenizerException.java |    6 +-
 .../core/uri/parser/search/SearchUnaryImpl.java |    6 +-
 .../uri/queryoption/AliasQueryOptionImpl.java   |    4 +-
 .../core/uri/queryoption/CountOptionImpl.java   |    4 +-
 .../uri/queryoption/CustomQueryOptionImpl.java  |    4 +-
 .../core/uri/queryoption/ExpandItemImpl.java    |    8 +-
 .../core/uri/queryoption/ExpandOptionImpl.java  |    4 +-
 .../core/uri/queryoption/FilterOptionImpl.java  |    4 +-
 .../core/uri/queryoption/FormatOptionImpl.java  |    4 +-
 .../core/uri/queryoption/IdOptionImpl.java      |    4 +-
 .../core/uri/queryoption/LevelsOptionImpl.java  |    4 +-
 .../core/uri/queryoption/OrderByItemImpl.java   |   12 +-
 .../core/uri/queryoption/OrderByOptionImpl.java |    4 +-
 .../core/uri/queryoption/QueryOptionImpl.java   |    4 +-
 .../core/uri/queryoption/SearchOptionImpl.java  |    6 +-
 .../core/uri/queryoption/SelectItemImpl.java    |    4 +-
 .../core/uri/queryoption/SelectOptionImpl.java  |    4 +-
 .../core/uri/queryoption/SkipOptionImpl.java    |    4 +-
 .../uri/queryoption/SkipTokenOptionImpl.java    |    4 +-
 .../uri/queryoption/SystemQueryOptionImpl.java  |    4 +-
 .../core/uri/queryoption/TopOptionImpl.java     |    4 +-
 .../uri/queryoption/expression/AliasImpl.java   |   20 +-
 .../uri/queryoption/expression/BinaryImpl.java  |   40 +-
 .../queryoption/expression/EnumerationImpl.java |   36 +-
 .../queryoption/expression/ExpressionImpl.java  |   25 -
 .../queryoption/expression/LambdaRefImpl.java   |   21 +-
 .../uri/queryoption/expression/LiteralImpl.java |   29 +-
 .../uri/queryoption/expression/MemberImpl.java  |   31 +-
 .../uri/queryoption/expression/MethodImpl.java  |  110 +-
 .../queryoption/expression/TypeLiteralImpl.java |   21 +-
 .../uri/queryoption/expression/UnaryImpl.java   |   30 +-
 .../uri/validator/UriValidationException.java   |    9 +-
 .../server/core/uri/validator/UriValidator.java |  272 +-
 .../server-core-exceptions-i18n.properties      |   22 +-
 .../server/core/ContentNegotiatorTest.java      |    8 +-
 .../olingo/server/core/ExceptionHelperTest.java |    6 +-
 .../server/core/ODataHttpHandlerImplTest.java   |    6 +-
 .../olingo/server/core/ODataImplTest.java       |    4 +-
 .../core/TranslatedExceptionSubclassesTest.java |    4 +-
 .../batchhandler/MockedBatchHandlerTest.java    |    4 +-
 .../server/core/debug/AbstractDebugTabTest.java |    8 +-
 .../server/core/debug/DebugTabBodyTest.java     |    4 +-
 .../server/core/debug/DebugTabRequestTest.java  |    4 +-
 .../server/core/debug/DebugTabResponseTest.java |    4 +-
 .../server/core/debug/DebugTabServerTest.java   |    6 +-
 .../core/debug/ServerCoreDebuggerTest.java      |    6 +-
 .../FixedFormatDeserializerTest.java            |    4 +-
 .../deserializer/batch/BatchLineReaderTest.java |    4 +-
 .../batch/BatchParserCommonTest.java            |    4 +-
 .../batch/BatchRequestParserTest.java           |   16 +-
 .../core/deserializer/batch/HeaderTest.java     |    4 +-
 .../batch/HttpRequestStatusLineTest.java        |    4 +-
 .../json/ODataJsonDeserializerBasicTest.java    |    4 +-
 .../olingo/server/core/etag/ETagHelperTest.java |    4 +-
 .../olingo/server/core/etag/ETagParserTest.java |    4 +-
 .../server/core/prefer/PreferencesTest.java     |    8 +-
 .../serializer/AsyncResponseSerializerTest.java |   18 +-
 .../serializer/BatchResponseSerializerTest.java |   20 +-
 .../serializer/FixedFormatSerializerTest.java   |    4 +-
 .../json/ServerErrorSerializerTest.java         |    8 +-
 .../utils/CircleStreamBufferTest.java           |    5 +-
 .../serializer/utils/ContextURLBuilderTest.java |    4 +-
 .../xml/MetadataDocumentXmlSerializerTest.java  |  205 +-
 .../xml/ServerErrorXmlSerializerTest.java       |   18 +-
 .../xml/ServiceDocumentXmlSerializerTest.java   |   24 +-
 .../olingo/server/core/uri/UriInfoImplTest.java |  202 +
 .../core/uri/parser/ExpressionParserTest.java   |  271 +
 .../server/core/uri/parser/LexerTest.java       |  318 +
 .../server/core/uri/parser/UriDecoderTest.java  |   95 +
 .../core/uri/parser/UriTokenizerTest.java       |  657 ++
 .../search/SearchParserAndTokenizerTest.java    |  139 +-
 .../uri/parser/search/SearchParserTest.java     |   29 +-
 .../uri/parser/search/SearchTokenizerTest.java  |  121 +-
 .../src/test/resources/simplelogger.properties  |   20 -
 lib/server-tecsvc/pom.xml                       |    2 +-
 .../server/tecsvc/data/DataProviderTest.java    |    4 +-
 lib/server-test/pom.xml                         |   11 +-
 .../server/core/PreconditionsValidatorTest.java |   25 +-
 .../serializer/utils/ContextURLHelperTest.java  |    4 +-
 .../olingo/server/core/uri/UriHelperTest.java   |    4 +-
 .../olingo/server/core/uri/UriInfoImplTest.java |  212 -
 .../server/core/uri/UriResourceImplTest.java    |  172 +-
 .../core/uri/antlr/TestFullResourcePath.java    | 6009 ------------------
 .../olingo/server/core/uri/antlr/TestLexer.java |  303 -
 .../core/uri/antlr/TestUriParserImpl.java       | 1177 ----
 .../server/core/uri/parser/ParserTest.java      |   60 +-
 .../server/core/uri/parser/RawUriTest.java      |  150 -
 .../core/uri/parser/TestFullResourcePath.java   | 5906 +++++++++++++++++
 .../core/uri/parser/TestUriParserImpl.java      | 1047 +++
 .../core/uri/queryoption/QueryOptionTest.java   |   20 +-
 .../queryoption/expression/ExpressionTest.java  |  143 +-
 .../core/uri/testutil/ExpandValidator.java      |   19 +-
 .../core/uri/testutil/FilterValidator.java      |  112 +-
 .../core/uri/testutil/ParserWithLogging.java    |   56 -
 .../core/uri/testutil/ResourceValidator.java    |   14 +-
 .../core/uri/testutil/TestErrorLogger.java      |  105 -
 .../core/uri/testutil/TestUriValidator.java     |   52 +-
 .../core/uri/testutil/TokenValidator.java       |  193 -
 .../core/uri/testutil/UriLexerWithTrace.java    |   85 -
 .../core/uri/validator/UriValidatorTest.java    |   21 +-
 .../src/test/resources/simplelogger.properties  |   20 -
 pom.xml                                         |   16 +-
 samples/client/pom.xml                          |    2 +-
 samples/osgi/server/README.txt                  |   10 +-
 samples/osgi/server/pom.xml                     |    2 +-
 samples/pom.xml                                 |    2 +-
 samples/server/pom.xml                          |    2 +-
 samples/tutorials/p0_all/pom.xml                |    4 +-
 samples/tutorials/p10_media/pom.xml             |    4 +-
 samples/tutorials/p11_batch/pom.xml             |    4 +-
 samples/tutorials/p12_deep_insert/pom.xml       |    4 +-
 .../p12_deep_insert_preparation/pom.xml         |    4 +-
 samples/tutorials/p1_read/pom.xml               |    4 +-
 samples/tutorials/p2_readep/pom.xml             |    4 +-
 samples/tutorials/p3_write/pom.xml              |    4 +-
 samples/tutorials/p4_navigation/pom.xml         |    4 +-
 samples/tutorials/p5_queryoptions-tcs/pom.xml   |    4 +-
 samples/tutorials/p6_queryoptions-es/pom.xml    |    4 +-
 samples/tutorials/p7_queryoptions-o/pom.xml     |    4 +-
 samples/tutorials/p8_queryoptions-f/pom.xml     |    4 +-
 samples/tutorials/p9_action/pom.xml             |    4 +-
 samples/tutorials/p9_action_preparation/pom.xml |    4 +-
 samples/tutorials/pom.xml                       |    2 +-
 579 files changed, 16609 insertions(+), 16456 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
----------------------------------------------------------------------
diff --cc lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
index e2aee4e,743d437..d3ec8e8
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/data/EntityCollection.java
@@@ -26,14 -25,11 +26,11 @@@ import java.util.List
  /**
   * Data representation for a collection of single entities.
   */
 -public class EntityCollection extends AbstractODataObject {
 +public class EntityCollection extends AbstractODataObject implements Iterable<Entity> {
  
-   private Integer count;
- 
    private final List<Entity> entities = new ArrayList<Entity>();
- 
+   private Integer count;
    private URI next;
- 
    private URI deltaLink;
  
    /**
@@@ -100,7 -96,24 +97,29 @@@
    }
  
    @Override
 +  public Iterator<Entity> iterator() {
 +    return this.entities.iterator();
 +  }
++
++  @Override
+   public boolean equals(final Object o) {
+     if (!super.equals(o)) {
+       return false;
+     }
+     final EntityCollection other = (EntityCollection) o;
+     return entities.equals(other.entities)
+         && (count == null ? other.count == null : count.equals(other.count))
+         && (next == null ? other.next == null : next.equals(other.next))
+         && (deltaLink == null ? other.deltaLink == null : deltaLink.equals(other.deltaLink));
+   }
+ 
+   @Override
+   public int hashCode() {
+     int result = super.hashCode();
+     result = 31 * result + entities.hashCode();
+     result = 31 * result + (count == null ? 0 : count.hashCode());
+     result = 31 * result + (next == null ? 0 : next.hashCode());
+     result = 31 * result + (deltaLink == null ? 0 : deltaLink.hashCode());
+     return result;
+   }
  }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataResponse.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/SerializerResult.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/SerializerResultImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --cc lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index ce0258c,a912862..7f84319
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@@ -767,13 -767,13 +767,13 @@@ public class ODataJsonSerializer extend
  
    }
  
-   void writeContextURL(final ContextURL contextURL, JsonGenerator json) throws IOException {
 -  private void writeContextURL(final ContextURL contextURL, final JsonGenerator json) throws IOException {
++  void writeContextURL(final ContextURL contextURL, final JsonGenerator json) throws IOException {
      if (!isODataMetadataNone && contextURL != null) {
        json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
      }
    }
  
-   void writeMetadataETag(final ServiceMetadata metadata, JsonGenerator json) throws IOException {
 -  private void writeMetadataETag(final ServiceMetadata metadata, final JsonGenerator json) throws IOException {
++  void writeMetadataETag(final ServiceMetadata metadata, final JsonGenerator json) throws IOException {
      if (!isODataMetadataNone
          && metadata != null
          && metadata.getServiceMetadataETagSupport() != null
@@@ -783,7 -783,7 +783,7 @@@
      }
    }
  
-   void writeCount(final EntityCollection entityCollection, JsonGenerator json) throws IOException {
 -  private void writeCount(final EntityCollection entityCollection, final JsonGenerator json) throws IOException {
++  void writeCount(final EntityCollection entityCollection, final JsonGenerator json) throws IOException {
      if (entityCollection.getCount() != null) {
        if (isIEEE754Compatible) {
          json.writeStringField(Constants.JSON_COUNT, entityCollection.getCount().toString());
@@@ -793,7 -793,7 +793,7 @@@
      }
    }
  
-   void writeNextLink(final EntityCollection entitySet, JsonGenerator json) throws IOException {
 -  private void writeNextLink(final EntityCollection entitySet, final JsonGenerator json) throws IOException {
++  void writeNextLink(final EntityCollection entitySet, final JsonGenerator json) throws IOException {
      if (entitySet.getNext() != null) {
        json.writeStringField(Constants.JSON_NEXT_LINK, entitySet.getNext().toASCIIString());
      }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/CircleStreamBuffer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c02215e2/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
----------------------------------------------------------------------


[20/21] olingo-odata4 git commit: [OLINGO-832] Merge branch 'OLINGO-832_StreamSerializerPoC'

Posted by mi...@apache.org.
[OLINGO-832] Merge branch 'OLINGO-832_StreamSerializerPoC'


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

Branch: refs/heads/master
Commit: 47bc730a8947e63bea9a5aea384b9d471a581352
Parents: c86009a 09fd6d9
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Feb 22 08:03:01 2016 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Feb 22 08:03:01 2016 +0100

----------------------------------------------------------------------
 .../fit/tecsvc/http/BasicStreamITCase.java      |  66 +++++++
 .../core/serialization/AtomSerializer.java      |   2 +-
 .../api/data/AbstractEntityCollection.java      |  30 +++
 .../commons/api/data/EntityCollection.java      |  11 +-
 .../olingo/commons/api/data/EntityIterator.java |  58 ++++++
 .../api/ex/ODataNotSupportedException.java      |  56 ++++++
 .../apache/olingo/server/api/ODataContent.java  |  28 +++
 .../apache/olingo/server/api/ODataResponse.java |  13 +-
 .../server/api/WriteContentErrorCallback.java   |  30 +++
 .../server/api/WriteContentErrorContext.java    |  27 +++
 .../EntityCollectionSerializerOptions.java      |  27 ++-
 .../server/api/serializer/ODataSerializer.java  |  20 +-
 .../api/serializer/SerializerStreamResult.java  |  33 ++++
 .../server/core/ODataHttpHandlerImpl.java       |  27 ++-
 .../server/core/ODataWritableContent.java       | 188 +++++++++++++++++++
 .../core/serializer/SerializerResultImpl.java   |  24 ++-
 .../serializer/SerializerStreamResultImpl.java  |  48 +++++
 .../serializer/json/ODataJsonSerializer.java    |  75 ++++++--
 .../serializer/utils/CircleStreamBuffer.java    |  19 ++
 .../core/serializer/utils/ResultHelper.java     |  65 +++++++
 .../core/serializer/xml/ODataXmlSerializer.java |  86 ++++++++-
 .../uri/parser/search/SearchTokenizerTest.java  |  14 +-
 .../processor/TechnicalEntityProcessor.java     |  87 ++++++++-
 .../json/ODataJsonSerializerTest.java           |  98 +++++++++-
 24 files changed, 1073 insertions(+), 59 deletions(-)
----------------------------------------------------------------------