Search in sources :

Example 1 with WSDLException

use of javax.wsdl.WSDLException in project tdi-studio-se by Talend.

the class ComponentBuilder method createschemafromtype.

private XmlSchema createschemafromtype(org.w3c.dom.Element schemaElement, Definition wsdlDefinition, String documentBase) throws WSDLException {
    if (schemaElement == null) {
        throw new WSDLException(WSDLException.INVALID_WSDL, "Unable to find schema extensibility element in WSDL");
    }
    XmlSchema xmlSchema = null;
    XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection();
    xmlSchemaCollection.setBaseUri(fixDocumentBase(documentBase));
    xmlSchema = xmlSchemaCollection.read(schemaElement);
    return xmlSchema;
}
Also used : WSDLException(javax.wsdl.WSDLException) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection)

Example 2 with WSDLException

use of javax.wsdl.WSDLException in project Activiti by Activiti.

the class CxfWSDLImporter method importFrom.

public void importFrom(String url) {
    this.wsServices.clear();
    this.wsOperations.clear();
    this.structures.clear();
    this.wsdlLocation = url;
    try {
        Bus bus = BusFactory.getDefaultBus();
        final Enumeration<URL> xjcBindingUrls = Thread.currentThread().getContextClassLoader().getResources(JAXB_BINDINGS_RESOURCE);
        if (xjcBindingUrls.hasMoreElements()) {
            final URL xjcBindingUrl = xjcBindingUrls.nextElement();
            if (xjcBindingUrls.hasMoreElements()) {
                throw new ActivitiException("Several JAXB binding definitions found for activiti-cxf: " + JAXB_BINDINGS_RESOURCE);
            }
            DynamicClientFactory.newInstance(bus).createClient(url, Arrays.asList(new String[] { xjcBindingUrl.toString() }));
            WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
            Definition def = wsdlManager.getDefinition(url);
            WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
            List<ServiceInfo> services = builder.buildServices(def);
            for (ServiceInfo service : services) {
                WSService wsService = this.importService(service);
                this.wsServices.put(this.namespace + wsService.getName(), wsService);
            }
            if (def != null && def.getTypes() != null) {
                this.importTypes(def.getTypes());
            }
        } else {
            throw new ActivitiException("The JAXB binding definitions are not found for activiti-cxf: " + JAXB_BINDINGS_RESOURCE);
        }
    } catch (WSDLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        throw new ActivitiException("Error retrieveing the JAXB binding definitions", e);
    }
}
Also used : Bus(org.apache.cxf.Bus) ActivitiException(org.activiti.engine.ActivitiException) WSDLException(javax.wsdl.WSDLException) StructureDefinition(org.activiti.engine.impl.bpmn.data.StructureDefinition) SimpleStructureDefinition(org.activiti.engine.impl.bpmn.data.SimpleStructureDefinition) Definition(javax.wsdl.Definition) PrimitiveStructureDefinition(org.activiti.engine.impl.bpmn.data.PrimitiveStructureDefinition) IOException(java.io.IOException) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) WSDLManager(org.apache.cxf.wsdl.WSDLManager)

Example 3 with WSDLException

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

the class WSDLToCorbaBinding method generateCORBABinding.

private Binding generateCORBABinding(Definition definition, PortType portType) throws Exception {
    QName bqname = null;
    if (extReg == null) {
        extReg = def.getExtensionRegistry();
    }
    bindingNames = new ArrayList<>();
    String interfaceName = portType.getQName().getLocalPart();
    String bname = getMappedBindingName(interfaceName);
    String prefix = definition.getPrefix(definition.getTargetNamespace());
    if (prefix == null) {
        prefix = "";
    }
    if (bname == null && !allbindings) {
        bname = bindingName;
    }
    if (bname == null) {
        bname = mangleInterfaceName(interfaceName) + "CORBABinding";
        setBindingName(bname);
        bqname = new QName(definition.getTargetNamespace(), bname, prefix);
        int count = 0;
        StringBuilder builder = new StringBuilder(bname);
        while (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
            builder.append(count);
            bqname = new QName(definition.getTargetNamespace(), builder.toString(), prefix);
        }
        bname = builder.toString();
    } else {
        bqname = new QName(definition.getTargetNamespace(), bname, prefix);
        // Check if the Binding with name already exists
        if (WSDLToCorbaHelper.queryBinding(definition, bqname)) {
            String msgStr = "Binding " + bqname.getLocalPart() + " already exists in WSDL.";
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
            throw new Exception(msg.toString());
        }
    }
    // jwsdl model should have all other bindings in it.
    String pfx = definition.getPrefix(CorbaConstants.NU_WSDL_CORBA);
    if (pfx == null) {
        pfx = "corba";
        def.addNamespace(pfx, CorbaConstants.NU_WSDL_CORBA);
    }
    Binding binding = null;
    binding = def.createBinding();
    binding.setPortType(portType);
    binding.setQName(bqname);
    bindingNames.add(bname);
    mapBindingToInterface(portType.getQName().getLocalPart(), bname);
    BindingType bindingType = null;
    addCorbaTypeMap(def);
    try {
        bindingType = (BindingType) extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
        bindingType.setRepositoryID(WSDLToCorbaHelper.REPO_STRING + binding.getPortType().getQName().getLocalPart().replace('.', '/') + WSDLToCorbaHelper.IDL_VERSION);
        binding.addExtensibilityElement((ExtensibilityElement) bindingType);
    } catch (WSDLException ex) {
        ex.printStackTrace();
    }
    try {
        addBindingOperations(def, portType, binding);
        binding.setUndefined(false);
        definition.addBinding(binding);
    } catch (Exception ex) {
        binding.setUndefined(true);
    }
    cleanUpTypeMap(typeMappingType);
    return binding;
}
Also used : Binding(javax.wsdl.Binding) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType)

Example 4 with WSDLException

use of javax.wsdl.WSDLException 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().size() > 0) {
            for (Import wsdlImport : WSDLDefinitionBuilder.getImports(def)) {
                Definition wsdlDef = wsdlImport.getDefinition();
                File wsdlFile = null;
                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 e) {
        e.printStackTrace();
    } catch (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)

Example 5 with WSDLException

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

the class AttributeVisitor method generateCorbaOperation.

/**
 * Generates a corba:operation in the corba:binding container within a wsdl:binding.
 *
 * Only one (or none) corba parameter and only one (or none) corba return parameter are supported.
 *
 * @param op is the wsdl operation to bind.
 * @param param is the corba parameter, none if null.
 * @param arg is the corba return parameter, none if null.
 * @return the generated corba:operation.
 */
private OperationType generateCorbaOperation(Operation op, ParamType param, ArgType arg) {
    OperationType operation = null;
    try {
        operation = (OperationType) extReg.createExtension(BindingOperation.class, CorbaConstants.NE_CORBA_OPERATION);
    } catch (WSDLException ex) {
        throw new RuntimeException(ex);
    }
    operation.setName(op.getName());
    if (param != null) {
        operation.getParam().add(param);
    }
    if (arg != null) {
        operation.setReturn(arg);
    }
    return operation;
}
Also used : WSDLException(javax.wsdl.WSDLException) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType)

Aggregations

WSDLException (javax.wsdl.WSDLException)48 ToolException (org.apache.cxf.tools.common.ToolException)18 Message (org.apache.cxf.common.i18n.Message)12 IOException (java.io.IOException)11 QName (javax.xml.namespace.QName)11 Definition (javax.wsdl.Definition)10 WSDLReader (javax.wsdl.xml.WSDLReader)10 WSDLWriter (javax.wsdl.xml.WSDLWriter)7 Writer (java.io.Writer)6 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)6 Document (org.w3c.dom.Document)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 WSDLManager (org.apache.cxf.wsdl.WSDLManager)5 File (java.io.File)4 WSDLFactory (javax.wsdl.factory.WSDLFactory)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 URL (java.net.URL)3 Binding (javax.wsdl.Binding)3 Port (javax.wsdl.Port)3