Search in sources :

Example 41 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project cxf by apache.

the class WSDLManagerImpl method getDefinition.

public Definition getDefinition(final Element el) throws WSDLException {
    synchronized (definitionsMap) {
        if (definitionsMap.containsKey(el)) {
            return definitionsMap.get(el);
        }
    }
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setExtensionRegistry(registry);
    final Definition def;
    // This is needed to avoid security exceptions when running with a security manager
    if (System.getSecurityManager() == null) {
        def = reader.readWSDL("", el);
    } else {
        try {
            def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL("", el));
        } catch (PrivilegedActionException paex) {
            throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
        }
    }
    synchronized (definitionsMap) {
        definitionsMap.put(el, def);
    }
    return def;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) WSDLException(javax.wsdl.WSDLException) Definition(javax.wsdl.Definition) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 42 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project cxf by apache.

the class WSDLManagerImpl method loadDefinition.

protected Definition loadDefinition(String url) throws WSDLException {
    final WSDLReader reader = factory.newWSDLReader();
    reader.setFeature("javax.wsdl.verbose", false);
    reader.setFeature("javax.wsdl.importDocuments", true);
    reader.setExtensionRegistry(registry);
    // we'll create a new String here to make sure the passed in key is not referenced in the loading of
    // the wsdl and thus would be held onto from the cached map from both the weak reference (key) and
    // from the strong reference (Definition).  For example, the Definition sometimes keeps the original
    // string as the documentBaseLocation which would result in it being held onto strongly
    // from the definition.  With this, the String the definition holds onto would be unique
    url = new String(url);
    CatalogWSDLLocator catLocator = new CatalogWSDLLocator(url, bus);
    final ResourceManagerWSDLLocator wsdlLocator = new ResourceManagerWSDLLocator(url, catLocator, bus);
    InputSource src = wsdlLocator.getBaseInputSource();
    final Definition def;
    if (src.getByteStream() != null || src.getCharacterStream() != null) {
        final Document doc;
        XMLStreamReader xmlReader = null;
        try {
            xmlReader = StaxUtils.createXMLStreamReader(src);
            if (xmlStreamReaderWrapper != null) {
                xmlReader = xmlStreamReaderWrapper.wrap(xmlReader);
            }
            doc = StaxUtils.read(xmlReader, true);
            if (src.getSystemId() != null) {
                try {
                    doc.setDocumentURI(new String(src.getSystemId()));
                } catch (Exception e) {
                // ignore - probably not DOM level 3
                }
            }
        } catch (Exception e) {
            throw new WSDLException(WSDLException.PARSER_ERROR, e.getMessage(), e);
        } finally {
            try {
                StaxUtils.close(xmlReader);
            } catch (XMLStreamException ex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, ex.getMessage(), ex);
            }
        }
        // This is needed to avoid security exceptions when running with a security manager
        if (System.getSecurityManager() == null) {
            def = reader.readWSDL(wsdlLocator, doc.getDocumentElement());
        } else {
            try {
                def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator, doc.getDocumentElement()));
            } catch (PrivilegedActionException paex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
            }
        }
    } else {
        if (System.getSecurityManager() == null) {
            def = reader.readWSDL(wsdlLocator);
        } else {
            try {
                def = AccessController.doPrivileged((PrivilegedExceptionAction<Definition>) () -> reader.readWSDL(wsdlLocator));
            } catch (PrivilegedActionException paex) {
                throw new WSDLException(WSDLException.PARSER_ERROR, paex.getMessage(), paex);
            }
        }
    }
    return def;
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) WSDLException(javax.wsdl.WSDLException) PrivilegedActionException(java.security.PrivilegedActionException) Definition(javax.wsdl.Definition) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Document(org.w3c.dom.Document) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) BusException(org.apache.cxf.BusException) WSDLException(javax.wsdl.WSDLException) XMLStreamException(javax.xml.stream.XMLStreamException) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 43 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project cxf by apache.

the class PublishedEndpointUrlTest method testPublishedEndpointUrl.

@Test
public void testPublishedEndpointUrl() throws Exception {
    Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
    String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceClass(Greeter.class);
    svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
    svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
    svrFactory.setServiceBean(implementor);
    Server server = svrFactory.create();
    WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
    HttpURLConnection connect = (HttpURLConnection) url.openConnection();
    assertEquals(500, connect.getResponseCode());
    Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
    assertNotNull(wsdl);
    Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
    final String failMesg = "WSDL provided incorrect soap:address location";
    for (Service service : services) {
        Collection<Port> ports = CastUtils.cast(service.getPorts().values());
        for (Port port : ports) {
            List<?> extensions = port.getExtensibilityElements();
            for (Object extension : extensions) {
                String actualUrl = null;
                if (extension instanceof SOAP12Address) {
                    actualUrl = ((SOAP12Address) extension).getLocationURI();
                } else if (extension instanceof SOAPAddress) {
                    actualUrl = ((SOAPAddress) extension).getLocationURI();
                }
                // System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
                assertEquals(failMesg, publishedEndpointUrl, actualUrl);
            }
        }
    }
    server.stop();
    server.destroy();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) WSDLReader(javax.wsdl.xml.WSDLReader) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

Example 44 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project cxf by apache.

the class ServiceWSDLBuilderTest method setupWSDL.

private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
    String wsdlUrl = getClass().getResource(wsdlPath).toString();
    LOG.info("the path of wsdl file is " + wsdlUrl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    def = wsdlReader.readWSDL(wsdlUrl);
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
    destinationFactory = control.createMock(DestinationFactory.class);
    wsdlServiceBuilder = new WSDLServiceBuilder(bus, false);
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            break;
        }
    }
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(new WSDLManagerImpl()).anyTimes();
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager);
    EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory);
    control.replay();
    serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
    ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
    builder.setUseSchemaImports(doXsdImports);
    builder.setBaseFileName("HelloWorld");
    newDef = builder.build(new HashMap<String, SchemaInfo>());
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HashMap(java.util.HashMap) Service(javax.wsdl.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLManager(org.apache.cxf.wsdl.WSDLManager) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 45 with WSDLReader

use of javax.wsdl.xml.WSDLReader in project cxf by apache.

the class WSDLServiceBuilderTest method setUpDefinition.

private void setUpDefinition(String wsdl, int serviceSeq) throws Exception {
    URL url = getClass().getResource(wsdl);
    assertNotNull("could not find wsdl " + wsdl, url);
    String wsdlUrl = url.toString();
    LOG.info("the path of wsdl file is " + wsdlUrl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    def = wsdlReader.readWSDL(new CatalogWSDLLocator(wsdlUrl));
    int seq = 0;
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            if (seq == serviceSeq) {
                break;
            }
            seq++;
        }
    }
}
Also used : WSDLFactory(javax.wsdl.factory.WSDLFactory) Service(javax.wsdl.Service) URL(java.net.URL) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

WSDLReader (javax.wsdl.xml.WSDLReader)60 Definition (javax.wsdl.Definition)35 WSDLFactory (javax.wsdl.factory.WSDLFactory)25 WSDLException (javax.wsdl.WSDLException)16 URL (java.net.URL)15 Test (org.junit.Test)13 Service (javax.wsdl.Service)8 File (java.io.File)7 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)7 JBossWSTest (org.jboss.wsf.test.JBossWSTest)7 Document (org.w3c.dom.Document)7 QName (javax.xml.namespace.QName)6 InputSource (org.xml.sax.InputSource)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Bus (org.apache.cxf.Bus)5 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4