Skip to content

Instantly share code, notes, and snippets.

@zubairov
Created July 20, 2011 09:17
Show Gist options
  • Save zubairov/1094631 to your computer and use it in GitHub Desktop.
Save zubairov/1094631 to your computer and use it in GitHub Desktop.
How to parse WSDL and associated XML Schemas in Eclipse
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: WSDLParsing
Bundle-SymbolicName: WSDLParsing
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.wst.wsdl;bundle-version="1.2.104",
org.junit;bundle-version="3.8.2",
org.eclipse.emf;bundle-version="2.6.0",
org.eclipse.emf.ecore;bundle-version="2.6.1",
org.eclipse.xsd;bundle-version="2.6.0",
org.eclipse.core.resources;bundle-version="3.6.1",
org.eclipse.core.runtime;bundle-version="3.6.0",
org.apache.xerces;bundle-version="2.9.0",
javax.wsdl;bundle-version="1.5.1"
/*
* Milyn - Copyright (C) 2006 - 2011
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License (version 2.1) as published by the Free Software
* Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License for more details:
* http://www.gnu.org/licenses/lgpl.txt
*/
package org.talend.test;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Operation;
import org.eclipse.wst.wsdl.PortType;
import org.eclipse.wst.wsdl.Types;
import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDSchema;
public class WSDLParsingTest extends TestCase {
public void testParsing() throws Exception {
ResourceSet rs = new ResourceSetImpl();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("wsdl", new WSDLResourceFactoryImpl());
Resource resource = rs.createResource(URI
.createFileURI("airport_soap.wsdl"));
assertNotNull(resource);
resource.load(null);
assertEquals(1, resource.getContents().size());
Definition root = (Definition) resource.getContents().iterator().next();
// Schemas
Types eTypes = root.getETypes();
List schemas = eTypes.getSchemas();
assertEquals(1, schemas.size());
XSDSchema schema = (XSDSchema) schemas.iterator().next();
EList<XSDElementDeclaration> els = schema.getElementDeclarations();
assertEquals(3, els.size());
// Messages
Map messages = root.getMessages();
Collection portTypes = root.getPortTypes().values();
assertEquals(1, portTypes.size());
PortType type = (PortType) portTypes.iterator().next();
List operations = type.getOperations();
Operation op = (Operation) operations.iterator().next();
assertEquals("getAirportInformationByISOCountryCode", op.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment