Search in sources :

Example 61 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class WSDLGeneratorFactory method newGenerator.

public AbstractGenerator<?> newGenerator() {
    AbstractGenerator<?> generator = null;
    String clzName = getGeneratorClassName();
    try {
        generator = (AbstractGenerator<?>) Class.forName(clzName).newInstance();
    } catch (Exception e) {
        throw new ToolException("Can not find the Generator for: " + clzName, e);
    }
    return generator;
}
Also used : ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 62 with ToolException

use of org.apache.cxf.tools.common.ToolException 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 63 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class JavaMethod method addParameter.

public void addParameter(JavaParameter param) {
    if (hasParameter(param.getName())) {
        JavaParameter paramInList = getParameter(param.getName());
        if (isEquiv(paramInList.getClassName(), param.getClassName()) && paramInList.isIN() || paramInList.isINOUT()) {
            // removeParameter(paramInList);
            replaceParameter(paramInList, param);
            return;
        }
        Message message = new Message("PARAMETER_ALREADY_EXIST", LOG, param.getName(), getName(), paramInList.getType(), param.getType());
        throw new ToolException(message);
    }
    if (param.getType() == null && param.getClassName() == null) {
        Message msg = new Message("FAIL_TO_CREATE_JAVA_PARAMETER", LOG, param.name, this.getName());
        throw new ToolException(msg);
    }
    param.setMethod(this);
    parameters.add(param);
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException)

Example 64 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class AbstractToolContainer method init.

public void init() throws ToolException {
    // initialize
    if (toolspec == null) {
        Message message = new Message("TOOLSPEC_NOT_INITIALIZED", LOG);
        LOG.log(Level.SEVERE, message.toString());
        throw new ToolException(message);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException)

Example 65 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class AbstractToolContainer method getBus.

public Bus getBus() {
    Bus bus = BusFactory.getDefaultBus();
    OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);
    String catalogLocation = getCatalogURL();
    if (!StringUtils.isEmpty(catalogLocation)) {
        try {
            catalogManager.loadCatalog(new URI(catalogLocation).toURL());
        } catch (Exception e) {
            e.printStackTrace(err);
            throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG, catalogLocation));
        }
    }
    return bus;
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.common.i18n.Message) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) URI(java.net.URI) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException)

Aggregations

ToolException (org.apache.cxf.tools.common.ToolException)129 Message (org.apache.cxf.common.i18n.Message)69 IOException (java.io.IOException)38 File (java.io.File)30 QName (javax.xml.namespace.QName)19 WSDLException (javax.wsdl.WSDLException)18 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)16 ToolContext (org.apache.cxf.tools.common.ToolContext)15 XMLStreamException (javax.xml.stream.XMLStreamException)14 FileNotFoundException (java.io.FileNotFoundException)12 Test (org.junit.Test)12 Element (org.w3c.dom.Element)10 InputStream (java.io.InputStream)9 Writer (java.io.Writer)9 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)8 WSDLWriter (javax.wsdl.xml.WSDLWriter)7