use of com.eviware.soapui.config.DefintionPartConfig in project microcks by microcks.
the class SoapUIProjectImporter method getResourceDefinitions.
@Override
public List<Resource> getResourceDefinitions(Service service) {
List<Resource> results = new ArrayList<>();
// For now, only available for Wsdl based projects having mocked interfaces.
WsdlMockService wsdlMockService = project.getMockServiceByName(service.getName());
if (wsdlMockService != null) {
// Use only the first interface of the mock service corresponding to service.
WsdlInterface wi = project.getMockServiceByName(service.getName()).getMockedInterfaces()[0];
// Find the name of the definition we must look for within all interfaces.
String definitionName = wi.getConfig().getDefinition();
List<Interface> pis = project.getInterfaceList();
for (Interface pi : pis) {
if (pi instanceof WsdlInterface) {
WsdlInterface candidateWI = (WsdlInterface) pi;
if (candidateWI.getDefinition().equals(definitionName)) {
List<DefintionPartConfig> parts = candidateWI.getConfig().getDefinitionCache().getPartList();
if (parts != null && parts.size() > 0) {
// First part is always the wsdl definition, get its content as string.
String wsdlContent = parts.get(0).getContent().newCursor().getTextValue();
// Then browse the following one (XSD) and change relative path in imports.
for (int i = 1; i < parts.size(); i++) {
DefintionPartConfig xsdConfig = parts.get(i);
String xsdUrl = xsdConfig.getUrl();
String xsdName = xsdUrl.substring(xsdUrl.lastIndexOf('/') + 1);
String xsdContent = xsdConfig.getContent().newCursor().getTextValue();
// Build a new xsd resource for this part.
Resource xsdResource = new Resource();
xsdResource.setName(xsdName);
xsdResource.setType(ResourceType.XSD);
xsdResource.setContent(xsdContent);
results.add(xsdResource);
// URL references within WSDL must be replaced by their local counterpart.
wsdlContent = wsdlContent.replace(xsdUrl, "./" + xsdName);
}
// Finally, declare englobing wsdl resource.
Resource wsdlResource = new Resource();
wsdlResource.setName(service.getName() + "-" + service.getVersion() + ".wsdl");
wsdlResource.setType(ResourceType.WSDL);
wsdlResource.setContent(wsdlContent);
results.add(wsdlResource);
}
}
}
}
}
return results;
}
Aggregations