Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D366CC60C for ; Thu, 3 May 2012 16:43:41 +0000 (UTC) Received: (qmail 90613 invoked by uid 500); 3 May 2012 16:43:41 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 90555 invoked by uid 500); 3 May 2012 16:43:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 90546 invoked by uid 99); 3 May 2012 16:43:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:43:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 May 2012 16:43:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5F6EB2388860; Thu, 3 May 2012 16:43:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1333540 - in /cxf/branches/2.5.x-fixes: api/src/main/java/org/apache/cxf/tools/common/ common/common/src/main/java/org/apache/cxf/common/util/ maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/ maven-plugins/codegen-pl... Date: Thu, 03 May 2012 16:43:12 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120503164313.5F6EB2388860@eris.apache.org> Author: dkulp Date: Thu May 3 16:43:11 2012 New Revision: 1333540 URL: http://svn.apache.org/viewvc?rev=1333540&view=rev Log: Merged revisions 1333209 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1333209 | dkulp | 2012-05-02 17:09:01 -0400 (Wed, 02 May 2012) | 7 lines [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/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl (with props) Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Compiler.java cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java cxf/branches/2.5.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java cxf/branches/2.5.x-fixes/testutils/pom.xml cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java cxf/branches/2.5.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java cxf/branches/2.5.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java (original) +++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/tools/common/ToolConstants.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Compiler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Compiler.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Compiler.java (original) +++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/Compiler.java Thu May 3 16:43:11 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); @@ -282,5 +287,9 @@ public class Compiler { return strBuffer.toString().length() > 4096 ? true : false; } + public void setEncoding(String string) { + encoding = string; + } + } Modified: cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java (original) +++ cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/AbstractCodegenMoho.java Thu May 3 16:43:11 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 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 classPath, List effectiveWsdlOptions) throws MojoExecutionException { List toDo = new LinkedList(); @@ -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'); @@ -519,9 +531,9 @@ public abstract class AbstractCodegenMoh if (file != null) { 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/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java (original) +++ cxf/branches/2.5.x-fixes/maven-plugins/codegen-plugin/src/main/java/org/apache/cxf/maven_plugin/wsdl2java/WSDL2JavaMojo.java Thu May 3 16:43:11 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 generateCommandLine(GenericWsdlOption wsdlOption) + throws MojoExecutionException { + List ret = super.generateCommandLine(wsdlOption); + ret.add(0, "-encoding"); + ret.add(1, encoding); + return ret; + } @Override protected Bus generate(GenericWsdlOption genericWsdlOption, @@ -182,9 +195,11 @@ public class WSDL2JavaMojo extends Abstr } doneFile.delete(); - List list = wsdlOption.generateCommandLine(outputDirFile, basedir, wsdlURI, getLog() - .isDebugEnabled()); - String[] args = (String[])list.toArray(new String[list.size()]); + List 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)); if (!"false".equals(fork)) { Modified: cxf/branches/2.5.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java (original) +++ cxf/branches/2.5.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/tools/XMLBeansToolingDataBinding.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/testutils/pom.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/testutils/pom.xml?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/testutils/pom.xml (original) +++ cxf/branches/2.5.x-fixes/testutils/pom.xml Thu May 3 16:43:11 2012 @@ -170,9 +170,11 @@ rt-javascript/*.wsdl - + + true + 1 Modified: cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java (original) +++ cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ClassUtils.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java (original) +++ cxf/branches/2.5.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/FileWriterUtil.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/AbstractGenerator.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Thu May 3 16:43:11 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 = (S2JJAXBModel)rawJaxbModelGenCode; Modified: cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/Messages.properties Thu May 3 16:43:11 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/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/TypesCodeWriter.java Thu May 3 16:43:11 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 generatedFiles = new ArrayList(); - public TypesCodeWriter(File ftarget, List excludePkgs) throws IOException { + public TypesCodeWriter(File ftarget, List 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/branches/2.5.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml Thu May 3 16:43:11 2012 @@ -353,6 +353,15 @@ Examples: fault-serialVersionUID + - Modified: cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java?rev=1333540&r1=1333539&r2=1333540&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java (original) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenOptionTest.java Thu May 3 16:43:11 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/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl?rev=1333540&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl (added) +++ cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl Thu May 3 16:43:11 2012 @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + porttype documntation + + porttype op docs in сўяїГѓїС + + + + + + + + + + + + + + + + + + + + + + + + Propchange: cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: cxf/branches/2.5.x-fixes/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/hello_world_encoding.wsdl ------------------------------------------------------------------------------ svn:mime-type = text/xml