Author: konstantin.mishin
Date: 2007-11-28 13:47:58 -0500 (Wed, 28 Nov 2007)
New Revision: 4325
Added:
trunk/sandbox/samples/fileUploadPOC/src/main/java/org/richfaces/SleepFilter.java
Modified:
trunk/sandbox/samples/fileUploadPOC/pom.xml
trunk/sandbox/samples/fileUploadPOC/src/main/webapp/WEB-INF/web.xml
trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/frame.xhtml
trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/index.xhtml
Log:
RF-1209
Modified: trunk/sandbox/samples/fileUploadPOC/pom.xml
===================================================================
--- trunk/sandbox/samples/fileUploadPOC/pom.xml 2007-11-28 18:07:29 UTC (rev 4324)
+++ trunk/sandbox/samples/fileUploadPOC/pom.xml 2007-11-28 18:47:58 UTC (rev 4325)
@@ -9,8 +9,30 @@
<artifactId>fileUploadPOC</artifactId>
<packaging>war</packaging>
<name>fileUploadPOC Maven Webapp</name>
- <version>1.0-SNAPSHOT</version>
+ <version>3.2.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3</version>
+ </dependency>
+ </dependencies>
<build>
<finalName>fileUploadPOC</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
</build>
</project>
\ No newline at end of file
Added: trunk/sandbox/samples/fileUploadPOC/src/main/java/org/richfaces/SleepFilter.java
===================================================================
--- trunk/sandbox/samples/fileUploadPOC/src/main/java/org/richfaces/SleepFilter.java
(rev 0)
+++
trunk/sandbox/samples/fileUploadPOC/src/main/java/org/richfaces/SleepFilter.java 2007-11-28
18:47:58 UTC (rev 4325)
@@ -0,0 +1,89 @@
+package org.richfaces;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.ProgressListener;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+
+public class SleepFilter implements Filter {
+
+ public void destroy() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse response,
+ FilterChain chain) throws IOException, ServletException {
+ HttpServletRequest request = (HttpServletRequest)servletRequest;
+ if (ServletFileUpload.isMultipartContent(request)) {
+ FileItemFactory factory = new DiskFileItemFactory();
+
+ // Create a new file upload handler
+ ServletFileUpload upload = new ServletFileUpload(factory);
+
+ //Create a progress listener
+ ProgressListener progressListener = new ProgressListener(){
+ public void update(long pBytesRead, long pContentLength, int pItems) {
+ System.out.println("We are currently reading item " + pItems);
+ if (pContentLength == -1) {
+ System.out.println("So far, " + pBytesRead + " bytes have
been read.");
+ } else {
+ System.out.println("So far, " + pBytesRead + " of " +
pContentLength
+ + " bytes have been read.");
+ }
+ try {
+ Thread.sleep((long)3E3);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ };
+ upload.setProgressListener(progressListener); // Parse the request
+ try {
+ List list= upload.parseRequest(request);
+ // Process the uploaded items
+ Iterator iter = list.iterator();
+ while (iter.hasNext()) {
+ FileItem item = (FileItem) iter.next();
+
+ if (item.isFormField()) {
+ // processFormField(item);
+ } else {
+ String fieldName = item.getFieldName();
+ String fileName = item.getName();
+ String contentType = item.getContentType();
+ boolean isInMemory = item.isInMemory();
+ long sizeInBytes = item.getSize();
+ System.out.println(fieldName+" "+fileName+"
"+contentType+" "+isInMemory+" "+sizeInBytes);
+ }
+ }
+ } catch (FileUploadException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ chain.doFilter(servletRequest, response);
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: trunk/sandbox/samples/fileUploadPOC/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/sandbox/samples/fileUploadPOC/src/main/webapp/WEB-INF/web.xml 2007-11-28
18:07:29 UTC (rev 4324)
+++ trunk/sandbox/samples/fileUploadPOC/src/main/webapp/WEB-INF/web.xml 2007-11-28
18:47:58 UTC (rev 4325)
@@ -14,6 +14,10 @@
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
+ <context-param>
+ <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
+ <param-value>com.sun.facelets.FaceletViewHandler</param-value>
+ </context-param>
<!--
-->
<filter>
@@ -21,7 +25,20 @@
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
+ <filter>
+ <display-name>Sleep Filter</display-name>
+ <filter-name>sleepFilter</filter-name>
+ <filter-class>org.richfaces.SleepFilter</filter-class>
+ </filter>
<filter-mapping>
+ <filter-name>sleepFilter</filter-name>
+ <servlet-name>Faces Servlet</servlet-name>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>FORWARD</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ <dispatcher>ERROR</dispatcher>
+ </filter-mapping>
+ <filter-mapping>
<filter-name>ajax4jsf</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
Modified: trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/frame.xhtml
===================================================================
--- trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/frame.xhtml 2007-11-28
18:07:29 UTC (rev 4324)
+++ trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/frame.xhtml 2007-11-28
18:47:58 UTC (rev 4325)
@@ -7,10 +7,6 @@
xmlns:c="http://java.sun.com/jsp/jstl/core"
<body>
- <form action="frame.jsf">
- <input type="file"/>
- <input type="file"/>
- <input type="submit"/>
- </form>
+ xXx
</body>
</html>
\ No newline at end of file
Modified: trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/index.xhtml
===================================================================
--- trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/index.xhtml 2007-11-28
18:07:29 UTC (rev 4324)
+++ trunk/sandbox/samples/fileUploadPOC/src/main/webapp/pages/index.xhtml 2007-11-28
18:47:58 UTC (rev 4325)
@@ -7,6 +7,12 @@
xmlns:c="http://java.sun.com/jsp/jstl/core"
<body>
- <iframe src="pages/frame.jsf"/>
- </body>
+ <iframe id="frame" name="frame"/>
+ <form target="frame" action="pages/frame.jsf"
enctype="multipart/form-data" method="post">
+ <input type="file" name="input1"/>
+ <input type="file" name="input2"/>
+ <input type="submit"/>
+ </form>
+ <input type="button"
onclick="debugger;document.getElementById('frame').contentWindow.location.href='';"/>
+ </body>
</html>
\ No newline at end of file