Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5393

Update ZK jars to jakarta-friendly uploads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • 10.0.0
    • 10.0.0, 9.6.3, 10.0.0-Beta
    • None
    • Security Level: Jimmy

       

      General information

      ZK uses common-fileupload to handle multiplart upload.

      Jakarta doesn't seem to have an equivalent fileupload option (since it's legacy javax servlet code)

      Instead of relying on commons-fileupload, ZK should provide pure servlet upload classes, using multipartConfig on upload servlets:

      https://docs.oracle.com/javaee/7/tutorial/servlets011.htm

       

      Debug Information

      Thanks to Felipe Reyes for providing the detailed sample and POC implementation attached.

      zk library

      pom.xml (from "zk.jar"): removed old dependencies (it should be removed also from parent pom.xml):
      <dependency>
      <groupId>org.zkoss.zk</groupId>
      <artifactId>zkwebfragment</artifactId>
      <version>${project.version}</version>
      </dependency>
      <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      </dependency>

      Added three interfaces to zk.jar: "org.apache.commons.fileupload.FileItem", "org.apache.commons.fileupload.FileItemHeaders" and "org.apache.commons.fileupload.FileItemHeadersSupport", taken from original commons-file-upload source project. ZK contains some definitions based on this interfaces, and I think it's a good idea to mantain them. Specifically interface "org.zkoss.zk.ui.sys.DiskFileItemFactory" which uses them to convert "FileItem" into ZK "Media"... if somebody has developed a new DiskFileItemFactory, it's going to continue working.

      "org.zkoss.zk.au.http.ZKFileItem": New class, extends "FileItem" and it's created based on a Jakarta Part. It's used to avoid changing all the code, and simplifying the changes I've made.

      "org.zkoss.zk.au.http.UploaderRequestInfo": It was created to simplify the code of AuDropUploader and AuUploader classes, because this class replaces the old and ugly Map created on this classes with a nice and easier to understand (and mantain) class. It uses the same original logic taken from "AuDropUploader.parseRequest" function, but it uses properties rather than a generic map to save the information needed on the function, to process items. Of course, it only processes parts called "file", because later in the same function, only use the parts called "file". The logic is the same; however, I tried to code them easily to understand.

      Removed "org.zkoss.zk.au.http.ServletRequestContext". This class doesn't have any sense here, because it was a helper class used with Commons File Uploader.

      "org.zkoss.zk.au.http.DHtmlUpdateServlet": Modified two error messages, and added two annotations on the first part of the class, just to enable Jakarta "Multipart" processing. For this reason, the jar "zkwebfragment" it's not needed anymore on Jakarta version.

      "org.zkoss.zk.au.http.AuDropUploader": Edited a lot, but I think I've mantained the same original logic.

      "org.zkoss.zk.au.http.AuUploader": Edited a lot, but I think I've mantained the same original logic.
       

      Changes included in CK ZKEditor:

      NOTE: It depends on the ZK Jakarta modified version (without commons-fileupload!)

      1) ckez\pom.xml:

      • Added "-jakarta" to the end of the version (as ZK base package does!)
      • Changed zk.version for any ZK Version with jakarta
        <properties>
        <zk.version>9.6.0.2-jakarta</zk.version>
        </properties>
      • Removed "javax.servlet" and "commons-fileupload" dependency
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.4</version>
        <optional>true</optional>
        </dependency>
        <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.4</version>
        </dependency>
      • Added "jakarta" dependency (provided)
        <dependency>
        <groupId>jakarta.servlet</groupId>
        <artifactId>jakarta.servlet-api</artifactId>
        <version>6.0.0</version>
        <scope>provided</scope>
        </dependency>
      • Changed "source" to 1.8 (at least!) because Jakarta starts on 1.8 version

      2) "org.zkforge.ckez.CKeditor": Correctly modified to use Jakarta Servlets, instead of java servlets

      3) "org.zkforge.ckez.CkezFileWriter": Correctly modified Jakarta objects, instead of java servlets

      4) "org.zkforge.ckez.CkezUploadExtension": Correctly modified Jakarta objects, instead of java servlets

       

      Workaround

       attached sample files

        1. ckEditor.zip
          6 kB
        2. ZKFileItem.java
          5 kB
        3. zk-jakarta-changes.zip
          25 kB

            rebeccalai rebeccalai
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: