Wednesday, 14 August 2013

Running Calabash XML From Code

Running Calabash XML From Code

I downloaded Calabash XML a couple of days back and got it working easily
enough from the command prompt. I then tried to run it from Java code I
noticed there was no API (e.g. the Calabash main method is massive with
code calls to everywhere). To get it working was very messy as I had to
copy huge chunks from the main method to a wrapper class, and divert from
the System.out to a byte array output stream (and eventually into a
String) i.e.
...
ByteArrayOutputStream baos = new ByteArrayOutputStream (); // declare at top
...
WritableDocument wd = null;
if (uri != null) {
URI furi = new URI(uri);
String filename = furi.getPath();
FileOutputStream outfile = new FileOutputStream(filename);
wd = new WritableDocument(runtime,filename,serial,outfile);
} else {
wd = new WritableDocument(runtime,uri,serial, baos); // new "baos"
parameter
}
The performance seems really, really slow e.g. i ran a simple filter 1000
times ...
<p:filter>
<p:with-option name="select"
select="'/result/meta-data/neighbors/document/title'" />
</p:filter>
On average each time took 17ms which doesn't seem like much but my spring
REST controller with calls to Mongo DB and encryption calls etc take on
average 3/4 ms.
Has anyone encountered this when running Calabash from code? Is there
something I can do to speed things up?
For example, I this is being called each time -
XProcRuntime runtime = new XProcRuntime(config);
Can this be created once and reused? Any help is appreciated as I don't
want to have to pay money to use Calamet but really want to get Xproc
working from code to an acceptable performance.

No comments:

Post a Comment