You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/08/17 13:40:29 UTC
olingo-odata4 git commit: [OLINGO-659] FIx all stream handling issues
Repository: olingo-odata4
Updated Branches:
refs/heads/master 262cee8b7 -> 75b552308
[OLINGO-659] FIx all stream handling issues
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/75b55230
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/75b55230
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/75b55230
Branch: refs/heads/master
Commit: 75b552308045f90182056cf128f308e131d6fe45
Parents: 262cee8
Author: Christian Amend <ch...@sap.com>
Authored: Mon Aug 17 13:29:48 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Mon Aug 17 13:30:27 2015 +0200
----------------------------------------------------------------------
.../core/debug/DebugResponseHelperImpl.java | 16 +++++++++-------
.../olingo/server/core/debug/DebugTabUri.java | 20 ++++++++++++--------
.../serializer/json/ODataJsonSerializer.java | 7 ++++---
.../core/serializer/xml/ODataXmlSerializer.java | 5 +++--
4 files changed, 28 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/75b55230/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
index 7c0d617..aec8858 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
@@ -21,6 +21,7 @@ package org.apache.olingo.server.core.debug;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
@@ -133,11 +134,13 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
}
private InputStream wrapInJson(final List<DebugTab> parts) throws IOException {
- CircleStreamBuffer csb = new CircleStreamBuffer();
IOException cachedException = null;
+ OutputStream outputStream = null;
try {
- JsonGenerator gen = new JsonFactory().createGenerator(csb.getOutputStream(), JsonEncoding.UTF8);
+ CircleStreamBuffer csb = new CircleStreamBuffer();
+ outputStream = csb.getOutputStream();
+ JsonGenerator gen = new JsonFactory().createGenerator(outputStream, JsonEncoding.UTF8);
gen.writeStartObject();
DebugTab requestInfo = parts.get(0);
@@ -159,14 +162,15 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
gen.writeEndObject();
gen.close();
- csb.getOutputStream().close();
+ outputStream.close();
+ return csb.getInputStream();
} catch (IOException e) {
throw e;
} finally {
- if (csb != null && csb.getOutputStream() != null) {
+ if (outputStream != null) {
try {
- csb.getOutputStream().close();
+ outputStream.close();
} catch (IOException e) {
if (cachedException != null) {
throw cachedException;
@@ -176,8 +180,6 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
}
}
}
-
- return csb.getInputStream();
}
/**
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/75b55230/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabUri.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabUri.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabUri.java
index 9953cee..5e1a921 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabUri.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabUri.java
@@ -19,6 +19,8 @@
package org.apache.olingo.server.core.debug;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.io.Writer;
import java.util.List;
@@ -256,19 +258,20 @@ public class DebugTabUri implements DebugTab {
private String getJsonString() throws IOException {
CircleStreamBuffer csb = new CircleStreamBuffer();
IOException cachedException = null;
+ OutputStream outputStream = csb.getOutputStream();
try {
JsonGenerator json =
- new JsonFactory().createGenerator(csb.getOutputStream(), JsonEncoding.UTF8)
+ new JsonFactory().createGenerator(outputStream, JsonEncoding.UTF8)
.setPrettyPrinter(new DefaultPrettyPrinter());
appendJson(json);
json.close();
- csb.getOutputStream().close();
+ outputStream.close();
} catch (IOException e) {
throw e;
} finally {
- if (csb != null && csb.getOutputStream() != null) {
+ if (outputStream != null) {
try {
- csb.getOutputStream().close();
+ outputStream.close();
} catch (IOException e) {
if (cachedException != null) {
throw cachedException;
@@ -279,16 +282,17 @@ public class DebugTabUri implements DebugTab {
}
}
+ InputStream inputStream = csb.getInputStream();
try {
- String jsonString = IOUtils.toString(csb.getInputStream());
- csb.getInputStream().close();
+ String jsonString = IOUtils.toString(inputStream);
+ inputStream.close();
return jsonString;
} catch (IOException e) {
throw e;
} finally {
- if (csb != null && csb.getInputStream() != null) {
+ if (inputStream != null) {
try {
- csb.getInputStream().close();
+ inputStream.close();
} catch (IOException e) {
if (cachedException != null) {
throw cachedException;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/75b55230/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 8c18f8f..57fc471 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
@@ -21,6 +21,7 @@ package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -83,7 +84,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
throws SerializerException {
OutputStream outputStream = null;
- SerializerException cachedException = null;
+ SerializerException cachedException = null;
try {
CircleStreamBuffer buffer = new CircleStreamBuffer();
@@ -319,7 +320,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final SelectOption select, final JsonGenerator json)
throws IOException, SerializerException {
final boolean all = ExpandSelectHelper.isAll(select);
- final Set<String> selected = all ? null :
+ final Set<String> selected = all ? new HashSet<String>() :
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
for (final String propertyName : type.getPropertyNames()) {
if (all || selected.contains(propertyName)) {
@@ -337,7 +338,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
final JsonGenerator json) throws SerializerException, IOException {
if (ExpandSelectHelper.hasExpand(expand)) {
final boolean expandAll = ExpandSelectHelper.isExpandAll(expand);
- final Set<String> expanded = expandAll ? null :
+ final Set<String> expanded = expandAll ? new HashSet<String>() :
ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems());
for (final String propertyName : type.getNavigationPropertyNames()) {
if (expandAll || expanded.contains(propertyName)) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/75b55230/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 547c45f..b40d4ef 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
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -495,7 +496,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final List<Property> properties, final SelectOption select, final XMLStreamWriter writer)
throws XMLStreamException, SerializerException {
final boolean all = ExpandSelectHelper.isAll(select);
- final Set<String> selected = all ? null :
+ final Set<String> selected = all ? new HashSet<String>() :
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
for (final String propertyName : type.getPropertyNames()) {
if (all || selected.contains(propertyName)) {
@@ -513,7 +514,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final XMLStreamWriter writer) throws SerializerException, XMLStreamException {
if (ExpandSelectHelper.hasExpand(expand)) {
final boolean expandAll = ExpandSelectHelper.isExpandAll(expand);
- final Set<String> expanded = expandAll ? null :
+ final Set<String> expanded = expandAll ? new HashSet<String>() :
ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems());
for (final String propertyName : type.getNavigationPropertyNames()) {
final EdmNavigationProperty property = type.getNavigationProperty(propertyName);