MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 7 as of 2015-12-09 18:26:58
  • SoapUI

SoapUI

Rest OnRequest sample Groovy

  • http://www.soapui.org/apidocs/com/eviware/soapui/impl/rest/mock/RestMockRequest.html

  • http://www.soapui.org/apidocs/com/eviware/soapui/impl/rest/mock/RestMockResult.html

  • https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html

  • https://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html

import com.eviware.soapui.impl.rest.mock.RestMockResult

RestMockResult res = new RestMockResult( mockRequest )
String val ="{test:1234}"
mockRequest.httpResponse.writer << val
mockRequest.httpResponse.status = 200 
mockRequest.httpResponse.header = "Content-type: application/json"
mockRequest 
return res
  • http://www.soapui.org/scripting---properties/the-soapui-object-model.html

WAR generation from SoapUI project

SoapUI is able to generate a WAR to create mock servers to run on Tomcat. The SoapUI project is stored inside the WAR in WEB-INF/soapui/soapuiprj.xml .

Sample onRequest script to call groovy scripts inside WEB-INF/soapui/. They can be changed on runtime after Tomcat has exploded the WAR file.

Inside the onRequestScript

import groovy.util.GroovyScriptEngine
import com.eviware.soapui.support.GroovyUtils
def gru = new GroovyUtils(context)
GroovyScriptEngine ge = new GroovyScriptEngine(gru.projectPath)
Binding b = new Binding()
b.setVariable("mockRequest", mockRequest);
ge.run( "scriptx.groovy" , b )

scriptx.groovy

import com.eviware.soapui.impl.rest.mock.RestMockResult

RestMockResult res = new RestMockResult( mockRequest )
println "Message in tomcat console"
def servletContext = mockRequest.httpRequest.getServletContext()
println servletContext.getServerInfo()
println servletContext.getServletContextName()
servletContext.log("servlet context log") //INFO: in file logs\localhost.XXXX.log in apache

String paramx = mockRequest.httpRequest.getParameter("paramx")
String rendered = String.format("<html><body><p>Page with %s</p></body></html>",paramx)
mockRequest.httpResponse.writer << rendered
mockRequest.httpResponse.setStatus(200)
mockRequest.httpResponse.setContentType("text/html")
mockRequest.httpResponse.setContentLength( rendered.length() )
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01