Cannot run multiple virts on the same port
When attempting to start multiple virts on the same port, but with different paths (equivalent works fine in SoapUI Pro 4 & 5), I get the following error:
com.smartbear.servicev.core.model.SvpException: Port: 8888 is already occupied by virt virtName. Please choose another port.
I've tried multiple virts in the same project, as well as separate projects for each virt. Since we have 10s to 100s of virts (depending on application), putting each of them on a different port isn't an option.
So, thinking about writing a java proxy to sit in front of ServiceV (and deciding that I still didn't like the idea of all the services on different ports), I came up with this solution:
I created a new empty SOAP project, with an empty Virt, and added a "MockRunListener.onMockRequest" event handler, which loops through every service for every project in the current workspace, compares the path to the requested path, and dispatches as appropriate. This pretty closely duplicates the old functionality, and since the original virts don't actually have to be running, they don't have to be modified to run on different ports. Some example code without any error handling is below:
import com.eviware.soapui.impl.wsdl.mock.WsdlMockService if (request.getAttribute("xReadyApiProxied")) { return } for (project in runner.getMockContext().getMockService().getParent().getParent().getChildren()) { for (service in project.getChildren()) { if (service instanceof WsdlMockService) { def ws = (WsdlMockService)service; if (request.getPathInfo() == ws.getPath()) { log.info "Proxying request for " + request.getPathInfo() + " to " + project.name + " : " + ws.name def runner = ws.getMockRunner(); if (runner == null) { runner = ws.start(); } request.setAttribute("xReadyApiProxied", true) runner.dispatchRequest(request, response) } } } }