use of com.eviware.soapui.impl.wsdl.WsdlOperation 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.WsdlOperation in project microcks by microcks.
the class SoapUIProjectImporter method extractOperations.
/**
* Extract the list of operations from MockService according WsdlInterface.
*/
private List<Operation> extractOperations(MockService mockService, WsdlInterface wi) {
List<Operation> result = new ArrayList<Operation>();
List<MockOperation> operations = mockService.getMockOperationList();
for (MockOperation mockOperation : operations) {
// Build a new operation.
Operation operation = new Operation();
operation.setName(mockOperation.getName());
// Retrieve part name from Wsdl operation coming from interface.
WsdlOperation wo = wi.getOperationByName(mockOperation.getName());
operation.setAction(wo.getAction());
operation.setInputName(wo.getInputName());
operation.setOutputName(wo.getOutputName());
WsdlMockOperation wmo = (WsdlMockOperation) mockOperation;
operation.setDispatcher(wmo.getDispatchStyle());
// Check dispatcher configuration.
MockOperationDispatcher dispatcher = wmo.getDispatcher();
if (dispatcher instanceof QueryMatchMockOperationDispatcher) {
QueryMatchMockOperationDispatcher qmDispatcher = (QueryMatchMockOperationDispatcher) dispatcher;
String query = qmDispatcher.getQueryAt(0).getQuery();
operation.setDispatcherRules(query);
} else if (dispatcher instanceof ScriptMockOperationDispatcher) {
ScriptMockOperationDispatcher sDispatcher = (ScriptMockOperationDispatcher) dispatcher;
String script = sDispatcher.getMockOperation().getScript();
operation.setDispatcherRules(script);
}
result.add(operation);
}
return result;
}
Aggregations