Search in sources :

Example 71 with ToolException

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

the class WSDLToProcessor method parseWSDL.

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);
    }
}
Also used : Bus(org.apache.cxf.Bus) WSDLException(javax.wsdl.WSDLException) WSDLServiceBuilder(org.apache.cxf.wsdl11.WSDLServiceBuilder) WSDLManager(org.apache.cxf.wsdl.WSDLManager) ToolException(org.apache.cxf.tools.common.ToolException)

Example 72 with ToolException

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

the class JAXBDataBinding method initialize.

public void initialize(ToolContext c) throws ToolException {
    this.context = c;
    checkEncoding(c);
    SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
    Bus bus = context.get(Bus.class);
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    Options opts = null;
    opts = getOptions(schemaCompiler);
    hackInNewInternalizationLogic(schemaCompiler, catalog, opts);
    ClassCollector classCollector = context.get(ClassCollector.class);
    ClassNameAllocatorImpl allocator = new ClassNameAllocatorImpl(classCollector, c.optionSet(ToolConstants.CFG_AUTORESOLVE));
    schemaCompiler.setClassNameAllocator(allocator);
    listener = new JAXBBindErrorListener(context.isVerbose(), context.getErrorListener());
    schemaCompiler.setErrorListener(listener);
    // Collection<SchemaInfo> schemas = serviceInfo.getSchemas();
    List<InputSource> jaxbBindings = context.getJaxbBindingFile();
    SchemaCollection schemas = (SchemaCollection) context.get(ToolConstants.XML_SCHEMA_COLLECTION);
    List<String> args = new ArrayList<>();
    if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null) {
        // hard code to enable jaxb extensions
        args.add("-extension");
        String name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding.xml";
        if (isJAXB22()) {
            name = "/org/apache/cxf/tools/common/jaxb/W3CEPRJaxbBinding_jaxb22.xml";
        }
        URL bindingFileUrl = getClass().getResource(name);
        InputSource ins = new InputSource(bindingFileUrl.toString());
        opts.addBindFile(ins);
    }
    if (context.get(ToolConstants.CFG_XJC_ARGS) != null) {
        Object o = context.get(ToolConstants.CFG_XJC_ARGS);
        if (o instanceof String) {
            o = new String[] { (String) o };
        }
        String[] xjcArgss = (String[]) o;
        for (String xjcArgs : xjcArgss) {
            StringTokenizer tokenizer = new StringTokenizer(xjcArgs, ",", false);
            while (tokenizer.hasMoreTokens()) {
                String arg = tokenizer.nextToken();
                args.add(arg);
                LOG.log(Level.FINE, "xjc arg:" + arg);
            }
        }
    }
    if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null || context.get(ToolConstants.CFG_XJC_ARGS) != null) {
        try {
            // keep parseArguments happy, supply dummy required command-line
            // opts
            opts.addGrammar(new InputSource("null"));
            opts.parseArguments(args.toArray(new String[args.size()]));
        } catch (BadCommandLineException e) {
            StringBuilder msg = new StringBuilder("XJC reported 'BadCommandLineException' for -xjc argument:");
            for (String arg : args) {
                msg.append(arg + " ");
            }
            LOG.log(Level.FINE, msg.toString(), e);
            if (opts != null) {
                String pluginUsage = getPluginUsageString(opts);
                msg.append(System.getProperty("line.separator"));
                if (args.contains("-X")) {
                    throw new ToolException(pluginUsage, e);
                }
                msg.append(pluginUsage);
            }
            throw new ToolException(msg.toString(), e);
        }
    }
    if (context.optionSet(ToolConstants.CFG_MARK_GENERATED)) {
        // '-mark-generated' attribute to jaxb xjc.
        try {
            opts.parseArgument(new String[] { "-mark-generated" }, 0);
        } catch (BadCommandLineException e) {
            LOG.log(Level.SEVERE, e.getMessage());
            throw new ToolException(e);
        }
    }
    addSchemas(opts, schemaCompiler, schemas);
    addBindingFiles(opts, jaxbBindings, schemas);
    parseSchemas(schemaCompiler);
    rawJaxbModelGenCode = schemaCompiler.bind();
    addedEnumClassToCollector(schemas, allocator);
    if (context.get(ToolConstants.CFG_DEFAULT_VALUES) != null) {
        String cname = (String) context.get(ToolConstants.CFG_DEFAULT_VALUES);
        if (StringUtils.isEmpty(cname)) {
            defaultValues = new RandomValueProvider();
        } else {
            if (cname.charAt(0) == '=') {
                cname = cname.substring(1);
            }
            try {
                defaultValues = (DefaultValueProvider) Class.forName(cname).newInstance();
            } catch (Exception e) {
                LOG.log(Level.SEVERE, e.getMessage());
                throw new ToolException(e);
            }
        }
    }
    initialized = true;
}
Also used : Bus(org.apache.cxf.Bus) Options(com.sun.tools.xjc.Options) BadCommandLineException(com.sun.tools.xjc.BadCommandLineException) InputSource(org.xml.sax.InputSource) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ArrayList(java.util.ArrayList) SchemaCompiler(com.sun.tools.xjc.api.SchemaCompiler) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) SAXException(org.xml.sax.SAXException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) BadCommandLineException(com.sun.tools.xjc.BadCommandLineException) SAXParseException(org.xml.sax.SAXParseException) StringTokenizer(java.util.StringTokenizer) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) RandomValueProvider(org.apache.cxf.tools.wsdlto.core.RandomValueProvider)

Example 73 with ToolException

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

the class JAXBDataBinding method generate.

public void generate(ToolContext c) throws ToolException {
    if (!initialized) {
        initialize(c);
    }
    if (rawJaxbModelGenCode == null) {
        return;
    }
    if (c.getErrorListener().getErrorCount() > 0) {
        return;
    }
    try {
        String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
        TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), context.getExcludePkgList(), (String) context.get(ToolConstants.CFG_ENCODING), context.get(OutputStreamCreator.class));
        S2JJAXBModel schem2JavaJaxbModel = rawJaxbModelGenCode;
        ClassCollector classCollector = context.get(ClassCollector.class);
        for (JClass cls : schem2JavaJaxbModel.getAllObjectFactories()) {
            classCollector.getTypesPackages().add(cls._package().name());
        }
        JCodeModel jcodeModel = schem2JavaJaxbModel.generateCode(null, null);
        if (!isSuppressCodeGen()) {
            jcodeModel.build(fileCodeWriter);
        }
        context.put(JCodeModel.class, jcodeModel);
        for (String str : fileCodeWriter.getExcludeFileList()) {
            context.getExcludeFileList().add(str);
        }
        return;
    } catch (IOException e) {
        Message msg = new Message("FAIL_TO_GENERATE_TYPES", LOG);
        throw new ToolException(msg, e);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JClass(com.sun.codemodel.JClass) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) S2JJAXBModel(com.sun.tools.xjc.api.S2JJAXBModel) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) JCodeModel(com.sun.codemodel.JCodeModel)

Example 74 with ToolException

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

the class WSDLToJavaScriptProcessor method getOutputFile.

private File getOutputFile(String defaultOutputFile) {
    String output = (String) context.get(ToolConstants.CFG_OUTPUTFILE);
    String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
    if (dir == null) {
        dir = "./";
    }
    File result;
    if (output != null) {
        result = new File(output);
        if (!result.isAbsolute()) {
            result = new File(new File(dir), output);
        }
    } else {
        result = new File(new File(dir), defaultOutputFile);
    }
    // rename the exising js
    if (result.exists() && !result.renameTo(new File(result.getParent(), result.getName()))) {
        throw new ToolException(new Message("OUTFILE_EXISTS", LOG));
    }
    return result;
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File)

Example 75 with ToolException

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

the class JAXWSContainer method validate.

public void validate(ToolContext env) throws ToolException {
    env.put("service.target", getServiceTarget());
    env.put("service.superclass", getServiceSuperclass());
    super.validate(env);
    if (env.containsKey(ToolConstants.CFG_BINDING)) {
        String[] bindings = (String[]) env.get(ToolConstants.CFG_BINDING);
        URIResolver resolver = null;
        for (int i = 0; i < bindings.length; i++) {
            try {
                resolver = new URIResolver(bindings[i]);
            } catch (IOException ioe) {
                throw new ToolException(ioe);
            }
            if (!resolver.isResolved()) {
                Message msg = new Message("FILE_NOT_EXIST", LOG, bindings[i]);
                throw new ToolException(msg);
            }
        }
        env.put(ToolConstants.CFG_BINDING, bindings);
    }
    cleanArrays(env, ToolConstants.CFG_ASYNCMETHODS);
    cleanArrays(env, ToolConstants.CFG_BAREMETHODS);
    cleanArrays(env, ToolConstants.CFG_MIMEMETHODS);
}
Also used : Message(org.apache.cxf.common.i18n.Message) URIResolver(org.apache.cxf.resource.URIResolver) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

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