Author: ema
Date: Tue Mar 5 02:55:24 2013
New Revision: 1452641
URL: http://svn.apache.org/r1452641
Log:
Merged revisions 1452640 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1452640 | ema | 2013-03-05 10:27:41 +0800 (Tue, 05 Mar 2013) | 1 line
[CXF-4871]:add -clientjar to wsdl2java tool
........
Modified:
cxf/branches/2.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/helpers/FileUtils.java
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ClassCollector.java
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/Messages.properties
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
cxf/branches/2.7.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
svn:mergeinfo = /cxf/trunk:1452640
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/helpers/FileUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/helpers/FileUtils.java?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/helpers/FileUtils.java
(original)
+++
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/helpers/FileUtils.java
Tue Mar 5 02:55:24 2013
@@ -58,38 +58,43 @@ public final class FileUtils {
}
}
if (defaultTempDir == null) {
- int x = (int)(Math.random() * 1000000);
- s = SystemPropertyAction.getProperty("java.io.tmpdir");
- File checkExists = new File(s);
- if (!checkExists.exists() || !checkExists.isDirectory()) {
- throw new RuntimeException("The directory "
- + checkExists.getAbsolutePath()
- + " does not exist, please set
java.io.tempdir"
- + " to an existing directory");
- }
- if (!checkExists.canWrite()) {
- throw new RuntimeException("The directory "
- + checkExists.getAbsolutePath()
- + " is now writable, please set
java.io.tempdir"
- + " to an writable directory");
- }
- File f = new File(s, "cxf-tmp-" + x);
- while (!f.mkdir()) {
- x = (int)(Math.random() * 1000000);
- f = new File(s, "cxf-tmp-" + x);
- }
- defaultTempDir = f;
- final File f2 = f;
- Thread hook = new Thread() {
- @Override
- public void run() {
- removeDir(f2, true);
- }
- };
- Runtime.getRuntime().addShutdownHook(hook);
+ defaultTempDir = createTmpDir();
}
return defaultTempDir;
}
+
+ public static File createTmpDir() {
+ int x = (int)(Math.random() * 1000000);
+ String s = SystemPropertyAction.getProperty("java.io.tmpdir");
+ File checkExists = new File(s);
+ if (!checkExists.exists() || !checkExists.isDirectory()) {
+ throw new RuntimeException("The directory "
+ + checkExists.getAbsolutePath()
+ + " does not exist, please set
java.io.tempdir"
+ + " to an existing directory");
+ }
+ if (!checkExists.canWrite()) {
+ throw new RuntimeException("The directory "
+ + checkExists.getAbsolutePath()
+ + " is now writable, please set
java.io.tempdir"
+ + " to an writable directory");
+ }
+ File f = new File(s, "cxf-tmp-" + x);
+ while (!f.mkdir()) {
+ x = (int)(Math.random() * 1000000);
+ f = new File(s, "cxf-tmp-" + x);
+ }
+ File newTmpDir = f;
+ final File f2 = f;
+ Thread hook = new Thread() {
+ @Override
+ public void run() {
+ removeDir(f2, true);
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(hook);
+ return newTmpDir;
+ }
public static void mkDir(File dir) {
if (dir == null) {
Modified:
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
(original)
+++
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/common/ToolConstants.java
Tue Mar 5 02:55:24 2013
@@ -50,6 +50,7 @@ public final class ToolConstants {
public static final String CFG_WEBSERVICE = "webservice";
public static final String CFG_SERVER = "server";
public static final String CFG_CLIENT = "client";
+ public static final String CFG_CLIENT_JAR = "clientjar";
public static final String CFG_ALL = "all";
public static final String CFG_IMPL = "impl";
public static final String CFG_PACKAGENAME = "packagename";
Modified:
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ClassCollector.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ClassCollector.java?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ClassCollector.java
(original)
+++
cxf/branches/2.7.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/ClassCollector.java
Tue Mar 5 02:55:24 2013
@@ -29,12 +29,12 @@ import java.util.TreeSet;
public class ClassCollector {
- private final Map<String, String> seiClassNames
+ private Map<String, String> seiClassNames
= new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
- private final Map<String, String> typesClassNames = new HashMap<String,
String>();
- private final Map<String, String> exceptionClassNames = new
HashMap<String, String>();
- private final Map<String, String> serviceClassNames = new HashMap<String,
String>();
- private final Map<String, String> implClassNames = new HashMap<String,
String>();
+ private Map<String, String> typesClassNames = new HashMap<String,
String>();
+ private Map<String, String> exceptionClassNames = new HashMap<String,
String>();
+ private Map<String, String> serviceClassNames = new HashMap<String,
String>();
+ private Map<String, String> implClassNames = new HashMap<String, String>();
private final Map<String, String> clientClassNames = new HashMap<String,
String>();
private final Map<String, String> serverClassNames = new HashMap<String,
String>();
private final Map<String, String> reservedClassNames = new HashMap<String,
String>();
@@ -154,5 +154,36 @@ public class ClassCollector {
generatedFileList.addAll(clientClassNames.values());
return generatedFileList;
}
-
+
+ public Map<String, String> getSeiClassNames() {
+ return seiClassNames;
+ }
+ public void setSeiClassNames(Map<String, String> seiClassNames) {
+ this.seiClassNames = seiClassNames;
+ }
+ public Map<String, String> getTypesClassNames() {
+ return typesClassNames;
+ }
+ public void setTypesClassNames(Map<String, String> typesClassNames) {
+ this.typesClassNames = typesClassNames;
+ }
+ public Map<String, String> getExceptionClassNames() {
+ return exceptionClassNames;
+ }
+ public void setExceptionClassNames(Map<String, String>
exceptionClassNames) {
+ this.exceptionClassNames = exceptionClassNames;
+ }
+ public Map<String, String> getServiceClassNames() {
+ return serviceClassNames;
+ }
+ public void setServiceClassNames(Map<String, String> serviceClassNames) {
+ this.serviceClassNames = serviceClassNames;
+ }
+ public Map<String, String> getImplClassNames() {
+ return implClassNames;
+ }
+ public void setImplClassNames(Map<String, String> implClassNames) {
+ this.implClassNames = implClassNames;
+ }
+
}
Modified:
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/Messages.properties
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/Messages.properties?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/Messages.properties
(original)
+++
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/Messages.properties
Tue Mar 5 02:55:24 2013
@@ -27,3 +27,8 @@ FOUND_NO_DATABINDING = Can not find data
FOUND_NO_FRONTEND = Can not find frontend
NO_WSDL_URL = WSDL URL can not be null
+
+FAILED_TO_CREAT_CLIENTJAR = Failed to create client jar
+FAILED_ADD_JARENTRY = Failed to add jarentry into client jar file
+FAILED_TO_GEN_LOCAL_WSDL = Failed to generate local wsdl for clientjar
+
Modified:
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
(original)
+++
cxf/branches/2.7.x-fixes/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
Tue Mar 5 02:55:24 2013
@@ -19,14 +19,22 @@
package org.apache.cxf.tools.wsdlto;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Writer;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -34,12 +42,19 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
import javax.xml.namespace.QName;
+import org.w3c.dom.Element;
+
import org.apache.cxf.Bus;
import org.apache.cxf.common.WSDLConstants;
import org.apache.cxf.common.i18n.Message;
@@ -49,6 +64,10 @@ import org.apache.cxf.common.util.String
import org.apache.cxf.common.util.URIParserUtil;
import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.FileUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.service.model.InterfaceInfo;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.tools.common.AbstractCXFToolContainer;
@@ -64,12 +83,15 @@ import org.apache.cxf.tools.common.tools
import org.apache.cxf.tools.common.toolspec.parser.CommandDocument;
import org.apache.cxf.tools.common.toolspec.parser.ErrorVisitor;
import org.apache.cxf.tools.util.ClassCollector;
+import org.apache.cxf.tools.util.FileWriterUtil;
+import org.apache.cxf.tools.util.OutputStreamCreator;
import org.apache.cxf.tools.validator.ServiceValidator;
import org.apache.cxf.tools.wsdlto.core.AbstractWSDLBuilder;
import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
import org.apache.cxf.tools.wsdlto.core.FrontEndProfile;
import org.apache.cxf.wsdl.WSDLManager;
import org.apache.cxf.wsdl11.WSDLServiceBuilder;
+import org.apache.ws.commons.schema.XmlSchema;
public class WSDLToJavaContainer extends AbstractCXFToolContainer {
@@ -266,6 +288,11 @@ public class WSDLToJavaContainer extends
if (context.getErrorListener().getErrorCount() > 0) {
return;
}
+
+ if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
+ enforceWSDLLocation(context);
+ }
+
if (!isSuppressCodeGen()) {
// Generate artifacts
for (FrontEndGenerator generator : frontend.getGenerators()) {
@@ -286,6 +313,91 @@ public class WSDLToJavaContainer extends
throw new ToolException(e);
}
}
+ if (context.optionSet(ToolConstants.CFG_CLIENT_JAR)) {
+ processClientJar(context);
+ }
+ }
+
+ private void enforceWSDLLocation(ToolContext context) {
+ String wsdlURL = (String)context.get(ToolConstants.CFG_WSDLURL);
+ @SuppressWarnings("unchecked")
+ List<ServiceInfo> serviceList =
(List<ServiceInfo>)context.get(ToolConstants.SERVICE_LIST);
+ int slashIndex = wsdlURL.lastIndexOf("/");
+ int dotIndex = wsdlURL.indexOf(".", slashIndex);
+ String wsdlLocation = null;
+ if (slashIndex > -1 && dotIndex > -1) {
+ wsdlLocation = wsdlURL.substring(slashIndex + 1, dotIndex) +
".wsdl";
+ }
+ if (wsdlLocation == null) {
+ wsdlLocation = serviceList.get(0).getName().getLocalPart() +
".wsdl";
+ }
+ context.put(ToolConstants.CFG_WSDLLOCATION, wsdlLocation);
+ }
+
+ private void processClientJar(ToolContext context) {
+ ClassCollector oldCollector = context.get(ClassCollector.class);
+ ClassCollector newCollector = new ClassCollector();
+ String oldClassDir = (String)context.get(ToolConstants.CFG_CLASSDIR);
+ File tmpDir = FileUtils.createTmpDir();
+ context.put(ToolConstants.CFG_CLASSDIR, tmpDir.getAbsolutePath());
+
+ newCollector.setTypesClassNames(oldCollector.getTypesClassNames());
+ newCollector.setSeiClassNames(oldCollector.getSeiClassNames());
+
newCollector.setExceptionClassNames(oldCollector.getExceptionClassNames());
+ newCollector.setServiceClassNames(oldCollector.getServiceClassNames());
+ context.put(ClassCollector.class, newCollector);
+ new ClassUtils().compile(context);
+
+ generateLocalWSDL(context);
+
+
+ File clientJarFile = new
File((String)context.get(ToolConstants.CFG_OUTPUTDIR),
+
(String)context.get(ToolConstants.CFG_CLIENT_JAR));
+ JarOutputStream jarout = null;
+ try {
+ jarout = new JarOutputStream(new FileOutputStream(clientJarFile),
new Manifest());
+ createClientJar(tmpDir, jarout);
+ jarout.close();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE, "FAILED_TO_CREAT_CLIENTJAR", e);
+ Message msg = new Message("FAILED_TO_CREAT_CLIENTJAR", LOG);
+ throw new ToolException(msg, e);
+ }
+ context.put(ToolConstants.CFG_CLASSDIR, oldClassDir);
+ context.put(ClassCollector.class, oldCollector);
+ }
+
+ private void createClientJar(File tmpDirectory, JarOutputStream jarout) {
+ try {
+ URI parentFile = new
URI((String)context.get(ToolConstants.CFG_CLASSDIR));
+ for (File file : tmpDirectory.listFiles()) {
+ URI relativePath = parentFile.relativize(new
URI(file.getPath()));
+ String name = relativePath.toString().replace("\\", "/");
+ if (file.isDirectory()) {
+ if (!name.isEmpty()) {
+ if (!name.endsWith("/")) {
+ name += "/";
+ }
+ JarEntry entry = new JarEntry(name);
+ entry.setTime(file.lastModified());
+ jarout.putNextEntry(entry);
+ jarout.closeEntry();
+ }
+ createClientJar(file, jarout);
+ continue;
+ }
+ JarEntry entry = new JarEntry(name);
+ entry.setTime(file.lastModified());
+ jarout.putNextEntry(entry);
+ InputStream input = new BufferedInputStream(new
FileInputStream(file));
+ IOUtils.copy(input, jarout);
+ input.close();
+ jarout.closeEntry();
+ }
+ } catch (Exception e) {
+ Message msg = new Message("FAILED_ADD_JARENTRY", LOG);
+ throw new ToolException(msg, e);
+ }
}
private boolean isSuppressCodeGen() {
@@ -646,4 +758,121 @@ public class WSDLToJavaContainer extends
}
return validators;
}
+
+ @SuppressWarnings("unchecked")
+ private void generateLocalWSDL(ToolContext context) {
+ String outputdir = (String)context.get(ToolConstants.CFG_CLASSDIR);
+ File wsdlFile = new File(outputdir,
(String)context.get(ToolConstants.CFG_WSDLLOCATION));
+ Definition def = context.get(Definition.class);
+ try {
+ //get imported schemas
+ int xsdCount = 0;
+ SchemaCollection schemas = (SchemaCollection)
context.get(ToolConstants.XML_SCHEMA_COLLECTION);
+ Map<String, String> sourceMap = new HashMap<String, String>();
+ for (XmlSchema imp : schemas.getXmlSchemas()) {
+ if (imp.getSourceURI() != null &&
!imp.getSourceURI().contains(".wsdl#")) {
+ String schemaFileName = "schema" + (++xsdCount) + ".xsd";
+ sourceMap.put(imp.getTargetNamespace(), schemaFileName);
+ }
+ }
+
+ //get imported wsdls
+ List<Definition> defs =
(List<Definition>)context.get(ToolConstants.IMPORTED_DEFINITION);
+ Map<String, String> importWSDLMap = new HashMap<String, String>();
+ for (Definition importDef : defs) {
+ File importedWsdlFile = null;
+ if (!StringUtils.isEmpty(importDef.getDocumentBaseURI())) {
+ importedWsdlFile = new
File(importDef.getDocumentBaseURI());
+ } else {
+ importedWsdlFile = new
File(importDef.getQName().getLocalPart() + ".wsdl");
+ }
+ importWSDLMap.put(importDef.getTargetNamespace(),
importedWsdlFile.getName());
+ }
+
+
+ OutputStreamCreator outputStreamCreator = null;
+ if (context.get(OutputStreamCreator.class) != null) {
+ outputStreamCreator = context.get(OutputStreamCreator.class);
+ } else {
+ outputStreamCreator = new OutputStreamCreator();
+ context.put(OutputStreamCreator.class, outputStreamCreator);
+ }
+ Writer os = null;
+
+
+
+ for (XmlSchema imp : schemas.getXmlSchemas()) {
+ if (imp.getSourceURI() != null &&
!imp.getSourceURI().contains(".wsdl#")) {
+ String schemaFileName =
sourceMap.get(imp.getTargetNamespace());
+ File impfile = new File(wsdlFile.getParentFile(),
schemaFileName);
+ Element el = imp.getSchemaDocument().getDocumentElement();
+ updateImports(el, sourceMap);
+ os = new FileWriterUtil(impfile.getParent(),
context.get(OutputStreamCreator.class))
+ .getWriter(impfile, "UTF-8");
+ XMLUtils.writeTo(el, os, 2);
+ os.close();
+ }
+ }
+
+ //change the import location in wsdl file
+ OutputStream wsdloutput = new BufferedOutputStream(new
FileOutputStream(wsdlFile));
+ WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ wsdlWriter.writeWSDL(def, bout);
+ Element defEle =
XMLUtils.parse(bout.toByteArray()).getDocumentElement();
+ List<Element> xsdElements =
DOMUtils.findAllElementsByTagNameNS(defEle,
+
WSDLConstants.NS_SCHEMA_XSD,
+
"schema");
+ for (Element xsdEle : xsdElements) {
+ updateImports(xsdEle, sourceMap);
+ }
+ updateWSDLImports(defEle, importWSDLMap);
+ DOMUtils.writeXml(defEle, wsdloutput);
+ wsdloutput.close();
+
+
+ for (Definition importDef : defs) {
+ File importWsdlFile = new File(outputdir,
importWSDLMap.get(importDef.getTargetNamespace()));
+ OutputStream wsdlOs = new BufferedOutputStream(new
FileOutputStream(importWsdlFile));
+ bout = new ByteArrayOutputStream();
+ wsdlWriter.writeWSDL(importDef, bout);
+ Element importEle =
XMLUtils.parse(bout.toByteArray()).getDocumentElement();
+
+ xsdElements = DOMUtils.findAllElementsByTagNameNS(importEle,
WSDLConstants.NS_SCHEMA_XSD,
+ "schema");
+ for (Element xsdEle : xsdElements) {
+ updateImports(xsdEle, sourceMap);
+ }
+ updateWSDLImports(importEle, importWSDLMap);
+ DOMUtils.writeXml(importEle, wsdlOs);
+ wsdlOs.close();
+
+ }
+ } catch (Exception ex) {
+ LOG.log(Level.SEVERE, "FAILED_TO_GEN_LOCAL_WSDL", ex);
+ Message msg = new Message("FAILED_TO_GEN_LOCAL_WSDL", LOG);
+ throw new ToolException(msg, ex);
+ }
+ }
+
+ private void updateImports(Element el, Map<String, String> sourceMap) {
+ List<Element> imps = DOMUtils.getChildrenWithName(el,
+
WSDLConstants.NS_SCHEMA_XSD,
+ "import");
+ for (Element e : imps) {
+ String ns = e.getAttribute("namespace");
+ e.setAttribute("schemaLocation", sourceMap.get(ns));
+
+ }
+ }
+
+ private void updateWSDLImports(Element el, Map<String, String>
wsdlSourceMap) {
+ List<Element> imps = DOMUtils.getChildrenWithName(el,
+
WSDLConstants.QNAME_IMPORT.getNamespaceURI(),
+ "import");
+ for (Element e : imps) {
+ String ns = e.getAttribute("namespace");
+ e.setAttribute("location", wsdlSourceMap.get(ns));
+ }
+ }
}
Modified:
cxf/branches/2.7.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.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
(original)
+++
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/jaxws-toolspec.xml
Tue Mar 5 02:55:24 2013
@@ -166,6 +166,16 @@ Examples:
</annotation>
<switch>client</switch>
</option>
+
+ <option id="clientjar" maxOccurs="1">
+ <annotation>
+ Package all the client classes and wsdl in a jar file
+ </annotation>
+ <associatedArgument placement="afterSpace">
+ <annotation>jar-file-name</annotation>
+ </associatedArgument>
+ <switch>clientjar</switch>
+ </option>
<option id="all" maxOccurs="1">
<annotation>
Modified:
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
(original)
+++
cxf/branches/2.7.x-fixes/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/template/service.vm
Tue Mar 5 02:55:24 2013
@@ -95,6 +95,9 @@ public class ${service.Name} extends ${s
#elseif ($useGetResource)
URL url = ${service.Name}.class.getResource("$wsdlLocation");
if (url == null) {
+ url =
${service.Name}.class.getClassLoader().getResource("$wsdlLocation");
+ }
+ if (url == null) {
java.util.logging.Logger.getLogger(${service.Name}.class.getName())
.log(java.util.logging.Level.INFO,
"Can not initialize the default wsdl from {0}",
"$wsdlLocation");
Modified:
cxf/branches/2.7.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java?rev=1452641&r1=1452640&r2=1452641&view=diff
==============================================================================
---
cxf/branches/2.7.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
(original)
+++
cxf/branches/2.7.x-fixes/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenTest.java
Tue Mar 5 02:55:24 2013
@@ -19,6 +19,7 @@
package org.apache.cxf.tools.wsdlto.jaxws;
import java.io.File;
+import java.io.FileInputStream;
import java.io.ObjectStreamClass;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
@@ -26,8 +27,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
import javax.jws.HandlerChain;
import javax.jws.Oneway;
@@ -1651,4 +1655,29 @@ public class CodeGenTest extends Abstrac
assertTrue(seiFile.exists());
}
+ @Test
+ public void testClientJar() throws Exception {
+ env.put(ToolConstants.CFG_WSDLURL,
getLocation("/wsdl2java_wsdl/hello_world_wsdl_import.wsdl"));
+ env.put(ToolConstants.CFG_CLIENT_JAR, "test-client.jar");
+ processor.setContext(env);
+ processor.execute();
+ File clientjarFile = new File(output, "test-client.jar");
+ assertTrue(clientjarFile.exists());
+
+ List<String> jarEntries = new ArrayList<String>();
+ JarInputStream jarIns = new JarInputStream(new
FileInputStream(clientjarFile));
+ JarEntry entry = null;
+ while ((entry = jarIns.getNextJarEntry()) != null) {
+ if (entry.getName().endsWith(".wsdl") ||
entry.getName().endsWith(".class")) {
+ jarEntries.add(entry.getName());
+ }
+ }
+ jarIns.close();
+ assertEquals("15 files including wsdl and class files are expected",
15, jarEntries.size());
+ assertTrue("hello_world_messages.wsdl is expected",
+ jarEntries.contains("hello_world_messages.wsdl"));
+ assertTrue("org/apache/cxf/w2j/hello_world/SOAPService.class is
expected",
+
jarEntries.contains("org/apache/cxf/w2j/hello_world/SOAPService.class"));
+ }
+
}