Search in sources :

Example 1 with WSDLPopulationUtil

use of org.talend.repository.services.utils.WSDLPopulationUtil in project tesb-studio-se by Talend.

the class PublishMetadataRunnable method process.

@SuppressWarnings("unchecked")
private void process(Definition wsdlDefinition, Collection<XmlFileConnectionItem> selectTables) throws Exception, CoreException {
    List<IFile> tempFiles = new ArrayList<IFile>();
    try {
        File wsdlFile = null;
        String baseUri = wsdlDefinition.getDocumentBaseURI();
        URI uri = new URI(baseUri);
        if ("file".equals(uri.getScheme())) {
            wsdlFile = new File(uri.toURL().getFile());
        } else {
            Map<String, InputStream> load = new WSDLLoader().load(baseUri, "tempWsdl" + "%d.wsdl");
            InputStream inputStream = load.remove(WSDLLoader.DEFAULT_FILENAME);
            String name = File.createTempFile("tESBConsumer", ".wsdl").getName();
            IFile tempWsdlFile = createTempFile(name, inputStream);
            tempFiles.add(tempWsdlFile);
            wsdlFile = new File(tempWsdlFile.getLocation().toPortableString());
            // TESB-19040:save import wsdl files
            if (!load.isEmpty()) {
                for (Map.Entry<String, InputStream> importWsdl : load.entrySet()) {
                    tempFiles.add(createTempFile(importWsdl.getKey(), importWsdl.getValue()));
                }
            }
        }
        if (populationUtil == null) {
            populationUtil = new WSDLPopulationUtil();
            populationUtil.loadWSDL("file://" + wsdlFile.getAbsolutePath());
        }
        final Set<QName> portTypes = new HashSet<QName>();
        final Set<QName> alreadyCreated = new HashSet<QName>();
        for (Binding binding : (Collection<Binding>) wsdlDefinition.getAllBindings().values()) {
            final QName portType = binding.getPortType().getQName();
            if (portTypes.add(portType)) {
                for (BindingOperation operation : (Collection<BindingOperation>) binding.getBindingOperations()) {
                    Operation oper = operation.getOperation();
                    Input inDef = oper.getInput();
                    if (inDef != null) {
                        Message inMsg = inDef.getMessage();
                        if (inMsg != null) {
                            // fix for TDI-20699
                            List<QName> messageParts = getMessageParts(inMsg);
                            if (messageParts.isEmpty()) {
                                continue;
                            }
                            for (QName messagePart : messageParts) {
                                if (alreadyCreated.add(messagePart)) {
                                    XsdMetadataUtils.createMetadataFromXSD(messagePart, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                                }
                            }
                        }
                    }
                    Output outDef = oper.getOutput();
                    if (outDef != null) {
                        Message outMsg = outDef.getMessage();
                        if (outMsg != null) {
                            List<QName> messageParts = getMessageParts(outMsg);
                            if (messageParts.isEmpty()) {
                                continue;
                            }
                            for (QName messagePart : messageParts) {
                                if (alreadyCreated.add(messagePart)) {
                                    XsdMetadataUtils.createMetadataFromXSD(messagePart, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                                }
                            }
                        }
                    }
                    for (Fault fault : (Collection<Fault>) oper.getFaults().values()) {
                        Message faultMsg = fault.getMessage();
                        if (faultMsg != null) {
                            List<QName> messageParts = getMessageParts(faultMsg);
                            if (messageParts.isEmpty()) {
                                continue;
                            }
                            for (QName messagePart : messageParts) {
                                if (alreadyCreated.add(messagePart)) {
                                    XsdMetadataUtils.createMetadataFromXSD(messagePart, portType.getLocalPart(), oper.getName(), selectTables, wsdlFile, populationUtil);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        throw e;
    } finally {
        for (IFile tempFile : tempFiles) {
            tempFile.delete(true, null);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Message(javax.wsdl.Message) ArrayList(java.util.ArrayList) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) URI(java.net.URI) BindingOperation(javax.wsdl.BindingOperation) Input(javax.wsdl.Input) WSDLPopulationUtil(org.talend.repository.services.utils.WSDLPopulationUtil) Output(javax.wsdl.Output) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) HashSet(java.util.HashSet) Binding(javax.wsdl.Binding) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) Collection(java.util.Collection) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Map(java.util.Map)

Example 2 with WSDLPopulationUtil

use of org.talend.repository.services.utils.WSDLPopulationUtil in project tesb-studio-se by Talend.

the class WSDLPopulationUtilTest method testLoadWSDL.

/**
 * Test method for {@link org.talend.repository.services.utils.WSDLPopulationUtil#loadWSDL(java.lang.String)}.
 *
 * To validate an imported XSD/WSDL type files. TESB-19040
 */
@Test
public void testLoadWSDL() {
    Bundle b = Platform.getBundle("org.talend.esb.repository.services.test");
    try {
        // $NON-NLS-1$
        URL url = FileLocator.toFileURL(FileLocator.find(b, new Path("resources"), null));
        WSDLPopulationUtil wsdlPopulationUtil = new WSDLPopulationUtil();
        wsdlPopulationUtil.loadWSDL("file://" + url.getPath() + "/client_wsdl/cliente-v1_1.wsdl");
        Assert.assertNotNull(wsdlPopulationUtil.getXSDSchemaFromNamespace("http://www.supervielle.com.ar/xsd/Integracion/common/commonTypes-v1"));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Test testGetTemplateURL() method failure.");
    }
}
Also used : Path(org.eclipse.core.runtime.Path) WSDLPopulationUtil(org.talend.repository.services.utils.WSDLPopulationUtil) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 WSDLPopulationUtil (org.talend.repository.services.utils.WSDLPopulationUtil)2 File (java.io.File)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Binding (javax.wsdl.Binding)1 BindingOperation (javax.wsdl.BindingOperation)1 Fault (javax.wsdl.Fault)1 Input (javax.wsdl.Input)1 Message (javax.wsdl.Message)1 Operation (javax.wsdl.Operation)1 Output (javax.wsdl.Output)1 QName (javax.xml.namespace.QName)1