Size: 2250
Comment:
|
Size: 2251
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 23: | Line 23: |
== WAR generation from SoapUI project== | == WAR generation from SoapUI project == |
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
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 )
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() )