Alon Bar-Lev has uploaded a new change for review. Change subject: authentication: do not leak resources ......................................................................
authentication: do not leak resources Change-Id: Ic03a08f1ef136ca7a7b3af6f1102ee3e393e6b7a Signed-off-by: Alon Bar-Lev <[email protected]> --- M ovirt-engine-reports/EngineAuthentication/src/main/java/org/ovirt/authentication/EngineSimplePreAuthFilter.java 1 file changed, 15 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/96/23596/1 diff --git a/ovirt-engine-reports/EngineAuthentication/src/main/java/org/ovirt/authentication/EngineSimplePreAuthFilter.java b/ovirt-engine-reports/EngineAuthentication/src/main/java/org/ovirt/authentication/EngineSimplePreAuthFilter.java index e14ccd8..e69c5e7 100755 --- a/ovirt-engine-reports/EngineAuthentication/src/main/java/org/ovirt/authentication/EngineSimplePreAuthFilter.java +++ b/ovirt-engine-reports/EngineAuthentication/src/main/java/org/ovirt/authentication/EngineSimplePreAuthFilter.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; @@ -230,8 +231,6 @@ * This method gets a sessionID, and validates it with the engine, using the servlet input URL */ protected String callGetSessionUser(String sessionID) { - DataOutputStream output = null; - try { // Formatting data String data = String.format(SESSION_DATA_FORMAT, URLEncoder.encode(sessionID, "UTF-8")); @@ -244,10 +243,13 @@ } // Sending the sessionID parameter - output = new DataOutputStream(servletConnection.getOutputStream()); - output.writeBytes(data); - output.flush(); - output.close(); + try ( + OutputStream os = servletConnection.getOutputStream(); + DataOutputStream output = new DataOutputStream(os) + ) { + output.writeBytes(data); + output.flush(); + } // Checking the result if (servletConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { @@ -256,21 +258,15 @@ } // Getting the user name - InputStream inputStream = servletConnection.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - String inputLine; - inputLine = reader.readLine(); - return inputLine; - + try ( + InputStream in = servletConnection.getInputStream(); + InputStreamReader isreader = new InputStreamReader(in); + BufferedReader reader = new BufferedReader(isreader) + ) { + return reader.readLine(); + } } catch (Exception ex) { logger.error(ex); - } finally { - try { - if (output != null) - output.close(); - } catch (IOException ex) { - logger.error(ex); - } } return null; } -- To view, visit http://gerrit.ovirt.org/23596 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic03a08f1ef136ca7a7b3af6f1102ee3e393e6b7a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-reports Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
