Search in sources :

Example 1 with Import

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);
            }
        }
    }
}
Also used : Types(javax.wsdl.Types) MalformedURLException(java.net.MalformedURLException) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) Import(javax.wsdl.Import) Message(org.apache.cxf.message.Message) Schema(javax.wsdl.extensions.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) WSDLException(javax.wsdl.WSDLException) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) List(java.util.List)

Example 2 with Import

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;
}
Also used : Import(javax.wsdl.Import) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) Document(org.w3c.dom.Document)

Example 3 with Import

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;
}
Also used : Import(javax.wsdl.Import) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 4 with Import

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);
        }
    }
}
Also used : Import(javax.wsdl.Import) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with Import

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;
}
Also used : Import(javax.wsdl.Import) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) HashMap(java.util.HashMap) WSDLException(javax.wsdl.WSDLException) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) FileNotFoundException(java.io.FileNotFoundException) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) XMLStreamException(javax.xml.stream.XMLStreamException) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) WSDLWriter(javax.wsdl.xml.WSDLWriter) Writer(java.io.Writer) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Aggregations

Import (javax.wsdl.Import)18 List (java.util.List)9 Definition (javax.wsdl.Definition)8 ArrayList (java.util.ArrayList)6 SchemaImport (javax.wsdl.extensions.schema.SchemaImport)5 Binding (javax.wsdl.Binding)4 PortType (javax.wsdl.PortType)4 Collection (java.util.Collection)3 Map (java.util.Map)3 Message (javax.wsdl.Message)3 Port (javax.wsdl.Port)3 Types (javax.wsdl.Types)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Service (javax.wsdl.Service)2 WSDLException (javax.wsdl.WSDLException)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 Schema (javax.wsdl.extensions.schema.Schema)2 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)2 WSDLWriter (javax.wsdl.xml.WSDLWriter)2