[richfaces-svn-commits] JBoss Rich Faces SVN: r13619 - in trunk/framework/impl/src/main/java/org/ajax4jsf: webapp and 1 other directory.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Thu Apr 16 20:42:05 EDT 2009
Author: nbelaevski
Date: 2009-04-16 20:42:05 -0400 (Thu, 16 Apr 2009)
New Revision: 13619
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
Log:
https://jira.jboss.org/jira/browse/RF-6809
https://jira.jboss.org/jira/browse/RF-6495
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java 2009-04-16 18:21:12 UTC (rev 13618)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java 2009-04-17 00:42:05 UTC (rev 13619)
@@ -77,6 +77,9 @@
private int read = 0;
+ //we shouldn't allow to stop until request reaches PhaseListener because of portlets
+ private boolean canStop = false;
+
private Map<String, Param> parameters = null;
private Map<String, Object> percentMap = null;
@@ -308,6 +311,7 @@
}
private boolean shouldStop = false;
+ private boolean canceled;
public MultipartRequest(HttpServletRequest request,
boolean createTempFiles, int maxRequestSize, String uid) {
@@ -356,6 +360,8 @@
}
public void cancel() {
+ this.canceled = true;
+
if (parameters != null) {
Iterator<Param> it = parameters.values().iterator();
while (it.hasNext()) {
@@ -380,46 +386,41 @@
private int zeroReadAttempts = 20; // 20 attempts to read not-readable data
private void fillBuffer() throws IOException {
- if (!shouldStop) {
- if (pos < read) {
- // move the bytes that weren't read to the start of
- // the
- // buffer
- int bytesNotRead = read - pos;
+ if (pos < read) {
+ // move the bytes that weren't read to the start of
+ // the
+ // buffer
+ int bytesNotRead = read - pos;
+
+ if (bytesNotRead != buffer.length) {
+ System.arraycopy(buffer, pos, buffer, 0,
+ bytesNotRead);
+ read = input.read(buffer, bytesNotRead,
+ buffer.length - bytesNotRead);
- if (bytesNotRead != buffer.length) {
- System.arraycopy(buffer, pos, buffer, 0,
- bytesNotRead);
- read = input.read(buffer, bytesNotRead,
- buffer.length - bytesNotRead);
-
- if (read != 0 || --zeroReadAttempts != 0) {
- if (read > 0) {
- bytesRead += read;
- }
+ if (read != 0 || --zeroReadAttempts != 0) {
+ if (read > 0) {
+ bytesRead += read;
+ }
- read += bytesNotRead;
- } else {
- //read is already zero
- //read = 0;
- }
+ read += bytesNotRead;
} else {
- read = bytesNotRead;
+ //read is already zero
+ //read = 0;
}
} else {
- read = input.read(buffer);
+ read = bytesNotRead;
+ }
+ } else {
+ read = input.read(buffer);
- if (read > 0) {
- bytesRead += read;
- }
+ if (read > 0) {
+ bytesRead += read;
}
-
- fillProgressInfo();
- pos = 0;
- } else {
- cancel();
- read = -1;
}
+
+ fillProgressInfo();
+ pos = 0;
}
private void readNext() throws IOException {
@@ -607,15 +608,21 @@
}
public void parseRequest() {
+ canStop = true;
+
try {
initialize();
- while (read >= 0) {
+ while (read > 0) {
readNext();
}
} catch (IOException e) {
- throw new FileUploadException("IO Error parsing multipart request", e);
+ this.cancel();
+
+ if (!this.shouldStop) {
+ throw new FileUploadException("IO Error parsing multipart request", e);
+ }
}
}
@@ -790,15 +797,18 @@
}
if (param == null) {
- try {
- initialize();
+ if (!canceled) {
+ try {
+ initialize();
- while (param == null && read > 0) {
- readNext();
- param = parameters.get(name);
+ while (param == null && read > 0) {
+ readNext();
+ param = parameters.get(name);
+ }
+ } catch (IOException e) {
+ this.cancel();
+ throw new FileUploadException("IO Error parsing multipart request", e);
}
- } catch (IOException e) {
- throw new FileUploadException("IO Error parsing multipart request", e);
}
}
@@ -934,13 +944,20 @@
}
public void stop() {
- shouldStop = true;
+ if (canStop) {
+ shouldStop = true;
+ }
}
public boolean isStopped() {
- return shouldStop;
+ return this.shouldStop;
}
+ public boolean isDone() {
+ return !(this.shouldStop && (this.canceled ||
+ this.contentLength != null && this.contentLength.intValue() != this.bytesRead));
+ }
+
@Override
public String getContentType() {
return "application/x-www-form-urlencoded";
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2009-04-16 18:21:12 UTC (rev 13618)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseFilter.java 2009-04-17 00:42:05 UTC (rev 13619)
@@ -349,7 +349,7 @@
}
}, chain);
- if (multipartRequest.isStopped()) {
+ if (!multipartRequest.isDone()) {
printResponse(response, "<html id=\"_richfaces_file_upload_stopped\"></html>");
}
}
More information about the richfaces-svn-commits
mailing list