Search in sources :

Example 11 with WSDLException

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

the class SchemaFactory method newInstance.

/**
 * Get a new instance of a WSDLFactory. This method
 * returns an instance of the class factoryImplName.
 * Once an instance of a WSDLFactory is obtained, invoke
 * newDefinition(), newWSDLReader(), or newWSDLWriter(), to create
 * the desired instances.
 *
 * @param factoryImplName the fully-qualified class name of the
 * class which provides a concrete implementation of the abstract
 * class WSDLFactory.
 */
public static SchemaFactory newInstance(String factoryImplName) throws WSDLException {
    if (factoryImplName != null) {
        try {
            // get the appropriate class for the loading.
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Class<?> cl = loader.loadClass(factoryImplName);
            return (SchemaFactory) cl.newInstance();
        } catch (Exception e) {
            /*
                 Catches:
                 ClassNotFoundException
                 InstantiationException
                 IllegalAccessException
                 */
            throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Problem instantiating factory " + "implementation.", e);
        }
    }
    throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Unable to find name of factory " + "implementation.");
}
Also used : WSDLException(javax.wsdl.WSDLException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException)

Example 12 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().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)

Example 13 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;
    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 ToolException(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 = def.createBinding();
    binding.setPortType(portType);
    binding.setQName(bqname);
    bindingNames.add(bname);
    mapBindingToInterface(portType.getQName().getLocalPart(), bname);
    addCorbaTypeMap(def);
    try {
        BindingType 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) ToolException(org.apache.cxf.tools.common.ToolException)

Example 14 with WSDLException

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

the class JAXBExtensionHelper method marshall.

/* (non-Javadoc)
     * @see javax.wsdl.extensions.ExtensionSerializer#marshall(java.lang.Class,
     *  javax.xml.namespace.QName, javax.wsdl.extensions.ExtensibilityElement,
     *   java.io.PrintWriter, javax.wsdl.Definition, javax.wsdl.extensions.ExtensionRegistry)
     */
public void marshall(@SuppressWarnings("rawtypes") Class parent, QName qname, ExtensibilityElement obj, PrintWriter pw, final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
    try {
        Marshaller u = createMarshaller();
        u.setProperty("jaxb.encoding", StandardCharsets.UTF_8.name());
        u.setProperty("jaxb.fragment", Boolean.TRUE);
        u.setProperty("jaxb.formatted.output", Boolean.TRUE);
        Object mObj = obj;
        Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(typeClass) + ".ObjectFactory", true, obj.getClass().getClassLoader());
        Method[] methods = objectFactory.getDeclaredMethods();
        for (Method method : methods) {
            if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(typeClass)) {
                mObj = method.invoke(objectFactory.newInstance(), new Object[] { obj });
            }
        }
        javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
        XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), 2, getIndentLevel(parent));
        if (namespace != null && !namespace.equals(jaxbNamespace)) {
            Map<String, String> outMap = new HashMap<>();
            outMap.put("{" + jaxbNamespace + "}*", "{" + namespace + "}*");
            writer = new OutTransformWriter(writer, outMap, Collections.<String, String>emptyMap(), Collections.<String>emptyList(), false, "");
        }
        Map<String, String> nspref = new HashMap<>();
        for (Object ent : wsdl.getNamespaces().entrySet()) {
            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) ent;
            nspref.put((String) entry.getValue(), (String) entry.getKey());
        }
        JAXBUtils.setNamespaceMapper(bus, nspref, u);
        u.marshal(mObj, writer);
        writer.flush();
    } catch (Exception ex) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "", ex);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) WSDLException(javax.wsdl.WSDLException) Method(java.lang.reflect.Method) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) WSDLException(javax.wsdl.WSDLException) PrettyPrintXMLStreamWriter(org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter) OutTransformWriter(org.apache.cxf.staxutils.transform.OutTransformWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) PrettyPrintXMLStreamWriter(org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with WSDLException

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

the class JAXBExtensionHelper method unmarshall.

/* (non-Javadoc)
     * @see javax.wsdl.extensions.ExtensionDeserializer#unmarshall(java.lang.Class,
     *  javax.xml.namespace.QName, org.w3c.dom.Element,
     *   javax.wsdl.Definition,
     *   javax.wsdl.extensions.ExtensionRegistry)
     */
public ExtensibilityElement unmarshall(@SuppressWarnings("rawtypes") Class parent, QName qname, Element element, Definition wsdl, ExtensionRegistry registry) throws WSDLException {
    XMLStreamReader reader = null;
    Unmarshaller u = null;
    try {
        u = createUnmarshaller();
        Object o;
        if (namespace == null) {
            o = u.unmarshal(element, extensionClass);
        } else {
            reader = StaxUtils.createXMLStreamReader(element);
            reader = new MappingReaderDelegate(reader);
            o = u.unmarshal(reader, extensionClass);
        }
        if (o != null) {
            o = ((JAXBElement<?>) o).getValue();
        }
        ExtensibilityElement el = o instanceof ExtensibilityElement ? (ExtensibilityElement) o : new JAXBExtensibilityElement(o);
        el.setElementType(qname);
        return el;
    } catch (Exception ex) {
        throw new WSDLException(WSDLException.PARSER_ERROR, "Error reading element " + qname, ex);
    } finally {
        try {
            StaxUtils.close(reader);
        } catch (XMLStreamException ex) {
            throw new WSDLException(WSDLException.PARSER_ERROR, ex.getMessage(), ex);
        }
        JAXBUtils.closeUnmarshaller(u);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) WSDLException(javax.wsdl.WSDLException) Unmarshaller(javax.xml.bind.Unmarshaller) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) WSDLException(javax.wsdl.WSDLException)

Aggregations

WSDLException (javax.wsdl.WSDLException)56 ToolException (org.apache.cxf.tools.common.ToolException)18 WSDLReader (javax.wsdl.xml.WSDLReader)14 IOException (java.io.IOException)13 Definition (javax.wsdl.Definition)12 Message (org.apache.cxf.common.i18n.Message)12 QName (javax.xml.namespace.QName)11 WSDLWriter (javax.wsdl.xml.WSDLWriter)10 APIMgtWSDLException (org.wso2.carbon.apimgt.impl.wsdl.exceptions.APIMgtWSDLException)7 File (java.io.File)6 Writer (java.io.Writer)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)6 Document (org.w3c.dom.Document)6 URL (java.net.URL)5 WSDLManager (org.apache.cxf.wsdl.WSDLManager)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3