I have found the coproc2 utilities to be very useful and use them often when working on xslt stylesheets for the datapower devices. I have recently been doing quite a bit of such work involving ffd files for input and output mapping and with user written xslt functions that i include in my xsl, and i was finding it a bit of a hassle when one or more of those files was changing -- each time i had to upload the changed files before submitting my coproc2 test and this seemed somewhat to defeat the convenience and utility of coproc2 in the first place. I was using the java coproc2 client, and so I made some small modifications to HermannSW's java coproc2 program v1.2, such that the modified program would as well take a list of file names (on the pc) and upload them as part of a new http header added to the coproc2 HTTP POST, and then as well I modified the coproc2.xsl so as to save these files to the temporary:/// directory of the coproc2 domain.
The coproc2.java, the jar for this, and the coproc2.xsl files are included in the attached zip.
If you want to try this, either compile the new version of coproc2.java or add the attached jar file to your classpath. Also, copy the new version of coproc2.xsl to local:// directory for the domain where you have installed the coproc2 utility services (coproc2 and coproc2nonxml).
The new version java client takes as paramaters:
* @version 1.3
* @param stylesheet2Send stylesheet to be executed on DataPower
* @param xmlFile2Send xmlfile sent to DataPower (or '-' for standard input)
* @param url URL of coproc2 Endpoint on DataPower
* @param filesToUpload an optional list of one or more semicolon separated filenames to be uploaded to
* "temporary:///" directory in coproc3 service domain. For example: myFile1;myFile2
* @param -v optional, do verbose output
The optional parameters can be in either order.
The modifications are backwardly compatible so you can continue to use java coproc2 client as previously, or if you want to upload some files along with the POST then use coproc2 with the optional filesToUpload parameter for example:
coproc2 myxslfile.xsl myxmlfile.xml http://mydp:2223 myFile1;myFile2:myFile3
In this case the 3 files (myFile1 myFile2 and myFile3) will be written to the temporary:// directory of the domain where your coproc2 utilities are installed prior to the invocation of the main transformation, that is, prior to the execution of the myxslfile.xsl stylesheet with myxmlfile.xml as input.
A minor hassle with this implementation is that since I used <dp:dump-nodes> as part of how to get the files uploaded, then they can only be written to the temporary:/// directory of the domain where your coproc2 services are installed, so what this means is that anywhere you refer to them in your main xsl file, you need to reference them in the temporary directory. For example, if i had an <dp:input-mapping> element, in my main xsl it might look like:
<dp:input-mapping href= "temporary:///utf-8.ffd" type= "ffd"/>
or for functions or other included files:
<xsl:include href= "temporary:///my_funcs.xsl" />
A brief explanation of the file upload implementation:
In the java coproc2 client, a serialized xml string with the file names and content is created and then passed as the value of a new HTTP header named "filesXMLString" included with the POST -- the filesToUpload parameter is parsed for file names and then for each file the name and contents are each base64 encoded and added as elements to the xml string.
In the coproc service, the string value for the filesXMLString is parsed, and then processed to write each file to the temporary directory using <dp:dump-nodes> element.
The code for the coproc2.xsl follows:
<xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" xmlns:exsl= "http://exslt.org/common" extension-element-prefixes= "dp" > <xsl:output method= "xml" omit-xml-declaration= "yes"/> <xsl:template match= "/"> <!-- store xsl in context variable ( for use in next transform action) --> <dp:set-variable name= "'var://context/xsl'" value= "dp:inflate(dp:http-request-header('xsl'),'gzip')"/> <!-- force the skipping of backside send for this service --> <dp:set-variable name= "'var://service/mpgw/skip-backside'" value= "1"/> <!-- write any uploaded files to the temporary directory --> <xsl:variable name= "filesXMLString" select= "dp:http-request-header('filesXMLString')"/> <xsl: if test= "$filesXMLString != ''"> <xsl:variable name= "fileNode" select= "dp:parse($filesXMLString)"/> <xsl:for-each select= "$fileNode/files/file"> <dp:dump-nodes file= "dp:inflate(./filename/text(),'gzip')" nodes= "dp:parse(dp:inflate(./filecontent/text(),'gzip'))"/> </xsl:for-each> </xsl:if> </xsl:template> </xsl:stylesheet>
(One thing to note is that if you have an error in one of the files that you are uploading then this will often surface as a failed parse of some part of the filesXMLString -- check the default-log for the domain where you have installed the coproc2 services).
If you do try this and have any problems please do let me know. Also, any comments or suggestions are welcomed. Please let me know what you think.