Forum Discussion

robertc's avatar
robertc
Occasional Contributor
16 years ago

How do I extract base64Binary text from a response

I receive a response from the server which contains the following:

PD94bWwg.....ZW50cz4K

I want to see the base64Binary part converted to text. It is actually xml with utf-8 characters. Is there a way to automatically convert this or will I have to write a Groovy script to do it. If so can someone point me to an example please.

thanks
  • You will have to use Groovy for this. I think you'll need to do something along the lines of this:


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder("Your Request#Response")

    def.encoded = holder.getNodeValue("<get the base64 node content>")

    def decoded = new String(encoded.decodeBase64(), "utf-8")

    log.info decoded


    Good luck!

    Regards,
    Dain
    eviware.com
  • robertc's avatar
    robertc
    Occasional Contributor
    Thanks, but I now have a problem with the xpath:

    This is what I get back (slightly truncated in the middle)


     
         
            PD9...cz4K
         

     



    I run the following script:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

    def holder = groovyUtils.getXmlHolder("get_eligibility_document_xml#Response")

    def resp = holder.getNodeValue("//s-gensym6")

    log.info resp

    but resp is always null.

    Any thoughts?

    If I replace holder.getNodeValue... with holder.getXml() I get the complete response as expected.
  • Hello,

    You need a namespace declaration on the "getNodeValue"-line.
    Try this:


    def resp = holder.getNodeValue("//ns1:s-gensym6")


    or the shorter form:


    def resp = holder["//ns1:s-gensym6"]


    Regards,
    Dain
    eviware