Search in sources :

Example 1 with SchemaReference

use of javax.wsdl.extensions.schema.SchemaReference in project cxf by apache.

the class WSDLGetUtils method getDocument.

public Document getDocument(Message message, String base, Map<String, String> params, String ctxUri, EndpointInfo endpointInfo) {
    Document doc = null;
    try {
        Bus bus = message.getExchange().getBus();
        base = getPublishedEndpointURL(message, base, endpointInfo);
        // making sure this are existing map objects for the endpoint.
        Map<String, Definition> mp = getWSDLKeyDefinition(endpointInfo);
        Map<String, SchemaReference> smp = getSchemaKeySchemaReference(endpointInfo);
        updateWSDLKeyDefinition(bus, mp, message, smp, base, endpointInfo);
        // 
        if (params.containsKey("wsdl")) {
            String wsdl = URLDecoder.decode(params.get("wsdl"), "utf-8");
            doc = writeWSDLDocument(message, mp, smp, wsdl, base, endpointInfo);
        } else if (params.get("xsd") != null) {
            String xsd = URLDecoder.decode(params.get("xsd"), "utf-8");
            doc = readXSDDocument(bus, xsd, smp, base);
            updateDoc(doc, base, mp, smp, message, xsd);
        }
    } catch (WSDLQueryException wex) {
        throw wex;
    } catch (Exception wex) {
        LOG.log(Level.SEVERE, wex.getMessage(), wex);
        throw new WSDLQueryException(new org.apache.cxf.common.i18n.Message("COULD_NOT_PROVIDE_WSDL", LOG, base), wex);
    }
    return doc;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) Definition(javax.wsdl.Definition) Document(org.w3c.dom.Document) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) WSDLException(javax.wsdl.WSDLException)

Example 2 with SchemaReference

use of javax.wsdl.extensions.schema.SchemaReference in project cxf by apache.

the class WSDLGetUtils method readXSDDocument.

/**
 * Read the schema file and return as a Document object.
 *
 * @param bus CXF's hub for access to internal constructs
 * @param xsd name of xsd file to be read
 * @param smp a map of known xsd SchemaReference objects
 * @param base the request URL
 * @return Document
 * @throws XMLStreamException
 */
protected Document readXSDDocument(Bus bus, String xsd, Map<String, SchemaReference> smp, String base) throws XMLStreamException {
    Document doc = null;
    SchemaReference si = lookupSchemaReference(bus, xsd, smp, base);
    String uri = si.getReferencedSchema().getDocumentBaseURI();
    uri = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), uri, si.getReferencedSchema().getDocumentBaseURI());
    if (uri == null) {
        uri = si.getReferencedSchema().getDocumentBaseURI();
    }
    ResourceManagerWSDLLocator rml = new ResourceManagerWSDLLocator(uri, bus);
    InputSource src = rml.getBaseInputSource();
    if (src.getByteStream() != null || src.getCharacterStream() != null) {
        doc = StaxUtils.read(src);
    } else {
        // last resort lets try for the referenced schema itself.
        // its not thread safe if we use the same document
        doc = StaxUtils.read(new DOMSource(si.getReferencedSchema().getElement().getOwnerDocument()));
    }
    return doc;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) ResourceManagerWSDLLocator(org.apache.cxf.wsdl11.ResourceManagerWSDLLocator) Document(org.w3c.dom.Document)

Example 3 with SchemaReference

use of javax.wsdl.extensions.schema.SchemaReference in project cxf by apache.

the class WSDLGetUtils method getAndSaveRelativeSchemaLocationIfCatalogResolved.

/**
 * When the imported schema location has been resolved through catalog, we need to:
 * 1) get a valid relative location to use for recursion into the imported schema
 * 2) add an entry to the doneSchemas map using such a valid relative location, as that's
 *    what will be used later for import links
 *
 * The valid relative location for the imported schema is computed by first obtaining the
 * relative uri that maps the importing schema resolved location into the imported schema
 * resolved location, then such value is resolved on top of the valid relative location
 * that's saved in the doneSchemas map for the importing schema.
 *
 * @param doneSchemas
 * @param resolvedSchemaLocation
 * @param currentSchema
 * @param schemaReference
 * @return
 */
private String getAndSaveRelativeSchemaLocationIfCatalogResolved(Map<String, SchemaReference> doneSchemas, String resolvedSchemaLocation, Schema currentSchema, SchemaReference schemaReference) {
    String path = null;
    for (Map.Entry<String, SchemaReference> entry : doneSchemas.entrySet()) {
        Schema rs = entry.getValue().getReferencedSchema();
        String k = entry.getKey();
        String rsURI = rs.getDocumentBaseURI();
        if (currentSchema.equals(rs) && !rsURI.equals(k)) {
            try {
                String p = URIParserUtil.relativize(rsURI, resolvedSchemaLocation);
                if (p != null) {
                    path = new URI(k).resolve(p).toString();
                    break;
                }
            } catch (URISyntaxException e) {
            // ignore
            }
        }
    }
    if (path != null) {
        doneSchemas.put(path, schemaReference);
    }
    return path;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) Schema(javax.wsdl.extensions.schema.Schema) URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URI(java.net.URI)

Example 4 with SchemaReference

use of javax.wsdl.extensions.schema.SchemaReference in project cxf by apache.

the class WSDLGetUtils method getSchemaLocations.

public Map<String, String> getSchemaLocations(Message message, String base, String ctxUri, EndpointInfo endpointInfo) {
    Map<String, String> params = new HashMap<>();
    params.put("wsdl", "");
    getDocument(message, base, params, ctxUri, endpointInfo);
    Map<String, SchemaReference> mp = CastUtils.cast((Map<?, ?>) endpointInfo.getService().getProperty(SCHEMAS_KEY));
    Map<String, String> schemas = new HashMap<>();
    for (Map.Entry<String, SchemaReference> ent : mp.entrySet()) {
        params.clear();
        params.put("xsd", ent.getKey());
        Document doc = getDocument(message, base, params, ctxUri, endpointInfo);
        schemas.put(doc.getDocumentElement().getAttribute("targetNamespace"), buildUrl(base, ctxUri, "xsd=" + ent.getKey()));
    }
    return schemas;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Document(org.w3c.dom.Document) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 5 with SchemaReference

use of javax.wsdl.extensions.schema.SchemaReference in project cxf by apache.

the class WSDLGetUtils method mapUri.

protected String mapUri(Bus bus, String base, Map<String, SchemaReference> smp, String loc, String xsd, String resolvedXsd) throws UnsupportedEncodingException {
    String key = loc;
    try {
        boolean absoluteLocUri = new URI(loc).isAbsolute();
        if (!absoluteLocUri && xsd != null) {
            // XSD request
            // resolve requested location with relative import path
            key = new URI(xsd).resolve(loc).toString();
            SchemaReference ref = smp.get(URLDecoder.decode(key, "utf-8"));
            if (ref == null) {
                // if the result is not known, check if we can resolve it into something known
                String resolved = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), key, base);
                if (resolved != null && smp.containsKey(URLDecoder.decode(resolved, "utf-8"))) {
                    // if it is resolvable, we can use it
                    return base + "?xsd=" + key.replace(" ", "%20");
                }
            }
        } else if (!absoluteLocUri && xsd == null) {
            // WSDL request
            key = new URI(".").resolve(loc).toString();
        }
    } catch (URISyntaxException e) {
    // ignore
    }
    SchemaReference ref = smp.get(URLDecoder.decode(key, "utf-8"));
    if (ref == null && resolvedXsd != null) {
        try {
            String key2 = new URI(resolvedXsd).resolve(loc).toString();
            SchemaReference ref2 = smp.get(URLDecoder.decode(key2, "utf-8"));
            if (ref2 == null) {
                // if the result is not known, check if we can resolve it into something known
                String resolved = resolveWithCatalogs(OASISCatalogManager.getCatalogManager(bus), key2, base);
                if (resolved != null && smp.containsKey(URLDecoder.decode(resolved, "utf-8"))) {
                    // if it is resolvable, we can use it
                    ref = smp.get(URLDecoder.decode(resolved, "utf-8"));
                }
            } else {
                ref = smp.get(URLDecoder.decode(key2, "utf-8"));
            }
        } catch (URISyntaxException e) {
        // ignore, ref can remain null
        }
        if (ref != null) {
            // we are able to map this, but for some reason the default key passed in cannot
            // be used for a direct lookup, we need to create a unique import key
            int count = 1;
            while (smp.containsKey("_import" + count + ".xsd")) {
                count++;
            }
            key = "_import" + count + ".xsd";
            smp.put(key, ref);
        }
    }
    if (ref != null) {
        return base + "?xsd=" + key.replace(" ", "%20");
    }
    return null;
}
Also used : SchemaReference(javax.wsdl.extensions.schema.SchemaReference) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

SchemaReference (javax.wsdl.extensions.schema.SchemaReference)7 URISyntaxException (java.net.URISyntaxException)3 Document (org.w3c.dom.Document)3 URI (java.net.URI)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Schema (javax.wsdl.extensions.schema.Schema)2 SchemaImport (javax.wsdl.extensions.schema.SchemaImport)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 List (java.util.List)1 Definition (javax.wsdl.Definition)1 Types (javax.wsdl.Types)1 WSDLException (javax.wsdl.WSDLException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DOMSource (javax.xml.transform.dom.DOMSource)1 Bus (org.apache.cxf.Bus)1 Message (org.apache.cxf.message.Message)1 SchemaInfo (org.apache.cxf.service.model.SchemaInfo)1