new Contribution("test", contributionLocation));
node.start();
try {
RuntimeEndpointImpl endpoint = (RuntimeEndpointImpl)node.getDomainComposite().getComponents().get(0).getServices().get(0).getEndpoints().get(0);
WSDLInterface wsdlInterface = (WSDLInterface)endpoint.getBindingInterfaceContract().getInterface();
WSDLDefinition wsdlDefinition = wsdlInterface.getWsdlDefinition();
Definition definition = wsdlDefinition.getDefinition();
// write out a flattened WSDL along with XSD
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try {
WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
String baseURI = null;
if (wsdlDefinition.getLocation() != null) {
baseURI = wsdlDefinition.getLocation().toString();
} else {
baseURI = "GeneratedWSDL";
}
outStream.write(baseURI.getBytes());
outStream.write(separator);
writer.writeWSDL(definition, outStream);
for (WSDLDefinition importedWSDLDefintion : wsdlDefinition.getImportedDefinitions()){
outStream.write(separator);
baseURI = importedWSDLDefintion.getLocation().toString();
outStream.write(baseURI.getBytes());
outStream.write(separator);
writer.writeWSDL(importedWSDLDefintion.getDefinition(), outStream);
}
for (XSDefinition xsdDefinition : wsdlDefinition.getXmlSchemas()){
// we store a reference to the schema schema. We don't need to write that out.
// also ignore schema that are extract from the original WSDL (have in their location)
if (!xsdDefinition.getNamespace().equals("http://www.w3.org/2001/XMLSchema") &&
xsdDefinition.getSchema() != null){
writeSchema(outStream, xsdDefinition.getSchema());
}
}
} catch (Exception e){
throw new RuntimeException(e);
}
String wsdlString = outStream.toString();
//System.out.println(wsdlString);
// Read the WSDL and XSD back in from the string
String xmlArray[] = wsdlString.split("_X_");
String topWSDLLocation = null;
Map<String, XMLString> xmlMap = new HashMap<String, XMLString>();
for (int i = 0; i < xmlArray.length; i = i + 2){
String location = xmlArray[i];
String xml = xmlArray[i+1];
// strip the file name out of the location
location = location.substring(location.lastIndexOf("/") + 1);
if (location.endsWith(".wsdl")){
xmlMap.put(location,
new WSDLInfo(xmlArray[i],
xml));
if (topWSDLLocation == null){
topWSDLLocation = location;
}
} else {
xmlMap.put(location,
new XSDInfo(xmlArray[i],
xml));
}
}
ExtensionPointRegistry registry = endpoint.getCompositeContext().getExtensionPointRegistry();
FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory wsdlFactory = modelFactories.getFactory(org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory.class);
XSDFactory xsdFactory = modelFactories.getFactory(XSDFactory.class);
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
schemaCollection.setSchemaResolver(new XSDURIResolverImpl(xmlMap));