Options method with body on SoapUI (Test)

I've looking for how is possible call an OPTIONS method with body parameters using groovy on SoapUI. I read this is possible but, incredible or not, i haven't found an example.
I tried this:

    import groovyx.net.http.HTTPBuilder;
    public class HttpclassgetrRoles {
     static void main(String[] args){
         def message = '{"message":"this is a message"}'
         def baseUrl = new URL('https://MY-URL')

         HttpURLConnection connection = (HttpURLConnection) baseUrl.openConnection();
         connection.addRequestProperty("Accept", "application/json")
         connection.with {
           doOutput = true
           requestMethod = 'OPTIONS'
           println content.text


But it didn't work.
Other way was this:

def options = new URL("https://MY-URL"}'
def message = '{"message":"this is a message"}'
options.setRequestProperty("Content-Type", "application/json")
def optionsRC = options.getResponseCode();
if(optionsRC.equals(200)) {

but neither.
And this one:

import org.codehaus.groovy.runtime.StackTraceUtils

import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ParserRegistry
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT

def http = new HTTPBuilder('https://MY-URL')

http.option( path : '/complement',
contentType : TEXT,
query : [body:'{"parameter1":"value1"}'] ) { resp, reader ->

println "response status: ${resp.statusLine}"
println 'Headers: -----------'
resp.headers.each { h ->
println " ${h.name} : ${h.value}"
println 'Response data: -----'
System.out << reader
println '\n--------------------'

but nothing...

I'm continue looking for a solution but meanwhile i decided to launch the question here in order somebody can help me.

Thx 4 advance guys!

1 answer

  • answered 2018-03-13 20:44 Rao

    You should be able to use groovy-wslite library in order to achieve the same.

    If you notice the README, OPTIONS method is not listed there. However, if you check the logs of the repository, it is clear that the library is enhanced to supported the same.

    Here you go:

    • Download the source from git
    • Build it from source (as released version does not have OPTIONS)
    • Copy the library under SOAPUI_HOME/bin/ext directory
    • Restart the soapUI tool

    Use sample code provided here.

    Hope this helps.