Search in sources :

Example 76 with Definition

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

the class DefinitionVisitor method createDefinition.

/**
 * Creates the WSDL definition correspoinding to the module scope if none exists
 */
private Definition createDefinition(XmlSchema schema) {
    String tns = mapper.map(getScope());
    Definition defn = definition;
    if (tns != null) {
        defn = manager.getWSDLDefinition(tns);
        if (defn == null) {
            try {
                defn = manager.createWSDLDefinition(tns);
                String key = getScope().toString("_");
                String fileName = getWsdlVisitor().getOutputDir() + System.getProperty("file.separator") + key;
                manager.addWSDLDefinitionImport(definition, defn, key, fileName);
                if (schema == null) {
                    schema = manager.getXmlSchema(tns);
                }
                if (schema != null) {
                    // add a schema based on the module with a corresponding import to the actual schema
                    manager.addWSDLSchemaImport(defn, tns, fileName);
                    // make sure that if we are adding the import to the wsdl, then we also
                    // add the schema to the list of imported schemas
                    manager.getImportedXmlSchemas().put(new java.io.File(fileName + ".xsd"), schema);
                }
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    return defn;
}
Also used : Definition(javax.wsdl.Definition)

Example 77 with Definition

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

the class PortTypeVisitor method findPortType.

private PortType findPortType(Scope intfScope) {
    String tns = mapper.map(intfScope.getParent());
    String intfName = intfScope.toString();
    Definition defn = definition;
    if (tns != null) {
        defn = manager.getWSDLDefinition(tns);
        intfName = intfScope.tail();
    }
    if (defn != null) {
        tns = defn.getTargetNamespace();
        QName name = new QName(tns, intfName);
        return defn.getPortType(name);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition)

Example 78 with Definition

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

the class WSDLCorbaFactoryImpl method newDefinition.

/**
 * Create a new instance of a Definition, with an instance of a
 * PopulatedExtensionRegistry as its ExtensionRegistry.
 */
public Definition newDefinition() {
    Definition def = factory.newDefinition();
    ExtensionRegistry extReg = newPopulatedExtensionRegistry();
    def.setExtensionRegistry(extReg);
    return def;
}
Also used : Definition(javax.wsdl.Definition) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry)

Example 79 with Definition

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

the class JAXWSDefinitionBuilderTest method testBuildDefinitionWithXMLBinding.

@Test
public void testBuildDefinitionWithXMLBinding() {
    String qname = "http://apache.org/hello_world_xml_http/bare";
    String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();
    JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
    builder.setBus(BusFactory.getDefaultBus());
    builder.setContext(env);
    Definition def = builder.build(wsdlUrl);
    assertNotNull(def);
    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service) services.get(new QName(qname, "XMLService"));
    assertNotNull(service);
    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("XMLPort");
    assertNotNull(port);
    assertEquals(1, port.getExtensibilityElements().size());
    Object obj = port.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement) obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an AddressType", obj instanceof AddressType);
    Binding binding = port.getBinding();
    assertNotNull(binding);
    assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());
    BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
    assertNotNull(operation);
    BindingInput input = operation.getBindingInput();
    assertNotNull(input);
    assertEquals(1, input.getExtensibilityElements().size());
    obj = input.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement) obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat", obj instanceof XMLBindingMessageFormat);
}
Also used : Binding(javax.wsdl.Binding) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) AddressType(org.apache.cxf.wsdl.http.AddressType) JAXWSDefinitionBuilder(org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder) Test(org.junit.Test)

Example 80 with Definition

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

the class WSDL11Generator method generate.

public Definition generate(final File dir) {
    File file = getOutputBase();
    if (file == null && dir != null) {
        if (dir.isDirectory()) {
            file = new File(dir, getServiceModel().getName().getLocalPart() + ".wsdl");
        } else {
            file = dir;
        }
    } else if (dir == null) {
        file = new File(getServiceModel().getName().getLocalPart() + ".wsdl");
    }
    File outputdir = createOutputDir(file);
    Definition def = null;
    try {
        Writer os = new FileWriterUtil(file.getParent(), getOutputStreamCreator()).getWriter(file, StandardCharsets.UTF_8.name());
        WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(getBus(), getServiceModel());
        builder.setUseSchemaImports(this.allowImports());
        String name = file.getName();
        if (name.endsWith(".wsdl")) {
            name = name.substring(0, name.lastIndexOf(".wsdl"));
        }
        builder.setBaseFileName(name);
        Map<String, SchemaInfo> imports = new HashMap<>();
        def = builder.build(imports);
        wsdlWriter.writeWSDL(def, os);
        os.close();
        if (!def.getImports().isEmpty()) {
            for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
                Definition wsdlDef = wsdlImport.getDefinition();
                final File wsdlFile;
                if (!StringUtils.isEmpty(wsdlImport.getLocationURI())) {
                    wsdlFile = new File(outputdir, wsdlImport.getLocationURI());
                } else {
                    wsdlFile = new File(outputdir, wsdlDef.getQName().getLocalPart() + ".wsdl");
                }
                try (OutputStream wsdlOs = new BufferedOutputStream(Files.newOutputStream(wsdlFile.toPath()))) {
                    wsdlWriter.writeWSDL(wsdlDef, wsdlOs);
                }
            }
        }
        for (Map.Entry<String, SchemaInfo> imp : imports.entrySet()) {
            File impfile = new File(file.getParentFile(), imp.getKey());
            Element el = imp.getValue().getElement();
            updateImports(el, imports);
            FileWriterUtil fileWriterUtil = new FileWriterUtil(impfile.getParent(), getToolContext().get(OutputStreamCreator.class));
            os = fileWriterUtil.getWriter(impfile, StandardCharsets.UTF_8.name());
            StaxUtils.writeTo(el, os, 2);
            os.close();
        }
        customizing(outputdir, name, imports.keySet());
    } catch (WSDLException wex) {
        wex.printStackTrace();
    } catch (FileNotFoundException fnfe) {
        throw new ToolException("Output file " + file + " not found", fnfe);
    } catch (IOException | XMLStreamException e) {
        e.printStackTrace();
    }
    return def;
}
Also used : Import(javax.wsdl.Import) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) HashMap(java.util.HashMap) WSDLException(javax.wsdl.WSDLException) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) FileNotFoundException(java.io.FileNotFoundException) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) XMLStreamException(javax.xml.stream.XMLStreamException) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) WSDLWriter(javax.wsdl.xml.WSDLWriter) Writer(java.io.Writer) SchemaInfo(org.apache.cxf.service.model.SchemaInfo)

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