Topic
10 replies Latest Post - ‏2013-03-11T10:01:54Z by Jaango
HermannSW
HermannSW
4155 Posts
ACCEPTED ANSWER

Pinned topic coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

‏2011-08-15T07:29:04Z |
Hello,

today I want to post coproc2swa, another client for coproc2 service (for Linux or Cygwin under Windows):
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/tags/coproc2

This new (bash script) client is able to deal with SWA (Soap With Attachment) data, both for sending to coproc2 service
as well as for just inspecting the different parts of a SWA file by its -preamble, -print or -epilogue commands.

Because of the special crafting as all-in-one solution these two warnings are unavoidable:
  • MIME conformance violation: 7bit/8bit LF without CR (continuing) (CRLF line endings in preamble bash script do not work)
  • MIME conformance violation: 7bit/8bit line too long (continuing) (coproc2swa.pgm picture attachment is longer than the 998 bytes allowed by spec)

But let the tool speak for itself on what it does by its -preamble command "applied to itself":
(just the big comment at the top, you can skip the bash script and continue with next comment for samples)

$ coproc2swa cid:attman.xsl ~/bin/coproc2swa -preamble #!/bin/bash # # coproc2swa is another client 

for coproc2 service # - it allows to process SWA (Soap With Attachments) data # # $ coproc2swa stylesheet|CIDref SWAfile [command|endpoint [curl options]] #   (command is any of -print, -preamble or -epilogue) # # # You have to enable attachment processing 

for coproc2 service first # - open coproc2 in 
"Objects > Service Configuration > Multi-Protocol Gateway" # - 

switch to 
"Proxy Settings" tab # - set 
"Request attachment processing mode" to 
"Allow", then 
"Apply" # (

if you save the config now you have to 

do 

this once only) # # Attachment manifest is available in 
"local/attachment-manifest" variable. # # # This file is an all-in-one solution in that it # # 1) is the coproc2swa client 

for processing SWA data with coproc2 service #    (
"bash" script, in 
"preamble") # # 2) is a SWA file itself(!) and can be used as sample input # # 3) allows to inspect SWAfile by -preamble/-epilogue/-print (cids) # # 4) contains four demo stylesheets which may be referenced by 
"cid..." # #    attman.xsl #    - accessing attachment manifest and content-types # #    pgm1st.xsl #    - output first 
"image/x-portable-greymap" attachment (binary data!) # #    xml1st.xsl #    - output first 
"text/xml" attachment # #    zipit.xsl #    - 

return zip of all 
"text/xml" and 
"image/x-portable-greymap" attachments # # # these are the non-bash commands used in 

this script # - base64, curl, cut, echo, grep, gzip, head, tac, tail, sed, wc, zcat #   usage=
"coproc2swa stylesheet|CIDref SWAfile [command|endpoint [curl options]]\n (command is any of -print, -preamble or -epilogue)
"   # usage 

if [ 
"$2" = 
'' ]; then echo -e $usage exit fi     # determine SWA boundary boundary=` sed 
"s/--.$/--/g" $2 | grep -a 
"^--.*--$" | sed 
"s/^--\(.*\)--$/\1/g" | \ tail -1`  # take the outermost boundary in 

case of embedded multipart     # set 
"xsl" header (base64 encoded gziped data) 

if [[ ! ((
"$1" > 
'cid:') && (
"$1" < 
')) ]]; then # We get here in 

case of 
"not(starts-with($1,'cid:'))" 

if [ 
"$3" = 
'' ]; then echo -e $usage exit fi   xsl=
"xsl: `gzip -c $1 | base64 | sed -e :a -e '/.*[^\.]$/N;s/\n//;ba'`" 

else # Cut out body-part (http:
//www.ietf.org/rfc/rfc2046.txt) selected by cid  # which is everything between CRLF CRLF and delimiter(=CRLF dash-boundary).   

if [ $TERM != 
"cygwin" ]; then # For being able to deal with MIME CRLF violations (only LF) use 
"\{0,1\}". LFCRLF=`echo 
"^CR\{0,1\}$" | sed 
"s/CR/\x0D/"` 

else # Since Cygwin
's sed operates in binary mode there is no CR. LFCRLF=
"^$" fi   # Determine cid reference att=`echo $1 | cut -f2 -d:`   # Determine bodypart number of lines. wc=`sed -n 
'/^Content-Id: <'$att
'>/,/^--'$boundary
'/p' $2 | \ sed -n 
'/'$LFCRLF
'/,/^--'$boundary
'/p' | \ wc` lines=`echo $wc | cut -f1 -d\ ` let line1=$lines-1 let line2=$line1-1   # Cut out bodypart, gzip it, and then base64 encode the result. xsl=
"xsl: `sed -n '/^Content-Id: <'>/,/^--'$boundary'/p' $2 | \ sed -n 
'/'$LFCRLF
'/,/^--'$boundary
'/p' | \ head -$line1 | tail -$line2 | \ gzip -c - | base64 | sed -e :a -e 
'/.*[^\.]$/N;s/\n//;ba'`
"   # output/print cid 

if [ 
"$3" = 
'' ]; then echo 
"$xsl" | cut -b6- | base64 -id | zcat exit elif [[ 
"$3" = 
'-print' ]]; then tac $2 | sed -n 
'/^Content-Id: <'>/,/^--
'$boundary'/p
' | tac | \ grep -v 
'^Content-Id: <'>
' sed -n 
'/^Content-Id: <'>/,/^--
'$boundary'/p
' $2  exit fi fi     # print preamble or epilogue 

if [ 
"$3" = 
'-preamble' ]; then sed -n 
'1,/^--'$boundary
'/p' $2 exit elif [ 
"$3" = 
'-epilogue' ]; then sed -n 
'/^--'$boundary
'--/,//p' $2 exit fi     # set Content-Type swa=
'Content-Type: multipart/related; type="text/xml"; boundary="'$boundary
'"'     # set xml, endpoint and prepare optional parameters (like -s to silence curl) xml=$2 endpoint=$3 shift 3     #  send all against DataPower coproc2 endpoint, allowing 

for curl options curl -H 
"$xsl" -H 
"$swa" --data-binary @$xml $endpoint $* exit     So far is the preamble. This gets ignored.   --boundary-that-is-unique-enough-to-not-appear-in-attachment-data $


 
Hermann<myXsltBlog/>

Attachments

Updated on 2013-03-11T10:01:54Z at 2013-03-11T10:01:54Z by Jaango
  • HermannSW
    HermannSW
    4155 Posts
    ACCEPTED ANSWER

    Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

    ‏2011-08-15T07:41:06Z  in response to HermannSW
    We have already seen the -preamble command in action.

    The -epilogue command just outputs the epilogue (the final, closing binary and everything below) of a SWA file:
    
    $ coproc2swa cid:att1 ~/bin/coproc2swa -epilogue --boundary-that-is-unique-enough-to-not-appear-in-attachment-data--   This is the epilogue. It gets ignored too.   $
    


    The -print command allows to output an attachment referenced by its Content-Id:
    
    $ coproc2swa cid:att1 ~/bin/coproc2swa -print --boundary-that-is-unique-enough-to-not-appear-in-attachment-data Content-Id: <att1> Content-Type: text/plain   Here is attachment 1!! --boundary-that-is-unique-enough-to-not-appear-in-attachment-data $
    


    As can be seen the -print command outputs everything inclusive the enclosing boundaries.

    If you want just the attachment content without the boundaries and its MIME-part-headers you can just use the "empty" command:
    
    $ coproc2swa cid:att1 ~/bin/coproc2swa Here is attachment 1!! $
    


    This can be used to reference the stylesheet attachments, too, which will be used as samples in the next comments:
    
    $ coproc2swa cid:xml1st.xsl ~/bin/coproc2swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
    "dp:variable('var://local/attachment-manifest')" > <!ENTITY ATTHDR 
    "/manifest/attachments/attachment/header"        > ]> <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"/>   <xsl:template match=
    "/"> <xsl:variable name=
    "atthdrs"  select=
    "&ATTMAN;&ATTHDR;"/>   <xsl:variable name=
    "xml1st" select=
    "$atthdrs [name=
    'Content-Type' and value=
    'text/xml'][1]
    "/>   <xsl:variable name=
    "resp"> <dp:url-open target=
    "{$xml1st/../uri}" response=
    "xml"/> </xsl:variable>   <dp:strip-attachments/>   <xsl:copy-of select=
    "$resp/*" /> </xsl:template> </xsl:stylesheet> $
    


     
    Hermann<myXsltBlog/>
    • HermannSW
      HermannSW
      4155 Posts
      ACCEPTED ANSWER

      Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

      ‏2011-08-15T07:52:05Z  in response to HermannSW
      This is the first of the 4 samples attached to coproc2swa.
      attman.xsl outputs the following useful information for a SWA file:
      • headers
      • Content-Type
      • Original Content-Type (including boundary definition)
      • attachment-manifest ("var://local/attachment-manifest")

      The attachment-manifest contains information of all the attachments, see the information on attachment coproc2swa.pgm as an example:
      
      ... <attachment> <uri>cid:coproc2swa.pgm</uri> <size>2984</size> <header> <name>Content-Type</name> <value>image/x-portable-greymap</value> </header> <header> <name>Content-Transfer-Encoding</name> <value>8bit</value> </header> <header> <name>Content-ID</name> <value><coproc2swa.pgm></value> </header> </attachment> ...
      

      Here you can see cid:attman.xsl in action (also attached, output of "coproc2swa cid:attman.xsl ~/bin/coproc2swa >attman.xsl"):
      
      $ coproc2swa cid:attman.xsl ~/bin/coproc2swa http:
      //localhost:2223; echo <result>   <headers><header>User-Agent</header><header>Host</header><header>Accept</header><header>xsl</header><header>Content-Type</header><header>Content-Length</header><header>Via</header><header>X-Client-IP</header></headers>   <Content-Type>text/xml</Content-Type>   <originalCT>multipart/related; type=
      "text/xml"; boundary=
      "boundary-that-is-unique-enough-to-not-appear-in-attachment-data"</originalCT>   <manifest><package-headers/><root-headers><header><name>Content-Type</name><value>text/xml; charset=
      "UTF-8"</value></header><header><name>Content-Location</name><value>ab.xml</value></header></root-headers><media-type><value>multipart/related; boundary=
      "boundary-that-is-unique-enough-to-not-appear-in-attachment-data"; type=
      "text/xml"</value><type>multipart</type><sub-type>related</sub-type></media-type><attachments><attachment><uri>cid:att1</uri><size>22</size><header><name>Content-Id</name><value><att1></value></header><header><name>Content-Type</name><value>text/plain</value></header></attachment><attachment><uri>cid:attman.xsl</uri><size>1245</size><header><name>Content-Id</name><value><attman.xsl></value></header><header><name>Content-Type</name><value>text/xml</value></header></attachment><attachment><uri>cid:att3</uri><size>22</size><header><name>Content-Type</name><value>text/plain</value></header><header><name>Content-Id</name><value><att3></value></header></attachment><attachment><uri>cid:coproc2swa.pgm</uri><size>2984</size><header><name>Content-Type</name><value>image/x-portable-greymap</value></header><header><name>Content-Transfer-Encoding</name><value>8bit</value></header><header><name>Content-ID</name><value><coproc2swa.pgm></value></header></attachment><attachment><uri>cid:pgm1st.xsl</uri><size>982</size><header><name>Content-Type</name><value>text/xml</value></header><header><name>Content-Id</name><value><pgm1st.xsl></value></header></attachment><attachment><uri>cid:xml1st.xsl</uri><size>806</size><header><name>Content-Type</name><value>text/xml</value></header><header><name>Content-Id</name><value><xml1st.xsl></value></header></attachment><attachment><uri>cid:zipit.xsl</uri><size>3049</size><header><name>Content-Type</name><value>text/xml</value></header><header><name>Content-Id</name><value><zipit.xsl></value></header></attachment></attachments></manifest>   </result>   $
      


      And this is stylesheet attman.xsl:
      
      $ coproc2swa cid:attman.xsl ~/bin/coproc2swa <!DOCTYPE xsl:stylesheet [ <!ENTITY HDRMAN 
      "dp:variable('var://service/header-manifest')"       > <!ENTITY COTY   
      "dp:http-request-header('Content-Type')"             > <!ENTITY ORCOTY 
      "dp:variable('var://service/original-content-type')" > <!ENTITY ATTMAN 
      "dp:variable('var://local/attachment-manifest')"     > <!ENTITY LF     
      "<xsl:text>
      </xsl:text>"                         > ]> <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=
      "/"> <result>&LF; <!-- output header-manifest --> &LF;<xsl:copy-of select=
      "&HDRMAN;"/>&LF;   <!-- output content type header --> &LF;<Content-Type><xsl:value-of select=
      "&COTY;"/></Content-Type>&LF;   <!-- output original content type --> &LF;<originalCT><xsl:value-of select=
      "&ORCOTY;"/></originalCT>&LF;   <!-- output attachment-manifest --> &LF;<xsl:copy-of select=
      "&ATTMAN;"/>&LF;   <!-- strip attachments 
      
      for clean output --> <dp:strip-attachments/> &LF;</result>&LF; </xsl:template> </xsl:stylesheet> $
      

       
      Hermann<myXsltBlog/>
      • HermannSW
        HermannSW
        4155 Posts
        ACCEPTED ANSWER

        Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

        ‏2011-08-15T07:58:04Z  in response to HermannSW
        The second sample is xml1st.xsl (also attached, output of "coproc2swa cid:xml1st.xsl ~/bin/coproc2swa >xml1st.xsl").
        It just extracts the very first attachment of type "text/xml":
        
        $ coproc2swa cid:xml1st.xsl ~/bin/coproc2swa http:
        //dp3-l3:2223; echo <?xml version=
        "1.0" encoding=
        "UTF-8"?> <xsl:stylesheet version=
        "1.0" extension-element-prefixes=
        "dp" xmlns:xsl=
        "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
        "http://www.datapower.com/extensions"> <xsl:output omit-xml-declaration=
        "yes"/> <xsl:template match=
        "/"> <result><xsl:text> </xsl:text> <!-- output header-manifest --> <xsl:text> </xsl:text><xsl:copy-of select=
        "dp:variable('var://service/header-manifest')"/><xsl:text> </xsl:text>   <!-- output content type header --> <xsl:text> </xsl:text><Content-Type><xsl:value-of select=
        "dp:http-request-header('Content-Type')"/></Content-Type><xsl:text> </xsl:text>   <!-- output original content type --> <xsl:text> </xsl:text><originalCT><xsl:value-of select=
        "dp:variable('var://service/original-content-type')"/></originalCT><xsl:text> </xsl:text>   <!-- output attachment-manifest --> <xsl:text> </xsl:text><xsl:copy-of select=
        "dp:variable('var://local/attachment-manifest')"/><xsl:text> </xsl:text>   <!-- strip attachments 
        
        for clean output --> <dp:strip-attachments/> <xsl:text> </xsl:text></result><xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet> $
        


        And this is stylesheet xml1st.xsl:
        
        $ coproc2swa cid:xml1st.xsl ~/bin/coproc2swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
        "dp:variable('var://local/attachment-manifest')" > <!ENTITY ATTHDR 
        "/manifest/attachments/attachment/header"        > ]> <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"/>   <xsl:template match=
        "/"> <xsl:variable name=
        "atthdrs"  select=
        "&ATTMAN;&ATTHDR;"/>   <xsl:variable name=
        "xml1st" select=
        "$atthdrs [name=
        'Content-Type' and value=
        'text/xml'][1]
        "/>   <xsl:variable name=
        "resp"> <dp:url-open target=
        "{$xml1st/../uri}" response=
        "xml"/> </xsl:variable>   <dp:strip-attachments/>   <xsl:copy-of select=
        "$resp/*" /> </xsl:template> </xsl:stylesheet> $
        


        Hermann<myXsltBlog/>
        • HermannSW
          HermannSW
          4155 Posts
          ACCEPTED ANSWER

          Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

          ‏2011-08-15T08:06:01Z  in response to HermannSW
          The third sample is pgm1st.xsl.

          It extracts the very first (binary) file of type 'image/x-portable-greymap':
          (see the output of the non-binary first lines below, picture is attached also)
          
          $ coproc2swa cid:pgm1st.xsl ~/bin/coproc2swa http:
          //dp3-l3:2223 -s >coproc2swa.pgm $ head -3 coproc2swa.pgm P5 56 53 255 $
          


          And this is stylesheet pgm1st.xsl:
          
          $ coproc2swa cid:pgm1st.xsl ~/bin/coproc2swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
          "dp:variable('var://local/attachment-manifest')" > <!ENTITY ATTHDR 
          "/manifest/attachments/attachment/header"        > ]> <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:output-mapping href=
          "store:///pkcs7-convert-input.ffd"/>   <xsl:output method=
          "text"/>   <xsl:template match=
          "/"> <xsl:variable name=
          "atthdrs"  select=
          "&ATTMAN;&ATTHDR;"/>   <xsl:variable name=
          "pgm1st" select=
          "$atthdrs [name=
          'Content-Type' and value=
          'image/x-portable-greymap'][1]
          "/>   <xsl:variable name=
          "resp"> <dp:url-open target=
          "{$pgm1st/../uri}" response=
          "binaryNode"/> </xsl:variable>   <dp:strip-attachments/>   <object> <message> <xsl:copy-of select=
          "$resp/result/binary/node()"/> </message> </object> </xsl:template> </xsl:stylesheet> $
          

          Hermann<myXsltBlog/>
          • HermannSW
            HermannSW
            4155 Posts
            ACCEPTED ANSWER

            Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

            ‏2011-08-15T08:13:25Z  in response to HermannSW
            Last, but not least, stylesheet zipit.xsl (attached) demonstrates avanced zip-archive handling.

            It just determines all files of type "text/xml" and "image/x-portable-greymap",
            adds them to archive "archive-zip" and returns that archive as result:
            
            $ coproc2swa cid:zipit.xsl ~/bin/coproc2swa http:
            //dp3-l3:2223 -s >z.zip $ unzip -l z.zip Archive:  z.zip Length     Date   Time    Name --------    ----   ----    ---- 1188  08-15-11 04:08   attman.xsl 879  08-15-11 04:08   pgm1st.xsl 708  08-15-11 04:08   xml1st.xsl 2833  08-15-11 04:08   zipit.xsl 2984  08-15-11 04:08   coproc2swa.pgm --------                   ------- 8592                   5 files $
            


            And this is stylesheet zipit.xsl:
            
            $ coproc2swa cid:zipit.xsl ~/bin/coproc2swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
            "dp:variable('var://local/attachment-manifest')"     > <!ENTITY ATTHDR 
            "/manifest/attachments/attachment/header"            > ]> <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:output-mapping href=
            "store:///pkcs7-convert-input.ffd"/>     <xsl:template match=
            "/"> <!-- determine all attachment headers --> <xsl:variable name=
            "atthdrs"  select=
            "&ATTMAN;&ATTHDR;"/>   <!-- select the 
            'text/xml' ones --> <xsl:variable name=
            "allxml" select=
            "$atthdrs [name=
            'Content-Type' and value=
            'text/xml']
            "/>   <!-- select the 
            'image/x-portable-greymap' ones --> <xsl:variable name=
            "allpgm" select=
            "$atthdrs [name=
            'Content-Type' and value=
            'image/x-portable-greymap']
            "/>     <!-- extract all XML attachments and add to archive-zip --> <xsl:for-each select=
            "$allxml/../uri">   <!-- determine 
            
            new attachment uri --> <xsl:variable name=
            "nuri" select=
            "concat('attachment://INPUT/cid:archive-zip', 
            '?Archive=zip', 
            '&amp;Filename=',substring-after(., 
            'cid:') )
            " />   <!-- add to archive-zip --> <dp:url-open target=
            "{$nuri}" response=
            "ignore">   <!-- read current XML attachment --> <dp:url-open target=
            "{.}" response=
            "xml"/> </dp:url-open> </xsl:for-each>     <!-- extract all PGM attachments and add to archive-zip --> <xsl:for-each select=
            "$allpgm/../uri">   <!-- dermine 
            
            new attachment uri --> <xsl:variable name=
            "nuri" select=
            "concat('attachment://INPUT/cid:archive-zip', 
            '?Archive=zip', 
            '&amp;Filename=',substring-after(., 
            'cid:') )
            " />   <!-- add to archive-zip --> <dp:url-open target=
            "{$nuri}" data-type=
            "base64" response=
            "ignore">   <!-- read current PGM attachment as binaryNode --> <xsl:variable name=
            "resp"> <dp:url-open target=
            "{.}" response=
            "binaryNode"/> </xsl:variable>   <!-- the only safe way to pass binary data to dp:url-open is by base64 encoding it and 
            'data-type="base64"' in dp:url-open --> <xsl:value-of select=
            "dp:binary-encode($resp/result/binary/node())"/> </dp:url-open> </xsl:for-each>     <!-- now that archive-zip contains all files needed extract it as binaryNode 
            
            for sending to output --> <xsl:variable name=
            "resp"> <dp:url-open target=
            "cid:archive-zip" response=
            "binaryNode"/> </xsl:variable>   <!--cleanup --> <dp:strip-attachments/>     <!-- prepare 
            
            for dp:output-mapping --> <object> <message> <xsl:copy-of select=
            "$resp/result/binary/node()"/> </message> </object> </xsl:template> </xsl:stylesheet> $
            


             
            Hermann<myXsltBlog/>
            • HermannSW
              HermannSW
              4155 Posts
              ACCEPTED ANSWER

              Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

              ‏2011-08-24T12:58:37Z  in response to HermannSW
              This demonstration has been created for answering this posting:
              https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14675448#14675448

              Again, let "-preamble" command of coproc2swa tell what (attached) unzip.swa is about:
              $ coproc2swa cid:unzip1stxsl.xsl unzip.swa -preamble
               
              This file is a demonstration on how to extract files from a zip attachment
              of a Soap With Attachement (SWA) file with DataPower.
               
              You may want to use  coproc2swa  client posted here:
              https://www.ibm.com/developerworks/forums/thread.jspa?threadID=387511
               
              This file contains two demo stylesheets and a demo zip archive:
               
                 unzip1stxsl.xsl
                 - output first "*.xsl" file
                   found in first "application/zip" attachment
               
                 unzip1stpgm.xsl
                 - output first "*.pgm" file (binary data!)
                   found in first "application/zip" attachment
               
                 z.zip
                 - archive created by last demonstration from coproc2swa client
               
               
              So far is the preamble. This gets ignored.
               
              --boundary-that-is-unique-enough-to-not-appear-in-attachment-data
              $
              


               
              Hermann <myXsltBlog/>
              Updated on 2014-03-25T03:12:44Z at 2014-03-25T03:12:44Z by iron-man
              • HermannSW
                HermannSW
                4155 Posts
                ACCEPTED ANSWER

                Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

                ‏2011-08-24T13:09:07Z  in response to HermannSW
                Here you can see how stylesheet unzip1stxsl.xsl (also attached) determines
                • (atthdrs) all attachment headers from attachment manifest
                • (zip1st) the uri of first attachment of Content-Tpye "application/zip"
                • (attzip) the zip attachment information including file listing
                • (xsl1st) the first filename ending with ".xsl"
                and then opens and returns this first "*.xsl" file.

                
                $ coproc2swa cid:unzip1stxsl.xsl unzip.swa http:
                //dp3-l3:2223; echo <?xml version=
                "1.0" encoding=
                "UTF-8"?> <xsl:stylesheet version=
                "1.0" extension-element-prefixes=
                "dp" xmlns:xsl=
                "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
                "http://www.datapower.com/extensions"> <xsl:output omit-xml-declaration=
                "yes"/> ... ... </xsl:text> </xsl:template> </xsl:stylesheet> $
                


                And this is stylesheet unzip1stxsl.xsl (also attached):
                
                $ coproc2swa cid:unzip1stxsl.xsl unzip.swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
                "dp:variable('var://local/attachment-manifest')" > <!ENTITY ATTHDR 
                "/manifest/attachments/attachment/header"        > <!ENTITY ATTACH 
                "/manifest/attachments/attachment"               > ]> <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"/>   <xsl:template match=
                "/"> <xsl:variable name=
                "atthdrs"  select=
                "&ATTMAN;&ATTHDR;"/>   <xsl:variable name=
                "zip1st" select=
                "$atthdrs [name=
                'Content-Type' and value=
                'application/zip'][1]/../uri
                "/>   <xsl:variable name=
                "attzip" select=
                "&ATTMAN;&ATTACH;[uri=$zip1st]"/>   <xsl:variable name=
                "xsl1st" select=
                "$attzip/files/file/filename [contains(concat(.,
                '$$'),
                '.xsl$$')][1]
                "/>   <xsl:variable name=
                "resp"> <dp:url-open target=
                "{concat($zip1st,'?Archive=zip&amp;', 
                'Filename=',$xsl1st)
                }
                " response="xml
                "/> </xsl:variable>   <dp:strip-attachments/>   <xsl:copy-of select=
                "$resp/*" /> </xsl:template> </xsl:stylesheet> $
                


                 
                Hermann<myXsltBlog/>
                • HermannSW
                  HermannSW
                  4155 Posts
                  ACCEPTED ANSWER

                  Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

                  ‏2011-08-24T13:15:23Z  in response to HermannSW
                  Here you can see how stylesheet unzip1stpgm.xsl (also attached) determines
                  * (atthdrs) all attachment headers from attachment manifest
                  * (zip1st) the uri of first attachment of Content-Tpye "application/zip"
                  * (attzip) the zip attachment information including file listing
                  * (pgm1st) the first filename ending with ".pgm"
                  and then opens and returns this first "*.pgm" file (binary data).
                  
                  $ coproc2swa cid:unzip1stpgm.xsl unzip.swa http:
                  //dp3-l3:2223 -s >zz.pgm $ ls -l zz.pgm -rw-rw-r-- 1 stammw stammw 2986 Aug 24 15:13 zz.pgm $ head -3 zz.pgm P5 56 53 255 $
                  


                  This is stylesheet unzip1stpgm.xsl (also attached):
                  
                  $ coproc2swa cid:unzip1stpgm.xsl unzip.swa <!DOCTYPE xsl:stylesheet [ <!ENTITY ATTMAN 
                  "dp:variable('var://local/attachment-manifest')" > <!ENTITY ATTHDR 
                  "/manifest/attachments/attachment/header"        > <!ENTITY ATTACH 
                  "/manifest/attachments/attachment"               > ]> <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:output-mapping href=
                  "store:///pkcs7-convert-input.ffd"/>   <xsl:output method=
                  "text"/>   <xsl:template match=
                  "/"> <xsl:variable name=
                  "pgm1st" select=
                  "$atthdrs [name=
                  'Content-Type' and value=
                  'image/x-portable-greymap'][1]
                  "/>   <xsl:variable name=
                  "atthdrs"  select=
                  "&ATTMAN;&ATTHDR;"/>   <xsl:variable name=
                  "zip1st" select=
                  "$atthdrs [name=
                  'Content-Type' and value=
                  'application/zip'][1]/../uri
                  "/>   <xsl:variable name=
                  "attzip" select=
                  "&ATTMAN;&ATTACH;[uri=$zip1st]"/>   <xsl:variable name=
                  "pgm1st" select=
                  "$attzip/files/file/filename [contains(concat(.,
                  '$$'),
                  '.pgm$$')][1]
                  "/>   <xsl:variable name=
                  "resp"> <dp:url-open target=
                  "{concat($zip1st,'?Archive=zip&amp;Filename=', $pgm1st)
                  }
                  " response="binaryNode
                  "/> </xsl:variable>   <dp:strip-attachments/>   <object> <message> <xsl:copy-of select=
                  "$resp/result/binary/node()"/> </message> </object> </xsl:template> </xsl:stylesheet> $
                  


                   
                  Hermann<myXsltBlog/>
                  • HermannSW
                    HermannSW
                    4155 Posts
                    ACCEPTED ANSWER

                    Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

                    ‏2011-08-24T13:27:03Z  in response to HermannSW
                    Ups -- the (unused) "pgm1st" variable should not have been in last stylesheet -- but it does not hurt ...

                    Hermann<myXsltBlog/>
                    • Jaango
                      Jaango
                      256 Posts
                      ACCEPTED ANSWER

                      Re: coproc2swa -- coproc2 client able to deal with SWA (Soap With Attachment)

                      ‏2013-03-11T10:01:54Z  in response to HermannSW
                      Hi Hermann,
                      Is there a way that we can upload to files in dp filemanagement, from the incoming swa request?
                      The input xml is a soap with attachment, we would need to upload the attachment by the same name with extension under temp folder, using dp dump nodes.