Search in sources :

Example 31 with ToolContext

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

the class WSDLToJava method main.

public static void main(String[] pargs) {
    System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
    CommandInterfaceUtils.commandCommonMain();
    WSDLToJava w2j = new WSDLToJava(pargs);
    try {
        w2j.run(new ToolContext());
    } catch (ToolException ex) {
        System.err.println();
        System.err.println("WSDLToJava Error: " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    } catch (Exception ex) {
        System.err.println("WSDLToJava Error: " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    }
    if (w2j.isExitOnFinish()) {
        System.exit(0);
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 32 with ToolContext

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

the class WSDLToJavaContainer method execute.

public void execute() throws ToolException {
    if (hasInfoOption()) {
        return;
    }
    buildToolContext();
    boolean isWsdlList = context.optionSet(ToolConstants.CFG_WSDLLIST);
    if (isWsdlList) {
        BufferedReader reader = null;
        try {
            ToolContext initialContextState = context.makeCopy();
            String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
            wsdlURL = URIParserUtil.getAbsoluteURI(wsdlURL);
            URL url = new URL(wsdlURL);
            InputStream is = (InputStream) url.getContent();
            reader = new BufferedReader(new InputStreamReader(is));
            String tempLine = null;
            while ((tempLine = reader.readLine()) != null) {
                ToolContext freshContext = initialContextState.makeCopy();
                freshContext.put(ToolConstants.CFG_WSDLURL, tempLine);
                setContext(freshContext);
                buildToolContext();
                processWsdl();
            }
            if (context.getErrorListener().getErrorCount() > 0) {
                context.getErrorListener().throwToolException();
            }
        } catch (IOException e) {
            throw new ToolException(e);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                throw new ToolException(e);
            }
        }
    } else {
        processWsdl();
        if (context.getErrorListener().getErrorCount() > 0) {
            context.getErrorListener().throwToolException();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ToolContext(org.apache.cxf.tools.common.ToolContext) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL)

Example 33 with ToolContext

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

the class WSDLToJavaContainerTest method testWsdlLocationDefaultSchemeIsFile.

@Test
public void testWsdlLocationDefaultSchemeIsFile() throws Exception {
    WSDLToJavaContainer container = new WSDLToJavaContainer("dummy", null);
    ToolContext context = new ToolContext();
    context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world.wsdl"));
    container.setContext(context);
    container.validate(context);
    String wsdlLocation = (String) context.get(ToolConstants.CFG_WSDLLOCATION);
    assertTrue("default scheme for wsdlLocation is file", wsdlLocation.startsWith("file:"));
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 34 with ToolContext

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

the class AbstractGeneratorTest method testOverwrite.

@Test
public void testOverwrite() throws Exception {
    gen = new DummyGenerator();
    util = new FileWriterUtil(output.toString(), null);
    context = new ToolContext();
    context.put(ToolConstants.CFG_OUTPUTDIR, output.toString());
    gen.setEnvironment(context);
    Writer writer = util.getWriter(packageName, className + ".java");
    writer.write("hello world");
    writer.flush();
    writer.close();
    assertNotNull(gen.parseOutputName(packageName, className));
}
Also used : FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) ToolContext(org.apache.cxf.tools.common.ToolContext) Writer(java.io.Writer) Test(org.junit.Test)

Example 35 with ToolContext

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

the class JavaToJS method execute.

public void execute(boolean exitOnFinish) {
    Processor processor = new JavaToJSProcessor();
    try {
        super.execute(exitOnFinish);
        if (!hasInfoOption()) {
            ToolContext env = new ToolContext();
            env.setParameters(getParametersMap(new HashSet<>()));
            if (env.get(ToolConstants.CFG_OUTPUTDIR) == null) {
                env.put(ToolConstants.CFG_OUTPUTDIR, ".");
            }
            if (isVerboseOn()) {
                env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
            }
            env.put(ToolConstants.CFG_CMD_ARG, getArgument());
            validate(env);
            processor.setEnvironment(env);
            processor.process();
        }
    } catch (ToolException ex) {
        if (ex.getCause() instanceof BadUsageException) {
            printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
        }
        err.println();
        err.println("JavaToJS Error : " + ex.getMessage());
        if (isVerboseOn()) {
            ex.printStackTrace(err);
        }
    } catch (Exception ex) {
        err.println();
        err.println("JavaToJS Error : " + ex.getMessage());
        if (isVerboseOn()) {
            ex.printStackTrace(err);
        }
    } finally {
        tearDown();
    }
}
Also used : JavaToJSProcessor(org.apache.cxf.tools.java2js.processor.JavaToJSProcessor) JavaToJSProcessor(org.apache.cxf.tools.java2js.processor.JavaToJSProcessor) Processor(org.apache.cxf.tools.common.Processor) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) BadUsageException(org.apache.cxf.tools.common.toolspec.parser.BadUsageException) HashSet(java.util.HashSet)

Aggregations

ToolContext (org.apache.cxf.tools.common.ToolContext)69 Test (org.junit.Test)45 URISyntaxException (java.net.URISyntaxException)35 File (java.io.File)23 ToolException (org.apache.cxf.tools.common.ToolException)13 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)7 WADLToJava (org.apache.cxf.tools.wadlto.WADLToJava)5 BufferedReader (java.io.BufferedReader)4 Method (java.lang.reflect.Method)4 URLClassLoader (java.net.URLClassLoader)4 QName (javax.xml.namespace.QName)4 Before (org.junit.Before)4 FileReader (java.io.FileReader)3 URI (java.net.URI)3 LinkedHashSet (java.util.LinkedHashSet)3 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)3 Artifact (org.apache.maven.artifact.Artifact)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 IOException (java.io.IOException)2 Writer (java.io.Writer)2