refs bug 362924 - updated listener implementation and test cases for new apache version.
diff --git a/bundles/org.eclipse.rap.rwt.supplemental.fileupload/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadProcessor.java b/bundles/org.eclipse.rap.rwt.supplemental.fileupload/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadProcessor.java
index 90890cd..0d86828 100644
--- a/bundles/org.eclipse.rap.rwt.supplemental.fileupload/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadProcessor.java
+++ b/bundles/org.eclipse.rap.rwt.supplemental.fileupload/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadProcessor.java
@@ -106,18 +106,24 @@
private ProgressListener createProgressListener( final long maxFileSize ) {
ProgressListener result = new ProgressListener() {
-
- public void update( long bytesRead, long contentLength, int item ) {
- // Note: Apache fileupload 1.2 will throw an exception after the upload is finished.
- // So we handle the file size violation as best we can from here.
- // https://issues.apache.org/jira/browse/FILEUPLOAD-145
- if( maxFileSize != -1 && contentLength > maxFileSize ) {
- tracker.setException( new Exception( "File exceeds maximum allowed size." ) );
- tracker.handleFailed();
- } else {
- tracker.setContentLength( contentLength );
- tracker.setBytesRead( bytesRead );
- tracker.handleProgress();
+ long prevTotalBytesRead = -1;
+ public void update( long totalBytesRead, long contentLength, int item ) {
+ // Depending on the servlet engine and other environmental factors,
+ // this listener may be notified for every network packet, so don't notify unless there
+ // is an actual increase.
+ if ( totalBytesRead > prevTotalBytesRead ) {
+ prevTotalBytesRead = totalBytesRead;
+ // Note: Apache fileupload 1.2.x will throw an exception after the upload is finished.
+ // So we handle the file size violation as best we can from here.
+ // https://issues.apache.org/jira/browse/FILEUPLOAD-145
+ if( maxFileSize != -1 && contentLength > maxFileSize ) {
+ tracker.setException( new Exception( "File exceeds maximum allowed size." ) );
+ tracker.handleFailed();
+ } else {
+ tracker.setContentLength( contentLength );
+ tracker.setBytesRead( totalBytesRead );
+ tracker.handleProgress();
+ }
}
}
};
diff --git a/tests/org.eclipse.rap.rwt.supplemental.fileupload.test/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadServiceHandler_Test.java b/tests/org.eclipse.rap.rwt.supplemental.fileupload.test/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadServiceHandler_Test.java
index 6c8e647..756b14c 100644
--- a/tests/org.eclipse.rap.rwt.supplemental.fileupload.test/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadServiceHandler_Test.java
+++ b/tests/org.eclipse.rap.rwt.supplemental.fileupload.test/src/org/eclipse/rap/rwt/supplemental/fileupload/internal/FileUploadServiceHandler_Test.java
@@ -73,7 +73,7 @@
serviceHandler.service();
assertEquals( 0, getResponseErrorStatus() );
- String expected = "progress(4096/12134).progress(8175/12134).progress(12134/12134).finished.";
+ String expected = "progress(4096/12134).progress(8174/12134).progress(12134/12134).finished.";
assertEquals( expected, testListener.getLog() );
FileUploadEvent uploadedItem = testListener.getLastEvent();
assertEquals( content, new String( testReceiver.getContent() ) );