12 Replies Latest reply on Apr 25, 2008 12:06 PM by Bogdan Minciu

    rich:fileUpload ends conversation in Seam

    Uros Majeric Newbie

      Does aynone have a same problem?

      I have a page wich conversation begins in pages.xml (<begin-conversation join="true">) and when I select multiple files to upload and press the Upload button then fileUpload uploads 1st file ad then throws Conversation timeout.

      I have Seam 2.0 and richfaces 3.2.0

      Thanks, Uros

        • 1. Re: rich:fileUpload ends conversation in Seam
          I B Newbie

          could you post your configs and code sample please...
          How did you configured the web.xml and component.xml

          • 2. Re: rich:fileUpload ends conversation in Seam
            Uros Majeric Newbie

            This is my xhtml code:

             <rich:fileUpload fileUploadListener="#{galleryAction.uploadListener}"
             maxFilesQuantity="10" reRender="table" id="upload" style="width:100%;"
             immediateUpload="false" acceptedTypes="jpg, gif"
             addControlLabel="#{messages.add}" cancelEntryControlLabel="#{messages.remove}"
             clearAllControlLabel="#{messages.clear}" clearControlLabel="#{messages.clear}"
             stopControlLabel="#{messages.stop}" stopEntryControlLabel="#{messages.stop}"
             uploadControlLabel="#{messages.upload}" >
             <a4j:support event="onuploadcomplete" reRender="galleryForm" />
             </rich:fileUpload>
            


            pages.xml
             <page view-id="/gallery.xhtml" login-required="true" no-conversation-view-id="/galleries.xhtml">
             <!-- <action if="#{empty(gallery)}" execute="#{galleryAction.getGallery}" /> -->
             <begin-conversation join="true" />
             <param name="gid" value="#{galleryAction.galleryId}" />
             <navigation>
             <rule if="#{empty(gallery)}">
             <redirect view-id="/galleries.xhtml"/>
             </rule>
             </navigation>
             </page>
            


            web.xml
            <?xml version="1.0" ?>
            <web-app xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             version="2.5">
            
             <!-- Ajax4jsf -->
            
             <context-param>
             <param-name>org.richfaces.SKIN</param-name>
             <param-value>blueSky</param-value>
             </context-param>
            
             <!-- Seam -->
            
             <listener>
             <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
             </listener>
            
             <filter>
             <filter-name>Seam Filter</filter-name>
             <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
             </filter>
            
             <filter-mapping>
             <filter-name>Seam Filter</filter-name>
             <url-pattern>/*</url-pattern>
             </filter-mapping>
            
             <filter>
             <filter-name>UrlRewriteFilter</filter-name>
             <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
             <init-param>
             <param-name>logLevel</param-name>
             <param-value>ERROR</param-value>
             </init-param>
             </filter>
            
             <filter-mapping>
             <filter-name>UrlRewriteFilter</filter-name>
             <url-pattern>/*</url-pattern>
             </filter-mapping>
            
             <servlet>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Seam Resource Servlet</servlet-name>
             <url-pattern>/seam/resource/*</url-pattern>
             </servlet-mapping>
            
             <!-- Facelets development mode (disable in production) -->
            
             <context-param>
             <param-name>facelets.DEVELOPMENT</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <!-- JSF -->
            
             <context-param>
             <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
             <param-value>.xhtml</param-value>
             </context-param>
            
             <servlet>
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
             <load-on-startup>1</load-on-startup>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>Faces Servlet</servlet-name>
             <url-pattern>*.seam</url-pattern>
             </servlet-mapping>
            
             <context-param>
             <param-name>facelets.SKIP_COMMENTS</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <security-constraint>
             <display-name>Restrict raw XHTML Documents</display-name>
             <web-resource-collection>
             <web-resource-name>XHTML</web-resource-name>
             <url-pattern>*.xhtml</url-pattern>
             </web-resource-collection>
             <auth-constraint/>
             </security-constraint>
            
            
            
            </web-app>
            


            component.xml
             <core:manager concurrent-request-timeout="1500"
             conversation-timeout="300000"
             conversation-id-parameter="cid"/>
            
             <!-- 2097152 = 2MB -->
             <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true"/>
            
             <security:identity
             authenticate-method="#{authenticator.authenticate}"
             security-rules="#{securityRules}" />
            
             <persistence:managed-persistence-context auto-create="true"
             name="entityManager"
             persistence-unit-jndi-name="java:/dajvaseEntityManagerFactory" />
            


            and java code (if needed)
             public void uploadPicture() {
             try {
             log.info("gallery: "+editGallery+", this.fileName: "+this.fileName);
             String path = "Galleries/"+currentUser.getNickName()+"/"+editGallery.getTitle()+"/";
             String thumbName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_thumb";
             String mediumName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_medium";
             String largeName = new SimpleDateFormat("yyMMddHHmmss").format(new Date())+"_large";
            
             Image image = new Image().setInput(data);
            
             String contentType = image.getContentType().getMimeType();
             log.info("contentType: "+contentType);
             if (contentType.equals("image/gif")){
             thumbName += ".gif";
             mediumName += ".gif";
             largeName += ".gif";
             } else if (contentType.equals("image/jpeg")) {
             thumbName += ".jpg";
             mediumName += ".jpg";
             largeName += ".jpg";
             } else {
             facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "image_wrong_type");
             return;
             }
            
             log.info("contentType: "+contentType);
            // saveImageToDisk(image, path, largeName, 1280);
            
             saveImageToDisk(image, path, thumbName, 150);
             saveImageToDisk(image, path, mediumName, 640);
            
             editGallery = entityManager.merge(editGallery);
             Picture picture = new Picture(this.fileName);
             picture.setThumb("/"+path+thumbName);
             picture.setMedium("/"+path+mediumName);
             picture.setLarge("/"+path+largeName);
             picture.setGallery(editGallery);
             this.saveTagsToPicture(picture);
             editGallery.getPictures().add(picture);
            
             log.info("uploadPicture finished....");
             } catch (IOException e) {
             log.error(e.getMessage());
             } catch (Exception e) {
             log.error(e.getMessage());
             facesMessages.addFromResourceBundle(FacesMessage.SEVERITY_ERROR, "image_uploading_error");
             }
             }
            
             private boolean saveImageToDisk(Image image, String path, String fileName, int width) throws IOException {
             path = ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
             .getRealPath("/")+path;
             log.info("data (saveImageToDisk): "+data);
             image.scaleToWidth(width);
             ByteBuffer bbuf = ByteBuffer.wrap(image.getImage());
             log.info("Path: "+path+fileName);
            
             if (!(new File(path)).exists()){
             if (!(new File(path)).mkdirs()) {
             log.info("Directories: " + path + " created");
             return false;
             }
             }
             FileUtils.writeByteArrayToFile(new File(path+fileName), image.getImage());
             return true;
             }
            
             public void uploadListener(UploadEvent event) throws IOException {
             UploadItem item = event.getUploadItem();
            
             if (item.isFile()) {
             fileName = FilenameUtils.getName(item.getFileName());
             this.data = FileUtils.readFileToByteArray( item.getFile() );
             }
             log.info("data: "+data);
             this.uploadPicture();
             log.info("after uploadPicture");
             getGalleryPictures();
             facesMessages.addFromResourceBundle("image_uploaded");
             }
            


            Thanks,

            • 4. Re: rich:fileUpload ends conversation in Seam
              Sergey Smirnov Master

              if you use rich:fileUpload, the seam multipart filter must be turned off.

              • 5. Re: rich:fileUpload ends conversation in Seam
                Uros Majeric Newbie

                I have added:

                 <filter-name>Seam Multipart Filter</filter-name>
                 <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
                 </filter>
                
                 <filter-mapping>
                 <filter-name>Seam Multipart Filter</filter-name>
                 <url-pattern>*.seam</url-pattern>
                 </filter-mapping>
                

                in my web.xml file, but still doesn't work. It still ends my conversation!

                Uros

                • 6. Re: rich:fileUpload ends conversation in Seam
                  Uros Majeric Newbie

                  Sorry my bed.
                  I have overlooked that multipart filter has to be turned of. So I removed:

                   <filter-name>Seam Multipart Filter</filter-name>
                   <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
                   </filter>
                  
                   <filter-mapping>
                   <filter-name>Seam Multipart Filter</filter-name>
                   <url-pattern>*.seam</url-pattern>
                   </filter-mapping>
                  


                  and changed:
                   <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true" />
                  


                  to:
                   <web:multipart-filter url-pattern="*.seam" max-request-size="2097152" create-temp-files="true" disabled="true" />
                  


                  but still doesn't work.
                  Do I have to do something else?

                  Uros

                  • 7. Re: rich:fileUpload ends conversation in Seam
                    Andrei Markavtsov Apprentice

                    Hi,

                    I cannot understand the workflow of your application from this part of code.

                    Can you please add issue in JIRA and attach your WAR file there?

                    Thanks.

                    • 8. Re: rich:fileUpload ends conversation in Seam
                      Uros Majeric Newbie

                      Hi,

                      Unfortunately I can't attach my WAR file because it's big project which was made in in our company, and they wouldn't be happy if I would make it public :)

                      workflow is pretty simple. User click on a <h:commandButton /> wich opens the gallery.xhtml page. Conversation is began with this page and gallery is outjected to CONVERSATION context. but when I press the upload button application uploads me a few of files (sometimes one, othertime 3 or 4) and throws NoConversation.

                      Uros

                      • 9. Re: rich:fileUpload ends conversation in Seam
                        Andrei Markavtsov Apprentice

                        Anyway I cannot reproduce your problem. I created two pages. One of these contains File Upload component. This page should start conversation.

                        Another page contains commandButton which moves user to the page with file upload component.

                        I could not find any problem in this test.

                        It will be greate if you can create the simplest example where problem is reprodusible and attach it to JIRA.

                        Thanks a lot.

                        • 10. Re: rich:fileUpload ends conversation in Seam
                          nathan dennis Expert

                          I would seem that i am also experiencing this problem. It looks like the problem happens with multiple files are selected. in my case.. the first two files will land in the same object and the third in a new object. all uploads are persisted successfully,, just as if they are unrelated.. but the array containing the previews is broken by this behavior.

                          looking at the conversations independently reveals all data.

                          is it possible that the component sees one conversation is busy,, then automatically creates a second thread as a new conversation?

                          • 11. Re: rich:fileUpload ends conversation in Seam
                            Andrei Markavtsov Apprentice

                            File upload component has no any influence on conversations processing which controled by Seam framework.

                            Resolution should be find in researching with Seam, but not with file upload component.

                            • 12. Re: rich:fileUpload ends conversation in Seam
                              Bogdan Minciu Newbie

                              I solved this problem by modifying the concurrent-request-timeout value from:

                              <core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid"/>


                              to

                              <core:manager concurrent-request-timeout="5000" conversation-timeout="180000" conversation-id-parameter="cid"/>
                              

                              Thanks to Zahid: http://www.seamframework.org/Community/RichfileUploadListenerIsJumpingOutOfTheConversation