Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vollt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sonia Zorba
vollt
Commits
77257d61
Commit
77257d61
authored
6 years ago
by
Grégory Mantelet
Browse files
Options
Downloads
Patches
Plain Diff
[UWS] Minor fix: close a never-closed Scanner instance.
parent
68026217
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/uws/service/request/FormEncodedParser.java
+37
-28
37 additions, 28 deletions
src/uws/service/request/FormEncodedParser.java
with
37 additions
and
28 deletions
src/uws/service/request/FormEncodedParser.java
+
37
−
28
View file @
77257d61
...
@@ -2,21 +2,22 @@ package uws.service.request;
...
@@ -2,21 +2,22 @@ package uws.service.request;
/*
/*
* This file is part of UWSLibrary.
* This file is part of UWSLibrary.
*
*
* UWSLibrary is free software: you can redistribute it and/or modify
* UWSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* UWSLibrary is distributed in the hope that it will be useful,
* UWSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* GNU Lesser General Public License for more details.
*
*
* 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égory Mantelet (ARI)
* @author Grégory Mantelet (ARI
;CDS
)
* @version 4.
2
(0
7
/201
5
)
* @version 4.
3
(0
8
/201
8
)
* @since 4.1
* @since 4.1
*/
*/
public
class
FormEncodedParser
implements
RequestParser
{
public
class
FormEncodedParser
implements
RequestParser
{
...
@@ -60,11 +64,11 @@ public class FormEncodedParser implements RequestParser {
...
@@ -60,11 +64,11 @@ public class FormEncodedParser implements RequestParser {
public
final
static
String
EXPECTED_CONTENT_TYPE
=
"application/x-www-form-urlencoded"
;
public
final
static
String
EXPECTED_CONTENT_TYPE
=
"application/x-www-form-urlencoded"
;
@Override
@Override
public
final
Map
<
String
,
Object
>
parse
(
HttpServletRequest
request
)
throws
UWSException
{
public
final
Map
<
String
,
Object
>
parse
(
HttpServletRequest
request
)
throws
UWSException
{
if
(
request
==
null
)
if
(
request
==
null
)
return
new
HashMap
<
String
,
Object
>();
return
new
HashMap
<
String
,
Object
>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<
String
,
Object
>();
// Normal extraction for HTTP-POST and other HTTP methods:
// Normal extraction for HTTP-POST and other HTTP methods:
if
(
request
.
getMethod
()
==
null
||
!
request
.
getMethod
().
equalsIgnoreCase
(
"put"
)){
if
(
request
.
getMethod
()
==
null
||
!
request
.
getMethod
().
equalsIgnoreCase
(
"put"
)){
...
@@ -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
){
}
}
}
}
}
}
}
...
@@ -138,23 +147,23 @@ public class FormEncodedParser implements RequestParser {
...
@@ -138,23 +147,23 @@ public class FormEncodedParser implements RequestParser {
/**
/**
* <p>Consume the specified parameter: add it inside the given map.</p>
* <p>Consume the specified parameter: add it inside the given map.</p>
*
*
* <p>
* <p>
* By default, this function is just putting the given value inside the map. So, if the parameter already exists in the map,
* By default, this function is just putting the given value inside the map. So, if the parameter already exists in the map,
* its old value will be overwritten by the given one.
* its old value will be overwritten by the given one.
* </p>
* </p>
*
*
* @param name Name of the parameter to consume.
* @param name Name of the parameter to consume.
* @param value Its value.
* @param value Its value.
* @param allParams The list of all parameters read until now.
* @param allParams The list of all parameters read until now.
*/
*/
protected
void
consumeParameter
(
final
String
name
,
final
Object
value
,
final
Map
<
String
,
Object
>
allParams
){
protected
void
consumeParameter
(
final
String
name
,
final
Object
value
,
final
Map
<
String
,
Object
>
allParams
){
allParams
.
put
(
name
,
value
);
allParams
.
put
(
name
,
value
);
}
}
/**
/**
* <p>Utility method that determines whether the content of the given request is a application/x-www-form-urlencoded.</p>
* <p>Utility method that determines whether the content of the given request is a application/x-www-form-urlencoded.</p>
*
*
* <p><i>Important:
* <p><i>Important:
* This function just test the content-type of the request. The HTTP method (e.g. GET, POST, ...) is not tested.
* This function just test the content-type of the request. The HTTP method (e.g. GET, POST, ...) is not tested.
* </i></p>
* </i></p>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment