From d84f843f227d5a7f3f1240fb445efe5928751b63 Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Thu, 23 Oct 2014 14:38:17 +0200 Subject: [PATCH] [OLINGO-468] Minor code clean up --- .../olingo/commons/core/edm/AbstractEdm.java | 1 - .../server/core/ODataHttpHandlerImpl.java | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java index e9aea826d..bc0b304e9 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java @@ -106,7 +106,6 @@ public abstract class AbstractEdm implements Edm { aliasToNamespaceInfo = new HashMap(); for (EdmSchema schema : schemas.values()) { final String namespace = schema.getNamespace(); - schemas.put(namespace, schema); if (schema.getAlias() != null) { aliasToNamespaceInfo.put(schema.getAlias(), namespace); 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 b06c3c8dd..36cbd183f 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 @@ -18,6 +18,7 @@ */ package org.apache.olingo.server.core; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -59,7 +60,7 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { @Override public void process(final HttpServletRequest request, final HttpServletResponse response) { ODataRequest odRequest = null; - ODataResponse odResponse = null; + ODataResponse odResponse; try { odRequest = createODataRequest(request, split); odResponse = handler.process(odRequest); @@ -99,11 +100,11 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { InputStream input = odResponse.getContent(); if (input != null) { - OutputStream output; + OutputStream output = null; try { output = response.getOutputStream(); byte[] buffer = new byte[1024]; - int n = 0; + int n; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } @@ -111,13 +112,18 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { LOG.error(e.getMessage(), e); throw new ODataRuntimeException(e); } finally { - if (input != null) { - try { - input.close(); - } catch (IOException e) { - throw new ODataRuntimeException(e); - } - } + closeStream(output); + closeStream(input); + } + } + } + + private static void closeStream(Closeable closeable) { + if(closeable != null) { + try { + closeable.close(); + } catch (IOException e) { + LOG.error(e.getMessage(), e); } } } @@ -150,9 +156,9 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler { if (xHttpMethod == null && xHttpMethodOverride == null) { odRequest.setMethod(httpRequestMethod); - } else if (xHttpMethod == null && xHttpMethodOverride != null) { + } else if (xHttpMethod == null) { odRequest.setMethod(HttpMethod.valueOf(xHttpMethodOverride)); - } else if (xHttpMethod != null && xHttpMethodOverride == null) { + } else if (xHttpMethodOverride == null) { odRequest.setMethod(HttpMethod.valueOf(xHttpMethod)); } else { if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {