Try to use proper character encoding in multipart/form-data (file upload) requests.
This commit is contained in:
parent
fb3196cfd5
commit
6eb8cf9442
2 changed files with 21 additions and 23 deletions
|
@ -120,13 +120,22 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
protected void execute(HttpServletRequest request, HttpServletResponse response,
|
protected void execute(HttpServletRequest request, HttpServletResponse response,
|
||||||
byte method) {
|
byte method) {
|
||||||
RequestTrans reqtrans = new RequestTrans(method);
|
RequestTrans reqtrans = new RequestTrans(method);
|
||||||
// get app and path from original request path
|
|
||||||
// String pathInfo = request.getPathInfo ();
|
|
||||||
// String appID = getAppID (pathInfo);
|
|
||||||
// reqtrans.path = getRequestPath (pathInfo);
|
|
||||||
try {
|
try {
|
||||||
|
// get the character encoding
|
||||||
|
String encoding = request.getCharacterEncoding();
|
||||||
|
|
||||||
|
if (encoding == null) {
|
||||||
|
// no encoding from request, use standard one
|
||||||
|
encoding = defaultEncoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encoding == null) {
|
||||||
|
encoding = "ISO-8859-1";
|
||||||
|
}
|
||||||
|
|
||||||
// read and set http parameters
|
// read and set http parameters
|
||||||
Map parameters = parseParameters(request);
|
Map parameters = parseParameters(request, encoding);
|
||||||
|
|
||||||
for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
|
for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
|
||||||
Map.Entry entry = (Map.Entry) i.next();
|
Map.Entry entry = (Map.Entry) i.next();
|
||||||
|
@ -149,7 +158,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
(contentType.indexOf("multipart/form-data") == 0)) {
|
(contentType.indexOf("multipart/form-data") == 0)) {
|
||||||
// File Upload
|
// File Upload
|
||||||
try {
|
try {
|
||||||
FileUpload upload = getUpload(request);
|
FileUpload upload = getUpload(request, encoding);
|
||||||
|
|
||||||
if (upload != null) {
|
if (upload != null) {
|
||||||
Hashtable parts = upload.getParts();
|
Hashtable parts = upload.getParts();
|
||||||
|
@ -410,7 +419,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
res.setHeader("Location", location);
|
res.setHeader("Location", location);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUpload getUpload(HttpServletRequest request) throws Exception {
|
FileUpload getUpload(HttpServletRequest request, String encoding) throws Exception {
|
||||||
int contentLength = request.getContentLength();
|
int contentLength = request.getContentLength();
|
||||||
BufferedInputStream in = new BufferedInputStream(request.getInputStream());
|
BufferedInputStream in = new BufferedInputStream(request.getInputStream());
|
||||||
|
|
||||||
|
@ -421,7 +430,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
String contentType = request.getContentType();
|
String contentType = request.getContentType();
|
||||||
FileUpload upload = new FileUpload(uploadLimit);
|
FileUpload upload = new FileUpload(uploadLimit);
|
||||||
|
|
||||||
upload.load(in, contentType, contentLength);
|
upload.load(in, contentType, contentLength, encoding);
|
||||||
|
|
||||||
return upload;
|
return upload;
|
||||||
}
|
}
|
||||||
|
@ -500,18 +509,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
map.put(name, newValues);
|
map.put(name, newValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map parseParameters(HttpServletRequest request) {
|
protected Map parseParameters(HttpServletRequest request, String encoding) {
|
||||||
String encoding = request.getCharacterEncoding();
|
|
||||||
|
|
||||||
if (encoding == null) {
|
|
||||||
// no encoding from request, use standard one
|
|
||||||
encoding = defaultEncoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoding == null) {
|
|
||||||
encoding = "ISO-8859-1";
|
|
||||||
}
|
|
||||||
|
|
||||||
HashMap parameters = new HashMap();
|
HashMap parameters = new HashMap();
|
||||||
|
|
||||||
// Parse any query string parameters from the request
|
// Parse any query string parameters from the request
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class FileUpload {
|
||||||
* @throws MimeParserException ...
|
* @throws MimeParserException ...
|
||||||
* @throws IOException ...
|
* @throws IOException ...
|
||||||
*/
|
*/
|
||||||
public void load(InputStream is, String contentType, int contentLength)
|
public void load(InputStream is, String contentType, int contentLength, String encoding)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
parts = new Hashtable();
|
parts = new Hashtable();
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public class FileUpload {
|
||||||
|
|
||||||
parts.put(name, part);
|
parts.put(name, part);
|
||||||
} else {
|
} else {
|
||||||
parts.put(name, new String(newb));
|
parts.put(name, new String(newb, encoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue