esben
13 years agoNew Contributor
MockService HTTP POST Parameters missing
Hi
I am trying to write a test where I get a POST request from an external party, and the parameters of that POST request needs to be used in a test.
So reading a bit around I figured I could write a MockService in SoapUi and parse the POST request from that.
In order to do that i have to use the "OnRequest" script part of a mocking service.
I got as far as to get the WsdlMockRequst context (mockRequest.requestContext) and from that i got the javax.servlet.http.HttpServletRequest (mockRequest.httpRequest).
However the httprequest seems to be missing the post parameters somehow. I get the "querystring" if i do something like
Any ideas, or other ways to get the parameters short of manually parsing the request context? Or is this an error in soapui (im using 4.5.1 on x64 btw)
The complete code block is something like this:
I am trying to write a test where I get a POST request from an external party, and the parameters of that POST request needs to be used in a test.
So reading a bit around I figured I could write a MockService in SoapUi and parse the POST request from that.
In order to do that i have to use the "OnRequest" script part of a mocking service.
I got as far as to get the WsdlMockRequst context (mockRequest.requestContext) and from that i got the javax.servlet.http.HttpServletRequest (mockRequest.httpRequest).
However the httprequest seems to be missing the post parameters somehow. I get the "querystring" if i do something like
log.info(mockRequest.requestContent)and analyzing the actual http request shows me that it does indeed contain POST parameters. However something like
log.info(mockRequest.httpRequest.getParameters()gives me a null value.
Any ideas, or other ways to get the parameters short of manually parsing the request context? Or is this an error in soapui (im using 4.5.1 on x64 btw)
The complete code block is something like this:
import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
import com.eviware.soapui.impl.wsdl.mock.WsdlMockRequest;
import com.eviware.soapui.impl.wsdl.mock.WsdlMockRunner;
import javax.servlet.http.HttpServletRequest;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def mockcontext = mockRequest.requestContext;
def httpRequest = mockRequest.httpRequest;
if(httpRequest.method == "POST")
{
log.info(httpRequest.getParameters()); // Logs null
log.info(mockRequest.requestContent); // Logs the request in string form
log.info(httpRequest.getParameter("status")); //Logs null even though i know it is there
mockRunner.returnFile( mockRequest.httpResponse, new File ( "C:\\temp\\something.html" ))
WsdlMockResult mockResult = new WsdlMockResult( mockRequest );
return mockResult;
}