use of org.apache.cxf.tools.wsdlto.WSDLToJava in project cxf by apache.
the class ForkOnceWSDL2Java method main.
public static void main(String[] args) throws Exception {
File file = new File(args[0]);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line = reader.readLine();
while (line != null) {
int i = Integer.parseInt(line);
if (i == -1) {
reader.close();
return;
}
String[] wargs = new String[i];
for (int x = 0; x < i; x++) {
wargs[x] = reader.readLine();
}
new WSDLToJava(wargs).run(new ToolContext());
line = reader.readLine();
}
}
}
use of org.apache.cxf.tools.wsdlto.WSDLToJava in project jbossws-cxf by jbossws.
the class CXFConsumerImpl method consume.
@Override
public void consume(URL wsdl) {
List<String> args = new ArrayList<String>();
PrintStream stream = messageStream;
boolean verbose = false;
if (stream != null) {
verbose = true;
} else {
stream = NullPrintStream.getInstance();
}
// Always set the target
if ("2.1".equals(target)) {
args.add("-frontend");
args.add("jaxws21");
} else if (target != null && !target.equals("2.2")) {
stream.println(Messages.MESSAGES.unsupportedTargetUsingDefault(target, "2.2"));
}
if (bindingFiles != null) {
for (File file : bindingFiles) {
args.add("-b");
args.add(file.getAbsolutePath());
}
}
if (catalog != null) {
args.add("-catalog");
args.add(catalog.getAbsolutePath());
}
if (clientJar != null) {
args.add("-clientjar");
args.add(clientJar.getName());
}
if (!nocompile) {
args.add("-compile");
}
args.add("-exsh");
args.add(additionalHeaders ? "true" : "false");
if (targetPackage != null) {
args.add("-p");
args.add(targetPackage);
}
File sourceTempDir = null;
if (generateSource) {
if (sourceDir == null) {
sourceDir = outputDir;
}
if (!sourceDir.exists() && !sourceDir.mkdirs())
throw Messages.MESSAGES.couldNotMakeDirectory(sourceDir.getName());
args.add("-d");
args.add(sourceDir.getAbsolutePath());
} else {
sourceTempDir = new File(outputDir, "tmp" + Math.round(Math.random() * 10000000));
FileUtils.mkDir(sourceTempDir);
args.add("-d");
args.add(sourceTempDir.getAbsolutePath());
}
if (wsdlLocation != null) {
args.add("-wsdlLocation");
args.add(wsdlLocation);
}
if (verbose) {
args.add("-verbose");
}
if (encoding != null) {
args.add("-encoding");
args.add(encoding);
}
if (extension) {
stream.println("TODO! Cheek SOAP 1.2 extension");
}
if (!outputDir.exists() && !outputDir.mkdirs())
throw Messages.MESSAGES.couldNotMakeDirectory(outputDir.getName());
// Always add the output directory and the wsdl location
if (!nocompile) {
args.add("-classdir");
args.add(outputDir.getAbsolutePath());
}
// Always generate wrapped style for reference element:CXF-1079
args.add("-allowElementReferences");
// finally the WSDL file
args.add(wsdl.toString());
// See WsimportTool#compileGeneratedClasses()
if (!additionalCompilerClassPath.isEmpty()) {
StringBuffer javaCP = new StringBuffer();
for (String s : additionalCompilerClassPath) {
javaCP.append(s).append(File.pathSeparator);
}
System.setProperty("java.class.path", javaCP.toString());
}
WSDLToJava w2j = new WSDLToJava(args.toArray(new String[0]));
try {
ToolContext ctx = new ToolContext();
ctx.put(ToolConstants.COMPILER, new JBossModulesAwareCompiler());
w2j.run(ctx, stream);
} catch (Throwable t) {
if (messageStream != null) {
messageStream.println(MESSAGES.failedToInvoke(WSDLToJava.class.getName()));
t.printStackTrace(messageStream);
} else {
t.printStackTrace();
}
} finally {
// hack to copy the clientjar file to outputdir
if (sourceTempDir != null) {
for (File file : sourceTempDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (!name.endsWith(".java")) {
return true;
}
return false;
}
})) {
try (InputStream input = new FileInputStream(file);
OutputStream output = new FileOutputStream(new File(outputDir, file.getName()))) {
IOUtils.copy(input, output);
} catch (FileNotFoundException e) {
// NOOP
} catch (IOException e) {
throw new RuntimeException(e);
}
}
FileUtils.removeDir(sourceTempDir);
}
}
}
Aggregations