2 Replies Latest reply on Aug 19, 2015 12:11 PM by Michal Petrov

    RichFaces 4.5.x FileUpload not Working with Weblogic 10.3.6 - Servlet 2.5

    Neal Brenner Newbie

      System setup:

      • RichFaces 4.5.6 (also tried all 4.5.x versions)
      • MyFaces 2.1.17
      • Spring 4.1.7
      • Hibernate 4.2.19
      • Weblogic 10.3.6 (Servlet 2.5)


      File upload was working fine with Tomcat 7 (Servlet 3.0), but when we went to our production environment of Weblogic 10.3.6, fileUpload was not working. Specifically, we were getting this AJAX response after clicking "Upload":








      Interestingly, this error was not showing up in our server log, it seems the exception and stack trace is swallowed somewhere. However, we were able to isolate the problem to the FileUploadRenderBase class. It looks like there are a few places in this file where HttpServletRequest.getServletContext() is called on our system which I believe is a 3.0 servlet method and not available in our 2.5 servlet: ServletRequest (Java EE 6 )

      The first place in the code where we were getting the exception was here:


                          long maxRequestSize = fileUpload.getMaxFileSize() != 0 ? fileUpload.getMaxFileSize() : getMaxRequestSize(httpRequest.getServletContext());


      So, a workaround was to set the maxFileSize in all the fileUpload components and that gets us a little further, but we then get this AJAX exception:








      Which is similarly the initializeUploadedFiles method:

                  if (request.getParts().size() > 0) {


      I think getParts() is another 3.0 servlet method. HttpServletRequest (Java EE 6 )


      In the end, we are including the below file for our 2.5 servlet deployment. This allows FileUpload to work in our Weblogic 10.3.6 setup. This takes away 3.0 support and also doesn't load some of the properties which we don't use in our application anyway. Please let me know if there is something we are doing wrong or if there is a different workaround available.


      public class FileUploadRendererBase extends RendererBase {

          private Iterable<UploadedFile> initializeUploadedFiles(ExternalContext context, HttpServletRequest request, String uploadId) {

              try {

                  List<UploadedFile> files = new LinkedList<UploadedFile>();

                  //boolean createTempFiles = isCreateTempFiles(request.getServletContext());

                  boolean createTempFiles = true;

                  //String tempFilesDirectory = getTempFilesDirectory(request.getServletContext());

                  String tempFilesDirectory = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();

                  MultipartRequestParser requestParser = new MultipartRequestParser(request, createTempFiles, tempFilesDirectory);

                  MultipartRequest multipartRequest = new MultipartRequest25(request, uploadId, requestParser);

                  files = (List<UploadedFile>) multipartRequest.getUploadedFiles();

                  return files;

              } catch (Exception e) {


                  throw new FileUploadException("couldn't parse request parts", e);




          protected void doDecode(FacesContext context, UIComponent component) {

              final AbstractFileUpload fileUpload = (AbstractFileUpload) component;

              final ExternalContext externalContext = context.getExternalContext();

              Object request = externalContext.getRequest();

              if (request instanceof HttpServletRequest) {

                  HttpServletRequest httpRequest = (HttpServletRequest) request;

                  if (httpRequest.getContentType() != null && httpRequest.getContentType().startsWith("multipart/")) {

                      String uid = MultipartRequestParser.getParameterValueFromQueryString(httpRequest.getQueryString());

                      if (uid != null) {

                          long contentLength = Long.parseLong(httpRequest.getHeader("Content-Length"));

                          //long maxRequestSize = fileUpload.getMaxFileSize() != 0 ? fileUpload.getMaxFileSize() : getMaxRequestSize(httpRequest.getServletContext());

                          long maxRequestSize = fileUpload.getMaxFileSize() != 0 ? fileUpload.getMaxFileSize() : 0;

                          if (maxRequestSize != 0 && contentLength > maxRequestSize) {




                          Iterable<UploadedFile> uploadedFiles = initializeUploadedFiles(externalContext, httpRequest, uid);

                          for (UploadedFile file : uploadedFiles) {

                              if (fileUpload.acceptsFile(file)) {

                                  fileUpload.queueEvent(new FileUploadEvent(fileUpload, file));