olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject olingo-odata4 git commit: [OLINGO-832] Removed 'write' from ODataResponse
Date Mon, 08 Feb 2016 10:30:22 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/OLINGO-832_StreamSerializerPoC a6e0fb1a5 -> 18a78981f


[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/OLINGO-832_StreamSerializerPoC
Commit: 18a78981fb590628f40bc1c36ade38dd0f135235
Parents: a6e0fb1
Author: mibo <mibo@apache.org>
Authored: Mon Feb 8 11:30:11 2016 +0100
Committer: mibo <mibo@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());


Mime
View raw message