use of javax.wsdl.Definition in project cxf by apache.
the class DefinitionVisitor method createDefinition.
/**
* Creates the WSDL definition correspoinding to the module scope if none exists
*/
private Definition createDefinition(XmlSchema schema) {
String tns = mapper.map(getScope());
Definition defn = definition;
if (tns != null) {
defn = manager.getWSDLDefinition(tns);
if (defn == null) {
try {
defn = manager.createWSDLDefinition(tns);
String key = getScope().toString("_");
String fileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + key;
manager.addWSDLDefinitionImport(definition, defn, key, fileName);
if (schema == null) {
schema = manager.getXmlSchema(tns);
}
if (schema != null) {
// add a schema based on the module with a corresponding import to the actual schema
manager.addWSDLSchemaImport(defn, tns, fileName);
// make sure that if we are adding the import to the wsdl, then we also
// add the schema to the list of imported schemas
manager.getImportedXmlSchemas().put(new java.io.File(fileName + ".xsd"), schema);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
return defn;
}
use of javax.wsdl.Definition in project cxf by apache.
the class PortTypeVisitor method findPortType.
private PortType findPortType(Scope intfScope) {
String tns = mapper.map(intfScope.getParent());
String intfName = intfScope.toString();
Definition defn = definition;
if (tns != null) {
defn = manager.getWSDLDefinition(tns);
intfName = intfScope.tail();
}
if (defn != null) {
tns = defn.getTargetNamespace();
QName name = new QName(tns, intfName);
return defn.getPortType(name);
}
return null;
}
use of javax.wsdl.Definition in project cxf by apache.
the class WSDLCorbaFactoryImpl method newDefinition.
/**
* Create a new instance of a Definition, with an instance of a
* PopulatedExtensionRegistry as its ExtensionRegistry.
*/
public Definition newDefinition() {
Definition def = factory.newDefinition();
ExtensionRegistry extReg = newPopulatedExtensionRegistry();
def.setExtensionRegistry(extReg);
return def;
}
use of javax.wsdl.Definition in project cxf by apache.
the class JAXWSDefinitionBuilderTest method testBuildDefinitionWithXMLBinding.
@Test
public void testBuildDefinitionWithXMLBinding() {
String qname = "http://apache.org/hello_world_xml_http/bare";
String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();
JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
builder.setBus(BusFactory.getDefaultBus());
builder.setContext(env);
Definition def = builder.build(wsdlUrl);
assertNotNull(def);
Map<?, ?> services = def.getServices();
assertNotNull(services);
assertEquals(1, services.size());
Service service = (Service) services.get(new QName(qname, "XMLService"));
assertNotNull(service);
Map<?, ?> ports = service.getPorts();
assertNotNull(ports);
assertEquals(1, ports.size());
Port port = service.getPort("XMLPort");
assertNotNull(port);
assertEquals(1, port.getExtensibilityElements().size());
Object obj = port.getExtensibilityElements().get(0);
if (obj instanceof JAXBExtensibilityElement) {
obj = ((JAXBExtensibilityElement) obj).getValue();
}
assertTrue(obj.getClass().getName() + " is not an AddressType", obj instanceof AddressType);
Binding binding = port.getBinding();
assertNotNull(binding);
assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());
BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
assertNotNull(operation);
BindingInput input = operation.getBindingInput();
assertNotNull(input);
assertEquals(1, input.getExtensibilityElements().size());
obj = input.getExtensibilityElements().get(0);
if (obj instanceof JAXBExtensibilityElement) {
obj = ((JAXBExtensibilityElement) obj).getValue();
}
assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat", obj instanceof XMLBindingMessageFormat);
}
use of javax.wsdl.Definition in project cxf by apache.
the class WSDL11Generator method generate.
public Definition generate(final File dir) {
File file = getOutputBase();
if (file == null && dir != null) {
if (dir.isDirectory()) {
file = new File(dir, getServiceModel().getName().getLocalPart() + ".wsdl");
} else {
file = dir;
}
} else if (dir == null) {
file = new File(getServiceModel().getName().getLocalPart() + ".wsdl");
}
File outputdir = createOutputDir(file);
Definition def = null;
try {
Writer os = new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, StandardCharsets.UTF_8.name());
WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(getBus(), getServiceModel());
builder.setUseSchemaImports(this.allowImports());
String name = file.getName();
if (name.endsWith(".wsdl")) {
name = name.substring(0, name.lastIndexOf(".wsdl"));
}
builder.setBaseFileName(name);
Map<String, SchemaInfo> imports = new HashMap<>();
def = builder.build(imports);
wsdlWriter.writeWSDL(def, os);
os.close();
if (!def.getImports().isEmpty()) {
for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
Definition wsdlDef = wsdlImport.getDefinition();
final File wsdlFile;
if (!StringUtils.isEmpty(wsdlImport.getLocationURI())) {
wsdlFile = new File(outputdir, wsdlImport.getLocationURI());
} else {
wsdlFile = new File(outputdir, wsdlDef.getQName().getLocalPart() + ".wsdl");
}
try (OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()))) {
wsdlWriter.writeWSDL(wsdlDef, wsdlOs);
}
}
}
for (Map.Entry<String, SchemaInfo> imp : imports.entrySet()) {
File impfile = new File(file.getParentFile(), imp.getKey());
Element el = imp.getValue().getElement();
updateImports(el, imports);
FileWriterUtil fileWriterUtil = new FileWriterUtil(impfile.getParent(), getToolContext().get(OutputStreamCreator.class));
os = fileWriterUtil.getWriter(impfile, StandardCharsets.UTF_8.name());
StaxUtils.writeTo(el, os, 2);
os.close();
}
customizing(outputdir, name, imports.keySet());
} catch (WSDLException wex) {
wex.printStackTrace();
} catch (FileNotFoundException fnfe) {
throw new ToolException("Output file " + file + " not found", fnfe);
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
}
return def;
}
Aggregations