Advice needed: Structuring SOAP Application with Disparate Parts

45 views
Skip to first unread message

F. Nikita Thomas

unread,
Aug 23, 2018, 5:29:39 PM8/23/18
to nodejs
Hello,
My first time here so...: There is a SOAP service which I'd like to model and output in various formats,(HTML, PDF, etc). Since I'm fairly new to NodeJS I've been testing techniques to build the application, but have come to an impasse in how to proceed. The main issue is in transforming the SOAP response and whether I should do it client-side or server-side. Here is what I've found so far

Using node-java and Saxon-HE server-side, (snippet):

const https = require('https')
const java = require('java')
const fs = require('fs')

java.classpath.push('C:\\Saxon-HE\\saxon9he.jar')
const Processor = java.import('net.sf.saxon.s9api.Processor')
const StreamSource = java.import('javax.xml.transform.stream.StreamSource')
const File = java.import('java.io.File')
const proc = new Processor(false)
const comp = proc.newXsltCompilerSync()
const exec = comp.compileSync(new StreamSource(new File('identity.xsl')))
const srce = proc.newDocumentBuilderSync().buildSync(new StreamSource(new File('soap-response.xml')))
const outp = proc.newSerializerSync()
outp.setOutputFile(new File('output.xml'))
trans = exec.loadSync()
trans.setInitialContextNodeSync(srce)
trans.setDestinationSync(outp)
trans.transformSync()

However, this seems slow as heck... so if I need to transform multiple documents for many users this could be problematic. Next, I tried pairing jsdom and Saxon-CE in the hope that I could transform the live page and write it back to the file system (REPL output is edited)


var sandbox = {console : console,require : require}

vm.runInNewContext("const fs = require('fs');const jsdom = require('jsdom');const {JSDOM} = jsdom;",sandbox,"myfile.vm")

vm.runInNewContext("JSDOM.fromURL('http://localhost/joshua.html',{pretendToBeVisual : true,runScripts : 'dangerously',resources : 'usable'}).then((dom)=>{this.window = dom.window;this.document = dom.window.document;this.dom = dom;console.log(dom.serialize());});",sandbox,"myfile.vm")

Error: Not implemented: navigation (except hash changes)
    at module.exports (C:\Users\user\AppData\Roaming\npm\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)


Apparently, jsdom's navigation is limited to hashes, so the magic little HTML file needed by Saxon-CE isn't cached and the process is halted. I can, however,  update the head element of the webpage with the transformation script and then write it back to the file system:


vm.runInNewContext("JSDOM.fromURL('http://localhost/joshua.html',{pretendToBeVisual : true}).then((dom)=>{this.window = dom.window;this.document = dom.window.document;this.dom = dom;console.log(dom.serialize());});",sandbox,"myfile.vm")

vm.runInNewContext("var script = document.createElement('script');script.type = 'text/javascript';script.text = 'onSaxonLoad = function(){proc = Saxon.run({stylesheet : \"mydemo.xsl\",source : \"mydemo.xml\",logLevel : \"SEVERE\"})}';document.getElementsByTagName(\"head\")[0].appendChild(script);",sandbox,"myfile.vm")

vm.runInNewContext("console.log(dom.serialize());data = dom.serialize();fs.writeFile('./../../wamp64/www/joshua.html',data,(err)=>{if (err) throw err;});",sandbox,"myfile.vm")



The main issue is I need to pass the outputted XML from XSL transformation to another as well as produce different output formats, and the other Node libraries I have seen are either dead or bleeding edge, emphasis on the exsanguination... Any advice on how to do this cogently and securely would be greatly appreciated. Thanks!!

N.




Mikkel Wilson

unread,
Aug 30, 2018, 3:09:17 PM8/30/18
to nodejs
The structure of this program seems very strange to me and that may explain the performance issue you describe. You appear to be trying to write a java program in node.js and using java objects/primitives; effectively controlling a JVM through javascript. This is possible with something like Vert.x but I think the method you're using here will launch a whole JVM each time it's run. Quite a drag on performance.

Sounds like you need to interact with a SOAP endpoint and produce some XML, HTML, or PDF. There are many libraries to help you do this that do not require java at all. NPM is a really impressive system and there are modules for everything you've described here. Many of them have native components which will outperform a Java implementation. 


HTH,
Mikkel

F. Nikita Thomas

unread,
Aug 31, 2018, 11:54:43 AM8/31/18
to nodejs
Hi Mikkel,
Sorry for the late reply, but I needed to attend to some class concerns. I think I need to clarify what I'm attempting and what has stymied me thus far:

      Saxonica provides different ways to access their XSLT processor with different levels of support for free and paid.
      The ones I've considered for my project -
            Saxon-HE(Home Edition) - Uses Java - and as you said will cause a performance hit especially if I perform the XML/XSLT
            server-side. I realized that almost immediately. Hence ...

            Saxon-CE(Client Edition) - Uses JavaScript - An in-browser solution. My main concern is piping files between the server
            and client to perform the necessary SOAP request/response transformations. I am looking at sockets for this. 

            Saxon/C - C/C++ variant of the Java libraries - looks promising but doesn't support my OS.

I can perform most of the tasks of generating XML, HTML, PDF, and SVG with XSLT alone, so the packages you've suggested would be unnecessary
for my needs. I was hoping that you could provide some practical advice on how to structure the application or the stack. For right now, I've decided
to go the Saxon-CE route which has the most promise so far. Thanks again.


N.
Reply all
Reply to author
Forward
0 new messages