use of com.eviware.soapui.impl.wsdl.WsdlInterface in project convertigo by convertigo.
the class WsReference method importSoapWebService.
private static HttpConnector importSoapWebService(Project project, WebServiceReference soapServiceReference) throws Exception {
List<HttpConnector> connectors = new ArrayList<HttpConnector>();
HttpConnector firstConnector = null;
String wsdlUrl = soapServiceReference.getUrlpath();
WsdlProject wsdlProject = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(wsdlProject, wsdlUrl);
int len = wsdls.length;
if (len > 0) {
WsdlInterface iface = wsdls[len - 1];
if (iface != null) {
// Retrieve definition name or first service name
String definitionName = null;
try {
Definition definition = iface.getWsdlContext().getDefinition();
QName qname = definition.getQName();
qname = (qname == null ? (QName) definition.getAllServices().keySet().iterator().next() : qname);
definitionName = qname.getLocalPart();
} catch (Exception e1) {
throw new Exception("No service found !");
}
// Modify reference's name
if (soapServiceReference.bNew) {
// Note : new reference may have already been added to the project (new object wizard)
// its name must be replaced with a non existing one !
String newDatabaseObjectName = project.getChildBeanName(project.getReferenceList(), StringUtils.normalize("Import_WS_" + definitionName), true);
soapServiceReference.setName(newDatabaseObjectName);
}
// Retrieve directory for WSDLs to download
File exportDir = null;
/* For further use...
if (!webServiceReference.getFilepath().isEmpty()) { // for update case
try {
exportDir = webServiceReference.getFile().getParentFile();
if (exportDir.exists()) {
File destDir = exportDir;
for (int index = 0; destDir.exists(); index++) {
destDir = new File(exportDir.getPath()+ "/v" + index);
}
Collection<File> files = GenericUtils.cast(FileUtils.listFiles(exportDir, null, false));
for (File file: files) {
FileUtils.copyFileToDirectory(file, destDir);
}
}
} catch (Exception ex) {}
}*/
if (soapServiceReference.bNew || exportDir == null) {
// for other cases
String projectDir = project.getDirPath();
exportDir = new File(projectDir + "/wsdl/" + definitionName);
for (int index = 1; exportDir.exists(); index++) {
exportDir = new File(projectDir + "/wsdl/" + definitionName + index);
}
}
// Download all needed WSDLs (main one and imported/included ones)
String wsdlPath = iface.getWsdlContext().export(exportDir.getPath());
// Modify reference's filePath : path to local main WSDL
String wsdlUriPath = new File(wsdlPath).toURI().getPath();
String wsdlLocalPath = ".//" + wsdlUriPath.substring(wsdlUriPath.indexOf("/wsdl") + 1);
soapServiceReference.setFilepath(wsdlLocalPath);
soapServiceReference.hasChanged = true;
// Add reference to project
if (soapServiceReference.getParent() == null) {
project.add(soapServiceReference);
}
// create an HTTP connector for each binding
if (soapServiceReference.bNew) {
for (int i = 0; i < wsdls.length; i++) {
iface = wsdls[i];
if (iface != null) {
Definition definition = iface.getWsdlContext().getDefinition();
XmlSchemaCollection xmlSchemaCollection = WSDLUtils.readSchemas(definition);
XmlSchema xmlSchema = xmlSchemaCollection.schemaForNamespace(definition.getTargetNamespace());
HttpConnector httpConnector = createSoapConnector(iface);
if (httpConnector != null) {
String bindingName = iface.getBindingName().getLocalPart();
String newDatabaseObjectName = project.getChildBeanName(project.getConnectorsList(), StringUtils.normalize(bindingName), true);
httpConnector.setName(newDatabaseObjectName);
boolean hasDefaultTransaction = false;
for (int j = 0; j < iface.getOperationCount(); j++) {
WsdlOperation wsdlOperation = (WsdlOperation) iface.getOperationAt(j);
XmlHttpTransaction xmlHttpTransaction = createSoapTransaction(xmlSchema, iface, wsdlOperation, project, httpConnector);
// Adds transaction
if (xmlHttpTransaction != null) {
httpConnector.add(xmlHttpTransaction);
if (!hasDefaultTransaction) {
xmlHttpTransaction.setByDefault();
hasDefaultTransaction = true;
}
}
}
connectors.add(httpConnector);
}
}
}
// add connector(s) to project
for (HttpConnector httpConnector : connectors) {
project.add(httpConnector);
if (firstConnector == null) {
firstConnector = httpConnector;
}
}
}
}
} else {
throw new Exception("No interface found !");
}
return firstConnector;
}
use of com.eviware.soapui.impl.wsdl.WsdlInterface in project microcks by microcks.
the class SoapUIProjectImporter method getSoapServiceDefinitions.
/**
* Get the definitions of Soap Services from mock services.
*/
private List<Service> getSoapServiceDefinitions(List<WsdlMockService> mockServices) throws MockRepositoryImportException {
List<Service> result = new ArrayList<>();
for (WsdlMockService wms : mockServices) {
// First assume it's a Soap one.
Service service = new Service();
service.setName(wms.getName());
service.setType(ServiceType.SOAP_HTTP);
// Ensure we've got only one interface and extract its namespace.
WsdlInterface[] wi = wms.getMockedInterfaces();
if (wi == null || wi.length > 1) {
// TODO Throw a typed exception here...
}
service.setXmlNS(wi[0].getBindingName().getNamespaceURI());
// Extract version from custom properties.
String version = wms.getPropertyValue(SERVICE_VERSION_PROPERTY);
if (version == null) {
log.error("Version property is missing in Project properties");
throw new MockRepositoryImportException("Version property is missing in Project properties");
}
service.setVersion(version);
// Then build its operations.
service.setOperations(extractOperations(wms, wi[0]));
result.add(service);
}
return result;
}
use of com.eviware.soapui.impl.wsdl.WsdlInterface 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