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();
}
}
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, '}'));
}
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();
}
}
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();
}
}
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();
}
}
Aggregations