Compressing Files

Gzip File

If you deploy your Nexaweb application to a server that supports gzip compressed files, you can use gzip to compress any files associated with your Nexaweb application.

Nexaweb platform includes a servlet, servlet com.nexaweb.server.servlet.CompressedFileServlet, to serve gzip files to clients from a Tomcat server. For other types of servers, you need to create your own servlet to provide gzip files to a Nexaweb application client.

servlet com.nexaweb.server.servlet.CompressedFileServlet does the following:

Checks whether the incoming client request supports gzip encoded responses.

- If not: the servlet forwards the file request directly to the web server.

- If so:

  • The servlet gets the appropriate mime-type for the file being requested (the original file request).
  • Checks for a .gz (gzipped) version of the file.
    - If found: returns the .gz version of the file.
      This response indicates the original file's mime-type and a content-encoding header specifiying gzip.

      For example, for the file: js.gz, you see the following:

      Content-Encoding: gzip
      Content-Type: application/x-javascript

    - If not found: forwards the file request directly to the web server. 

The platform seed web.xml file maps the path to this file as: /CompressedFileServlet.

To utilize this, use:
/CompressedFileServlet/path/to/file

 

pack200 Compression

Requires Platform 4.2+

Nexaweb 4.2.x supports pack200 compression formats.
 
Pack200, a Java application deployment compression format, efficiently compresses large JAR files.
 
Nexaweb support for pack200 compression means that:
  • pack200 compressed JAR files transfer significantly faster over a network than other JAR files
  • Nexaweb compresses NexawebClient.and Nexaweb-nfc JARs using pack200
  • You can now use pack200 to compress JARs containing libraries pre-loaded into your application’s client.

Using pack200 Compression

 This section describes when to use pack200 compression with Nexaweb applications. 

Requirements

 

EnvironmentRequirementDescription
Building Nexaweb applicationsJRE 5 (1.5)Required in build environment to
compress JARs with pack200

Client runtime

JRE 5 (1.5)

Installed on browser in which client runs
to unpack pack200 compressed JAR

Applet caching enabled on the browser JRE plug-in

Note: Nexaweb application development requires you to include a non-compressed JAR file containing your pre-loaded libraries to ensure that these libraries load in a browser even if it does not have the JRE 5 (1.5) plug-in.

Server runtimen/a 

 

 
 
The process of creating a pack200 compressed JAR for Nexaweb applications requires the following major steps:
  • Creating a pack200 compressed file
  • Adding a pack200 attribute entry into the Nexaweb client configuration file 

Creating a pack200 File

You need a JRE 1.5/JDK 1.5 installed on your build system to create a pack200 file.
 
To create a pack200 file, follow these steps: 
  1. Package pre-loaded library files in an unsigned JAR file.
    Note: To use signed files, see Java documentation on how to repackage a signed JAR.
  2. Locate the pack200 utility in JRE_HOME or JAVA_HOME bin directory.
  3. Copy the JAR file that you want to compress into the same bin directory as pack2000.
  4. Type the following command in a command window: pack200 MyLibrary.jar.pack.gz MyLibrary.jar
    where:
    - MyLibrary.jar.pack.gz is the name of the compressed JAR file that pack200 creates
    - MyLibrary.jar is the name of the original uncompressed file
  5. Copy both the compressed and uncompressed JARs (for example, MyLibrary.jar.pack.gz and MyLibrary.jar) into the directory where you save pre-loaded client libraries for your application. This process does not change the original MyLibrary.jar file, so if a copy of it already exists in this directory, you do not need to copy it into the directory again.
 Now go on to add the pack200 file to the nexaweb-client.xml configuration file.


Adding a pack200 file to the nexaweb-client.xml configuration file

You must specify the location of pre-loaded library JAR files in the client configuration file.
 
You specify pre-loaded libraries in the <pre-loaded-in-applet-def> section of the client configuration file, nexaweb-client.xml.
 
You can specify the pack200 file either as a path or URL attribute in this section of the Nexaweb-client.xml, but not as both. (If you specify both, the client uses the pack200Path.) In addition, the pack200Path or pack200Url attributes do not replace the path and URL attributes. The pack200Path or pack200Url attributes point to the compressed JAR files, while the path and URL attributes point to uncompressed versions of these files. The client requires both versions of the files in the event that a browser does not support the compressed files.
 
At runtime, if the client cannot find the pack200Path or the pack200Url is not available, the Nexaweb ClientClassService will automatically fall back to use the regular path or URL attributes. This adds overhead to the runtime.
 
You add either a 'pack200Path' or 'pack200Url' attribute to a pre-loaded library entry using the following format:
pack200Path="/WEB-INF/client/lib/foo.jar"
pack200Url=http://blah:18/foo.jar
To add the pack200 file to the nexaweb-client.xml, follow these steps:
  1. Locate the nexaweb-client.xml file for the Nexaweb application in the application’s WebContent\WEB-INF directory.
  2. Open nexaweb-client.xml file with a text editor.
  3. Locate the <pre-loaded-in-applet-def> section of the nexaweb-client.xml file, similar to the following:

    <client-classpath> 
      <pre-loaded-in-applet-def> 
         <archive name="MyLibrary.jar" 
            path="/WEB-INF/client/lib/MyLibrary.jar" /> 
       </pre-loaded-in-applet-def>
    </client-classpath>
  4. Add a pack200Path or pack200Url attribute, similar to the following:

     <client-classpath> 
         <pre-loaded-in-applet-def> 
           <archive name=" MyLibrary.jar " 
            path="/WEB-INF/client/lib/ MyLibrary.jar " 
            pack200Path="/WEB-INF/client/lib/ MyLibrary.jar.pack.gz"/> 
         </pre-loaded-in-applet-def>
     </client-classpath>
This completes the steps for creating a pack200 compressed JAR file and adding it as an attribute to the nexaweb-client.xml file.
 
You can now repackage and redeploy your Nexaweb application with this new feature. The pack200 support is transparent to the client. You don't need to do any special handling on the client side to make this work.
 

Troubleshooting

This section describes the following methods for troubleshooting network library loading issues:
  • Using a network monitor
  • Using Nexaweb platform’s service console
 
In addition to these methods, monitor the application server console or log for additional information. 

Using a Network Monitor

 
To troubleshoot network library loading issues, you can use a network monitor to monitor:
  • HTTP traffic
  • Resources requested
  • Resources returned
For example, you can use the Nexaweb platform’s TCP Tunnel from Apache SOAP utilities.
 
Use this monitor to check the request and response headers.
 
To determine whether a JDK 1.5 client makes a request to load a library, look for the following request and response headers:
 

 

ComponentHeaderHeader Type
Clientaccept-encoding: pack200-gzip,gzipRequest
Nexaweb’s ClientClassServiceIf properly configured, returns the pack200 file data and:
Content-Encoding: pack200-gzip
Response
Nexaweb’s ClientClassServiceIf pack200 file is already cached on the client side:
HTTP 304
Response

 

 
Note:  If a JRE 1.5 Plugin is not configured to use applet caching, it won't send an 'accept-encoding: pack200' to the Nexaweb server. This is a known Java Plugin bug. For information, see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5072902.
 

Using Nexaweb Platform's Service Console

To troubleshoot network library loading issues, you can use Nexaweb platform's Service console to monitor:
  • Library name and location mappings
  • Counters
 Nexaweb platform's Service console is a per-application based service console.
 
To access it:
  1. Enter the following address in a Web browser location bar: http://server:port/yourapp/Nexaweb/Services/index.jsp
  2. Click right menu on ClientClassService.
 
When the service is in normal status, you can find out the dynamic counters when each library is loaded in the performance section.
 
You can also see how the filename and path/URL are resolved in the status details. You should make sure the paths are valid when you are diagnosing a problem.
Note:  You might see the message: detect.jar.pack.gz is not found in the Nexaweb services console. This is an internal message from the Nexaweb platform and does not impact your application.