[OLINGO-659] FIx all stream handling issues
This commit is contained in:
parent
262cee8b7e
commit
75b5523080
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue