Topic
  • 93 replies
  • Latest Post - ‏2014-12-19T09:49:41Z by HermannSW
HermannSW
HermannSW
4654 Posts

Pinned topic coproc2

‏2011-03-06T23:43:43Z |
Hello,

with announcement Deprecated features in the 3.8.0 IBM WebSphere DataPower SOA Appliances products the coprocessor features (with xa.jar) has been deprecated.
It is still part of even 3.8.2.x firmware though.
Coprocessor mode allows for transparent execution of XSLT transformations on DataPower in Java environments by xa.jar.
In short the stylesheet and xmlfile are sent to DataPower appliance, the stylesheet gets compiled if not already in stylesheet cache,
is then applied to the xmlfile as input and returns the response generated by DataPower to the Java application.

While this is useful for processing it definitely is also useful for development and testing of stylesheets without always having to upload the stylesheets to the appliance explicitely.
(as you know processing of stylesheets making use of DataPower extension functions is not possible by other XSLT processors)

The recommended alternative from deprecation announcement was "Use HTTP loopback".

Find attached DataPower service coproc2.zip, it does allow for
  • processing of received xmlfile by received stylesheet on DataPower appliance
  • because it is a MPGW it also may be used on XB60 and XM70 models which never provided coproc support.

The service export was generated with firmware 3.7.3.15.
I successfully imported it on 3.8.0, 3.8.1 and 3.8.2 boxes.
Hermann<myXsltBlog/>

Attachments

Updated on 2013-03-21T09:40:27Z at 2013-03-21T09:40:27Z by HermannSW
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T00:04:33Z  
    coproc2 service
    • static backend "http://1.2.3.4"
    • request type: xml
    • reponse tye: does not matter because of skip-backside
    • HTTP FSH on port 2223

    Its policy consists of
    • match all
    • a first transform action from NULL to NULL with "local:///coproc2.xsl"
    • a second transform action from INPUT to OUTPUT with "xsl"
    If you try to create the 2nd transform in wizard it does not allow to specify context "xsl" for the transform.
    Select eg. store:///identity.xsl first and then change that in the Object screen of the MPGW later, or use CLI.

    This is stylesheet coproc2.xsl (also attached):
    
    <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <xsl:output method=
    "xml" omit-xml-declaration=
    "yes"/> <xsl:template match=
    "/"> <dp:set-variable name=
    "'var://context/xsl'" value=
    "dp:inflate(dp:http-request-header('xsl'),'gzip')"/>   <dp:set-variable name=
    "'var://service/mpgw/skip-backside'" value=
    "1"/> </xsl:template>   </xsl:stylesheet>
    


    It first does a "gunzip" of the received base64 encoded gzipped stylesheet found in HTTP header "xsl".
    Then it stores the stylesheet in context "xsl" for use as stylesheet by 2nd transformation.

    After that it sets skip-backside to 1 which makes the MPGW a loopback service.

    After that the 2nd transformation uses the stylesheet from context "xsl" to read and process the xmlfile data and send response back.

    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T00:13:21Z  
    • HermannSW
    • ‏2011-03-07T00:04:33Z
    coproc2 service
    • static backend "http://1.2.3.4"
    • request type: xml
    • reponse tye: does not matter because of skip-backside
    • HTTP FSH on port 2223

    Its policy consists of
    • match all
    • a first transform action from NULL to NULL with "local:///coproc2.xsl"
    • a second transform action from INPUT to OUTPUT with "xsl"
    If you try to create the 2nd transform in wizard it does not allow to specify context "xsl" for the transform.
    Select eg. store:///identity.xsl first and then change that in the Object screen of the MPGW later, or use CLI.

    This is stylesheet coproc2.xsl (also attached):
    <pre class="jive-pre"> <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" > <xsl:output method= "xml" omit-xml-declaration= "yes"/> <xsl:template match= "/"> <dp:set-variable name= "'var://context/xsl'" value= "dp:inflate(dp:http-request-header('xsl'),'gzip')"/> <dp:set-variable name= "'var://service/mpgw/skip-backside'" value= "1"/> </xsl:template> </xsl:stylesheet> </pre>

    It first does a "gunzip" of the received base64 encoded gzipped stylesheet found in HTTP header "xsl".
    Then it stores the stylesheet in context "xsl" for use as stylesheet by 2nd transformation.

    After that it sets skip-backside to 1 which makes the MPGW a loopback service.

    After that the 2nd transformation uses the stylesheet from context "xsl" to read and process the xmlfile data and send response back.

    Hermann<myXsltBlog/>
    Now what is missing is a client which sends a base64 encoded gzipped stylesheet as HTTP header "xsl" in addition to the xmlfile.

    This is what attached shell script coproc2 does (also attached, works for Linux or Cygwin under Windows):
    #!/bin/bash
    curl -H "xsl: `gzip -c $1 | base64 | sed -e :a -e '/.*[^\.]$/N;s/\n//;ba'`" --data-binary @$2 $3
    


    The format is:
    coproc2 stylesheet xmlfile coproc2endpoint

    The sed statement just removes all whitespace from the base64 encoded gzipped stylesheet.
    The "xsl" HTTP header is set via the "-H" option of curl.
    The xmlfile is sent by "--data-binary" option.

    Hermann <myXsltBlog/>

    Attachments

    Updated on 2014-03-25T03:34:07Z at 2014-03-25T03:34:07Z by iron-man
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T00:20:16Z  
    • HermannSW
    • ‏2011-03-07T00:13:21Z
    Now what is missing is a client which sends a base64 encoded gzipped stylesheet as HTTP header "xsl" in addition to the xmlfile.

    This is what attached shell script coproc2 does (also attached, works for Linux or Cygwin under Windows):
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">#!/bin/bash curl -H "xsl: `gzip -c $1 | base64 | sed -e :a -e '/.*[^\.]$/N;s/\n//;ba'`" --data-binary @$2 $3 </pre>

    The format is:
    coproc2 stylesheet xmlfile coproc2endpoint

    The sed statement just removes all whitespace from the base64 encoded gzipped stylesheet.
    The "xsl" HTTP header is set via the "-H" option of curl.
    The xmlfile is sent by "--data-binary" option.

    Hermann <myXsltBlog/>
    Let's take this stylesheet coproc2.xsl (also attached) as sample:
    <xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
    <xsl:output omit-xml-declaration="yes" />
     
      <xsl:template match="/">
        <xsl:value-of select="dp:radix-convert(dp:encode(.,'base-64'),64,16)"/>
      </xsl:template>
     
    </xsl:stylesheet>
    


    Because it makes use of DataPower extension function dp:radix-convert() it cannot be processed by other XSLT processors.

    The sample xmlfile is:
    <some>test</some>
    


    So 2hex.xsl just takes the string "test", encodes it as base64 string, and then converts that to hexadecimal.
    The hexadecimal representation of "test" is "74657374" as can be seen by this execution:
    $ coproc2 2hex.xsl some.xml http://dp3-l3.boeblingen.de.ibm.com:2223; echo
    74657374
    $
    


    Hermann <myXsltBlog/>

    Attachments

    Updated on 2014-03-25T03:34:02Z at 2014-03-25T03:34:02Z by iron-man
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T00:36:03Z  
    • HermannSW
    • ‏2011-03-07T00:20:16Z
    Let's take this stylesheet coproc2.xsl (also attached) as sample:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" > <xsl:output omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:value-of select="dp:radix-convert(dp:encode(.,'base-64'),64,16)"/> </xsl:template> </xsl:stylesheet> </pre>

    Because it makes use of DataPower extension function dp:radix-convert() it cannot be processed by other XSLT processors.

    The sample xmlfile is:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><some>test</some> </pre>

    So 2hex.xsl just takes the string "test", encodes it as base64 string, and then converts that to hexadecimal.
    The hexadecimal representation of "test" is "74657374" as can be seen by this execution:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ coproc2 2hex.xsl some.xml http://dp3-l3.boeblingen.de.ibm.com:2223; echo 74657374 $ </pre>

    Hermann <myXsltBlog/>
    Just before posting coproc2 service I thought on a client for Windows environments without cygwin.
    And because the shell script made use of curl, gzip, base64 and sed commands, I tried to come up with a single file solution.

    It turned out that SOAPClient4XG from 2001 developerWorks article A simple SOAP client was pretty close.
    It is a Java client capable of sending SOAP requests and receiving and displaying the corresponding response.

    I just needed to add the base64 encoded gzipped stylesheet as "xsl" HTTP header.

    This is the main addition to SOAPClient4XG I did (from attached complete coproc2.java):
    
    ... 
    // Read stylesheet2send into b2[] InputStream fin2 = 
    
    new FileInputStream(stylesheet2Send); ByteArrayOutputStream bout2 = 
    
    new ByteArrayOutputStream(); copy(fin2,bout2); fin2.close();   
    
    byte b2[] = bout2.toByteArray();   
    // B[] = gzip(b2[]) ByteArrayOutputStream bos = 
    
    new ByteArrayOutputStream(); GZIPOutputStream gz = 
    
    new GZIPOutputStream(bos); gz.write(b2); gz.close(); bos.close();   
    
    byte B[] = bos.toByteArray();   
    // base64 encoding characters 
    
    static 
    
    final 
    
    char b64[] = 
    { 
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'I',
    'J',
    'K',
    'L',
    'M', 
    'N',
    'O',
    'P',
    'Q',
    'R',
    'S',
    'T',
    'U',
    'V',
    'W',
    'X',
    'Y',
    'Z', 
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l',
    'm', 
    'n',
    'o',
    'p',
    'q',
    'r',
    's',
    't',
    'u',
    'v',
    'w',
    'x',
    'y',
    'z', 
    '0',
    '1',
    '2',
    '3',
    '4',
    '5',
    '6',
    '7',
    '8',
    '9',
    '+',
    '/' 
    }; 
    
    static 
    
    final 
    
    char pad = 
    '=';   
    // strb64 = base64(B[]) ByteArrayOutputStream bos2 = 
    
    new ByteArrayOutputStream(); 
    
    int i; 
    
    for(i=0; i<B.length-2; i+=3) 
    { bos2.write(b64[  ((
    
    int)B[i+0]&0xFF)      >>2 ]); bos2.write(b64[((((
    
    int)B[i+0]&0xFF)&0x03)<<4) | (((
    
    int)B[i+1]&0xFF)      >>4)]); bos2.write(b64[((((
    
    int)B[i+1]&0xFF)&0x0F)<<2) | (((
    
    int)B[i+2]&0xFF)      >>6)]); bos2.write(b64[  ((
    
    int)B[i+2]&0xFF)&0x3F     ]); 
    } 
    
    if (i < B.length) 
    { bos2.write(b64[  ((
    
    int)B[i+0]&0xFF)      >>2 ]);   
    
    if (i+2 == B.length) 
    { bos2.write(b64[((((
    
    int)B[i+0]&0xFF)&0x03)<<4) | (((
    
    int)B[i+1]&0xFF)      >>4)]); bos2.write(b64[((((
    
    int)B[i+1]&0xFF)&0x0F)<<2)]); 
    } 
    
    else 
    { bos2.write(b64[((((
    
    int)B[i+0]&0xFF)&0x03)<<4)]); bos2.write(pad); 
    } bos2.write(pad); 
    } bos2.close();   String strb64 = bos2.toString(); ...
    


    It was surprising to me that Java does provide gzip-capabilities, but does not support base64 encoding ...
    And dealing with byte indexes was not that easy because Java byte type is signed.

    Find here previous sample processed by Java client:
    
    $ java coproc2 2hex.xsl some.xml http:
    //dp3-l3.boeblingen.de.ibm.com:2223 74657374 $
    


    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T00:49:15Z  
    • HermannSW
    • ‏2011-03-07T00:36:03Z
    Just before posting coproc2 service I thought on a client for Windows environments without cygwin.
    And because the shell script made use of curl, gzip, base64 and sed commands, I tried to come up with a single file solution.

    It turned out that SOAPClient4XG from 2001 developerWorks article A simple SOAP client was pretty close.
    It is a Java client capable of sending SOAP requests and receiving and displaying the corresponding response.

    I just needed to add the base64 encoded gzipped stylesheet as "xsl" HTTP header.

    This is the main addition to SOAPClient4XG I did (from attached complete coproc2.java):
    <pre class="jive-pre"> ... // Read stylesheet2send into b2[] InputStream fin2 = new FileInputStream(stylesheet2Send); ByteArrayOutputStream bout2 = new ByteArrayOutputStream(); copy(fin2,bout2); fin2.close(); byte b2[] = bout2.toByteArray(); // B[] = gzip(b2[]) ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gz = new GZIPOutputStream(bos); gz.write(b2); gz.close(); bos.close(); byte B[] = bos.toByteArray(); // base64 encoding characters static final char b64[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; static final char pad = '='; // strb64 = base64(B[]) ByteArrayOutputStream bos2 = new ByteArrayOutputStream(); int i; for(i=0; i<B.length-2; i+=3) { bos2.write(b64[ (( int)B[i+0]&0xFF) >>2 ]); bos2.write(b64[(((( int)B[i+0]&0xFF)&0x03)<<4) | ((( int)B[i+1]&0xFF) >>4)]); bos2.write(b64[(((( int)B[i+1]&0xFF)&0x0F)<<2) | ((( int)B[i+2]&0xFF) >>6)]); bos2.write(b64[ (( int)B[i+2]&0xFF)&0x3F ]); } if (i < B.length) { bos2.write(b64[ (( int)B[i+0]&0xFF) >>2 ]); if (i+2 == B.length) { bos2.write(b64[(((( int)B[i+0]&0xFF)&0x03)<<4) | ((( int)B[i+1]&0xFF) >>4)]); bos2.write(b64[(((( int)B[i+1]&0xFF)&0x0F)<<2)]); } else { bos2.write(b64[(((( int)B[i+0]&0xFF)&0x03)<<4)]); bos2.write(pad); } bos2.write(pad); } bos2.close(); String strb64 = bos2.toString(); ... </pre>

    It was surprising to me that Java does provide gzip-capabilities, but does not support base64 encoding ...
    And dealing with byte indexes was not that easy because Java byte type is signed.

    Find here previous sample processed by Java client:
    <pre class="jive-pre"> $ java coproc2 2hex.xsl some.xml http: //dp3-l3.boeblingen.de.ibm.com:2223 74657374 $ </pre>

    Hermann<myXsltBlog/>
    Some words on the efficient DataPower SHA1 stylesheet caching.

    When sending a stylesheet for the first time to DataPower with one of the clients, it gets compiled and put into stylesheet cache.
    You may see this by first log entry at "information" level logging:
    
    mpgw (coproc2): rule (coproc2_rule_1): #1 xform: 
    'Transforming NULL with local:///coproc2.xsl results stored in NULL' completed OK.
    

    Second log entry:
    
    xmlmgr (
    
    default): xslt Compilation Request: Compilation complete of URL xa35:
    //tmp/temp_01442
    


    Now if the same stylesheet is received, DataPower computes the SHA1 value of it, detects the cached version and uses that without compilation.
    First log entry:
    
    mpgw (coproc2): rule (coproc2_rule_1): #1 xform: 
    'Transforming NULL with local:///coproc2.xsl results stored in NULL' completed OK.
    

    Second log entry:
    
    xmlmgr (
    
    default): xa35:
    //tmp/temp_01458 has identical SHA1 hash to xa35://tmp/temp_01131; using cached version.
    


    Because of the SHA1 stylesheet cache coproc2 service is pretty performant.

    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T02:12:45Z  
    • HermannSW
    • ‏2011-03-07T00:49:15Z
    Some words on the efficient DataPower SHA1 stylesheet caching.

    When sending a stylesheet for the first time to DataPower with one of the clients, it gets compiled and put into stylesheet cache.
    You may see this by first log entry at "information" level logging:
    <pre class="jive-pre"> mpgw (coproc2): rule (coproc2_rule_1): #1 xform: 'Transforming NULL with local:///coproc2.xsl results stored in NULL' completed OK. </pre>
    Second log entry:
    <pre class="jive-pre"> xmlmgr ( default): xslt Compilation Request: Compilation complete of URL xa35: //tmp/temp_01442 </pre>

    Now if the same stylesheet is received, DataPower computes the SHA1 value of it, detects the cached version and uses that without compilation.
    First log entry:
    <pre class="jive-pre"> mpgw (coproc2): rule (coproc2_rule_1): #1 xform: 'Transforming NULL with local:///coproc2.xsl results stored in NULL' completed OK. </pre>
    Second log entry:
    <pre class="jive-pre"> xmlmgr ( default): xa35: //tmp/temp_01458 has identical SHA1 hash to xa35://tmp/temp_01131; using cached version. </pre>

    Because of the SHA1 stylesheet cache coproc2 service is pretty performant.

    Hermann<myXsltBlog/>
    Oops!

    After rearranging the source before posting I did work with 1.6 JDK only.
    Above attached coproc2.java does not compile with 1.4 and 1.5 JDK.

    Just removing "static" makes it compile and work for 1.4 and 1.5 JDK.
    74c74
    <     static final char b64[] = {
    ---
    >     final char b64[] = {
    81c81
    <     static final char pad = '=';
    ---
    >     final char pad = '=';
    

    Hermann <myXsltBlog/>
    Updated on 2014-03-25T03:33:57Z at 2014-03-25T03:33:57Z by iron-man
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-07T02:31:39Z  
    • HermannSW
    • ‏2011-03-07T02:12:45Z
    Oops!

    After rearranging the source before posting I did work with 1.6 JDK only.
    Above attached coproc2.java does not compile with 1.4 and 1.5 JDK.

    Just removing "static" makes it compile and work for 1.4 and 1.5 JDK.
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">74c74 < static final char b64[] = { --- > final char b64[] = { 81c81 < static final char pad = '='; --- > final char pad = '='; </pre>
    Hermann <myXsltBlog/>
    Combined screenshot of Linux/Cygwin/Windows coproc2 executions:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc210
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-10T11:08:40Z  
    • HermannSW
    • ‏2011-03-07T02:31:39Z
    Combined screenshot of Linux/Cygwin/Windows coproc2 executions:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc210
    Hermann<myXsltBlog/>
    Posting "xs:decimal()" may be interesting as it shows that having more than one coproc2 service may
    make sense if needing different XML Manager settings for execution ("XSLT 2.0" in posting):
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/xs_decimal19?lang=en

    That means "coproc2 stylesheet xmlfile coproc2endpoint" really allows for changing all three arguments.
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: coproc2

    ‏2011-03-16T15:02:05Z  
    • HermannSW
    • ‏2011-03-10T11:08:40Z
    Posting "xs:decimal()" may be interesting as it shows that having more than one coproc2 service may
    make sense if needing different XML Manager settings for execution ("XSLT 2.0" in posting):
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/xs_decimal19?lang=en

    That means "coproc2 stylesheet xmlfile coproc2endpoint" really allows for changing all three arguments.
    Hermann<myXsltBlog/>
    Hermann,

    Do we have to install/add any components to cygwin, in case we want to use gzip, base64 and sed commands. If so, could you please share any links.I will try with the java client as well, that you have mentioned. This can save a lot of time during development activities.
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-16T15:56:38Z  
    • Jaango
    • ‏2011-03-16T15:02:05Z
    Hermann,

    Do we have to install/add any components to cygwin, in case we want to use gzip, base64 and sed commands. If so, could you please share any links.I will try with the java client as well, that you have mentioned. This can save a lot of time during development activities.
    Maneesh,

    > Do we have to install/add any components to cygwin, in case we want to use gzip, base64 and sed commands.
    > If so, could you please share any links.
    I think gzip, base64 and sed commands are part of basic cygwin setup.
    If not just start setup again, select any download server, and when seeing the package selection screen just type in eg. "base64" in search field.
    This will display only those packages where "base64" is contained.
    Open any of these, change "base64" from "Skip" to "install" and then finish install.

    In case of trouble you may execute these commands and compare with my outputs:
    $ which coproc2
    ~/bin/coproc2
    $ which curl
    /usr/bin/curl
    $ which gzip
    /usr/bin/gzip
    $ which base64
    /usr/bin/base64
    $ which sed
    /bin/sed
    $
    


    But the easiest solution is to use the Java client as that contains everything and is functionally equivalent.
    (This was the reason that I decided to implement base64 encoding myself instead of using available but separately to install packages)

    > I will try with the java client as well, that you have mentioned. This can save a lot of time during development activities.
    Yes!

     
    Hermann <myXsltBlog/>
    Updated on 2014-03-25T03:33:53Z at 2014-03-25T03:33:53Z by iron-man
  • Jaango
    Jaango
    267 Posts

    Re: coproc2

    ‏2011-03-16T16:33:28Z  
    • Jaango
    • ‏2011-03-16T15:02:05Z
    Hermann,

    Do we have to install/add any components to cygwin, in case we want to use gzip, base64 and sed commands. If so, could you please share any links.I will try with the java client as well, that you have mentioned. This can save a lot of time during development activities.
    Hi Hermann,

    I am not sure why I am getting the below error. Do u have any thoughts. I used command prompt and placed all the files including coproc2.java in D:drive and got the below.

    D:\>java coproc2 2hex.xsl some.xml http://boxname:2223
    Exception in thread "main" java.lang.NoClassDefFoundError: coproc2
    Caused by: java.lang.ClassNotFoundException: coproc2
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: coproc2. Program will exit.
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-16T17:33:35Z  
    • Jaango
    • ‏2011-03-16T16:33:28Z
    Hi Hermann,

    I am not sure why I am getting the below error. Do u have any thoughts. I used command prompt and placed all the files including coproc2.java in D:drive and got the below.

    D:\>java coproc2 2hex.xsl some.xml http://boxname:2223
    Exception in thread "main" java.lang.NoClassDefFoundError: coproc2
    Caused by: java.lang.ClassNotFoundException: coproc2
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: coproc2. Program will exit.
    Maneesh,

    is coproc2.class present in "D:\" ?
    (if not, do javac coproc2.java there first)

     
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: coproc2

    ‏2011-03-17T12:22:43Z  
    • HermannSW
    • ‏2011-03-16T17:33:35Z
    Maneesh,

    is coproc2.class present in "D:\" ?
    (if not, do javac coproc2.java there first)

     
    Hermann<myXsltBlog/>
    Perfect,

    Thanks Hermann.
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-28T18:16:33Z  
    "coproc2 again -- integration in Eclipse"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc2_again_integration_in_eclipse44

    (you can get the screenshots in big by clicking on the small ones)

     
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: coproc2

    ‏2011-03-29T08:31:56Z  
    • HermannSW
    • ‏2011-03-28T18:16:33Z
    "coproc2 again -- integration in Eclipse"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc2_again_integration_in_eclipse44

    (you can get the screenshots in big by clicking on the small ones)

     
    Hermann<myXsltBlog/>
    Hermann,

    Thanks. The features look very useful during the development activities. Just curious, is there a way to see line by line debug option, where we can see the values of the variables, available with this?
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2

    ‏2011-03-29T17:30:47Z  
    • Jaango
    • ‏2011-03-29T08:31:56Z
    Hermann,

    Thanks. The features look very useful during the development activities. Just curious, is there a way to see line by line debug option, where we can see the values of the variables, available with this?
    > Thanks. The features look very useful during the development activities.
    > Just curious, is there a way to see line by line debug option, where we can see the values of the variables, available with this?
    Not with coproc2 as it just sends XSLT+XML to DataPower box and gets response back.

    But perhaps you may be interested in "Stylesheet Tracing" on DataPower?
    http://www-01.ibm.com/support/docview.wss?uid=swg27019118&aid=1#page=6

     
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: coproc2

    ‏2011-03-31T10:33:12Z  
    • HermannSW
    • ‏2011-03-29T17:30:47Z
    > Thanks. The features look very useful during the development activities.
    > Just curious, is there a way to see line by line debug option, where we can see the values of the variables, available with this?
    Not with coproc2 as it just sends XSLT+XML to DataPower box and gets response back.

    But perhaps you may be interested in "Stylesheet Tracing" on DataPower?
    http://www-01.ibm.com/support/docview.wss?uid=swg27019118&aid=1#page=6

     
    Hermann<myXsltBlog/>
    Hermann,

    Thanks. This is excatly what I was looking for. However I am not sure which page in the webgui to go for getting the http trace output. Can you please help me. I configured a matching rule at the debug level for the xmlmanager.
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2 [v1.2 available]

    ‏2011-05-28T01:04:07Z  
    Hello,

    I was asked on the latest status of coproc2.

    coproc2 DataPower service attached to initial posting of this thread
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14590913#14590913
    is still current -- there was no need to change anything since then.

    Early march posting "xs:decimal()"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/xs_decimal19
    discussed modying the XML manager of DataPower coproc2 service.

    End of march posting "coproc2 again -- integration in Eclipse"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc2_again_integration_in_eclipse44
    showed how to make use of coproc2.java in Eclipse.

    April 1st posting
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/april_1_2011_5_15_pm14
    screenshot did show output of HTTP response code as well as HTTP response headers.
    I did not post that version of coproc2.java until now.

    After that related posting "webDataPower"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/webdatapower19
    showed a solution of sending a stylesheet and XML file to DataPower for execution as coproc2 does.
    The difference is that webDataPower does it from within a browser form.

    So today I post new version 1.2 of coproc2.java (attached).
    Find the version feature description in its header:
    
    /** * coproc2 * - send stylesheet and xmlfile to a DataPower appliance; * - display DataPower result of applying stylesheet to xmlfile. * * Modification of SOAPClient4XG from this article: * http://www.ibm.com/developerworks/xml/library/x-soapcl/ * * Added sending of base64(gzip(stylesheet2Send)) as HTTP header. * * 1.1: * Removed "static" from final variables b64[] and pad for JDK 1.4 and 1.5 * * 1.2: * Fixed reading of response in case of HTTP errors, from here: * http://stackoverflow.com/questions/613307/read-error-response-body-in-java/2092749#2092749 * * Allowed '-' as xmlFile2Send to read from standard input. * * Added optional verbose option for output of response HTTP headers. * * if (not verbose) { *   if (HTTP response code >= 400) output it  [error] * } else { *   output HTTP response code *   output HTTP response headers * } * * * @author  Hermann Stamm-Wilbrandt * @version 1.2 * @param   stylesheet2Send  stylesheet to be executed on DataPower * @param   xmlFile2Send     xmlfile sent to DataPower (or '-' for standard input) * @param   url              URL of coproc2 Endpoint on DataPower * @param   [-v]             optional, do verbose output */
    


    All postings tagged with coproc2:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/tags/coproc2

     
    Hermann<myXsltBlog/>
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2 [v1.2 available]

    ‏2011-05-28T01:49:26Z  
    • HermannSW
    • ‏2011-05-28T01:04:07Z
    Hello,

    I was asked on the latest status of coproc2.

    coproc2 DataPower service attached to initial posting of this thread
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14590913#14590913
    is still current -- there was no need to change anything since then.

    Early march posting "xs:decimal()"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/xs_decimal19
    discussed modying the XML manager of DataPower coproc2 service.

    End of march posting "coproc2 again -- integration in Eclipse"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/coproc2_again_integration_in_eclipse44
    showed how to make use of coproc2.java in Eclipse.

    April 1st posting
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/april_1_2011_5_15_pm14
    screenshot did show output of HTTP response code as well as HTTP response headers.
    I did not post that version of coproc2.java until now.

    After that related posting "webDataPower"
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/webdatapower19
    showed a solution of sending a stylesheet and XML file to DataPower for execution as coproc2 does.
    The difference is that webDataPower does it from within a browser form.

    So today I post new version 1.2 of coproc2.java (attached).
    Find the version feature description in its header:
    <pre class="jive-pre"> /** * coproc2 * - send stylesheet and xmlfile to a DataPower appliance; * - display DataPower result of applying stylesheet to xmlfile. * * Modification of SOAPClient4XG from this article: * http://www.ibm.com/developerworks/xml/library/x-soapcl/ * * Added sending of base64(gzip(stylesheet2Send)) as HTTP header. * * 1.1: * Removed "static" from final variables b64[] and pad for JDK 1.4 and 1.5 * * 1.2: * Fixed reading of response in case of HTTP errors, from here: * http://stackoverflow.com/questions/613307/read-error-response-body-in-java/2092749#2092749 * * Allowed '-' as xmlFile2Send to read from standard input. * * Added optional verbose option for output of response HTTP headers. * * if (not verbose) { * if (HTTP response code >= 400) output it [error] * } else { * output HTTP response code * output HTTP response headers * } * * * @author Hermann Stamm-Wilbrandt * @version 1.2 * @param stylesheet2Send stylesheet to be executed on DataPower * @param xmlFile2Send xmlfile sent to DataPower (or '-' for standard input) * @param url URL of coproc2 Endpoint on DataPower * @param [-v] optional, do verbose output */ </pre>

    All postings tagged with coproc2:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/tags/coproc2

     
    Hermann<myXsltBlog/>

    new features demonstration


    Let me demonstrate the new features by this stylesheet (also attached):
    
    $ cat reject.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <xsl:output omit-xml-declaration=
    "yes" />   <xsl:template match=
    "/"> <dp:set-variable name=
    "'var://service/error-protocol-response'" value=
    "." /> <dp:reject>reject with error-protocol-response</dp:reject> </xsl:template>   </xsl:stylesheet> $
    


    So we will use standard input to provide the XML file to process by selecting '-'.
    The input data will be taken by above stylesheet as HTTP code to return after reject.

    without new verbose mode.


    If HTTP response code is not an error code (<400) then only the normal response is given:
    
    $ echo 
    "<code>200</code>" | \ > java coproc2 reject.xsl - http:
    //dp3-l3:2223  <?xml version=
    "1.0" encoding=
    "UTF-8"?> <env:Envelope xmlns:env=
    "http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>env:Client</faultcode><faultstring>reject with error-protocol-response (from client)</faultstring></env:Fault></env:Body></env:Envelope> $
    


    If HTTP response code is an error code (>=400) it is appended as XML comment to the normal response (this circumvents the problem of forbidden preceding of xml declaration):
    
    $ echo 
    "<code>418</code>" | \ > java coproc2 reject.xsl - http:
    //dp3-l3:2223  <?xml version=
    "1.0" encoding=
    "UTF-8"?> <env:Envelope xmlns:env=
    "http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>env:Client</faultcode><faultstring>reject with error-protocol-response (from client)</faultstring></env:Fault></env:Body></env:Envelope> <!-- HTTP response: 418 Error --> $
    


    new verbose mode.


    In verbose mode always the HTTP response code is appended to normal response, together with all HTTP response headers:
    
    $ echo 
    "<code>200</code>" | \ > java coproc2 reject.xsl - http:
    //dp3-l3:2223 -v <?xml version=
    "1.0" encoding=
    "UTF-8"?> <env:Envelope xmlns:env=
    "http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>env:Client</faultcode><faultstring>reject with error-protocol-response (from client)</faultstring></env:Fault></env:Body></env:Envelope> <!-- HTTP/1.1 200 Error Content-Type: text/xml Connection: close X-Backside-Transport: FAIL FAIL --> $
    


    standard input XML data


    Being able to process XML data from standard input opens up a whole new range of applications.

    See for example posting "Nice combination of xpath++ and doSoma tools for querying AdminState and OpState of MQ FSHs":
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/nice_combination_of_xpath_and_dosoma_tools_for_querying_adminstate_and_opstate_of_mq_fshs

    There the output of a XML management call was further processed by xpath++ tool.
    The power of a stylesheet is much bigger than pure XPath statements.
    See the same XML management output nicely formatted by stylesheet ObjectStatus.xsl and executed by coproc2.java:
    
    $ doSoma admin ObjectStatus.xml dp3-l3:5550 | \ > java coproc2 ObjectStatus.xsl - http:
    //dp3-l3:2223 Enter host password 
    
    for user 
    'admin': Name......AdminState..OpState ----------------------------- MQ_FSH_1..disabled....down.... MQ_FSW_2..enabled.....down.... $ $ cat ObjectStatus.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:str=
    "http://exslt.org/strings" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <xsl:output method=
    "text" /> <xsl:template match=
    "text()"/>   <xsl:template match=
    "*"> <xsl:value-of select=
    "str:align(Name, '..........', 'left')" /> <xsl:value-of select=
    "str:align(AdminState, '............', 'left')" /> <xsl:value-of select=
    "str:align(OpState, '........', 'left')" /> <xsl:text>
    </xsl:text> </xsl:template> <xsl:template match=
    "/"> <xsl:text>Name......AdminState..OpState&​#10;</xsl:text> <xsl:text>-----------------------------&​#10;</xsl:text> <xsl:apply-templates select=
    "//ObjectStatus[Class='MQSourceProtocolHandler']"/> </xsl:template> </xsl:stylesheet> $
    


    Hermann<myXsltBlog/>

    Attachments

  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2 / coproc2nonxml

    ‏2011-10-04T13:17:39Z  
    The coproc2 client ("coproc2" bash script as well as "coproc2.java") is able to send Non-XML data,
    but the coproc2 service attached at top of this thread is not able to deal with that.

    Find service coproc2nonxml attached to this posting:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14676613#14675883

    The only changes to coproc2 service are:
    • Non-XML request type
    • "Transform Binary" action instead of "Transform" action
    • listening on port 2224 instead of port 2223
    (input INPUT, output OUTPUT and transform in context "xsl" as before)

    It allows to process Non-XML data in binary-transform stylesheets.
    And even more, it allows for chaining Non-XML and XML transformations by pipelining coproc2 calls against the different endpoints!
    See the sample discussed in the posting.

    $ coproc2 ampify.xsl 412.html http://dp3-l3:2224 | coproc2 body2Extract.xsl - http://dp3-l3:2223
    


     
    Hermann <myXsltBlog/>
    Updated on 2014-03-25T03:09:35Z at 2014-03-25T03:09:35Z by iron-man
  • Jaango
    Jaango
    267 Posts

    Re: coproc2 / coproc2nonxml

    ‏2011-10-10T07:59:56Z  
    • HermannSW
    • ‏2011-10-04T13:17:39Z
    The coproc2 client ("coproc2" bash script as well as "coproc2.java") is able to send Non-XML data,
    but the coproc2 service attached at top of this thread is not able to deal with that.

    Find service coproc2nonxml attached to this posting:
    https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14676613#14675883

    The only changes to coproc2 service are:
    • Non-XML request type
    • "Transform Binary" action instead of "Transform" action
    • listening on port 2224 instead of port 2223
    (input INPUT, output OUTPUT and transform in context "xsl" as before)

    It allows to process Non-XML data in binary-transform stylesheets.
    And even more, it allows for chaining Non-XML and XML transformations by pipelining coproc2 calls against the different endpoints!
    See the sample discussed in the posting.

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ coproc2 ampify.xsl 412.html http://dp3-l3:2224 | coproc2 body2Extract.xsl - http://dp3-l3:2223 </pre>

     
    Hermann <myXsltBlog/>
    Hi,
    Is there a way to get the size of the input, in non xml format, using xsl?In WTX we have the SIZE() function. For example in the attached file, 41, the size of file is 1 byte/character.

    Attachments

  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2 / coproc2nonxml

    ‏2011-10-10T16:37:51Z  
    • Jaango
    • ‏2011-10-10T07:59:56Z
    Hi,
    Is there a way to get the size of the input, in non xml format, using xsl?In WTX we have the SIZE() function. For example in the attached file, 41, the size of file is 1 byte/character.
    Hi Maneesh,
    >
    > Is there a way to get the size of the input, in non xml format, using xsl?
    > In WTX we have the SIZE() function. For example in the attached file, 41, the size of file is 1 byte/character.
    >
    OK, so your input is zip-archive 41.zip.
    And you want the size of file "41" in that archive (which is 1):
    
    $ unzip -l 41.zip Archive:  41.zip Length     Date   Time    Name --------    ----   ----    ---- 1  01-18-11 13:17   41 --------                   ------- 1                   1 file $ ls -l 41.zip -rw-rw-r-- 1 stammw stammw 103 Oct 10 17:59 41.zip $
    


    I will give the 2nd WSTE webcast on "Non-XML data processing in DataPower stylesheets" this Thursday.
    The presentation is already online, slide 19 shows "makeSwa" solution I used to create unzip-l.xsl from it:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=1#page=19
    Stylesheet unzip-l.xsl does the same as "unzip -l" command (giving you access to all information):
    
    $ coproc2 unzip-l.xsl 41.zip http:
    //dp3-l3:2224 -s | tidy -q -xml <attachment> <uri>cid:myZip</uri> <size>103</size> <header> <name>Content-ID</name> <value><myZip></value> </header> <header> <name>Content-Transfer-Encoding</name> <value>binary</value> </header> <header> <name>Content-Type</name> <value>application/zip</value> </header> <files> <file> <filename>41</filename> <size>1</size> </file> </files> </attachment>   $
    

    Stylesheet unzip-l.xsl (also attached):
    
    <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output omit-xml-declaration=
    "yes"/>   <xsl:template match=
    "/"> <!-- a SOAP message --> <xsl:variable name=
    "dummy"> <env:Envelope xmlns:env=
    "http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <dummySOAPnode/> </env:Body> </env:Envelope> </xsl:variable>     <!-- create context 
    "swa" with that SOAP message --> <dp:set-variable name=
    "'var://context/swa'" value=
    "$dummy" />   <!-- set Content-Type --> <dp:set-http-request-header name=
    "'Content-Type'" value=
    "'application/soap+xml'" />   <!-- attach zip-archive to context 
    "swa" (
    "myZip" Content-ID) --> <dp:url-open target=
    "attachment://swa/cid:myZip" data-type=
    "base64" response=
    "ignore" content-type=
    "application/zip" > <xsl:value-of select=
    "dp:binary-encode(/object/message/node())" /> </dp:url-open>     <!-- output context swa
    's attachment manifest (only) attachment --> <xsl:copy-of select=
    "dp:variable('var://context/swa/attachment-manifest')/ manifest/attachments/attachment
    "/> </xsl:template>   </xsl:stylesheet>
    


    And this is the output of applying unzip-l.zip to a zip-archive containing more files and directory structure!
    
    $ coproc2 unzip-l.xsl coproc2.zip http:
    //dp3-l3:2224 -s | tidy -q -xml <attachment> <uri>cid:myZip</uri> <size>409705</size> <header> <name>Content-ID</name> <value><myZip></value> </header> <header> <name>Content-Transfer-Encoding</name> <value>binary</value> </header> <header> <name>Content-Type</name> <value>application/zip</value> </header> <files> <file> <filename>export.xml</filename> <size>11288</size> </file> <file> <filename>local/</filename> <size>0</size> </file> <file> <filename>local/coproc2.xsl</filename> <size>642</size> </file> <file> <filename>dp-aux/</filename> <size>0</size> </file> <file> <filename>dp-aux/clixform.xsl</filename> <size>200647</size> </file> <file> <filename>dp-aux/SchemaUtil.xsl</filename> <size>20520</size> </file> <file> <filename>dp-aux/management.xsl</filename> <size>7101</size> </file> <file> <filename>dp-aux/map-dmz.xsl</filename> <size>5684</size> </file> <file> <filename>dp-aux/drMgmt.xml</filename> <size>2997463</size> </file> <file> <filename>dp-aux/basetypes.xml</filename> <size>6819</size> </file> </files> </attachment>   $
    


     
    Hermann<myXsltBlog/>
  • Jaango
    Jaango
    267 Posts

    Re: coproc2 / coproc2nonxml

    ‏2011-10-11T09:14:29Z  
    • HermannSW
    • ‏2011-10-10T16:37:51Z
    Hi Maneesh,
    >
    > Is there a way to get the size of the input, in non xml format, using xsl?
    > In WTX we have the SIZE() function. For example in the attached file, 41, the size of file is 1 byte/character.
    >
    OK, so your input is zip-archive 41.zip.
    And you want the size of file "41" in that archive (which is 1):
    <pre class="jive-pre"> $ unzip -l 41.zip Archive: 41.zip Length Date Time Name -------- ---- ---- ---- 1 01-18-11 13:17 41 -------- ------- 1 1 file $ ls -l 41.zip -rw-rw-r-- 1 stammw stammw 103 Oct 10 17:59 41.zip $ </pre>

    I will give the 2nd WSTE webcast on "Non-XML data processing in DataPower stylesheets" this Thursday.
    The presentation is already online, slide 19 shows "makeSwa" solution I used to create unzip-l.xsl from it:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=1#page=19
    Stylesheet unzip-l.xsl does the same as "unzip -l" command (giving you access to all information):
    <pre class="jive-pre"> $ coproc2 unzip-l.xsl 41.zip http: //dp3-l3:2224 -s | tidy -q -xml <attachment> <uri>cid:myZip</uri> <size>103</size> <header> <name>Content-ID</name> <value><myZip></value> </header> <header> <name>Content-Transfer-Encoding</name> <value>binary</value> </header> <header> <name>Content-Type</name> <value>application/zip</value> </header> <files> <file> <filename>41</filename> <size>1</size> </file> </files> </attachment> $ </pre>
    Stylesheet unzip-l.xsl (also attached):
    <pre class="jive-pre"> <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" > <dp:input-mapping href= "store:///pkcs7-convert-input.ffd" type= "ffd"/> <xsl:output omit-xml-declaration= "yes"/> <xsl:template match= "/"> <!-- a SOAP message --> <xsl:variable name= "dummy"> <env:Envelope xmlns:env= "http://schemas.xmlsoap.org/soap/envelope/"> <env:Body> <dummySOAPnode/> </env:Body> </env:Envelope> </xsl:variable> <!-- create context "swa" with that SOAP message --> <dp:set-variable name= "'var://context/swa'" value= "$dummy" /> <!-- set Content-Type --> <dp:set-http-request-header name= "'Content-Type'" value= "'application/soap+xml'" /> <!-- attach zip-archive to context "swa" ( "myZip" Content-ID) --> <dp:url-open target= "attachment://swa/cid:myZip" data-type= "base64" response= "ignore" content-type= "application/zip" > <xsl:value-of select= "dp:binary-encode(/object/message/node())" /> </dp:url-open> <!-- output context swa 's attachment manifest (only) attachment --> <xsl:copy-of select= "dp:variable('var://context/swa/attachment-manifest')/ manifest/attachments/attachment "/> </xsl:template> </xsl:stylesheet> </pre>

    And this is the output of applying unzip-l.zip to a zip-archive containing more files and directory structure!
    <pre class="jive-pre"> $ coproc2 unzip-l.xsl coproc2.zip http: //dp3-l3:2224 -s | tidy -q -xml <attachment> <uri>cid:myZip</uri> <size>409705</size> <header> <name>Content-ID</name> <value><myZip></value> </header> <header> <name>Content-Transfer-Encoding</name> <value>binary</value> </header> <header> <name>Content-Type</name> <value>application/zip</value> </header> <files> <file> <filename>export.xml</filename> <size>11288</size> </file> <file> <filename>local/</filename> <size>0</size> </file> <file> <filename>local/coproc2.xsl</filename> <size>642</size> </file> <file> <filename>dp-aux/</filename> <size>0</size> </file> <file> <filename>dp-aux/clixform.xsl</filename> <size>200647</size> </file> <file> <filename>dp-aux/SchemaUtil.xsl</filename> <size>20520</size> </file> <file> <filename>dp-aux/management.xsl</filename> <size>7101</size> </file> <file> <filename>dp-aux/map-dmz.xsl</filename> <size>5684</size> </file> <file> <filename>dp-aux/drMgmt.xml</filename> <size>2997463</size> </file> <file> <filename>dp-aux/basetypes.xml</filename> <size>6819</size> </file> </files> </attachment> $ </pre>

     
    Hermann<myXsltBlog/>
    Hermann,

    Thanks. Can we also count the number of characters(in the attached text file, it is 412 characters/bytes) for text files, using a non xml, xsl transformation?
  • HermannSW
    HermannSW
    4654 Posts

    Re: coproc2 / coproc2nonxml

    ‏2011-10-11T10:10:10Z  
    • Jaango
    • ‏2011-10-11T09:14:29Z
    Hermann,

    Thanks. Can we also count the number of characters(in the attached text file, it is 412 characters/bytes) for text files, using a non xml, xsl transformation?
    Hi Maneesh,
    >
    > Thanks. Can we also count the number of characters(in the attached text file, it is 412 characters/bytes) for text files, using a non xml, xsl transformation?
    >
    Yes.

    Depending on the frontside handler you may get the request size from 'var://service/mpgw/request-size' (eg. for HTTP).

    So there is an easy solution, and a nice solution when the variable does not get populated (will be 0 for eg. MQ FSH).

    First the easy solution (read request-size variable):
    
    $ ls -l filename.txt -rw-rw-r-- 1 stammw stammw 412 Oct 11 11:51 filename.txt $ $ coproc2 request-size.xsl filename.txt http:
    //dp3-l3:2224; echo 412 $ $ cat request-size.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:value-of select=
    "dp:variable('var://service/mpgw/request-size')"/> </xsl:template> </xsl:stylesheet> $
    

    And here the nice solution making used of func:base64-length():
    
    $ coproc2 req-size.xsl filename.txt http:
    //dp3-l3:2224; echo 412 $ $ cat req-size.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:func=
    "http://exslt.org/functions" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:copy-of select=
    "func:base64-length(dp:binary-encode(/object/message/node()))"/> </xsl:template> <!-- 
    
    return length of decoded base64 string $bytes (string-length replacement) --> <func:function name=
    "func:base64-length"> <xsl:param name=
    "bytes"/>   <xsl:choose> <xsl:when test=
    "contains($bytes,'==')"> <func:result select=
    "(string-length($bytes) div 4) * 3 - 2"/> </xsl:when> <xsl:when test=
    "contains($bytes,'=')"> <func:result select=
    "(string-length($bytes) div 4) * 3 - 1"/> </xsl:when> <xsl:otherwise> <func:result select=
    "(string-length($bytes) div 4) * 3"/> </xsl:otherwise> </xsl:choose> </func:function>   </xsl:stylesheet>   $
    


     
    Hermann<myXsltBlog/>