Skip to content
Snippets Groups Projects
Commit 77257d61 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[UWS] Minor fix: close a never-closed Scanner instance.

parent 68026217
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,8 @@ package uws.service.request; ...@@ -16,7 +16,8 @@ package uws.service.request;
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>.
* *
* Copyright 2014-2015 - Astronomisches Rechen Institut (ARI) * Copyright 2014-2018 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI)
*/ */
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
...@@ -35,23 +36,26 @@ import javax.servlet.http.HttpServletRequest; ...@@ -35,23 +36,26 @@ import javax.servlet.http.HttpServletRequest;
import uws.UWSException; import uws.UWSException;
/** /**
* <p>Extract parameters encoded using the HTTP-GET method or the Content-type application/x-www-form-urlencoded * Extract parameters encoded using the HTTP-GET method or the Content-type
* with the HTTP-POST or HTTP-PUT method in an {@link HttpServletRequest}.</p> * application/x-www-form-urlencoded with the HTTP-POST or HTTP-PUT method in
* an {@link HttpServletRequest}.
* *
* <p> * <p>
* By default, this {@link RequestParser} overwrite parameter occurrences in the map: that's to say if a parameter is provided several times, * By default, this {@link RequestParser} overwrite parameter occurrences in
* only the last value will be kept. This behavior can be changed by overwriting the function {@link #consumeParameter(String, Object, Map)} * the map: that's to say if a parameter is provided several times, only the
* of this class. * last value will be kept. This behavior can be changed by overwriting the
* function {@link #consumeParameter(String, Object, Map)} of this class.
* </p> * </p>
* *
* <p><i>Note: * <p><i>Note:
* When HTTP-POST is used, these parameters are actually already extracted by the server application (like Apache/Tomcat) * When HTTP-POST is used, these parameters are actually already extracted by
* and are available with {@link HttpServletRequest#getParameterMap()}. * the server application (like Apache/Tomcat) and are available with
* However, when using HTTP-PUT, the parameters are extracted manually from the request content. * {@link HttpServletRequest#getParameterMap()}. However, when using HTTP-PUT,
* the parameters are extracted manually from the request content.
* </i></p> * </i></p>
* *
* @author Gr&eacute;gory Mantelet (ARI) * @author Gr&eacute;gory Mantelet (ARI;CDS)
* @version 4.2 (07/2015) * @version 4.3 (08/2018)
* @since 4.1 * @since 4.1
*/ */
public class FormEncodedParser implements RequestParser { public class FormEncodedParser implements RequestParser {
...@@ -88,6 +92,7 @@ public class FormEncodedParser implements RequestParser { ...@@ -88,6 +92,7 @@ public class FormEncodedParser implements RequestParser {
* This block is doing this extraction manually. */ * This block is doing this extraction manually. */
else{ else{
InputStream input = null; InputStream input = null;
Scanner scanner = null;
try{ try{
// Get the character encoding: // Get the character encoding:
...@@ -102,7 +107,7 @@ public class FormEncodedParser implements RequestParser { ...@@ -102,7 +107,7 @@ public class FormEncodedParser implements RequestParser {
// Get a stream on the request content: // Get a stream on the request content:
input = new BufferedInputStream(request.getInputStream()); input = new BufferedInputStream(request.getInputStream());
// Read the stream by iterating on each parameter pairs: // Read the stream by iterating on each parameter pairs:
Scanner scanner = new Scanner(input); scanner = new Scanner(input);
scanner.useDelimiter("&"); scanner.useDelimiter("&");
String pair; String pair;
int indSep; int indSep;
...@@ -124,11 +129,15 @@ public class FormEncodedParser implements RequestParser { ...@@ -124,11 +129,15 @@ public class FormEncodedParser implements RequestParser {
} }
} }
}catch(IOException ioe){}finally{ }catch(IOException ioe){
}finally{
if (scanner != null)
scanner.close();
if (input != null){ if (input != null){
try{ try{
input.close(); input.close();
}catch(IOException ioe2){} }catch(IOException ioe2){
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment