use of javax.wsdl.Import in project cxf by apache.
the class WSDLGetUtils method updateDefinition.
protected void updateDefinition(Bus bus, Definition def, Map<String, Definition> done, Map<String, SchemaReference> doneSchemas, String base, String docBase, String parentResolvedLocation) {
OASISCatalogManager catalogs = OASISCatalogManager.getCatalogManager(bus);
Collection<List<?>> imports = CastUtils.cast((Collection<?>) def.getImports().values());
for (List<?> lst : imports) {
List<Import> impLst = CastUtils.cast(lst);
for (Import imp : impLst) {
String start = imp.getLocationURI();
String decodedStart;
try {
decodedStart = URLDecoder.decode(start, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, start), e);
}
String resolvedSchemaLocation = resolveWithCatalogs(catalogs, start, base);
if (resolvedSchemaLocation == null) {
try {
// check to see if it's already in a URL format. If so, leave it.
new URL(start);
} catch (MalformedURLException e) {
try {
start = getLocationURI(start, docBase);
decodedStart = URLDecoder.decode(start, "utf-8");
} catch (Exception e1) {
// ignore
}
if (done.put(decodedStart, imp.getDefinition()) == null) {
if (imp.getDefinition() != null && imp.getDefinition().getDocumentBaseURI() != null) {
done.put(imp.getDefinition().getDocumentBaseURI(), imp.getDefinition());
}
updateDefinition(bus, imp.getDefinition(), done, doneSchemas, base, start, null);
}
}
} else {
if (done.put(decodedStart, imp.getDefinition()) == null) {
done.put(resolvedSchemaLocation, imp.getDefinition());
if (imp.getDefinition() != null && imp.getDefinition().getDocumentBaseURI() != null) {
done.put(imp.getDefinition().getDocumentBaseURI(), imp.getDefinition());
}
updateDefinition(bus, imp.getDefinition(), done, doneSchemas, base, start, resolvedSchemaLocation);
}
}
}
}
/* This doesn't actually work. Setting setSchemaLocationURI on the import
* for some reason doesn't actually result in the new URI being written
* */
Types types = def.getTypes();
if (types != null) {
for (ExtensibilityElement el : CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class)) {
if (el instanceof Schema) {
updateSchemaImports(bus, (Schema) el, docBase, doneSchemas, base, parentResolvedLocation);
}
}
}
}
use of javax.wsdl.Import 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.Import in project cxf by apache.
the class SoapBindingFactory method findMessage.
private javax.wsdl.Message findMessage(QName qn, Definition def, List<Definition> done) {
javax.wsdl.Message msg = def.getMessage(qn);
if (msg == null) {
if (done.contains(def)) {
return null;
}
done.add(def);
Collection<List<Import>> ilist = CastUtils.cast(def.getImports().values());
for (List<Import> list : ilist) {
for (Import i : list) {
if (qn.getNamespaceURI().equals(i.getDefinition().getTargetNamespace())) {
return i.getDefinition().getMessage(qn);
}
}
}
for (List<Import> list : ilist) {
for (Import i : list) {
msg = findMessage(qn, i.getDefinition(), done);
if (msg != null) {
return msg;
}
}
}
}
return msg;
}
use of javax.wsdl.Import in project cxf by apache.
the class WSDLServiceBuilder method parseImports.
private void parseImports(Definition def, List<Definition> defList) {
List<Import> importList = new ArrayList<>();
Collection<List<Import>> ilist = cast(def.getImports().values());
for (List<Import> list : ilist) {
importList.addAll(list);
}
for (Import impt : importList) {
if (!defList.contains(impt.getDefinition())) {
defList.add(impt.getDefinition());
parseImports(impt.getDefinition(), defList);
}
}
}
use of javax.wsdl.Import 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