Compiling a Java Extension
To compile Java Extensions for use with the Traffic Manager, you need the following items:
•Java Development Kit (JDK), which contains the Java compiler. This can be downloaded from http://www.oracle.com/technetwork/java/index.html.
•Java Servlet API, which can be found in the user interface by going to Catalogs > Java Extensions Catalog and clicking the Java Servlet API link.
•Java Extensions API, which can be found in the user interface under Catalogs > Java Extensions Catalog and clicking the Traffic Manager Java Extensions API link.
To compile a Java Extension, complete the following steps:
1.Copy the servlet.jar and zxtm-servlet.jar files to the directory where you are compiling the Java Extension.
2.Run the following command:
$ javac -cp servlet.jar:zxtm-servlet.jar MyServlet.java
This creates a class file called MyServlet.class.
You can bundle a Java Extension with any other needed classes in a single .jar file. The Traffic Manager automatically searches .jar files for the Java Extensions to use.
Running a Java Extension
ATTENTION
To run a Java extension on the Traffic Manager, you must first enable Java support. For more information, see Setting Up the Traffic Manager.
First, compile and upload the Java Extension to the Traffic Manager.
To upload the Java Extension, go to the Catalogs > Java Extensions Catalog page of the user interface, and specify the class or .jar file in the Upload section.
Alternatively, you can copy the file(s) to the $ZEUSHOME/zxtm/conf/jars directory.
Whenever a Java Extension is uploaded, a new TrafficScript rule is created. The new TrafficScript rule contains the code java.run (using the “extension class name” convention).
The Extension user interface page should then show your Java Extension in the Java Extensions Catalog section, as shown below.
Unrecognized Extensions
If an Extension is listed in the Java Libraries & Data Catalog section, it means that the Extension has not been recognized. The Extension will be listed as invalid, along with an error message detailing why it failed to load.
Ensure that the class extends the GenericServlet (or a subclass of GenericServlet, such as HttpServlet) and that any JAR libraries required to run the Extension have been uploaded, or are present in the java!lib directory specified on the Global Settings page.
Replacing Extensions
Extensions are cached in memory when they are being used. If you replace an Extension with an updated version by copying the Extension directly into the Traffic Manager configuration instead of using the management interface, you may need to tell the Traffic Manager to reload the new Extension.
To do this, go to the Extension catalog, select your Extension, check confirm, and click Reload selected.
Reloading the Extension causes the Extension Runner to remove your Servlet from memory, so any information the Servlet was storing will be lost.
Extensions are not applied directly to virtual servers; Extension must be called (initiated) from within rules. You can create a default Rulebuilder rule when uploading the Extension, which allows you to use the Extension in a virtual server.
Alternatively, you can run your Extension from TrafficScript using the function:
java.run( "MyPackage.MyServlet" );
Extension Parameters
You can pass parameters to an Extension by using the following command:
java.run( "MyPackage.MyServlet", "Hey there!" );
The Extension can access these parameters using the following code:
String[] args = (String[]) req.getAttribute( "args" );
You can also specify parameters through the Extensions catalog by using the Catalogs > Extensions menu and selecting the Extension you want to edit. These parameters are set every time an Extension is used, and, therefore, are useful for defining global settings. The parameters can also be accessed from inside your Extension using the following command:
ServletConfig config=getServletConfig();
String param = config.getInitParameter( "param_name" );