Discussion:
[nodejs] Advice needed: Structuring SOAP Application with Disparate Parts
F. Nikita Thomas
2018-08-23 19:34:11 UTC
Permalink
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 nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/f58ab6ac-e321-4524-aa06-321efbdb42fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mikkel Wilson
2018-08-30 16:27:10 UTC
Permalink
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>
Post by F. Nikita Thomas
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
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
'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
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 =
\"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 nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
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.
F. Nikita Thomas
2018-08-31 14:13:40 UTC
Permalink
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.
Post by Mikkel Wilson
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>
Post by F. Nikita Thomas
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
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
'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
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 =
\"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 nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/ae4ec687-6493-46ef-b356-35cd4269dd24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...