Class ZipLet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
de.businesscode.bcdui.web.servlets.ZipLet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class ZipLet extends jakarta.servlet.http.HttpServlet
Servlet for compression and uncompression of XML data. To compress an XML document you need to POST it to this servlet and to uncompress the data you must use GET with the parameter data=xxx (where xxx stands for the compressed data). The servlet offers two compression modes: XML string optimization for small XML documents and GZIP compression. It also supports two encodings: Alphabet translation (when the input has an alphabet of at most 64 characters) and 6 bit 64-character encoding (similar to base 64). All encodings are chosen so that the result does not need to be escaped for being used as an HTML GET parameter.
It is possible to determine the encoding/compression combination from the compressed document by testing the first character of the encoded data
  • "z" uses XML string optimization with alphabet translation.
  • "x" uses XML string optimization with 6 bit encoding.
  • Otherwise GZIP compression with 6 bit encoding is used.
Extension to support tiny urls e.g. in case browser limit is exceeded compressionPackage.js can rerun the compression with url param 'tiny' (=limit) to return a 't' style string which is followed by the size and encoded sha1 value. The sha1 value is used as key element in a table specified via tinyUrlBindingName. The table needs the following fields: tiny_url varchar (33) (size = 32 + digits count of allowed hash collisions) , long_url (clob) , creation_dt (date) , last_used_dt (date) Extension done by rs
See Also:
  • Field Summary

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    compress(String uncompressedString)
    Compresses (and encodes) the string parameter.
    static String
    A convenience method for compressing a DOM document and returning an encoded string representation.
    static Document
    decodeAndDecompressToXML(String compressedString)
    Deprecated. 
    static Document
    decodeAndDecompressToXML(String compressedString, jakarta.servlet.http.HttpServletRequest request)
    Decodes and decompresses the specified string to an XML document.
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Decompresses the XML document given in the "data" parameter and returns it in the response object.
    protected void
    doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Compresses the data which has been posted to this servlet.
    static Connection
     
    static String
     
    static String
    getUnpackedGuiStatus(jakarta.servlet.http.HttpServletRequest request)
     
    void
    init(jakarta.servlet.ServletConfig config)
     
    static boolean
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPatch, doPut, doTrace, getLastModified, isSensitiveHeader, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ZipLet

      public ZipLet()
  • Method Details

    • init

      public void init(jakarta.servlet.ServletConfig config) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Servlet
      Overrides:
      init in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
    • doPost

      protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Compresses the data which has been posted to this servlet. It will write an XML document to the response with a single root element named "data" containing a text node with the compressed and encoded data (as provided by the compress method).
      Overrides:
      doPost in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
      See Also:
      • compress(InputStream)
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Decompresses the XML document given in the "data" parameter and returns it in the response object.
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Parameters:
      request - The request holding the "data" parameter to be decoded.
      response - The response containing the (stringified) decompressed XML document.
      Throws:
      jakarta.servlet.ServletException
      IOException
    • getUnpackedGuiStatus

      public static String getUnpackedGuiStatus(jakarta.servlet.http.HttpServletRequest request)
      Parameters:
      request -
      Returns:
      returns unpacked XML String or NULL if guiStatusGZ parameter was null or empty
    • compressAndEncode

      public static String compressAndEncode(Document doc) throws Exception
      A convenience method for compressing a DOM document and returning an encoded string representation.
      Parameters:
      doc - The DOM document to be compressed.
      Returns:
      An encoded String representation of the DOM document.
      Throws:
      Exception
    • compress

      public static String compress(String uncompressedString) throws Exception
      Compresses (and encodes) the string parameter. This is a string-argument wrapper for the compress method taking an InputStream.
      Parameters:
      uncompressedString - The string to be compressed.
      Returns:
      A 64-character encoding of the compressed string.
      Throws:
      Exception - If the compression fails.
      See Also:
      • compress(InputStream)
    • decodeAndDecompressToXML

      public static Document decodeAndDecompressToXML(String compressedString, jakarta.servlet.http.HttpServletRequest request) throws Exception
      Decodes and decompresses the specified string to an XML document.
      Parameters:
      compressedString - The stringified encoding of the compressed XML document.
      Returns:
      The original XML document the compressed string has been generated from.
      Throws:
      Exception - If the decompression or the XML parsing fails.
    • decodeAndDecompressToXML

      @Deprecated public static Document decodeAndDecompressToXML(String compressedString) throws Exception
      Deprecated.
      Decodes and decompresses the specified string to an XML document.
      Parameters:
      compressedString - The stringified encoding of the compressed XML document.
      Returns:
      The original XML document the compressed string has been generated from.
      Throws:
      Exception - If the decompression or the XML parsing fails.
    • testTinyUrlBinding

      public static boolean testTinyUrlBinding()
    • getControlConnection

      public static Connection getControlConnection() throws Exception
      Throws:
      Exception
    • getTransformSQL

      public static String getTransformSQL(String sql)