use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.
the class WSDLGetUtils method updateWSDLKeyDefinition.
/**
* Create a wsdl Definition object from the endpoint information and register
* it in the local data structure for future reference.
*
* @param bus CXF's hub for access to internal constructs
* @param mp a map of known wsdl Definition objects
* @param message
* @param smp a map of known xsd SchemaReference objects
* @param base the request URL
* @param endpointInfo information for a web service 'port' inside of a service
* @throws WSDLException
*/
protected void updateWSDLKeyDefinition(Bus bus, Map<String, Definition> mp, Message message, Map<String, SchemaReference> smp, String base, EndpointInfo endpointInfo) throws WSDLException {
if (!mp.containsKey("")) {
ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, endpointInfo.getService());
builder.setUseSchemaImports(MessageUtils.getContextualBoolean(message, WSDL_CREATE_IMPORTS, false));
// base file name is ignored if createSchemaImports == false!
builder.setBaseFileName(endpointInfo.getService().getName().getLocalPart());
Definition def = builder.build(new HashMap<String, SchemaInfo>());
mp.put("", def);
updateDefinition(bus, def, mp, smp, base, "", "");
}
}
use of org.apache.cxf.wsdl11.ServiceWSDLBuilder 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 org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.
the class CodeFirstWSDLTest method createService.
private Definition createService(Class<?> clazz) throws Exception {
JaxWsImplementorInfo info = new JaxWsImplementorInfo(clazz);
ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean(info);
Bus bus = getBus();
bean.setBus(bus);
Service service = bean.create();
InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
assertEquals(5, i.getOperations().size());
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.setBus(bus);
svrFactory.setServiceFactory(bean);
svrFactory.setServiceBean(clazz.newInstance());
svrFactory.setAddress(address);
svrFactory.create();
Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
assertEquals(1, bindings.size());
ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
return wsdlBuilder.build();
}
use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.
the class CodeFirstWSDLTest method testDocumentationOnSEI.
@Test
public void testDocumentationOnSEI() throws Exception {
// CXF-3093
EndpointImpl ep = (EndpointImpl) Endpoint.publish("local://foo", new CXF3093Impl());
ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, ep.getService().getServiceInfos().get(0));
Definition def = wsdlBuilder.build();
Document d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
// org.apache.cxf.helpers.XMLUtils.printDOM(d);
assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:portType/wsdl:documentation", "My portType documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
JaxwsServiceBuilder builder = new JaxwsServiceBuilder();
builder.setServiceClass(CXF3093Impl.class);
ServiceInfo serviceInfo = builder.createService();
wsdlBuilder = new ServiceWSDLBuilder(bus, serviceInfo);
def = wsdlBuilder.build();
d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
// org.apache.cxf.helpers.XMLUtils.printDOM(d);
assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:portType/wsdl:documentation", "My portType documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
}
use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.
the class JaxWsServerFactoryBeanTest method testSimpleServiceClass.
@Test
public void testSimpleServiceClass() throws Exception {
ServerFactoryBean factory = new ServerFactoryBean();
factory.setServiceClass(Hello.class);
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);
}
Aggregations