Search code examples
xmlhttprequestservlet-filtersseammultipartform-data

Understanding seam filter url-pattern and possible conflicts


I made a custom editor plugin, in a Seam 2.2.2 project, which makes file upload this way:

1) config the editor to load my specific xhtml upload page;

2) call the following method inside this page, and return a javascript callback;

public String sendImageToServer()
    {
        HttpServletRequest request = ServletContexts.instance().getRequest();
        try
        {
            List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
            processItems(items);//set the file data to specific att
            saveOpenAttachment();//save the file to disk
        }
        //build callback

For this to work I have to put this inside components.xml:

<web:multipart-filter create-temp-files="false"  
                  max-request-size="1024000" url-pattern="*"/> 

The attribute create-temp-files do not seems to matter whatever its value. But url-pattern has to be "" or "/myUploadPage.seam", any other value makes the item list returns empty. Does Anyone know why?

This turns into a problem because when I use a url-pattern that work to this case, every form with enctype="multipart/form-data" in my application stops to submit data. So I end up with other parts of the system crashing. Could someone help me?


Solution

  • To solve my problem, I changed the solution to be like Seam multipart filter handle requests:

    ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        try
        {
          if (!(request instanceof MultipartRequest))
          {
             request = unwrapMultipartRequest(request);
          }
    
          if (request instanceof MultipartRequest)
          {
             MultipartRequest multipartRequest = (MultipartRequest) request;
    
             String clientId = "upload";
             setFileData(multipartRequest.getFileBytes(clientId));
             setFileContentType(multipartRequest.getFileContentType(clientId));
             setFileName(multipartRequest.getFileName(clientId));
             saveOpenAttachment();
          }
        }
    

    Now I handle the request like Seam do, and do not need the web:multipart-filter config that was breaking other types of request.