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 7c0d617f2..aec88586f 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 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(); } /** 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 9953ceeb2..5e1a92158 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; 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 8c18f8f03..57fc4712b 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 selected = all ? null : + final Set selected = all ? new HashSet() : 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 expanded = expandAll ? null : + final Set expanded = expandAll ? new HashSet() : ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems()); for (final String propertyName : type.getNavigationPropertyNames()) { if (expandAll || expanded.contains(propertyName)) { 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 547c45f36..b40d4efa4 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 properties, final SelectOption select, final XMLStreamWriter writer) throws XMLStreamException, SerializerException { final boolean all = ExpandSelectHelper.isAll(select); - final Set selected = all ? null : + final Set selected = all ? new HashSet() : 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 expanded = expandAll ? null : + final Set expanded = expandAll ? new HashSet() : ExpandSelectHelper.getExpandedPropertyNames(expand.getExpandItems()); for (final String propertyName : type.getNavigationPropertyNames()) { final EdmNavigationProperty property = type.getNavigationProperty(propertyName);