Hi,
I have a WSDL file that contains one import statement to another WSDL
file as well as several schema imports that I need to flatten out to
one single file. WSDLFlattener looks very promising but there are some
things missing when i try. I get the schemas, messages and porttype
from the wsdl file referenced in the import nicely included in the new
file but i am missing the binding and service elements from the "base"
wsdl file.
The base WSLD contains an import, a binding and a service. The
referenced WSDL contains types (including schema imports), messages
and a portType.
This is what i do:
public void testFlattener(String wsdlFile, String targetFile)
throws Exception {
WSDLFactory wsdlFactory =
WSDLFactory.newInstance("oracle.webservices.wsdl.WSDLFactoryImpl");
//--Create a reader and register the standard extensions
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
ExtensionRegistry extensionRegistry =
wsdlFactory.newPopulatedExtensionRegistry();
wsdlReader.setExtensionRegistry(extensionRegistry);
//--Read a WSDL file, including any imports
wsdlReader.setFeature("javax.wsdl.importDocuments", true);
Definition def = wsdlReader.readWSDL(wsdlFile);
// Use the first port type available
PortType portType =
(PortType)def.getPortTypes().values().iterator().next();
WSDLFlattener flattener = new WSDLFlattener (def);
flattener.initialize();
Definition flatDef = flattener.getDefinition(portType.getQName());
File outputFile = new File(targetFile);
WSDLWriter writer = wsdlFactory.newWSDLWriter();
FileWriter fileWriter = new FileWriter(outputFile);
writer.writeWSDL(flatDef, fileWriter);
fileWriter.close();
}
If i try to just add the binding and service elements from the base
wsdl i get a namespace issue for the binding. WSDL2Java reports that
"There is an undefined binding
(ProvisioningNotificationInterfaceBinding) in the WSDL document. Hint:
make sure <port binding=".."> is fully qualified."
I was trying to binding and service simply by doing this:
Collection<Binding> bindings = def.getBindings().values();
for (Binding binding: bindings) {
flatDef.addBinding(binding);
}
Collection<Service> services = def.getServices().values();
for (Service service:services) {
flatDef.addService(service);
}
Is there a simpler way to flatten a wsdl file using the WSDLFlattener?
Maybe some other wrapper utility I have not found?
Best regards,
Per