Search in sources :

Example 66 with Definition

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

the class SoapBindingFactory method addMessageFromBinding.

protected void addMessageFromBinding(ExtensibilityElement ext, BindingOperationInfo bop, boolean isInput) {
    SoapHeader header = SOAPBindingUtil.getSoapHeader(ext);
    ServiceInfo serviceInfo = bop.getBinding().getService();
    if (header != null && header.getMessage() == null) {
        throw new RuntimeException("Problem with WSDL: soap:header element" + " for operation " + bop.getName() + " under binding " + bop.getBinding().getName() + " does not contain a valid message attribute.");
    }
    if (header != null && serviceInfo.getMessage(header.getMessage()) == null) {
        Definition def = (Definition) serviceInfo.getProperty(WSDLServiceBuilder.WSDL_DEFINITION);
        SchemaCollection schemas = serviceInfo.getXmlSchemaCollection();
        if (def != null && schemas != null) {
            QName qn = header.getMessage();
            javax.wsdl.Message msg = findMessage(qn, def);
            if (msg != null) {
                addOutOfBandParts(bop, msg, schemas, isInput, header.getPart());
                serviceInfo.refresh();
            } else {
                throw new RuntimeException("Problem with WSDL: soap:header element" + " for operation " + bop.getName() + " is referring to an undefined wsdl:message element: " + qn);
            }
        }
    }
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection)

Example 67 with Definition

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

the class WSDLManagerImplTest method testBuildImportedWSDL.

@Test
public void testBuildImportedWSDL() throws Exception {
    String wsdlUrl = getClass().getResource("hello_world_services.wsdl").toString();
    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(wsdlUrl);
    assertNotNull(def);
    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    String serviceQName = "http://apache.org/hello_world/services";
    Service service = (Service) services.get(new QName(serviceQName, "SOAPService"));
    assertNotNull(service);
    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
    Binding binding = port.getBinding();
    assertNotNull(binding);
    QName bindingQName = new QName("http://apache.org/hello_world/bindings", "SOAPBinding");
    assertEquals(bindingQName, binding.getQName());
    PortType portType = binding.getPortType();
    assertNotNull(portType);
    QName portTypeQName = new QName("http://apache.org/hello_world", "Greeter");
    assertEquals(portTypeQName, portType.getQName());
    Operation op1 = portType.getOperation("sayHi", "sayHiRequest", "sayHiResponse");
    assertNotNull(op1);
    QName messageQName = new QName("http://apache.org/hello_world/messages", "sayHiRequest");
    assertEquals(messageQName, op1.getInput().getMessage().getQName());
    Part part = op1.getInput().getMessage().getPart("in");
    assertNotNull(part);
    assertEquals(new QName("http://apache.org/hello_world/types", "sayHi"), part.getElementName());
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Service(javax.wsdl.Service) Operation(javax.wsdl.Operation) PortType(javax.wsdl.PortType) Test(org.junit.Test)

Example 68 with Definition

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

the class WSDLManagerImplTest method testRemoveDefinition.

@Test
public void testRemoveDefinition() throws Exception {
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    // Copy hello_world.wsdl so that we can delete it
    Path path1 = FileSystems.getDefault().getPath(basedir, "/src/test/resources/org/apache/cxf/wsdl11/hello_world.wsdl");
    Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/hello_world2.wsdl");
    Files.copy(path1, path2);
    // Load the resource
    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(path2.toString());
    assertNotNull(def);
    // Delete the resource
    Files.delete(path2);
    // Now load it again to test caching
    def = builder.getDefinition(path2.toString());
    assertNotNull(def);
    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    String qname = "http://apache.org/hello_world_soap_http";
    Service service = (Service) services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);
    // Now remove it
    builder.removeDefinition(def);
    // This time loading should fail as the original resource is removed
    try {
        builder.getDefinition(path2.toString());
        fail("Failure expected");
    } catch (NullPointerException ex) {
    // expected
    }
}
Also used : Path(java.nio.file.Path) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Service(javax.wsdl.Service) File(java.io.File) Test(org.junit.Test)

Example 69 with Definition

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

the class WSDLManagerImplTest method testXMLStreamReaderWrapper.

@Test
public void testXMLStreamReaderWrapper() throws Exception {
    final Map<String, String> map = new HashMap<>();
    map.put("org.apache.cxf.test.wsdl11.port", "99999");
    String wsdlUrl = getClass().getResource("hello_world_wrap.wsdl").toString();
    WSDLManagerImpl builder = new WSDLManagerImpl();
    builder.setXMLStreamReaderWrapper(new XMLStreamReaderWrapper() {

        @Override
        public XMLStreamReader wrap(XMLStreamReader reader) {
            return new PropertiesExpandingStreamReader(reader, map);
        }
    });
    Definition def = builder.getDefinition(wsdlUrl);
    java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
    builder.getWSDLFactory().newWSDLWriter().writeWSDL(def, bos);
    assertTrue(bos.toString().contains("http://localhost:99999/SoapContext/SoapPort"));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PropertiesExpandingStreamReader(org.apache.cxf.staxutils.PropertiesExpandingStreamReader) HashMap(java.util.HashMap) XMLStreamReaderWrapper(org.apache.cxf.staxutils.XMLStreamReaderWrapper) Definition(javax.wsdl.Definition) Test(org.junit.Test)

Example 70 with Definition

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

the class WSDLManagerImplTest method testLocalNamespacedWSDL.

@Test
public void testLocalNamespacedWSDL() throws Exception {
    String wsdlUrl = getClass().getResource("hello_world_local_nsdecl.wsdl").toString();
    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(wsdlUrl);
    java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
    builder.getWSDLFactory().newWSDLWriter().writeWSDL(def, bos);
}
Also used : Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Test(org.junit.Test)

Aggregations

Definition (javax.wsdl.Definition)226 Test (org.junit.Test)113 QName (javax.xml.namespace.QName)61 File (java.io.File)52 Document (org.w3c.dom.Document)44 Element (org.w3c.dom.Element)40 HashMap (java.util.HashMap)36 WSDLReader (javax.wsdl.xml.WSDLReader)35 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)31 JBossWSTest (org.jboss.wsf.test.JBossWSTest)31 Service (javax.wsdl.Service)24 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)23 URL (java.net.URL)21 ArrayList (java.util.ArrayList)21 Port (javax.wsdl.Port)21 WSDLToIDLAction (org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction)21 Bus (org.apache.cxf.Bus)20 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)20 WSDLManager (org.apache.cxf.wsdl.WSDLManager)20 IOException (java.io.IOException)18