Search in sources :

Example 11 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class OASISCatalogTest method testWSDLLocatorWithoutCatalog.

@Test
public void testWSDLLocatorWithoutCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    OASISCatalogManager catalog = new OASISCatalogManager();
    CatalogWSDLLocator wsdlLocator = new CatalogWSDLLocator(wsdl.toString(), catalog);
    try {
        wsdlReader.readWSDL(wsdlLocator);
        fail("Test did not fail as expected");
    } catch (WSDLException e) {
    // ignore
    }
}
Also used : WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLException(javax.wsdl.WSDLException) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) CatalogWSDLLocator(org.apache.cxf.wsdl11.CatalogWSDLLocator) URL(java.net.URL) WSDLReader(javax.wsdl.xml.WSDLReader) Test(org.junit.Test)

Example 12 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class OASISCatalogTest method testClientWithoutCatalog.

@Test
public void testClientWithoutCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);
    // set Catalog on the Bus
    Bus bus = BusFactory.getDefaultBus();
    OASISCatalogManager catalog = new OASISCatalogManager();
    bus.setExtension(catalog, OASISCatalogManager.class);
    // prevent cache from papering over the lack of a schema.
    WSDLManagerImpl mgr = (WSDLManagerImpl) bus.getExtension(WSDLManager.class);
    mgr.setDisableSchemaCache(true);
    try {
        SOAPService service = new SOAPService(wsdl, serviceName);
        service.getPort(portName, Greeter.class);
        fail("Test did not fail as expected");
    } catch (WebServiceException e) {
    // ignore
    }
    // update catalog dynamically now
    Enumeration<URL> jaxwscatalog = getClass().getClassLoader().getResources("META-INF/jax-ws-catalog.xml");
    assertNotNull(jaxwscatalog);
    while (jaxwscatalog.hasMoreElements()) {
        URL url = jaxwscatalog.nextElement();
        catalog.loadCatalog(url);
    }
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    assertNotNull(greeter);
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.hello_world.Greeter) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) WSDLManager(org.apache.cxf.wsdl.WSDLManager) URL(java.net.URL) Test(org.junit.Test)

Example 13 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class DynamicClientFactory method addSchemas.

private void addSchemas(Options opts, SchemaCompiler schemaCompiler, List<ServiceInfo> serviceList, SchemaCollection schemaCollection) {
    Map<String, Element> done = new HashMap<>();
    Map<String, Element> notDone = new HashMap<>();
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        if (done.containsKey(key)) {
            continue;
        }
        if (!key.startsWith("file:") && !key.startsWith("jar:")) {
            XmlSchemaSerializer xser = new XmlSchemaSerializer();
            xser.setExtReg(schemaCollection.getExtReg());
            Document[] docs;
            try {
                docs = xser.serializeSchema(schema, false);
            } catch (XmlSchemaSerializerException e) {
                throw new RuntimeException(e);
            }
            Element ele = docs[0].getDocumentElement();
            ele = removeImportElement(ele, key, catalog, done, notDone);
            try {
                docs[0].setDocumentURI(key);
            } catch (Throwable t) {
            // ignore - DOM level 3
            }
            if (ele != null) {
                InputSource is = new InputSource((InputStream) null);
                // key = key.replaceFirst("#types[0-9]+$", "");
                is.setSystemId(key);
                is.setPublicId(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, ele);
            }
        }
    }
    for (XmlSchema schema : schemaCollection.getXmlSchemas()) {
        if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
            continue;
        }
        String key = schema.getSourceURI();
        if (done.containsKey(key)) {
            continue;
        }
        if (key.startsWith("file:") || key.startsWith("jar:")) {
            InputStream in = null;
            try {
                if (key.contains("#")) {
                    for (ServiceInfo si : serviceList) {
                        for (SchemaInfo sci : si.getSchemas()) {
                            if (key != null && key.equals(sci.getSystemId())) {
                                key = null;
                            }
                        }
                    }
                }
                if (key == null) {
                    continue;
                }
                if (key.startsWith("file:")) {
                    in = Files.newInputStream(new File(new URI(key)).toPath());
                } else {
                    in = new URL(key).openStream();
                }
                XMLStreamReader reader = StaxUtils.createXMLStreamReader(key, in);
                reader = new LocationFilterReader(reader, catalog);
                InputSource is = new InputSource(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, reader);
                reader.close();
            } catch (RuntimeException ex) {
                throw ex;
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    }
    for (ServiceInfo si : serviceList) {
        for (SchemaInfo sci : si.getSchemas()) {
            String key = sci.getSystemId();
            if (done.containsKey(key)) {
                continue;
            }
            Element ele = sci.getElement();
            ele = removeImportElement(ele, key, catalog, done, notDone);
            if (ele != null) {
                InputSource is = new InputSource((InputStream) null);
                // key = key.replaceFirst("#types[0-9]+$", "");
                is.setSystemId(key);
                is.setPublicId(key);
                opts.addGrammar(is);
                schemaCompiler.parseSchema(key, StaxUtils.createXMLStreamReader(ele, key));
            }
        }
    }
    for (Map.Entry<String, Element> el : notDone.entrySet()) {
        InputSource is = new InputSource((InputStream) null);
        // key = key.replaceFirst("#types[0-9]+$", "");
        is.setSystemId(el.getKey());
        is.setPublicId(el.getKey());
        opts.addGrammar(is);
        schemaCompiler.parseSchema(el.getKey(), StaxUtils.createXMLStreamReader(el.getValue(), el.getKey()));
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URI(java.net.URI) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) SchemaInfo(org.apache.cxf.service.model.SchemaInfo) InputStream(java.io.InputStream) XmlSchemaSerializer(org.apache.ws.commons.schema.XmlSchemaSerializer) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 14 with OASISCatalogManager

use of org.apache.cxf.catalog.OASISCatalogManager in project cxf by apache.

the class WSDL11Validator method getWSDLDoc.

private Document getWSDLDoc(String wsdl) {
    LOG.log(Level.FINE, new Message("VALIDATE_WSDL", LOG, wsdl).toString());
    try {
        OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(this.getBus());
        String nw = new OASISCatalogManagerHelper().resolve(catalogResolver, wsdl, null);
        if (nw == null) {
            nw = wsdl;
        }
        return new Stax2DOM().getDocument(URIParserUtil.getAbsoluteURI(nw));
    } catch (FileNotFoundException fe) {
        LOG.log(Level.WARNING, "Cannot find the wsdl " + wsdl + "to validate");
        return null;
    } catch (Exception e) {
        throw new ToolException(e);
    }
}
Also used : OASISCatalogManagerHelper(org.apache.cxf.catalog.OASISCatalogManagerHelper) Message(org.apache.cxf.common.i18n.Message) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) FileNotFoundException(java.io.FileNotFoundException) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Aggregations

OASISCatalogManager (org.apache.cxf.catalog.OASISCatalogManager)14 URL (java.net.URL)10 IOException (java.io.IOException)9 URISyntaxException (java.net.URISyntaxException)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 Bus (org.apache.cxf.Bus)5 ToolException (org.apache.cxf.tools.common.ToolException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 Message (org.apache.cxf.common.i18n.Message)4 XmlSchemaSerializerException (org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException)4 DOMException (org.w3c.dom.DOMException)4 SAXException (org.xml.sax.SAXException)4 SAXParseException (org.xml.sax.SAXParseException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 WSDLException (javax.wsdl.WSDLException)3 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)3