Search in sources :

Example 16 with WSDLToJava

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();
        }
    }
}
Also used : WSDLToJava(org.apache.cxf.tools.wsdlto.WSDLToJava) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ToolContext(org.apache.cxf.tools.common.ToolContext) File(java.io.File)

Example 17 with WSDLToJava

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);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) NullPrintStream(org.jboss.ws.common.utils.NullPrintStream) WSDLToJava(org.apache.cxf.tools.wsdlto.WSDLToJava) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ToolContext(org.apache.cxf.tools.common.ToolContext) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FilenameFilter(java.io.FilenameFilter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

ToolContext (org.apache.cxf.tools.common.ToolContext)17 WSDLToJava (org.apache.cxf.tools.wsdlto.WSDLToJava)17 File (java.io.File)14 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)14 Test (org.junit.Test)14 ToolException (org.apache.cxf.tools.common.ToolException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 WSDLRuntimeException (org.apache.cxf.wsdl11.WSDLRuntimeException)2 BufferedReader (java.io.BufferedReader)1 DataOutputStream (java.io.DataOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 FilenameFilter (java.io.FilenameFilter)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 URI (java.net.URI)1