• Share
  • ?
  • Profiles ▼
  • Communities ▼
  • Apps ▼

Blogs

  • My Blogs
  • Public Blogs
  • My Updates
  • Administration
  • Log in to participate

▼ Tags

 

▼ Similar Entries

Daylight Saving Time...

Blog: Ingolf's z/VS...
Ingolf24 120000DRN3
Updated
0 people like thisLikes 0
No CommentsComments 0

Mathias Bynens: "Asy...

Blog: HermannSW
HermannSW 2700006U54
Updated
0 people like thisLikes 0
No CommentsComments 0

Pattern Matching usi...

Blog: DB2 for z/OS ...
Jane Man 110000HG1H
Updated
0 people like thisLikes 0
No CommentsComments 0

sync_wait.js and wai...

Blog: HermannSW
HermannSW 2700006U54
Updated
0 people like thisLikes 0
No CommentsComments 0

How to generate UUID...

Blog: HermannSW
HermannSW 2700006U54
Updated
0 people like thisLikes 0
No CommentsComments 0

▼ Similar Ideas

Importance of settin...

Ideation Blog: IBM PureData-...
DeepashriKrishnaraja 270001C7Y3
Updated
Votes 2 CommentsComments 5

▼ Archive

  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • September 2018
  • March 2018
  • November 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • October 2016
  • May 2016
  • April 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011

▼ Blog Authors

HermannSW

View All Entries
Clicking the button causes a full page refresh. The user could go to the "Entry list" region to view the new content.) Entry list

Generate GatewayScript in DataPower XSLT and execute it -- and why that might not be a good idea

HermannSW 2700006U54 | | Tags:  face time gatewayscript xml javascript xslt unicode nodejs datapower ‎ | 11,784 Views

Found this in my GatewayScript folder, written some time ago and never posted.

Long ago I found some Javascript code snippet somewhere converting epoch time (#seconds since Jan 1st 1970) into time face unicode symbol.

And I wanted to execute it with GatewayScript, but doing so directly was too easy. So I wanted to execute it from DataPower XSLT via "dp:gatewayscript()".

The trick is to write to the only filesystem accessible to XSLT output without accessing the XML Managament Interface. DataPower XSLT can output to "temporary:" folder via <dp:dump:nodes>.

There is one disadvantage when writing JavaScript that way -- you cannot write '<' nor '&' characters, because those get XML escaped.

There is another reason why doing this might not be what you want to do in production:
nodejs "eval()" function is disabled in GatewayScript for good (security) reasons.
You can (and should not, or only if you really know what you do) use below method to get something like nodejs "eval()" inside DataPower.

$ coproc2 doGatewayScript.xsl <(echo '<_/>') http://dp1-l3:2223; echo
🕔  2016-10-15T17:14:58Z
$ coproc2 doGatewayScript.xsl <(echo '<_/>') http://dp1-l3:2223; echo
🕠  2016-10-15T17:15:02Z
$ 
$ cat doGatewayScript.xsl 
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:date="http://exslt.org/dates-and-times"
  xmlns:dpfunc="http://www.datapower.com/extensions/functions"
  xmlns:dp="http://www.datapower.com/extensions"
  extension-element-prefixes="dp"
>
  <xsl:output method="text"/>

  <xsl:include href="store:///utilities.xsl"/>

  <xsl:template match="/">
    <xsl:variable name="js">
      var d=~~(Date.now()/18e5+.5)%24;d+=d>=2?0:24;
      session.output.write(String.fromCharCode(55357,56655+(d%2?23+d:d)/2));
    </xsl:variable>

    <dp:dump-nodes file=" 'doit.js' " nodes="$js"/>

    <xsl:value-of
      select="dp:gatewayscript('temporary:///doit.js')
                /gatewayscript/result/text()"
    />
    <xsl:text>  </xsl:text>
    <xsl:value-of select="dpfunc:zulu-time(date:seconds(date:dateTime()))"/>
  </xsl:template>
  
</xsl:stylesheet>
$ 


Hermann.

Modified on by HermannSW 2700006U54
  • Add a Comment Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry
Notify Other People
notification

Send Email Notification

+

Quarantine this entry

deleteEntry
duplicateEntry

Mark as Duplicate

  • Previous Entry
  • Main
  • Next Entry
Feed for Blog Entries | Feed for Blog Comments | Feed for Comments for this Entry