I need to create a sample Soap request by calling the endpoint URL and give the necessary login and password info and then send a request and get a response in XML. I'm writing the groovy script in eclipse IDE and creating a jar file and call that jar file into SoapUI and call the code within the jar file into SoapUI.
I am getting an error and how should I resolve this? Is there any other way to achieve my goal? Please help me.
The Output:
Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run. It should either: - have a main method, - be a JUnit test or extend GroovyTestCase, - implement the Runnable interface, - or be compatible with a registered script runner. Known runners: * org.apache.groovy.plugin.DefaultRunners$Junit3TestRunner * org.apache.groovy.plugin.DefaultRunners$Junit3SuiteRunner * org.apache.groovy.plugin.DefaultRunners$Junit4TestRunner
Here is the code:
package com.xyz.demo class ABC { public setUP() { // set data def url = new URL("https://qwertywq.asmx").openConnection(); if(soapaction != null) connection.setRequestProperty("SOAPAction", soapaction); connection.setRequestProperty("Content-Type", "Text/xml"); String AuthorizationString = "Basic " + (username + ":" + password).bytes.encodeBase64(); connection.setRequestProperty("Authorization", authorizationString); OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); wr.write(xml); wr.close(); // Get the response String response; InputStream responseStream; try { responseStream = connection.getInputStream(); success = 1; } catch( IOException e ) { success = 0; if( connection.getResponseCode() == 500 ) { responseStream = connection.getErrorStream(); } else throw e; } response = responseStream.getText("utf-8"); responseStream.close(); return response; }