Forum Discussion
ITAbteilung
12 years agoContributor
Now I've solved it that way: in the onRequest script of the MockUp I execute the following code, which works generically for all MockUps that caches its definition:
In general it works. There is only one curious bug: We are deploying the mock on a server and using the WebUI (the web interface of the mockup where requests, responses and scriptlog can be viewed). Normally, when I send a request to the mock and it sends the response, the whole conversation can be seen at the WebUI. BUT: when the request is invalid and the script returns the WsdlMockResult, nothing but the scriptlog can be seen and WORSE: the upper third part of the WebUI does not work anymore until redeploying the mockup!!! Instead of showing timestamp, time taken, mockoperation and so on, an Exception appears:
We are using SoapUI-Pro4.5.1. Please could you fix that Exception! It would be an enormous help for us and all other developers who want to use request validation!
Thanks in advance,
Gilbert Fritz
import com.eviware.soapui.impl.wsdl.WsdlOperation
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation
import com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockRequestMessageExchange;
import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;
WsdlContext wsdlcontext = context.mockService.getMockedInterfaces()[0].getDefinitionContext();
WsdlValidator validator = new WsdlValidator(wsdlcontext);
String operationName = mockRequest.soapAction.substring(mockRequest.soapAction.lastIndexOf('/') +1).split("#")[1];
WsdlMockOperation operation = context.mockService.getMockOperationByName( operationName);
WsdlMockRequestMessageExchange msgExchange = new WsdlMockRequestMessageExchange(mockRequest, operation);
def errors = validator.assertRequest(msgExchange, false);
if (errors.length > 0 ){
log.info( "returning ValidationError");
String validationErrors = "VALIDATION ERRORS: " + errors.collect(){ '\n' + it };
String content = '''<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>Server</faultcode>
<faultstring>''' + validationErrors + '''</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>''';
WsdlMockResult mr = new WsdlMockResult(mockRequest);
mockRequest.httpResponse.writer << content;
mockRequest.httpResponse.status = 200;
return mr;
}
In general it works. There is only one curious bug: We are deploying the mock on a server and using the WebUI (the web interface of the mockup where requests, responses and scriptlog can be viewed). Normally, when I send a request to the mock and it sends the response, the whole conversation can be seen at the WebUI. BUT: when the request is invalid and the script returns the WsdlMockResult, nothing but the scriptlog can be seen and WORSE: the upper third part of the WebUI does not work anymore until redeploying the mockup!!! Instead of showing timestamp, time taken, mockoperation and so on, an Exception appears:
java.lang.NullPointerException:
com.eviware.soapui.mockaswar.MockAsWarServlet.printMaster(MockAsWarServlet.java:422)
com.eviware.soapui.mockaswar.MockAsWarProServlet$MockServletSoapUIProCore.dispatchRequest(SourceFile:128)
com.eviware.soapui.mockaswar.MockAsWarServlet.service(MockAsWarServlet.java:190)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
We are using SoapUI-Pro4.5.1. Please could you fix that Exception! It would be an enormous help for us and all other developers who want to use request validation!
Thanks in advance,
Gilbert Fritz
Related Content
- 12 years agoMitchM