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/10 06:39:08 UTC

[1/2] olingo-odata4 git commit: [OLINGO-832] Added new SerializerStreamResult

Repository: olingo-odata4
Updated Branches:
  refs/heads/OLINGO-832_StreamSerializerPoC 31dea712e -> 5174f7089


[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/OLINGO-832_StreamSerializerPoC
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,


[2/2] 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/OLINGO-832_StreamSerializerPoC
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());