Search in sources :

Example 1 with Types

use of javax.wsdl.Types in project Lucee by lucee.

the class JaxWSClient method toDumpData.

private DumpData toDumpData(BindingOperation bo) {
    Map<QName, Message> messages = wsdl.getMessages();
    DumpTable table = new DumpTable("#99cc99", "#ccffcc", "#000000");
    DumpTable attributes = new DumpTable("#99cc99", "#ccffcc", "#000000");
    String returns = "void";
    attributes.appendRow(3, new SimpleDumpData("name"), new SimpleDumpData("type"));
    Operation op = bo.getOperation();
    // attributes
    Input in = op.getInput();
    Message msg = in.getMessage();
    // msg=WSUtil.getMessageByLocalName(messages,bo.getBindingInput().getName());
    // print.e(msg.getQName());
    List<Part> parts = msg.getOrderedParts(null);
    Iterator<Part> it = parts.iterator();
    Part p;
    QName en;
    QName type;
    while (it.hasNext()) {
        p = it.next();
        en = p.getElementName();
        if (en != null) {
            type = en;
            Types types = wsdl.getTypes();
        } else
            type = p.getTypeName();
        attributes.appendRow(0, new SimpleDumpData(en + ":" + p.getName()), new SimpleDumpData(toLuceeType(type)));
    }
    // return
    msg = bo.getOperation().getOutput().getMessage();
    msg = wsdl.getMessage(msg.getQName());
    parts = msg.getOrderedParts(null);
    it = parts.iterator();
    while (it.hasNext()) {
        p = it.next();
        returns = toLuceeType(p.getTypeName());
    }
    table.appendRow(1, new SimpleDumpData("arguments"), attributes);
    table.appendRow(1, new SimpleDumpData("return type"), new SimpleDumpData(returns));
    return table;
}
Also used : DumpTable(lucee.runtime.dump.DumpTable) Types(javax.wsdl.Types) Input(javax.wsdl.Input) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) SimpleDumpData(lucee.runtime.dump.SimpleDumpData) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation)

Example 2 with Types

use of javax.wsdl.Types in project carbon-apimgt by wso2.

the class WSDL11SOAPOperationExtractor method initModels.

/**
 * Initiallize SOAP to REST Operations
 *
 * @return true if extracting operations was successful
 */
private boolean initModels() throws APIMgtWSDLException {
    wsdlDefinition = getWSDLDefinition();
    boolean canProcess = true;
    targetNamespace = wsdlDefinition.getTargetNamespace();
    Types types = wsdlDefinition.getTypes();
    if (types != null) {
        typeList = types.getExtensibilityElements();
    }
    if (typeList != null) {
        for (Object ext : typeList) {
            if (ext instanceof Schema) {
                Schema schema = (Schema) ext;
                Map importedSchemas = schema.getImports();
                Element schemaElement = schema.getElement();
                NodeList schemaNodes = schemaElement.getChildNodes();
                schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaNodes));
                // gets types from imported schemas from the parent wsdl. Nested schemas will not be imported.
                if (importedSchemas != null) {
                    for (Object importedSchemaObj : importedSchemas.keySet()) {
                        String schemaUrl = (String) importedSchemaObj;
                        if (importedSchemas.get(schemaUrl) != null) {
                            Vector vector = (Vector) importedSchemas.get(schemaUrl);
                            for (Object schemaVector : vector) {
                                if (schemaVector instanceof SchemaImport) {
                                    Schema referencedSchema = ((SchemaImport) schemaVector).getReferencedSchema();
                                    if (referencedSchema != null && referencedSchema.getElement() != null) {
                                        if (referencedSchema.getElement().hasChildNodes()) {
                                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(referencedSchema.getElement().getChildNodes()));
                                        } else {
                                            log.warn("The referenced schema : " + schemaUrl + " doesn't have any defined types");
                                        }
                                    } else {
                                        boolean isInlineSchema = false;
                                        for (Object aSchema : typeList) {
                                            if (schemaUrl.equalsIgnoreCase(((Schema) aSchema).getElement().getAttribute(TARGET_NAMESPACE_ATTRIBUTE))) {
                                                isInlineSchema = true;
                                                break;
                                            }
                                        }
                                        if (isInlineSchema) {
                                            log.debug(schemaUrl + " is already defined inline. Hence continue.");
                                        } else {
                                            log.warn("Cannot access referenced schema for the schema defined at: " + schemaUrl);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    log.info("No any imported schemas found in the given wsdl.");
                }
                List schemaIncludes = schema.getIncludes();
                for (Iterator iter = schemaIncludes.iterator(); iter.hasNext(); ) {
                    SchemaReference schemaInclude = (SchemaReference) iter.next();
                    Schema schemaImp = schemaInclude.getReferencedSchema();
                    String schemaLoc = schemaInclude.getSchemaLocationURI();
                    if (schemaImp != null && schemaImp.getElement() != null) {
                        if (schemaImp.getElement().hasChildNodes()) {
                            schemaNodeList.addAll(SOAPOperationBindingUtils.list(schemaImp.getElement().getChildNodes()));
                        } else {
                            log.warn("The referenced schema : " + schemaLoc + " doesn't have any defined types");
                        }
                    }
                }
                if (log.isDebugEnabled()) {
                    Gson gson = new GsonBuilder().setExclusionStrategies(new SwaggerFieldsExcludeStrategy()).create();
                    log.debug("swagger definition model map from the wsdl: " + gson.toJson(parameterModelMap));
                }
                if (schemaNodeList == null) {
                    log.warn("No schemas found in the type element for target namespace:" + schema.getDocumentBaseURI());
                }
            }
        }
        if (schemaNodeList != null) {
            for (Node node : schemaNodeList) {
                WSDLParamDefinition wsdlParamDefinition = new WSDLParamDefinition();
                ModelImpl model = new ModelImpl();
                Property currentProperty = null;
                try {
                    traverseTypeElement(node, null, model, currentProperty);
                } catch (APIManagementException e) {
                    throw new APIMgtWSDLException(e);
                }
                if (StringUtils.isNotBlank(model.getName())) {
                    parameterModelMap.put(model.getName(), model);
                }
                if (wsdlParamDefinition.getDefinitionName() != null) {
                    wsdlParamDefinitions.add(wsdlParamDefinition);
                }
            }
        } else {
            log.info("No schema is defined in the wsdl document");
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
    }
    return canProcess;
}
Also used : Types(javax.wsdl.Types) SwaggerFieldsExcludeStrategy(org.wso2.carbon.apimgt.impl.wsdl.util.SwaggerFieldsExcludeStrategy) WSDLParamDefinition(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLParamDefinition) SchemaImport(javax.wsdl.extensions.schema.SchemaImport) GsonBuilder(com.google.gson.GsonBuilder) Schema(javax.wsdl.extensions.schema.Schema) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Gson(com.google.gson.Gson) SchemaReference(javax.wsdl.extensions.schema.SchemaReference) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtWSDLException(org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) Vector(java.util.Vector) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty)

Example 3 with Types

use of javax.wsdl.Types 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 4 with Types

use of javax.wsdl.Types in project cxf by apache.

the class ServiceWSDLBuilder method buildTypesWithSchemaImports.

/**
 * @param schemas
 * @param imports
 * @param def
 */
protected void buildTypesWithSchemaImports(final Collection<SchemaInfo> schemas, final Map<String, SchemaInfo> imports, final Definition def) {
    Types types = def.createTypes();
    Map<String, Schema> namespaceToSchemaMap = new HashMap<>();
    Map<String, SchemaInfo> namespaceToSchemaInfo = new HashMap<>();
    for (SchemaInfo schemaInfo : schemas) {
        Schema schema = getSchemaImplementation(def);
        schema.setRequired(true);
        schema.setElementType(WSDLConstants.QNAME_SCHEMA);
        String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
        schema.setDocumentBaseURI(name);
        schema.setElement(schemaInfo.getElement());
        namespaceToSchemaMap.put(schemaInfo.getNamespaceURI(), schema);
        namespaceToSchemaInfo.put(schemaInfo.getNamespaceURI(), schemaInfo);
        imports.put(name, schemaInfo);
    }
    for (Schema schema : namespaceToSchemaMap.values()) {
        Element docElement = schema.getElement();
        List<Element> elementList = DOMUtils.findAllElementsByTagNameNS(docElement, "http://www.w3.org/2001/XMLSchema", "import");
        for (Element el : elementList) {
            String sn = el.getAttribute("namespace");
            Schema referencedSchema = namespaceToSchemaMap.get(sn);
            if (referencedSchema != null) {
                SchemaInfo schemaInfo = namespaceToSchemaInfo.get(sn);
                el.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
                addSchemaImport(schema, schemaInfo, referencedSchema);
            }
        }
    }
    Document doc = DOMUtils.createDocument();
    Element nd = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "schema");
    nd.setAttribute("xmlns", WSDLConstants.NS_SCHEMA_XSD);
    doc.appendChild(nd);
    Schema schema = getSchemaImplementation(def);
    schema.setRequired(true);
    schema.setElementType(WSDLConstants.QNAME_SCHEMA);
    Collection<String> defNamespaces = CastUtils.cast(def.getNamespaces().values());
    for (SchemaInfo schemaInfo : schemas) {
        Schema referencedSchema = namespaceToSchemaMap.get(schemaInfo.getNamespaceURI());
        // this ensures only the schemas directly referenced by the wsdl are included.
        if (defNamespaces.contains(schemaInfo.getNamespaceURI())) {
            Element impElement = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "import");
            impElement.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
            impElement.setAttribute("namespace", schemaInfo.getNamespaceURI());
            nd.appendChild(impElement);
            addSchemaImport(schema, schemaInfo, referencedSchema);
        }
    }
    schema.setElement(nd);
    types.addExtensibilityElement(schema);
    def.setTypes(types);
}
Also used : Types(javax.wsdl.Types) HashMap(java.util.HashMap) Schema(javax.wsdl.extensions.schema.Schema) WSDLElement(javax.wsdl.WSDLElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

Example 5 with Types

use of javax.wsdl.Types in project cxf by apache.

the class SchemaUtil method getSchemaList.

// Workaround for getting the elements
private void getSchemaList(Definition def) {
    Types typesElement = def.getTypes();
    if (typesElement != null) {
        Iterator<?> ite = typesElement.getExtensibilityElements().iterator();
        while (ite.hasNext()) {
            Object obj = ite.next();
            if (obj instanceof Schema) {
                Schema schema = (Schema) obj;
                addSchema(schema.getDocumentBaseURI(), schema);
            }
        }
    }
}
Also used : Types(javax.wsdl.Types) XmlSchema(org.apache.ws.commons.schema.XmlSchema) Schema(javax.wsdl.extensions.schema.Schema)

Aggregations

Types (javax.wsdl.Types)17 Schema (javax.wsdl.extensions.schema.Schema)14 XmlSchema (org.apache.ws.commons.schema.XmlSchema)7 Element (org.w3c.dom.Element)7 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)6 SchemaImport (javax.wsdl.extensions.schema.SchemaImport)6 QName (javax.xml.namespace.QName)6 List (java.util.List)3 Import (javax.wsdl.Import)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Definition (javax.wsdl.Definition)2 Message (javax.wsdl.Message)2 WSDLException (javax.wsdl.WSDLException)2 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)2 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1