Encoding to Base64

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Encoding to Base64

Stephen Bayliss
Suppose I have a SOAP call that requires base64-encoded xml.

I can't see a converter that will do this; the only way I can see
currently is:
(a) A page-flow defining a "service" URL, that has a parameter, which is
the xml document to encode; calling (b) (as the model)...
(b) A pipeline that simply returns the same document using the HTTP
serializer
(c) Another pipeline, input is the document to encode, uses
oxf:url-generator to call the URL specified in the page flow above;
forcing the content type to binary (here the encoding is done)

So (c) is the base64-encode utility pipeline called by other pipelines
in the application

Am I missing something?  Is there a much easier way of doing this?

Steve

Example:

====================
Page-flow (fragment)
====================
<page id="service-to-base64" path-info="/service/toBase64"
default-submission="get-base64.xsl" model="service-get-base64.xpl">
        <setvalue ref="/data" parameter="xml"/>
</page>
====================
Get-base64.xsl default submission:
====================
<data></data>

====================
Service-get-base64.xpl (fragment)
====================
<p:param type="input" name="data"/>
    <p:processor name="oxf:xml-converter">
         <p:input name="data" href="#data"/>
         <p:input name="config">
             <config>
                 <content-type>application/xml</content-type>
                 <encoding>utf-8</encoding>
                 <version>1.0</version>
             </config>
         </p:input>
         <p:output name="data" id="xml-output"/>
     </p:processor>
     <p:processor name="oxf:http-serializer">
         <p:input name="config">
             <config>
                 <content-type>application/xml</content-type>
                 <force-content-type>true</force-content-type>
             </config>
         </p:input>
         <p:input name="data" href="#xml-output"/>
     </p:processor>
====================
Utility pipeline to call the above - this is what is called from other
pipelines
(this probably needs to URL-encode the "xml" parameter, not shown here)
Input is <data> with the doc to encode:
====================
<p:param type="input" name="data"/>
<p:param type="output" name="data"/>

<!-- produce the config input for the url-generator
     Including forcing content type to binary -->
<p:processor name="oxf:xslt">
        <p:input name="data" href="#data"/>
        <p:input name="config">
                <config xsl:version="2.0">
                        <url>oxf:/service/toBase64?xml=<xsl:copy-of
select="/"/></url>
       
<content-type>application/octet-stream</content-type>
                </config>
        <p:output name="data" id="url"/>
</p:processor>

<!-- use url-generator to generate output as base64 encoded -->
<p:processor name="oxf:url-generator">
        <p:input name="config" href="#url">
        <p:output name="data" ref="data"/>
</p:processor>




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Encoding to Base64

Boon Low-2
Hi Steve,

I have managed to encode XML in Base64 binary in a pipeline by:

1. Serialise the XML into a temporay file (you may want to assigned  
the file with unique ID for multiple user scenarios, e.g. using the  
scope-generator/serializer processors)

2. Read the file as binary (e.g. 'image/jpeg') using the url-
generator processor.

Regards,

Boon

-----
Boon Low
System Development Officer,
EGEE Training and Induction
UK National e-Science Centre
http://homepages.ed.ac.uk/boon

On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:

> Suppose I have a SOAP call that requires base64-encoded xml.
>
> I can't see a converter that will do this; the only way I can see
> currently is:
> (a) A page-flow defining a "service" URL, that has a parameter,  
> which is
> the xml document to encode; calling (b) (as the model)...
> (b) A pipeline that simply returns the same document using the HTTP
> serializer
> (c) Another pipeline, input is the document to encode, uses
> oxf:url-generator to call the URL specified in the page flow above;
> forcing the content type to binary (here the encoding is done)
>
> So (c) is the base64-encode utility pipeline called by other pipelines
> in the application
>
> Am I missing something?  Is there a much easier way of doing this?
>
> Steve
>
> Example:
>
> ====================
> Page-flow (fragment)
> ====================
> <page id="service-to-base64" path-info="/service/toBase64"
> default-submission="get-base64.xsl" model="service-get-base64.xpl">
>         <setvalue ref="/data" parameter="xml"/>
> </page>
> ====================
> Get-base64.xsl default submission:
> ====================
> <data></data>
>
> ====================
> Service-get-base64.xpl (fragment)
> ====================
> <p:param type="input" name="data"/>
>     <p:processor name="oxf:xml-converter">
>          <p:input name="data" href="#data"/>
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <encoding>utf-8</encoding>
>                  <version>1.0</version>
>              </config>
>          </p:input>
>          <p:output name="data" id="xml-output"/>
>      </p:processor>
>      <p:processor name="oxf:http-serializer">
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <force-content-type>true</force-content-type>
>              </config>
>          </p:input>
>          <p:input name="data" href="#xml-output"/>
>      </p:processor>
> ====================
> Utility pipeline to call the above - this is what is called from other
> pipelines
> (this probably needs to URL-encode the "xml" parameter, not shown  
> here)
> Input is <data> with the doc to encode:
> ====================
> <p:param type="input" name="data"/>
> <p:param type="output" name="data"/>
>
> <!-- produce the config input for the url-generator
>      Including forcing content type to binary -->
> <p:processor name="oxf:xslt">
>     <p:input name="data" href="#data"/>
>     <p:input name="config">
>         <config xsl:version="2.0">
>             <url>oxf:/service/toBase64?xml=<xsl:copy-of
> select="/"/></url>
>
> <content-type>application/octet-stream</content-type>
>         </config>
>     <p:output name="data" id="url"/>
> </p:processor>
>
> <!-- use url-generator to generate output as base64 encoded -->
> <p:processor name="oxf:url-generator">
>     <p:input name="config" href="#url">
>     <p:output name="data" ref="data"/>
> </p:processor>
>
>
>
> --
> You receive this message as a subscriber of the ops-
> [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
> wws
>



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Encoding to Base64

Boon Low
In reply to this post by Stephen Bayliss
Hi Steve,

I have managed to encode XML in Base64 binary in a pipeline by:

1. Serialise the XML into a temporay file (you may want to assigned  
the file with unique ID for multiple user scenarios, e.g. using the  
scope-generator/serializer processors)

2. Read the file as binary (e.g. 'image/jpeg') using the url-
generator processor.

Regards,

Boon

-----
Boon Low
System Development Officer,
EGEE Training and Induction
UK National e-Science Centre
http://homepages.ed.ac.uk/boon


On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:


> Suppose I have a SOAP call that requires base64-encoded xml.
>
> I can't see a converter that will do this; the only way I can see
> currently is:
> (a) A page-flow defining a "service" URL, that has a parameter,  
> which is
> the xml document to encode; calling (b) (as the model)...
> (b) A pipeline that simply returns the same document using the HTTP
> serializer
> (c) Another pipeline, input is the document to encode, uses
> oxf:url-generator to call the URL specified in the page flow above;
> forcing the content type to binary (here the encoding is done)
>
> So (c) is the base64-encode utility pipeline called by other pipelines
> in the application
>
> Am I missing something?  Is there a much easier way of doing this?
>
> Steve
>
> Example:
>
> ====================
> Page-flow (fragment)
> ====================
> <page id="service-to-base64" path-info="/service/toBase64"
> default-submission="get-base64.xsl" model="service-get-base64.xpl">
>         <setvalue ref="/data" parameter="xml"/>
> </page>
> ====================
> Get-base64.xsl default submission:
> ====================
> <data></data>
>
> ====================
> Service-get-base64.xpl (fragment)
> ====================
> <p:param type="input" name="data"/>
>     <p:processor name="oxf:xml-converter">
>          <p:input name="data" href="#data"/>
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <encoding>utf-8</encoding>
>                  <version>1.0</version>
>              </config>
>          </p:input>
>          <p:output name="data" id="xml-output"/>
>      </p:processor>
>      <p:processor name="oxf:http-serializer">
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <force-content-type>true</force-content-type>
>              </config>
>          </p:input>
>          <p:input name="data" href="#xml-output"/>
>      </p:processor>
> ====================
> Utility pipeline to call the above - this is what is called from other
> pipelines
> (this probably needs to URL-encode the "xml" parameter, not shown  
> here)
> Input is <data> with the doc to encode:
> ====================
> <p:param type="input" name="data"/>
> <p:param type="output" name="data"/>
>
> <!-- produce the config input for the url-generator
>      Including forcing content type to binary -->
> <p:processor name="oxf:xslt">
>     <p:input name="data" href="#data"/>
>     <p:input name="config">
>         <config xsl:version="2.0">
>             <url>oxf:/service/toBase64?xml=<xsl:copy-of
> select="/"/></url>
>
> <content-type>application/octet-stream</content-type>
>         </config>
>     <p:output name="data" id="url"/>
> </p:processor>
>
> <!-- use url-generator to generate output as base64 encoded -->
> <p:processor name="oxf:url-generator">
>     <p:input name="config" href="#url">
>     <p:output name="data" ref="data"/>
> </p:processor>
>
>
>
> --
> You receive this message as a subscriber of the ops-
> [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
> wws
>
>




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Encoding to Base64

Stephen Bayliss
In reply to this post by Stephen Bayliss
Thanks Boon

I have now managed to get the extension function method that Erik
proposed in your earlier exchange to work:

Example (trivial!):

<p:processor name="oxf:unsafe-xslt">
   <p:input name="data" href="#instance"/>
    <p:input name="config">
       <xsl:stylesheet version="2.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:Base64="org.orbeon.oxf.util.Base64">
            <xsl:template match="/">
                <base64Data><xsl:value-of
select="Base64:encode(string-to-codepoints('one two
three'))"/></base64Data>
            </xsl:template>
        </xsl:stylesheet>
     </p:input>
     <p:output name="data" id="xml"/>
</p:processor>

Pertinent bits are
* use oxf:unsafe-xslt as the processor
* include the Base64 namespace declaration in <xsl:stylesheet> (this is
a ref to the class)
* wrap the string in a string-to-codepoints() function within the
Base64:encode function
* note that calling a java method this way only works on static methods;
there's other stuff you need to otherwise

Seems to work fine here, needs a bit of stress-testing before I'll be
completely happy.



-----Original Message-----
From: Boon Low [mailto:[hidden email]]
Sent: 12 October 2005 14:13
To: [hidden email]
Subject: Re: [ops-users] Encoding to Base64

Hi Steve,

I have managed to encode XML in Base64 binary in a pipeline by:

1. Serialise the XML into a temporay file (you may want to assigned  
the file with unique ID for multiple user scenarios, e.g. using the  
scope-generator/serializer processors)

2. Read the file as binary (e.g. 'image/jpeg') using the url-
generator processor.

Regards,

Boon

-----
Boon Low
System Development Officer,
EGEE Training and Induction
UK National e-Science Centre
http://homepages.ed.ac.uk/boon


On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:


> Suppose I have a SOAP call that requires base64-encoded xml.
>
> I can't see a converter that will do this; the only way I can see
> currently is:
> (a) A page-flow defining a "service" URL, that has a parameter,  
> which is
> the xml document to encode; calling (b) (as the model)...
> (b) A pipeline that simply returns the same document using the HTTP
> serializer
> (c) Another pipeline, input is the document to encode, uses
> oxf:url-generator to call the URL specified in the page flow above;
> forcing the content type to binary (here the encoding is done)
>
> So (c) is the base64-encode utility pipeline called by other pipelines
> in the application
>
> Am I missing something?  Is there a much easier way of doing this?
>
> Steve
>
> Example:
>
> ====================
> Page-flow (fragment)
> ====================
> <page id="service-to-base64" path-info="/service/toBase64"
> default-submission="get-base64.xsl" model="service-get-base64.xpl">
>         <setvalue ref="/data" parameter="xml"/>
> </page>
> ====================
> Get-base64.xsl default submission:
> ====================
> <data></data>
>
> ====================
> Service-get-base64.xpl (fragment)
> ====================
> <p:param type="input" name="data"/>
>     <p:processor name="oxf:xml-converter">
>          <p:input name="data" href="#data"/>
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <encoding>utf-8</encoding>
>                  <version>1.0</version>
>              </config>
>          </p:input>
>          <p:output name="data" id="xml-output"/>
>      </p:processor>
>      <p:processor name="oxf:http-serializer">
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <force-content-type>true</force-content-type>
>              </config>
>          </p:input>
>          <p:input name="data" href="#xml-output"/>
>      </p:processor>
> ====================
> Utility pipeline to call the above - this is what is called from other
> pipelines
> (this probably needs to URL-encode the "xml" parameter, not shown  
> here)
> Input is <data> with the doc to encode:
> ====================
> <p:param type="input" name="data"/>
> <p:param type="output" name="data"/>
>
> <!-- produce the config input for the url-generator
>      Including forcing content type to binary -->
> <p:processor name="oxf:xslt">
>     <p:input name="data" href="#data"/>
>     <p:input name="config">
>         <config xsl:version="2.0">
>             <url>oxf:/service/toBase64?xml=<xsl:copy-of
> select="/"/></url>
>
> <content-type>application/octet-stream</content-type>
>         </config>
>     <p:output name="data" id="url"/>
> </p:processor>
>
> <!-- use url-generator to generate output as base64 encoded -->
> <p:processor name="oxf:url-generator">
>     <p:input name="config" href="#url">
>     <p:output name="data" ref="data"/>
> </p:processor>
>
>
>
> --
> You receive this message as a subscriber of the ops-
> [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
> wws
>
>






--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Encoding to Base64

Erik Bruchez
Administrator
In reply to this post by Boon Low
Of course this solution suffers from some complexity and probably fairly
poor performance compared to a native processor or calling a function
from XSLT!

Thanks for the tip though!

-Erik

Boon Low wrote:

> Hi Steve,
>
> I have managed to encode XML in Base64 binary in a pipeline by:
>
> 1. Serialise the XML into a temporay file (you may want to assigned  the
> file with unique ID for multiple user scenarios, e.g. using the  
> scope-generator/serializer processors)
>
> 2. Read the file as binary (e.g. 'image/jpeg') using the url- generator
> processor.
>
> Regards,
>
> Boon


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Encoding to Base64

Stephen Bayliss
In reply to this post by Stephen Bayliss
Following on from this, I can't get this technique to work to encode a
whole XML document, only strings within it.

Putting in a full xml node-tree results in just the literal data being
encoded.  Which does make sense... you would expect an XSLT engine to
interpret XML as XML, not as text.

It works if the whole lot is put in a <![CDATA[ ]]> section, but I can't
get xslt working to do that either (for some reason oxf:xslt seems to
ignore the <xsl:output cdata-section-elements="namelist" /> element)

-----Original Message-----
From: Stephen Bayliss
Sent: 12 October 2005 14:43
To: [hidden email]
Subject: RE: [ops-users] Encoding to Base64

Thanks Boon

I have now managed to get the extension function method that Erik
proposed in your earlier exchange to work:

Example (trivial!):

<p:processor name="oxf:unsafe-xslt">
   <p:input name="data" href="#instance"/>
    <p:input name="config">
       <xsl:stylesheet version="2.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:Base64="org.orbeon.oxf.util.Base64">
            <xsl:template match="/">
                <base64Data><xsl:value-of
select="Base64:encode(string-to-codepoints('one two
three'))"/></base64Data>
            </xsl:template>
        </xsl:stylesheet>
     </p:input>
     <p:output name="data" id="xml"/>
</p:processor>

Pertinent bits are
* use oxf:unsafe-xslt as the processor
* include the Base64 namespace declaration in <xsl:stylesheet> (this is
a ref to the class)
* wrap the string in a string-to-codepoints() function within the
Base64:encode function
* note that calling a java method this way only works on static methods;
there's other stuff you need to otherwise

Seems to work fine here, needs a bit of stress-testing before I'll be
completely happy.



-----Original Message-----
From: Boon Low [mailto:[hidden email]]
Sent: 12 October 2005 14:13
To: [hidden email]
Subject: Re: [ops-users] Encoding to Base64

Hi Steve,

I have managed to encode XML in Base64 binary in a pipeline by:

1. Serialise the XML into a temporay file (you may want to assigned  
the file with unique ID for multiple user scenarios, e.g. using the  
scope-generator/serializer processors)

2. Read the file as binary (e.g. 'image/jpeg') using the url-
generator processor.

Regards,

Boon

-----
Boon Low
System Development Officer,
EGEE Training and Induction
UK National e-Science Centre
http://homepages.ed.ac.uk/boon


On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:


> Suppose I have a SOAP call that requires base64-encoded xml.
>
> I can't see a converter that will do this; the only way I can see
> currently is:
> (a) A page-flow defining a "service" URL, that has a parameter,  
> which is
> the xml document to encode; calling (b) (as the model)...
> (b) A pipeline that simply returns the same document using the HTTP
> serializer
> (c) Another pipeline, input is the document to encode, uses
> oxf:url-generator to call the URL specified in the page flow above;
> forcing the content type to binary (here the encoding is done)
>
> So (c) is the base64-encode utility pipeline called by other pipelines
> in the application
>
> Am I missing something?  Is there a much easier way of doing this?
>
> Steve
>
> Example:
>
> ====================
> Page-flow (fragment)
> ====================
> <page id="service-to-base64" path-info="/service/toBase64"
> default-submission="get-base64.xsl" model="service-get-base64.xpl">
>         <setvalue ref="/data" parameter="xml"/>
> </page>
> ====================
> Get-base64.xsl default submission:
> ====================
> <data></data>
>
> ====================
> Service-get-base64.xpl (fragment)
> ====================
> <p:param type="input" name="data"/>
>     <p:processor name="oxf:xml-converter">
>          <p:input name="data" href="#data"/>
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <encoding>utf-8</encoding>
>                  <version>1.0</version>
>              </config>
>          </p:input>
>          <p:output name="data" id="xml-output"/>
>      </p:processor>
>      <p:processor name="oxf:http-serializer">
>          <p:input name="config">
>              <config>
>                  <content-type>application/xml</content-type>
>                  <force-content-type>true</force-content-type>
>              </config>
>          </p:input>
>          <p:input name="data" href="#xml-output"/>
>      </p:processor>
> ====================
> Utility pipeline to call the above - this is what is called from other
> pipelines
> (this probably needs to URL-encode the "xml" parameter, not shown  
> here)
> Input is <data> with the doc to encode:
> ====================
> <p:param type="input" name="data"/>
> <p:param type="output" name="data"/>
>
> <!-- produce the config input for the url-generator
>      Including forcing content type to binary -->
> <p:processor name="oxf:xslt">
>     <p:input name="data" href="#data"/>
>     <p:input name="config">
>         <config xsl:version="2.0">
>             <url>oxf:/service/toBase64?xml=<xsl:copy-of
> select="/"/></url>
>
> <content-type>application/octet-stream</content-type>
>         </config>
>     <p:output name="data" id="url"/>
> </p:processor>
>
> <!-- use url-generator to generate output as base64 encoded -->
> <p:processor name="oxf:url-generator">
>     <p:input name="config" href="#url">
>     <p:output name="data" ref="data"/>
> </p:processor>
>
>
>
> --
> You receive this message as a subscriber of the ops-
> [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
> wws
>
>








--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Encoding to Base64

Erik Bruchez
Administrator
Then use saxon:serialize() first. It "returns the XML representation of
a document or element, as a string".

http://www.saxonica.com/documentation/extensions/functions/serialize.html

-Erik

Stephen Bayliss wrote:

> Following on from this, I can't get this technique to work to encode a
> whole XML document, only strings within it.
>
> Putting in a full xml node-tree results in just the literal data being
> encoded.  Which does make sense... you would expect an XSLT engine to
> interpret XML as XML, not as text.
>
> It works if the whole lot is put in a <![CDATA[ ]]> section, but I can't
> get xslt working to do that either (for some reason oxf:xslt seems to
> ignore the <xsl:output cdata-section-elements="namelist" /> element)
>
> -----Original Message-----
> From: Stephen Bayliss
> Sent: 12 October 2005 14:43
> To: [hidden email]
> Subject: RE: [ops-users] Encoding to Base64
>
> Thanks Boon
>
> I have now managed to get the extension function method that Erik
> proposed in your earlier exchange to work:
>
> Example (trivial!):
>
> <p:processor name="oxf:unsafe-xslt">
>    <p:input name="data" href="#instance"/>
>     <p:input name="config">
>        <xsl:stylesheet version="2.0"
>             xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>             xmlns:Base64="org.orbeon.oxf.util.Base64">
>             <xsl:template match="/">
>                 <base64Data><xsl:value-of
> select="Base64:encode(string-to-codepoints('one two
> three'))"/></base64Data>
>             </xsl:template>
>         </xsl:stylesheet>
>      </p:input>
>      <p:output name="data" id="xml"/>
> </p:processor>
>
> Pertinent bits are
> * use oxf:unsafe-xslt as the processor
> * include the Base64 namespace declaration in <xsl:stylesheet> (this is
> a ref to the class)
> * wrap the string in a string-to-codepoints() function within the
> Base64:encode function
> * note that calling a java method this way only works on static methods;
> there's other stuff you need to otherwise
>
> Seems to work fine here, needs a bit of stress-testing before I'll be
> completely happy.
>
>
>
> -----Original Message-----
> From: Boon Low [mailto:[hidden email]]
> Sent: 12 October 2005 14:13
> To: [hidden email]
> Subject: Re: [ops-users] Encoding to Base64
>
> Hi Steve,
>
> I have managed to encode XML in Base64 binary in a pipeline by:
>
> 1. Serialise the XML into a temporay file (you may want to assigned  
> the file with unique ID for multiple user scenarios, e.g. using the  
> scope-generator/serializer processors)
>
> 2. Read the file as binary (e.g. 'image/jpeg') using the url-
> generator processor.
>
> Regards,
>
> Boon
>
> -----
> Boon Low
> System Development Officer,
> EGEE Training and Induction
> UK National e-Science Centre
> http://homepages.ed.ac.uk/boon
>
>
> On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:
>
>
>
>>Suppose I have a SOAP call that requires base64-encoded xml.
>>
>>I can't see a converter that will do this; the only way I can see
>>currently is:
>>(a) A page-flow defining a "service" URL, that has a parameter,  
>>which is
>>the xml document to encode; calling (b) (as the model)...
>>(b) A pipeline that simply returns the same document using the HTTP
>>serializer
>>(c) Another pipeline, input is the document to encode, uses
>>oxf:url-generator to call the URL specified in the page flow above;
>>forcing the content type to binary (here the encoding is done)
>>
>>So (c) is the base64-encode utility pipeline called by other pipelines
>>in the application
>>
>>Am I missing something?  Is there a much easier way of doing this?
>>
>>Steve
>>
>>Example:
>>
>>====================
>>Page-flow (fragment)
>>====================
>><page id="service-to-base64" path-info="/service/toBase64"
>>default-submission="get-base64.xsl" model="service-get-base64.xpl">
>>        <setvalue ref="/data" parameter="xml"/>
>></page>
>>====================
>>Get-base64.xsl default submission:
>>====================
>><data></data>
>>
>>====================
>>Service-get-base64.xpl (fragment)
>>====================
>><p:param type="input" name="data"/>
>>    <p:processor name="oxf:xml-converter">
>>         <p:input name="data" href="#data"/>
>>         <p:input name="config">
>>             <config>
>>                 <content-type>application/xml</content-type>
>>                 <encoding>utf-8</encoding>
>>                 <version>1.0</version>
>>             </config>
>>         </p:input>
>>         <p:output name="data" id="xml-output"/>
>>     </p:processor>
>>     <p:processor name="oxf:http-serializer">
>>         <p:input name="config">
>>             <config>
>>                 <content-type>application/xml</content-type>
>>                 <force-content-type>true</force-content-type>
>>             </config>
>>         </p:input>
>>         <p:input name="data" href="#xml-output"/>
>>     </p:processor>
>>====================
>>Utility pipeline to call the above - this is what is called from other
>>pipelines
>>(this probably needs to URL-encode the "xml" parameter, not shown  
>>here)
>>Input is <data> with the doc to encode:
>>====================
>><p:param type="input" name="data"/>
>><p:param type="output" name="data"/>
>>
>><!-- produce the config input for the url-generator
>>     Including forcing content type to binary -->
>><p:processor name="oxf:xslt">
>>    <p:input name="data" href="#data"/>
>>    <p:input name="config">
>>        <config xsl:version="2.0">
>>            <url>oxf:/service/toBase64?xml=<xsl:copy-of
>>select="/"/></url>
>>
>><content-type>application/octet-stream</content-type>
>>        </config>
>>    <p:output name="data" id="url"/>
>></p:processor>
>>
>><!-- use url-generator to generate output as base64 encoded -->
>><p:processor name="oxf:url-generator">
>>    <p:input name="config" href="#url">
>>    <p:output name="data" ref="data"/>
>></p:processor>
>>
>>
>>
>>--
>>You receive this message as a subscriber of the ops-
>>[hidden email] mailing list.
>>To unsubscribe: mailto:[hidden email]
>>For general help: mailto:[hidden email]?subject=help
>>ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
>>wws
>>
>>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Encoding to Base64

Stephen Bayliss
In reply to this post by Stephen Bayliss
Perfect!  Thanks Erik.

I now have a working utility pipeline that converts xml input into
base64-encoded output, in the OXF binary document format.

Reproduced below for anyone else that needs to do the same (pending
writing the processor for this!)

Steve

=============================
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
   
    <p:param type="input" name="data"/>
    <p:param type="output" name="data"/>

    <p:processor name="oxf:unsafe-xslt">
       <p:input name="data" href="#data"/>
        <p:input name="config">
           <xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:Base64="org.orbeon.oxf.util.Base64"
                xmlns:saxon="http://saxon.sf.net/">
               <xsl:output name="default" method="xml"/>
                <xsl:template match="/">
                    <document xsi:type="xs:base64Binary"
content-type="application/octet-stream"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><xsl:value-of
select="Base64:encode(string-to-codepoints(saxon:serialize(/,'default'))
)"/></document>
                </xsl:template>
            </xsl:stylesheet>
         </p:input>
         <p:output name="data" ref="data"/>
    </p:processor>
</p:config>
=============================

-----Original Message-----
From: Erik Bruchez [mailto:[hidden email]] On Behalf Of Erik Bruchez
Sent: 13 October 2005 10:57
To: [hidden email]
Subject: Re: [ops-users] Encoding to Base64

Then use saxon:serialize() first. It "returns the XML representation of
a document or element, as a string".

http://www.saxonica.com/documentation/extensions/functions/serialize.htm
l

-Erik

Stephen Bayliss wrote:
> Following on from this, I can't get this technique to work to encode a
> whole XML document, only strings within it.
>
> Putting in a full xml node-tree results in just the literal data being
> encoded.  Which does make sense... you would expect an XSLT engine to
> interpret XML as XML, not as text.
>
> It works if the whole lot is put in a <![CDATA[ ]]> section, but I
can't

> get xslt working to do that either (for some reason oxf:xslt seems to
> ignore the <xsl:output cdata-section-elements="namelist" /> element)
>
> -----Original Message-----
> From: Stephen Bayliss
> Sent: 12 October 2005 14:43
> To: [hidden email]
> Subject: RE: [ops-users] Encoding to Base64
>
> Thanks Boon
>
> I have now managed to get the extension function method that Erik
> proposed in your earlier exchange to work:
>
> Example (trivial!):
>
> <p:processor name="oxf:unsafe-xslt">
>    <p:input name="data" href="#instance"/>
>     <p:input name="config">
>        <xsl:stylesheet version="2.0"
>             xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>             xmlns:Base64="org.orbeon.oxf.util.Base64">
>             <xsl:template match="/">
>                 <base64Data><xsl:value-of
> select="Base64:encode(string-to-codepoints('one two
> three'))"/></base64Data>
>             </xsl:template>
>         </xsl:stylesheet>
>      </p:input>
>      <p:output name="data" id="xml"/>
> </p:processor>
>
> Pertinent bits are
> * use oxf:unsafe-xslt as the processor
> * include the Base64 namespace declaration in <xsl:stylesheet> (this
is
> a ref to the class)
> * wrap the string in a string-to-codepoints() function within the
> Base64:encode function
> * note that calling a java method this way only works on static
methods;

> there's other stuff you need to otherwise
>
> Seems to work fine here, needs a bit of stress-testing before I'll be
> completely happy.
>
>
>
> -----Original Message-----
> From: Boon Low [mailto:[hidden email]]
> Sent: 12 October 2005 14:13
> To: [hidden email]
> Subject: Re: [ops-users] Encoding to Base64
>
> Hi Steve,
>
> I have managed to encode XML in Base64 binary in a pipeline by:
>
> 1. Serialise the XML into a temporay file (you may want to assigned  
> the file with unique ID for multiple user scenarios, e.g. using the  
> scope-generator/serializer processors)
>
> 2. Read the file as binary (e.g. 'image/jpeg') using the url-
> generator processor.
>
> Regards,
>
> Boon
>
> -----
> Boon Low
> System Development Officer,
> EGEE Training and Induction
> UK National e-Science Centre
> http://homepages.ed.ac.uk/boon
>
>
> On 12 Oct 2005, at 10:55, Stephen Bayliss wrote:
>
>
>
>>Suppose I have a SOAP call that requires base64-encoded xml.
>>
>>I can't see a converter that will do this; the only way I can see
>>currently is:
>>(a) A page-flow defining a "service" URL, that has a parameter,  
>>which is
>>the xml document to encode; calling (b) (as the model)...
>>(b) A pipeline that simply returns the same document using the HTTP
>>serializer
>>(c) Another pipeline, input is the document to encode, uses
>>oxf:url-generator to call the URL specified in the page flow above;
>>forcing the content type to binary (here the encoding is done)
>>
>>So (c) is the base64-encode utility pipeline called by other pipelines
>>in the application
>>
>>Am I missing something?  Is there a much easier way of doing this?
>>
>>Steve
>>
>>Example:
>>
>>====================
>>Page-flow (fragment)
>>====================
>><page id="service-to-base64" path-info="/service/toBase64"
>>default-submission="get-base64.xsl" model="service-get-base64.xpl">
>>        <setvalue ref="/data" parameter="xml"/>
>></page>
>>====================
>>Get-base64.xsl default submission:
>>====================
>><data></data>
>>
>>====================
>>Service-get-base64.xpl (fragment)
>>====================
>><p:param type="input" name="data"/>
>>    <p:processor name="oxf:xml-converter">
>>         <p:input name="data" href="#data"/>
>>         <p:input name="config">
>>             <config>
>>                 <content-type>application/xml</content-type>
>>                 <encoding>utf-8</encoding>
>>                 <version>1.0</version>
>>             </config>
>>         </p:input>
>>         <p:output name="data" id="xml-output"/>
>>     </p:processor>
>>     <p:processor name="oxf:http-serializer">
>>         <p:input name="config">
>>             <config>
>>                 <content-type>application/xml</content-type>
>>                 <force-content-type>true</force-content-type>
>>             </config>
>>         </p:input>
>>         <p:input name="data" href="#xml-output"/>
>>     </p:processor>
>>====================
>>Utility pipeline to call the above - this is what is called from other
>>pipelines
>>(this probably needs to URL-encode the "xml" parameter, not shown  
>>here)
>>Input is <data> with the doc to encode:
>>====================
>><p:param type="input" name="data"/>
>><p:param type="output" name="data"/>
>>
>><!-- produce the config input for the url-generator
>>     Including forcing content type to binary -->
>><p:processor name="oxf:xslt">
>>    <p:input name="data" href="#data"/>
>>    <p:input name="config">
>>        <config xsl:version="2.0">
>>            <url>oxf:/service/toBase64?xml=<xsl:copy-of
>>select="/"/></url>
>>
>><content-type>application/octet-stream</content-type>
>>        </config>
>>    <p:output name="data" id="url"/>
>></p:processor>
>>
>><!-- use url-generator to generate output as base64 encoded -->
>><p:processor name="oxf:url-generator">
>>    <p:input name="config" href="#url">
>>    <p:output name="data" ref="data"/>
>></p:processor>
>>
>>
>>
>>--
>>You receive this message as a subscriber of the ops-
>>[hidden email] mailing list.
>>To unsubscribe: mailto:[hidden email]
>>For general help: mailto:[hidden email]?subject=help
>>ObjectWeb mailing lists service home page: http://www.objectweb.org/ 
>>wws
>>
>>
>
>
>
>
>
>
>
>
>
>
------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the
[hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page:
http://www.objectweb.org/wws






--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws