cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1333209 - in /cxf/trunk: api/src/main/java/org/apache/cxf/common/util/ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/ rt/databinding...
Date Wed, 02 May 2012 21:09:02 GMT
Author: dkulp
Date: Wed May  2 21:09:01 2012
New Revision: 1333209

URL: http://svn.apache.org/viewvc?rev=1333209&view=rev
Log:
[CXF-2937, CXF-2450] Add an -encoding flag to wsdl2java and wire it into
JAXB and XMLBeans.
Update codegen-mojo to pass the endoding maven is using in.  Also update
the fork mode to properly display output while it's occuring.
If JAXB doesn't support encoding (2.2.5 or newer needed), warn and
default to current behavior.

Added:
    cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
  (with props)
Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
    cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
    cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java
    cxf/trunk/testutils/pom.xml
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
    cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java
    cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties
    cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java
    cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
    cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/Compiler.java Wed May  2 21:09:01
2012
@@ -38,6 +38,7 @@ public class Compiler {
     private String target;
     private String outputDir;
     private String classPath;
+    private String encoding;
     private boolean forceFork = Boolean.getBoolean(Compiler.class.getName() + "-fork");
     
     public Compiler() {
@@ -70,6 +71,10 @@ public class Compiler {
         if (verbose) {
             list.add("-verbose");
         }
+        if (!StringUtils.isEmpty(encoding)) {
+            list.add("-encoding");
+            list.add(encoding);
+        }
         if (!StringUtils.isEmpty(target)) {
             list.add("-target");
             list.add(target);
@@ -280,5 +285,9 @@ public class Compiler {
         return strBuffer.toString().length() > 4096 ? true : false;
     }
 
+    public void setEncoding(String string) {
+        encoding = string;
+    }
+
     
 }

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java
Wed May  2 21:09:01 2012
@@ -55,10 +55,10 @@ import org.apache.maven.settings.Proxy;
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.jar.Manifest;
 import org.codehaus.plexus.archiver.jar.Manifest.Attribute;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
 
 public abstract class AbstractCodegenMoho extends AbstractMojo {
 
@@ -352,6 +352,17 @@ public abstract class AbstractCodegenMoh
     
     protected abstract String getMarkerSuffix();
     
+    protected List<String> generateCommandLine(GenericWsdlOption wsdlOption)
+        throws MojoExecutionException {
+        
+        File outputDirFile = wsdlOption.getOutputDir();
+        outputDirFile.mkdirs();
+        URI basedir = project.getBasedir().toURI();
+        URI wsdlURI = getWsdlURI(wsdlOption, basedir);
+        return wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI,
+                                              getLog().isDebugEnabled());
+    }
+    
     protected void forkOnce(Set<URI> classPath, List<GenericWsdlOption> effectiveWsdlOptions)
         throws MojoExecutionException {
         List<GenericWsdlOption> toDo = new LinkedList<GenericWsdlOption>();
@@ -370,8 +381,7 @@ public abstract class AbstractCodegenMoh
 
             toDo.add(wsdlOption);
 
-            wargs.add(wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI, getLog()
-                .isDebugEnabled()));
+            wargs.add(generateCommandLine(wsdlOption));
         }
         if (wargs.isEmpty()) {
             return;
@@ -485,9 +495,19 @@ public abstract class AbstractCodegenMoh
         }
         cmd.addArguments(args);
 
-        CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
-        CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
-
+        StreamConsumer out = new StreamConsumer() {
+            public void consumeLine(String line) {
+                getLog().info(line);
+            }
+        };
+        final StringBuilder b = new StringBuilder();
+        StreamConsumer err = new StreamConsumer() {
+            public void consumeLine(String line) {
+                b.append(line);
+                b.append("\n");
+                getLog().warn(line);
+            }
+        };
         int exitCode;
         try {
             exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
@@ -496,20 +516,12 @@ public abstract class AbstractCodegenMoh
             throw new MojoExecutionException(e.getMessage(), e);
         }
         
-        String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();
 
         String cmdLine = CommandLineUtils.toString(cmd.getCommandline());
 
         if (exitCode != 0) {
-            if (StringUtils.isNotEmpty(output)) {
-                getLog().info(output);
-            }
-
             StringBuffer msg = new StringBuffer("\nExit code: ");
             msg.append(exitCode);
-            if (StringUtils.isNotEmpty(err.getOutput())) {
-                msg.append(" - ").append(err.getOutput());
-            }
             msg.append('\n');
             msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
 
@@ -517,9 +529,9 @@ public abstract class AbstractCodegenMoh
         }
 
         file.delete();
-        if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("WSDL2Java
Error")) {
+        if (b.toString().contains("WSDL2Java Error")) {
             StringBuffer msg = new StringBuffer();
-            msg.append(err.getOutput());
+            msg.append(b.toString());
             msg.append('\n');
             msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
             throw new MojoExecutionException(msg.toString());

Modified: cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
(original)
+++ cxf/trunk/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java
Wed May  2 21:09:01 2012
@@ -75,6 +75,13 @@ public class WSDL2JavaMojo extends Abstr
     Option defaultOptions = new Option();
     
     /**
+     * Encoding to use for generated sources
+     * 
+     * @parameter default-value="${project.build.sourceEncoding}"
+     */
+    String encoding;
+    
+    /**
      * Merge WsdlOptions that point to the same file by adding the extraargs to the first
option and deleting
      * the second from the options list
      * 
@@ -163,8 +170,14 @@ public class WSDL2JavaMojo extends Abstr
         }
         return doWork;
     }
-
-
+    
+    protected List<String> generateCommandLine(GenericWsdlOption wsdlOption)
+        throws MojoExecutionException {
+        List<String> ret = super.generateCommandLine(wsdlOption);
+        ret.add(0, "-encoding");
+        ret.add(1, encoding);
+        return ret;
+    }
 
     @Override
     protected Bus generate(GenericWsdlOption genericWsdlOption, 
@@ -182,8 +195,10 @@ public class WSDL2JavaMojo extends Abstr
         }
         doneFile.delete();
 
-        List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir,
wsdlURI, getLog()
-                                                           .isDebugEnabled());
+        List<String> list = wsdlOption.generateCommandLine(outputDirFile, basedir,
wsdlURI, 
+                                                           getLog().isDebugEnabled());
+        list.add(0, "-encoding");
+        list.add(1, encoding);
         String[] args = list.toArray(new String[list.size()]);
         getLog().debug("Calling wsdl2java with args: " + Arrays.toString(args));
         

Modified: cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java
(original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java
Wed May  2 21:09:01 2012
@@ -236,6 +236,7 @@ public class XMLBeansToolingDataBinding 
             }
             */
             options.setGenerateJavaVersion("1.5");
+            options.setCharacterEncoding((String)context.get(ToolConstants.CFG_ENCODING));
 
             // save .xsb files
             typeSystem.save(filer);

Modified: cxf/trunk/testutils/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/pom.xml?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/testutils/pom.xml (original)
+++ cxf/trunk/testutils/pom.xml Wed May  2 21:09:01 2012
@@ -165,9 +165,9 @@
                                 <include>rt-javascript/*.wsdl</include>
                             </includes>
                             <defaultOptions>
-                                <extraargs>
+                                <!--extraargs>
                                     <extraarg>-verbose</extraarg>
-                                </extraargs>
+                                </extraargs-->
                                 <markGenerated>true</markGenerated>
                                 <faultSerialVersionUID>1</faultSerialVersionUID>
                             </defaultOptions>

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java (original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java Wed May
 2 21:09:01 2012
@@ -46,6 +46,8 @@ public class ClassUtils {
             compiler.setVerbose(true);
         }
         
+        compiler.setEncoding((String)context.get(ToolConstants.CFG_ENCODING));
+        
         if ("1.5".equals(System.getProperty("java.specification.version"))) {
             compiler.setTarget("1.5");
         }

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java (original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java Wed
May  2 21:09:01 2012
@@ -40,6 +40,7 @@ public final class ToolConstants {
     public static final String CFG_OUTPUTFILE = "outputfile";
     public static final String CFG_WSDLURL = "wsdlurl";
     public static final String CFG_WSDLLOCATION = "wsdlLocation";
+    public static final String CFG_ENCODING = "encoding";
     public static final String CFG_WSDLLIST = "wsdlList";
     public static final String CFG_NAMESPACE = "namespace";
     public static final String CFG_VERBOSE = "verbose";

Modified: cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java (original)
+++ cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java Wed
May  2 21:09:01 2012
@@ -53,7 +53,7 @@ public class FileWriterUtil {
     }
 
     public static Writer getWriter(File fn) throws IOException {
-        return new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(fn)),
"UTF-8");
+        return getWriter(fn, "UTF-8");
     }
 
     public static Writer getWriter(File fn, String encoding) throws IOException {
@@ -66,6 +66,9 @@ public class FileWriterUtil {
     public Writer getWriter(String packageName, String fileName) throws IOException {
         return getWriter(getFileToWrite(packageName, fileName));
     }
+    public Writer getWriter(String packageName, String fileName, String encoding) throws
IOException {
+        return getWriter(getFileToWrite(packageName, fileName), encoding);
+    }
 
     public boolean isCollision(String packageName, String fileName) throws ToolException
{
         File dir = buildDir(packageName);

Modified: cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
(original)
+++ cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java
Wed May  2 21:09:01 2012
@@ -82,7 +82,12 @@ public abstract class AbstractGenerator 
 
         fw = new FileWriterUtil(getOutputDir());
         try {
-            writer = fw.getWriter(packageName, filename + ext);
+            if (".java".equals(ext)) {
+                writer = fw.getWriter(packageName, filename + ext, 
+                                      (String)getEnvironment().get(ToolConstants.CFG_ENCODING));
+            } else {
+                writer = fw.getWriter(packageName, filename + ext);
+            }
         } catch (IOException ioe) {
             Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, packageName + "." + filename
+ ext);
             throw new ToolException(msg, ioe);

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
Wed May  2 21:09:01 2012
@@ -67,12 +67,14 @@ import org.xml.sax.SAXException;
 import org.xml.sax.helpers.XMLFilterImpl;
 
 import com.sun.codemodel.ClassType;
+import com.sun.codemodel.CodeWriter;
 import com.sun.codemodel.JClass;
 import com.sun.codemodel.JCodeModel;
 import com.sun.codemodel.JDefinedClass;
 import com.sun.codemodel.JMethod;
 import com.sun.codemodel.JType;
 import com.sun.tools.xjc.BadCommandLineException;
+import com.sun.tools.xjc.Driver;
 import com.sun.tools.xjc.ErrorReceiver;
 import com.sun.tools.xjc.Options;
 import com.sun.tools.xjc.Plugin;
@@ -277,9 +279,26 @@ public class JAXBDataBinding implements 
         DEFAULT_TYPE_MAP.addAll(JLDEFAULT_TYPE_MAP.keySet());
     }
 
+    private void checkEncoding(ToolContext c) {
+        String encoding = (String)c.get(ToolConstants.CFG_ENCODING);
+        if (encoding != null) {
+            try {
+                CodeWriter.class.getDeclaredField("encoding");
+            } catch (Throwable t) {
+                c.remove(ToolConstants.CFG_ENCODING);
+                String fenc = System.getProperty("file.encoding");
+                if (!encoding.equals(fenc)) {
+                    LOG.log(Level.WARNING, "JAXB_NO_ENCODING_SUPPORT", 
+                            new String[] {Driver.getBuildID(), fenc});
+                }
+            }
+        }
+        
+    }
+    
     public void initialize(ToolContext c) throws ToolException {
         this.context = c;
-
+        checkEncoding(c);
         SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
         Bus bus = context.get(Bus.class);
         OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
@@ -713,7 +732,9 @@ public class JAXBDataBinding implements 
         try {
             String dir = (String)context.get(ToolConstants.CFG_OUTPUTDIR);
 
-            TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir), context.getExcludePkgList());
+            TypesCodeWriter fileCodeWriter = new TypesCodeWriter(new File(dir),
+                                                                 context.getExcludePkgList(),
+                                                                 (String)context.get(ToolConstants.CFG_ENCODING));
 
             if (rawJaxbModelGenCode instanceof S2JJAXBModel) {
                 S2JJAXBModel schem2JavaJaxbModel = rawJaxbModelGenCode;

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties
Wed May  2 21:09:01 2012
@@ -21,6 +21,6 @@
 GENERATE_TYPES_ERROR = Error generating types.
 FAIL_TO_GENERATE_TYPES = Failed to generate types.
 FAIL_TO_CREATE_JAXBBINIDNG_FILE = Fail to create a JAXB binding file to customize the namepace
to package mapping
-
+JAXB_NO_ENCODING_SUPPORT = Version {0} of JAXB XJC does not support setting an encoding.
 Using default file encoding of {1}.
 
 

Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java
(original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java
Wed May  2 21:09:01 2012
@@ -23,12 +23,15 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 
 import com.sun.codemodel.CodeWriter;
 import com.sun.codemodel.JPackage;
 
+import org.apache.cxf.common.util.ReflectionUtil;
+
 public class TypesCodeWriter extends CodeWriter {
 
     /** The target directory to put source code. */
@@ -39,9 +42,23 @@ public class TypesCodeWriter extends Cod
     
     private List<File> generatedFiles = new ArrayList<File>();
 
-    public TypesCodeWriter(File ftarget, List<String> excludePkgs) throws IOException
{
+    public TypesCodeWriter(File ftarget, List<String> excludePkgs, String e)
+        throws IOException {
         target = ftarget;
         excludePkgList = excludePkgs;
+        setEncoding(e);
+    }
+    
+    private void setEncoding(String s) {
+        if (s != null) {
+            try {
+                //requires XJC 2.2.5 or newer
+                Field f = CodeWriter.class.getDeclaredField("encoding");
+                ReflectionUtil.setAccessible(f).set(this, s);
+            } catch (Throwable t) {
+                //ignore - should be caught in JAXBDataBinding.checkEncoding already
+            }
+        }
     }
 
     public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {

Modified: cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
(original)
+++ cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
Wed May  2 21:09:01 2012
@@ -353,6 +353,15 @@ Examples:
                     <annotation>fault-serialVersionUID</annotation>
                 </associatedArgument>
             </option>
+            <option id="encoding" maxOccurs="1">
+                <annotation>
+                    Specifies the charset encoding to use when generating java sources 
+                </annotation>
+                <switch>encoding</switch>
+                <associatedArgument placement="afterSpace">
+                    <annotation>encoding</annotation>
+                </associatedArgument>
+            </option>
 
             <option id="exceptionSuper" maxOccurs="1">
                 <annotation>
@@ -413,7 +422,6 @@ Examples:
 	            </annotation>
 	            <switch>wsdlList</switch>
 	        </option>
-
         </optionGroup>
         <argument id="wsdlurl" minOccurs="1" maxOccurs="1">
             <annotation>

Modified: cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java?rev=1333209&r1=1333208&r2=1333209&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java
(original)
+++ cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java
Wed May  2 21:09:01 2012
@@ -23,9 +23,12 @@ import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.List;
 
+import com.sun.codemodel.CodeWriter;
+
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolException;
@@ -316,5 +319,40 @@ public class CodeGenOptionTest extends A
                                                                                "SOAPService.java")));
         assertTrue(str, str.contains("getResource"));
     }
+    @Test
+    public void testEncoding() throws Exception {
+        try {
+            CodeWriter.class.getDeclaredField("encoding");
+        } catch (Throwable t) {
+            //version of jaxb that doesn't support this.  We'll just not run the test.
+            return;
+        }
+        env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_encoding.wsdl"));
+        env.put(ToolConstants.CFG_WSDLLOCATION, "/wsdl2java_wsdl/hello_world_encoding.wsdl");
+        env.put(ToolConstants.CFG_ENCODING, "Cp1251");
+        processor.setContext(env);
+        processor.execute();
+
+        File dir = new File(output, "org");
+        assertTrue("org directory is not found", dir.exists());
+        dir = new File(dir, "apache");
+        assertTrue("apache directory is not found", dir.exists());
+        dir = new File(dir, "cxf");
+        assertTrue("cxf directory is not found", dir.exists());
+        dir = new File(dir, "w2j");
+        assertTrue("w2j directory is not found", dir.exists());
+        dir = new File(dir, "hello_world_soap_http");
+        assertTrue("hello_world_soap_http directory is not found", dir.exists());
+
+        String str = IOUtils.readStringFromStream(new FileInputStream(new File(dir,
+                                                                               "SOAPService.java")));
+        assertTrue(str, str.contains("getResource"));
+        
+        Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.Greeter");
+        for (Method m : clz.getMethods()) {
+            String s = m.getName();
+            assertEquals(1039, s.charAt(2));
+        }
+    }
 
 }

Added: cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl?rev=1333209&view=auto
==============================================================================
--- cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
(added)
+++ cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
Wed May  2 21:09:01 2012
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:tns="http://cxf.apache.org/w2j/hello_world_soap_http"
+    xmlns:x1="http://cxf.apache.org/w2j/hello_world_soap_http/types"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="http://cxf.apache.org/w2j/hello_world_soap_http" name="HelloWorld">
+    <wsdl:types>
+        <schema targetNamespace="http://cxf.apache.org/w2j/hello_world_soap_http/types"
xmlns="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://cxf.apache.org/w2j/hello_world_soap_http/types"
elementFormDefault="qualified">
+            <element name="saЏHi">
+                <complexType>
+                	<sequence>
+                	    <element name="cдмРДпЎ" type="string"/>
+                	</sequence>
+                </complexType>
+            </element>
+            <element name="saЏHiResponse">
+                <complexType>
+                    <sequence>
+                        <element name="responseType" type="string"/>
+                    </sequence>
+                </complexType>
+            </element>
+        </schema>
+    </wsdl:types>
+    <wsdl:message name="saЏHiRequest">
+        <wsdl:part name="in" element="x1:saЏHi"/>
+    </wsdl:message>
+    <wsdl:message name="saЏHiResponse">
+        <wsdl:part name="out" element="x1:saЏHiResponse"/>
+    </wsdl:message>
+
+    <wsdl:portType name="Greeter">
+        <wsdl:documentation>porttype documntation</wsdl:documentation>
+        <wsdl:operation name="saЏHi">
+            <wsdl:documentation>porttype op docs in сўяїГѓїС</wsdl:documentation>
+            <wsdl:input name="saЏHiRequest" message="tns:saЏHiRequest"/>
+            <wsdl:output name="saЏHiResponse" message="tns:saЏHiResponse"/>
+        </wsdl:operation>      
+    </wsdl:portType>
+    <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
+        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="saЏHi">
+            <soap:operation style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="SOAPService">
+        <wsdl:port name="SoapPort" binding="tns:Greeter_SOAPBinding">
+            <soap:address location="http://localhost:9000/SoapContext/SoapPort"/>
+            <wswa:UsingAddressing xmlns:wswa="http://www.w3.org/2005/02/addressing/wsdl"/>
+        </wsdl:port>
+    </wsdl:service>
+</wsdl:definitions>
+

Propchange: cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message