use of javax.wsdl.xml.WSDLWriter in project cxf by apache.
the class WSDLGenerationTester method writeDefinition.
public File writeDefinition(File targetDir, File defnFile) throws Exception {
WSDLManager wm = BusFactory.getThreadDefaultBus().getExtension(WSDLManager.class);
File bkFile = new File(targetDir, "bk_" + defnFile.getName());
FileWriter writer = new FileWriter(bkFile);
WSDLFactory factory = WSDLFactory.newInstance("org.apache.cxf.tools.corba.utils.TestWSDLCorbaFactoryImpl");
WSDLReader reader = factory.newWSDLReader();
reader.setFeature("javax.wsdl.importDocuments", false);
reader.setExtensionRegistry(wm.getExtensionRegistry());
final String url = defnFile.toString();
CatalogWSDLLocator locator = new CatalogWSDLLocator(url, (Bus) null);
Definition wsdlDefn = reader.readWSDL(locator);
WSDLWriter wsdlWriter = factory.newWSDLWriter();
wsdlWriter.writeWSDL(wsdlDefn, writer);
writer.close();
writer = null;
reader = null;
return bkFile;
}
use of javax.wsdl.xml.WSDLWriter 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().size() > 0) {
for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
Definition wsdlDef = wsdlImport.getDefinition();
File wsdlFile = null;
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 e) {
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
return def;
}
use of javax.wsdl.xml.WSDLWriter in project cxf by apache.
the class AbstractAegisTest method getWSDLDocuments.
protected Collection<Document> getWSDLDocuments(String string) throws WSDLException {
WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
Collection<Document> docs = new ArrayList<>();
Definition definition = getWSDLDefinition(string);
if (definition == null) {
return null;
}
docs.add(writer.getDocument(definition));
for (Import wsdlImport : getImports(definition)) {
docs.add(writer.getDocument(wsdlImport.getDefinition()));
}
return docs;
}
use of javax.wsdl.xml.WSDLWriter in project cxf by apache.
the class JaxWsServerFactoryBeanTest method testJaxwsServiceClass.
@Test
public void testJaxwsServiceClass() throws Exception {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceClass(CalculatorPortType.class);
factory.setServiceBean(new CalculatorImpl());
String address = "http://localhost:9001/jaxwstest";
factory.setAddress(address);
Server server = factory.create();
Endpoint endpoint = server.getEndpoint();
ServiceInfo service = endpoint.getEndpointInfo().getService();
assertNotNull(service);
Bus bus = factory.getBus();
Definition def = new ServiceWSDLBuilder(bus, service).build();
WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
Document doc = wsdlWriter.getDocument(def);
Map<String, String> ns = new HashMap<>();
ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
XPathUtils xpather = new XPathUtils(ns);
xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding", doc, XPathConstants.NODE);
xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation", doc, XPathConstants.NODE);
xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='" + address + "']", doc, XPathConstants.NODE);
}
use of javax.wsdl.xml.WSDLWriter in project cxf by apache.
the class PolicyAnnotationTest method testAnnotationImplNoInterface.
@org.junit.Test
public void testAnnotationImplNoInterface() throws Exception {
Bus bus = BusFactory.getDefaultBus();
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setBus(bus);
factory.setServiceBean(new TestImplNoInterface());
factory.setStart(false);
List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
LocalTransportFactory f = new LocalTransportFactory();
f.getUriPrefixes().add("http");
f.setTransportIds(tp);
Server s = factory.create();
try {
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
Definition def = builder.build();
WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
Map<String, String> ns = new HashMap<>();
ns.put("wsdl", WSDLConstants.NS_WSDL11);
ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
ns.put("wsp", Constants.URI_POLICY_13_NS);
XPathUtils xpu = new XPathUtils(ns);
// org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/" + "wsp:PolicyReference[@URI='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']", wsdl).getLength());
final EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
assertNotNull(policy);
} finally {
bus.shutdown(true);
}
}
Aggregations