Search in sources :

Example 1 with WsdlOperation

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;
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) File(java.io.File)

Example 2 with WsdlOperation

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;
}
Also used : WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) ScriptMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.ScriptMockOperationDispatcher) WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) MockOperation(com.eviware.soapui.model.mock.MockOperation) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation) MockOperation(com.eviware.soapui.model.mock.MockOperation) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation) WsdlMockOperation(com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation) MockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.MockOperationDispatcher) ScriptMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.ScriptMockOperationDispatcher) QueryMatchMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.QueryMatchMockOperationDispatcher) QueryMatchMockOperationDispatcher(com.eviware.soapui.impl.wsdl.mock.dispatch.QueryMatchMockOperationDispatcher)

Aggregations

WsdlOperation (com.eviware.soapui.impl.wsdl.WsdlOperation)2 WsdlInterface (com.eviware.soapui.impl.wsdl.WsdlInterface)1 WsdlProject (com.eviware.soapui.impl.wsdl.WsdlProject)1 WsdlMockOperation (com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation)1 MockOperationDispatcher (com.eviware.soapui.impl.wsdl.mock.dispatch.MockOperationDispatcher)1 QueryMatchMockOperationDispatcher (com.eviware.soapui.impl.wsdl.mock.dispatch.QueryMatchMockOperationDispatcher)1 ScriptMockOperationDispatcher (com.eviware.soapui.impl.wsdl.mock.dispatch.ScriptMockOperationDispatcher)1 MockOperation (com.eviware.soapui.model.mock.MockOperation)1 XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)1 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)1 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Definition (javax.wsdl.Definition)1 QName (javax.xml.namespace.QName)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)1