zipget extracts a file from the specified zipfile and places it into the current DropZone. Unless it is subsequently removed, the file will be deployed to the appropriate Endpoint(s) in any subsequent transfer operation. WAR, JAR and EAR files are simply ZIP files with a different extension. You can thus use zipget (and zipadd and zipdel) with WAR, JAR and EAR files as well as with ZIP archives. This provides a powerful way of manipulating WAR, JAR and EAR files in the DropZone before onward deployment to the target Endpoint(s).


zipget is useful for extracting a file from a zip archive, modifying the file and then replacing the original version of the file in the archive with zipadd. You can use a combination of zipget and zipadd to manipulate XML configuration files that are embedded in a web archive.


zipget takes a mandatory named parameter. Other parameters can be specified depending on what is being extracted from the zipfile:


zipfile:

Mandatory. The name of the zipfile in the DropZone from which files should be extracted. If the specified file does not exist in the DropZone, a run time error is thrown.


files:

Optional. If specified, refers to either an array or list of DropZoneFile objects. Each file in the array or list is extracted from the specified zipfile and placed into the drop zone. The filename extracted from the zipfile is taken from the dzpath of the DropZoneFile object. Note: if the file referenced by the DropZoneFile object does not exist in the specified zipfile, then a run-time error is thrown.


file:

Optional. If specified, refers to either a DropZoneFile object or a string giving the name of a file to extract from the zipfile. If the file parameter refers to a DropZoneFile object, then the filename used is taken from the dzpath of that object. If the file parameter is a string, then it is taken to be a path to a file within the zipfile. In either case, the specified file is extracted from the specified zipfile and placed into the drop zone. If a file with the same name already exists in the drop zone then it is automatically replaced. If the file referenced does not exist in the zipfile then a run-time error is thrown.


NOTE: You can call dir() on a DropZoneFile object representing a zipfile to return an array of DropZoneFile objects that you can then pass to zipget.


Example 1: Extract all the files in a zipfile:


// get a list of myapp.war files in the DropZone (probably only one)

set warfilearr = ${DropZone.find("myapp.war")};

// Need to iterate since find returns an array keyed by filename.

// However, if there's only one "myapp.war", this will only execute once.

iterate(warfile: $warfilearr) {

   // get list of files in myapp.war

   set files = ${warfile.dir()};

   // Now extract all those files        

   zipget(zipfile: "myapp.war", files: $files);

}


Example 2: Modify a configuration file within a WAR file


// Step 1 – extract web.xml from the WAR file

//

zipget(zipfile: "mywapp.war", file: "web.xml");


// Step 2 - Set the ODBC connection string to the correct value for

// the target Environment. Note DBSTRING will be on the stack and is

// Environment specific.

//

modify(file: 'web.xml', modifier: "xml") {

   set_attribute(

   xpath: "/web-app/context-param/[@param-name=DBConnectionString]/@param-value",

   value: $DBSTRING);

}


// Step 3 – put the modified web.xml file back in the WAR file. Remove the

// modified file from the DropZone so we don't end up deploying it.

//

zipadd(zipfile: "myapp.war", file: "web.xml", delete: true);