Search in sources :

Example 36 with ToolContext

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

the class JavaToWSContainer method execute.

public void execute(boolean exitOnFinish) throws ToolException {
    // ErrorVisitor errors = new ErrorVisitor();
    try {
        super.execute(exitOnFinish);
        // checkParams(errors);
        if (!hasInfoOption()) {
            ToolContext env = new ToolContext();
            env.setParameters(getParametersMap(new HashSet<>()));
            if (env.get(ToolConstants.CFG_OUTPUTDIR) == null) {
                env.put(ToolConstants.CFG_OUTPUTDIR, ".");
            }
            if (env.get(ToolConstants.CFG_SOURCEDIR) == null) {
                env.put(ToolConstants.CFG_SOURCEDIR, ".");
            }
            if (isVerboseOn()) {
                env.put(ToolConstants.CFG_VERBOSE, Boolean.TRUE);
            }
            String ft = (String) env.get(ToolConstants.CFG_FRONTEND);
            if (ft == null || ToolConstants.JAXWS_FRONTEND.equals(ft)) {
                ft = ToolConstants.JAXWS_FRONTEND;
            } else {
                ft = ToolConstants.SIMPLE_FRONTEND;
                // use aegis databinding for simple front end by default
                env.put(ToolConstants.CFG_DATABINDING, ToolConstants.AEGIS_DATABINDING);
            }
            env.put(ToolConstants.CFG_FRONTEND, ft);
            processWSDL(env, ft);
        }
    } catch (ToolException ex) {
        if (ex.getCause() instanceof BadUsageException) {
            printUsageException(TOOL_NAME, (BadUsageException) ex.getCause());
            if (isVerboseOn()) {
                ex.printStackTrace(err);
            }
        }
        throw ex;
    } catch (Exception ex) {
        // Try to find an exception with a message on the stack
        Throwable e = ex;
        while ((e.getMessage() == null || "".equals(e.getMessage())) && e.getCause() != null) {
            e = e.getCause();
        }
        err.println("Error: " + e.toString());
        err.println();
        if (isVerboseOn()) {
            ex.printStackTrace(err);
        } else {
            err.println("Use the verbose setting to show the stacktrace of this error");
        }
        throw new ToolException(ex.getMessage(), ex.getCause());
    } finally {
        tearDown();
    }
}
Also used : 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)

Example 37 with ToolContext

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

the class WSDLToJavaScriptTest method testCXF3891.

@Test
public void testCXF3891() throws Exception {
    JavaScriptContainer container = new JavaScriptContainer(null);
    ToolContext context = new ToolContext();
    context.put(ToolConstants.CFG_WSDLURL, getLocation("hello_world_ref.wsdl"));
    context.put(ToolConstants.CFG_OUTPUTDIR, output.toString());
    String[] prefixes = new String[1];
    prefixes[0] = "http://apache.org/hello_world_soap_http=murble";
    context.put(ToolConstants.CFG_JSPACKAGEPREFIX, prefixes);
    container.setContext(context);
    container.execute();
    // now we really want to check some results.
    Path path = FileSystems.getDefault().getPath(output.getPath(), "SOAPService.js");
    assertTrue(Files.isReadable(path));
    String javascript = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
    assertTrue(javascript.contains("xmlns:murble='http://apache.org/hello_world_soap_http'"));
    assertEquals("Number of '{' does not match number of '}' in generated JavaScript.", countChar(javascript, '{'), countChar(javascript, '}'));
}
Also used : Path(java.nio.file.Path) ToolContext(org.apache.cxf.tools.common.ToolContext) Test(org.junit.Test)

Example 38 with ToolContext

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

the class JAXRSContainerTest method testCodeGenWithImportedSchemaAndResourceSet.

@Test
public void testCodeGenWithImportedSchemaAndResourceSet() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/bookstoreResourceRef.xml"));
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
        verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 39 with ToolContext

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

the class JAXRSContainerTest method testCodeGenWithImportedSchemaWithParentRefs.

@Test
public void testCodeGenWithImportedSchemaWithParentRefs() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/sub/bookstoreImport.xml"));
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        verifyFiles("java", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
        verifyFiles("class", false, false, "superbooks", "org.apache.cxf.jaxrs.model.wadl", 9);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

Example 40 with ToolContext

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

the class JAXRSContainerTest method testCodeGenNoIds3.

@Test
public void testCodeGenNoIds3() {
    try {
        JAXRSContainer container = new JAXRSContainer(null);
        ToolContext context = new ToolContext();
        context.put(WadlToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(WadlToolConstants.CFG_WADLURL, getLocation("/wadl/resourcesNoId.xml"));
        context.put(WadlToolConstants.CFG_COMPILE, "true");
        context.put(WadlToolConstants.CFG_INHERIT_PARAMS, "true");
        container.setContext(context);
        container.execute();
        assertNotNull(output.list());
        List<File> javaFiles = FileUtils.getFilesRecurse(output, ".+\\." + "java" + "$");
        assertEquals(1, javaFiles.size());
        assertTrue(checkContains(javaFiles, "application.TestRsResource.java"));
        List<File> classFiles = FileUtils.getFilesRecurse(output, ".+\\." + "class" + "$");
        assertEquals(1, classFiles.size());
        assertTrue(checkContains(classFiles, "application.TestRsResource.class"));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File) URISyntaxException(java.net.URISyntaxException) Test(org.junit.Test)

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