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);
}
}
}
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.");
}
}
Aggregations