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')
baseUrl.getOutputStream().write(message);
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.setRequestMethod("OPTIONS")
options.setDoOutput(true)
options.setRequestProperty("Content-Type", "application/json")
options.getOutputStream().write(message.getBytes("UTF-8"));
def optionsRC = options.getResponseCode();
println(optionsRC);
if(optionsRC.equals(200)) {
println(options.getInputStream().getText());
}
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!