Search in sources :

Example 1 with URIResolver

use of org.apache.cxf.resource.URIResolver in project Activiti by Activiti.

the class CxfWSDLImporter method importFrom.

public void importFrom(Import theImport, BpmnParse parse) {
    this.namespace = theImport.getNamespace() == null ? "" : theImport.getNamespace() + ":";
    try {
        final URIResolver uriResolver = new URIResolver(parse.getSourceSystemId(), theImport.getLocation());
        if (uriResolver.isResolved()) {
            if (uriResolver.getURI() != null) {
                this.importFrom(uriResolver.getURI().toString());
            } else if (uriResolver.isFile()) {
                this.importFrom(uriResolver.getFile().getAbsolutePath());
            } else if (uriResolver.getURL() != null) {
                this.importFrom(uriResolver.getURL().toString());
            }
        } else {
            throw new UncheckedException(new Exception("Unresolved import against " + parse.getSourceSystemId()));
        }
        this.transferImportsToParse(parse);
    } catch (final IOException e) {
        throw new UncheckedException(e);
    }
}
Also used : UncheckedException(org.apache.cxf.common.i18n.UncheckedException) URIResolver(org.apache.cxf.resource.URIResolver) IOException(java.io.IOException) ActivitiException(org.activiti.engine.ActivitiException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) UncheckedException(org.apache.cxf.common.i18n.UncheckedException)

Example 2 with URIResolver

use of org.apache.cxf.resource.URIResolver in project ddf by codice.

the class AttributeQueryClaimsHandler method createService.

/**
 * Creates a dynamic service from the provided wsdl location.
 */
protected final Service createService() {
    Service service = null;
    URL wsdlURL;
    if (StringUtils.isNotBlank(wsdlLocation) && StringUtils.isNotBlank(serviceName)) {
        try {
            URIResolver uriResolver = new URIResolver();
            uriResolver.resolve("", wsdlLocation, this.getClass());
            wsdlURL = uriResolver.isResolved() ? uriResolver.getURL() : new URL(wsdlLocation);
            service = AccessController.doPrivileged((PrivilegedAction<Service>) () -> Service.create(wsdlURL, QName.valueOf(serviceName)));
            auditRemoteConnection(wsdlURL);
        } catch (Exception e) {
            LOGGER.info("Unable to create service from WSDL location. Set log level for \"org.codice.ddf.security.claims.attributequery.common\" to DEBUG for more information.");
            LOGGER.debug("Unable to create service from WSDL location.", e);
        }
    }
    return service;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) Service(javax.xml.ws.Service) URIResolver(org.apache.cxf.resource.URIResolver) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 3 with URIResolver

use of org.apache.cxf.resource.URIResolver in project cxf by apache.

the class OASISCatalogManager method getResolver.

private static EntityResolver getResolver() {
    try {
        CatalogManager catalogManager = new CatalogManager();
        if (DEBUG_LEVEL != null) {
            catalogManager.debug.setDebug(Integer.parseInt(DEBUG_LEVEL));
        }
        catalogManager.setUseStaticCatalog(false);
        catalogManager.setIgnoreMissingProperties(true);
        return new CatalogResolver(catalogManager) {

            public String getResolvedEntity(String publicId, String systemId) {
                String s = super.getResolvedEntity(publicId, systemId);
                if (s != null && s.startsWith("classpath:")) {
                    try (URIResolver r = new URIResolver(s)) {
                        if (r.isResolved()) {
                            return r.getURL().toExternalForm();
                        }
                    } catch (IOException e) {
                    // ignore
                    }
                }
                return s;
            }
        };
    } catch (Throwable t) {
    // ignore
    }
    return null;
}
Also used : URIResolver(org.apache.cxf.resource.URIResolver) IOException(java.io.IOException) CatalogResolver(org.apache.xml.resolver.tools.CatalogResolver) CatalogManager(org.apache.xml.resolver.CatalogManager)

Example 4 with URIResolver

use of org.apache.cxf.resource.URIResolver in project cxf by apache.

the class CustomizationParser method getTargetNode.

public Element getTargetNode(String uri) {
    if (uri == null) {
        return null;
    }
    if (uri.equals(wsdlURL) && wsdlNode != null) {
        return wsdlNode;
    }
    Document doc = null;
    try (URIResolver resolver = new URIResolver(uri)) {
        if (!resolver.isResolved()) {
            return null;
        }
        XMLStreamReader reader = null;
        try {
            // NOPMD
            reader = StaxUtils.createXMLStreamReader(uri, resolver.getInputStream());
            doc = StaxUtils.read(reader, true);
        } catch (Exception e) {
            Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { uri });
            throw new ToolException(msg, e);
        } finally {
            try {
                StaxUtils.close(reader);
            } catch (XMLStreamException e) {
            // ignore
            }
        }
    } catch (IOException e1) {
        return null;
    }
    try {
        doc.setDocumentURI(uri);
    } catch (Exception ex) {
    // ignore - probably not DOM level 3
    }
    if (doc != null) {
        return doc.getDocumentElement();
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(org.apache.cxf.common.i18n.Message) XMLStreamException(javax.xml.stream.XMLStreamException) URIResolver(org.apache.cxf.resource.URIResolver) ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 5 with URIResolver

use of org.apache.cxf.resource.URIResolver in project cxf by apache.

the class SchemaResourceResolver method resolveResource.

public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    Message msg = new Message("RESOLVE_SCHEMA", LOG, namespaceURI, systemId, baseURI);
    LOG.log(Level.FINE, msg.toString());
    if (NSFILEMAP.containsKey(namespaceURI)) {
        return loadLSInput(namespaceURI);
    }
    LSInput lsin = null;
    String resURL = null;
    if (systemId != null) {
        String schemaLocation = "";
        if (baseURI != null) {
            schemaLocation = baseURI.substring(0, baseURI.lastIndexOf('/') + 1);
        }
        if (systemId.indexOf("http://") < 0) {
            resURL = schemaLocation + systemId;
        } else {
            resURL = systemId;
        }
    } else if (namespaceURI != null) {
        resURL = namespaceURI;
    }
    if (resURL == null) {
        return null;
    }
    String localFile = resURL;
    if (resURL.startsWith("http://")) {
        String filename = NSFILEMAP.get(resURL);
        if (filename != null) {
            localFile = ToolConstants.CXF_SCHEMAS_DIR_INJAR + filename;
        }
    }
    try {
        msg = new Message("RESOLVE_FROM_LOCAL", LOG, localFile);
        LOG.log(Level.FINE, msg.toString());
        @SuppressWarnings("resource") final URIResolver resolver = new URIResolver(localFile);
        if (resolver.isResolved()) {
            lsin = new LSInputImpl();
            lsin.setSystemId(localFile);
            lsin.setByteStream(resolver.getInputStream());
        }
    } catch (IOException e) {
        return null;
    }
    return lsin;
}
Also used : LSInputImpl(org.apache.cxf.common.xmlschema.LSInputImpl) Message(org.apache.cxf.common.i18n.Message) LSInput(org.w3c.dom.ls.LSInput) URIResolver(org.apache.cxf.resource.URIResolver) IOException(java.io.IOException)

Aggregations

URIResolver (org.apache.cxf.resource.URIResolver)10 IOException (java.io.IOException)8 Message (org.apache.cxf.common.i18n.Message)6 URISyntaxException (java.net.URISyntaxException)4 ToolException (org.apache.cxf.tools.common.ToolException)4 URL (java.net.URL)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 InputSource (org.xml.sax.InputSource)2 File (java.io.File)1 FileFilter (java.io.FileFilter)1 InputStream (java.io.InputStream)1 JarURLConnection (java.net.JarURLConnection)1 URI (java.net.URI)1 PrivilegedAction (java.security.PrivilegedAction)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1