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;
* You should have received a copy of the GNU Lesser General Public License
* 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;
......@@ -35,23 +36,26 @@ import javax.servlet.http.HttpServletRequest;
import uws.UWSException;
/**
* <p>Extract parameters encoded using the HTTP-GET method or the Content-type application/x-www-form-urlencoded
* with the HTTP-POST or HTTP-PUT method in an {@link HttpServletRequest}.</p>
* Extract parameters encoded using the HTTP-GET method or the Content-type
* application/x-www-form-urlencoded with the HTTP-POST or HTTP-PUT method in
* an {@link HttpServletRequest}.
*
* <p>
* By default, this {@link RequestParser} overwrite parameter occurrences in the map: that's to say if a parameter is provided several times,
* only the last value will be kept. This behavior can be changed by overwriting the function {@link #consumeParameter(String, Object, Map)}
* of this class.
* By default, this {@link RequestParser} overwrite parameter occurrences in
* the map: that's to say if a parameter is provided several times, only the
* last value will be kept. This behavior can be changed by overwriting the
* function {@link #consumeParameter(String, Object, Map)} of this class.
* </p>
*
* <p><i>Note:
* When HTTP-POST is used, these parameters are actually already extracted by the server application (like Apache/Tomcat)
* and are available with {@link HttpServletRequest#getParameterMap()}.
* However, when using HTTP-PUT, the parameters are extracted manually from the request content.
* When HTTP-POST is used, these parameters are actually already extracted by
* the server application (like Apache/Tomcat) and are available with
* {@link HttpServletRequest#getParameterMap()}. However, when using HTTP-PUT,
* the parameters are extracted manually from the request content.
* </i></p>
*
* @author Gr&eacute;gory Mantelet (ARI)
* @version 4.2 (07/2015)
* @author Gr&eacute;gory Mantelet (ARI;CDS)
* @version 4.3 (08/2018)
* @since 4.1
*/
public class FormEncodedParser implements RequestParser {
......@@ -88,6 +92,7 @@ public class FormEncodedParser implements RequestParser {
* This block is doing this extraction manually. */
else{
InputStream input = null;
Scanner scanner = null;
try{
// Get the character encoding:
......@@ -102,7 +107,7 @@ public class FormEncodedParser implements RequestParser {
// Get a stream on the request content:
input = new BufferedInputStream(request.getInputStream());
// Read the stream by iterating on each parameter pairs:
Scanner scanner = new Scanner(input);
scanner = new Scanner(input);
scanner.useDelimiter("&");
String pair;
int indSep;
......@@ -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){
try{
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