Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

soap - How do I build a base64 string from properties in SoapUI?

Here is what I've got.

  • There is a SOAP message that sends a base64 encoded clob as the data.
  • The clob is an xml file that is built from a set of properties we want to modify.

The questions I think I have are:

  • How do I pull properties to generate the xml
  • How do I convert that xml to a base64 encoded string
  • How do I take that base64 encoded string and add it to my payload?

I appreciate your time :)

question from:https://stackoverflow.com/questions/66048039/how-do-i-build-a-base64-string-from-properties-in-soapui

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This sample does the trick.

def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer) 
def propertyUrl = testRunner.testCase.getPropertyValue("url")

xml.records() { 
    car(name: 'HSV Maloo', make: 'Holden', year: 2006) {
        country('Australia')
        record(type: 'speed', propertyUrl)
    }
    car(name: 'Royale', make: 'Bugatti', year: 1931) {
        country('France')
        record(type: 'price', 'Most Valuable Car at $15 million')
    }
}

def records = new XmlSlurper().parseText(writer.toString()) 

xmlString = writer.toString()
log.info(xmlString)

xmlBase64 = xmlString.bytes.encodeBase64()
log.info(xmlBase64);

A couple things stumped me initially

  • The specific incantation to get the property from the test
  • using 'groovy.xml.MarkupBuilder' instead of just 'MarkupBuilder'

After that, it was a piece of cake :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...