Java Code Examples for org.apache.cxf.wsdl.WSDLManager#getDefinition()

The following examples show how to use org.apache.cxf.wsdl.WSDLManager#getDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSDLToProcessor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void parseWSDL(String wsdlUrl) {
    try {
        Bus bus = BusFactory.getThreadDefaultBus();
        WSDLManager mgr = bus.getExtension(WSDLManager.class);
        wsdlDefinition = mgr.getDefinition(wsdlUrl);
        WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
        builder.buildMockServices(wsdlDefinition);
        schemas = mgr.getSchemasForDefinition(wsdlDefinition);

        //remove this as we're going to be modifying it
        mgr.removeDefinition(wsdlDefinition);

    } catch (WSDLException we) {
        org.apache.cxf.common.i18n.Message msg =
                new org.apache.cxf.common.i18n.Message(
                "FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
        throw new ToolException(msg, we);
    }
}
 
Example 2
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildSimpleWSDL() throws Exception {
    String qname = "http://apache.org/hello_world_soap_http";
    String wsdlUrl = getClass().getResource("hello_world.wsdl").toString();

    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service)services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
}
 
Example 3
Source File: WSDLDefinitionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void parseWSDL(String wsdlURL) {
    try {
        WSDLManager mgr = bus.getExtension(WSDLManager.class);
        registerWSDLExtensibilityPlugins(mgr.getExtensionRegistry());
        wsdlDefinition = mgr.getDefinition(wsdlURL);

        parseImports(wsdlDefinition);

        if (wsdlDefinition.getServices().isEmpty()) {
            for (Definition def : importedDefinitions) {
                Set<QName> services = def.getServices().keySet();
                for (QName sName : services) {
                    if (!wsdlDefinition.getServices().keySet().contains(sName)) {
                        wsdlDefinition.getServices().put(sName, def.getService(sName));
                    }
                }
            }
        }
    } catch (Exception we) {
        Message msg = new Message("FAIL_TO_CREATE_WSDL_DEFINITION",
                                  LOG,
                                  wsdlURL,
                                  we.getMessage());
        throw new WSDLRuntimeException(msg, we);
    }
}
 
Example 4
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 5
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: STSClientTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testWCFWsdl() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();

    // Load WSDL
    InputStream inStream = getClass().getResourceAsStream("wcf.wsdl");
    Document doc = StaxUtils.read(inStream);


    NodeList metadataSections =
        doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2004/09/mex", "MetadataSection");
    Element wsdlDefinition = null;
    List<Element> schemas = new ArrayList<>();
    for (int i = 0; i < metadataSections.getLength(); i++) {
        Node node = metadataSections.item(i);
        if (node instanceof Element) {
            Element element = (Element)node;
            String dialect = element.getAttributeNS(null, "Dialect");
            if ("http://schemas.xmlsoap.org/wsdl/".equals(dialect)) {
                wsdlDefinition = DOMUtils.getFirstElement(element);
            } else if ("http://www.w3.org/2001/XMLSchema".equals(dialect)) {
                schemas.add(DOMUtils.getFirstElement(element));
            }
        }
    }

    assertNotNull(wsdlDefinition);
    assertFalse(schemas.isEmpty());

    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
    Definition definition = wsdlManager.getDefinition(wsdlDefinition);

    for (Element schemaElement : schemas) {
        QName schemaName =
            new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
        ExtensibilityElement
            exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
        ((Schema)exElement).setElement(schemaElement);
        definition.getTypes().addExtensibilityElement(exElement);
    }

    WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
    SourceDataBinding dataBinding = new SourceDataBinding();
    factory.setDataBinding(dataBinding);
    Service service = factory.create();
    service.setDataBinding(dataBinding);

}
 
Example 7
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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
    }
}
 
Example 8
Source File: WSDLManagerImplTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoveDefinitionByURL() 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(path2.toString());

    // This time loading should fail as the original resource is removed
    try {
        builder.getDefinition(path2.toString());
        fail("Failure expected");
    } catch (NullPointerException ex) {
        // expected
    }
}