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 <https://vertx.io/> 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. SOAP : https://www.npmjs.com/package/soap PDF: https://www.npmjs.com/package/pdfkit XML : https://www.npmjs.com/package/xmlbuilder DOM scraping : https://www.npmjs.com/package/cheerio HTH, Mikkel https://www.oblivious.io/ <https://www.oblivious.io/?r=nodejs> On Thursday, August 23, 2018 at 2:29:39 PM UTC-7, F. Nikita Thomas wrote: > > 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 <https://github.com/joeferner/node-java> and Saxon-HE > <http://saxon.sourceforge.net/> 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 <https://github.com/jsdom/jsdom> and Saxon-CE > <https://www.saxonica.com/ce/user-doc/1.1/html/about/> 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. > > > > > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/fb3c4f86-9992-4cea-a083-df29fc6e0ab5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
