Author: jason.greene(a)jboss.com
Date: 2007-01-27 00:59:35 -0500 (Sat, 27 Jan 2007)
New Revision: 2156
Added:
trunk/build/etc/wsgen.bat
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/WebServiceGeneratorTestCase.java
Modified:
trunk/build/etc/default.mf
trunk/build/etc/jboss.sh
trunk/build/etc/wsgen.sh
trunk/build/etc/wspublish.sh
trunk/build/etc/wstools.bat
trunk/build/etc/wstools.sh
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java
Log:
Add wsgen.bat
Add testcase for WebServiceGenerator API
Prevent classes from being added to the specified classloader
Property changes on: trunk/build/etc/default.mf
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Property changes on: trunk/build/etc/jboss.sh
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/build/etc/wsgen.bat
===================================================================
--- trunk/build/etc/wsgen.bat (rev 0)
+++ trunk/build/etc/wsgen.bat 2007-01-27 05:59:35 UTC (rev 2156)
@@ -0,0 +1,49 @@
+@echo off
+
+rem $Id$
+
+@if not "%ECHO%" == "" echo %ECHO%
+@if "%OS%" == "Windows_NT" setlocal
+
+set DIRNAME=.\
+if "%OS%" == "Windows_NT" set DIRNAME=%~dp0%
+set PROGNAME=run.bat
+if "%OS%" == "Windows_NT" set PROGNAME=%~nx0%
+
+rem Read all command line arguments
+
+REM
+REM The %ARGS% env variable commented out in favor of using %* to include
+REM all args in java command line. See bug #840239. [jpl]
+REM
+REM set ARGS=
+REM :loop
+REM if [%1] == [] goto endloop
+REM set ARGS=%ARGS% %1
+REM shift
+REM goto loop
+REM :endloop
+
+set JAVA=%JAVA_HOME%\bin\java
+set JBOSS_HOME=%DIRNAME%\..
+rem Setup the java endorsed dirs
+set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed
+
+rem Setup the wstools classpath
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jboss-xml-binding.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/activation.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/javassist.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/getopt.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jaxb-api.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jaxb-impl.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jbossall-client.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jbossretro-rt.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jboss-backport-concurrent.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jbossws-client.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/jbossws14-client.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/log4j.jar
+set WSGEN_CLASSPATH=%WSGEN_CLASSPATH%;%JBOSS_HOME%/client/mail.jar
+
+rem Execute the JVM
+"%JAVA%" %JAVA_OPTS% -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%"
-classpath "%WSGEN_CLASSPATH%" org.jboss.ws.tools.jaxws.WSGenerate %*
+
Property changes on: trunk/build/etc/wsgen.bat
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/build/etc/wsgen.sh
===================================================================
--- trunk/build/etc/wsgen.sh 2007-01-27 00:32:14 UTC (rev 2155)
+++ trunk/build/etc/wsgen.sh 2007-01-27 05:59:35 UTC (rev 2156)
@@ -1,6 +1,6 @@
#!/bin/sh
-# $Id: wstools.sh 1683 2006-12-21 12:40:22Z thomas.diesler(a)jboss.com $
+# $Id$
DIRNAME=`dirname $0`
PROGNAME=`basename $0`
@@ -69,22 +69,6 @@
JBOSS_ENDORSED_DIRS=`cygpath --path --windows "$JBOSS_ENDORSED_DIRS"`
fi
-# Display our environment
-# echo
"========================================================================="
-# echo ""
-# echo " WSTools Environment"
-# echo ""
-# echo " JBOSS_HOME: $JBOSS_HOME"
-# echo ""
-# echo " JAVA: $JAVA"
-# echo ""
-# echo " JAVA_OPTS: $JAVA_OPTS"
-# echo ""
-# echo " CLASSPATH: $WSGEN_CLASSPATH"
-# echo ""
-# echo
"========================================================================="
-# echo ""
-
# Execute the JVM
"$JAVA" $JAVA_OPTS \
-Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
Property changes on: trunk/build/etc/wsgen.sh
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/build/etc/wspublish.sh
===================================================================
--- trunk/build/etc/wspublish.sh 2007-01-27 00:32:14 UTC (rev 2155)
+++ trunk/build/etc/wspublish.sh 2007-01-27 05:59:35 UTC (rev 2156)
@@ -1,6 +1,6 @@
#!/bin/sh
-# $Id: WSPUBLISH.sh 214 2006-04-20 17:43:45Z thomas.diesler(a)jboss.com $
+# $Id$
DIRNAME=`dirname $0`
PROGNAME=`basename $0`
Property changes on: trunk/build/etc/wspublish.sh
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/build/etc/wstools.bat
===================================================================
--- trunk/build/etc/wstools.bat 2007-01-27 00:32:14 UTC (rev 2155)
+++ trunk/build/etc/wstools.bat 2007-01-27 05:59:35 UTC (rev 2156)
@@ -1,6 +1,6 @@
@echo off
-rem $Id: wstools.bat 1683 2006-12-21 12:40:22Z thomas.diesler(a)jboss.com $
+rem $Id$
@if not "%ECHO%" == "" echo %ECHO%
@if "%OS%" == "Windows_NT" setlocal
Property changes on: trunk/build/etc/wstools.bat
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: trunk/build/etc/wstools.sh
===================================================================
--- trunk/build/etc/wstools.sh 2007-01-27 00:32:14 UTC (rev 2155)
+++ trunk/build/etc/wstools.sh 2007-01-27 05:59:35 UTC (rev 2156)
@@ -1,6 +1,6 @@
#!/bin/sh
-# $Id: wstools.sh 1683 2006-12-21 12:40:22Z thomas.diesler(a)jboss.com $
+# $Id$
DIRNAME=`dirname $0`
PROGNAME=`basename $0`
Property changes on: trunk/build/etc/wstools.sh
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java
===================================================================
---
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java 2007-01-27
00:32:14 UTC (rev 2155)
+++
trunk/jbossws-core/src/main/java/org/jboss/ws/tools/jaxws/impl/WebServiceGeneratorImpl.java 2007-01-27
05:59:35 UTC (rev 2156)
@@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
+import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
@@ -52,12 +53,11 @@
private boolean generateWsdl = false;
private boolean generateSource = false;
private File outputDir = new File("output");
- private File resourceDir = outputDir;
- private File sourceDir = outputDir;
+ private File resourceDir = null;
+ private File sourceDir = null;
private PrintStream messageStream = new NullPrintStream();
- @Override
- public void generate(Class<?> endpointClass)
+ private void createDirectories(File resourceDir, File sourceDir)
{
if (!outputDir.exists())
if (!outputDir.mkdirs())
@@ -67,11 +67,13 @@
if (!resourceDir.mkdirs())
throw new WSException("Could not create directory: " +
resourceDir);
-
if (generateSource && !sourceDir.exists())
if (!sourceDir.mkdirs())
throw new WSException("Could not create directory: " + sourceDir);
-
+ }
+
+ private UnifiedDeploymentInfo createUDI(Class<?> endpointClass, ClassLoader
loader)
+ {
DeploymentType type = (endpointClass.isAnnotationPresent(Stateless.class)) ?
JAXWS_EJB3 : JAXWS_JSE;
UnifiedDeploymentInfo udi = new UnifiedDeploymentInfo(type)
{
@@ -82,7 +84,20 @@
}
};
udi.classLoader = loader;
+ return udi;
+ }
+
+ @Override
+ public void generate(Class<?> endpointClass)
+ {
+ // Use the output directory as the default
+ File resourceDir = (this.resourceDir != null) ? this.resourceDir : outputDir;
+ File sourceDir = (this.sourceDir != null) ? this.sourceDir : outputDir;
+ createDirectories(resourceDir, sourceDir);
+
+ // Create a dummy classloader to catch generated classes
+ ClassLoader loader = new URLClassLoader(new URL[0], this.loader);
UnifiedMetaData umd = new UnifiedMetaData(new ResourceLoaderAdapter(loader));
umd.setClassLoader(loader);
@@ -100,7 +115,8 @@
if (generateWsdl)
messageStream.println("Generating WSDL:");
-
+
+ UnifiedDeploymentInfo udi = createUDI(endpointClass, loader);
builder.buildWebServiceMetaData(umd, udi, endpointClass, null);
try
{
Added:
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/WebServiceGeneratorTestCase.java
===================================================================
---
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/WebServiceGeneratorTestCase.java
(rev 0)
+++
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/WebServiceGeneratorTestCase.java 2007-01-27
05:59:35 UTC (rev 2156)
@@ -0,0 +1,156 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.test.ws.tools.jaxws;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.jboss.test.ws.JBossWSTest;
+import org.jboss.test.ws.jaxws.jsr181.soapbinding.DocWrappedServiceImpl;
+import org.jboss.test.ws.jaxws.jsr181.soapbinding.PurchaseOrder;
+import org.jboss.test.ws.jaxws.jsr181.soapbinding.PurchaseOrderAck;
+import org.jboss.ws.core.utils.JavaUtils;
+import org.jboss.ws.tools.jaxws.api.WebServiceGenerator;
+import org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory;
+
+/**
+ * Tests the WebServiceGenerator API.
+ *
+ * @author <a href="mailto:jason.greene@jboss.com">Jason T.
Greene</a>
+ * @version $Revision$
+ */
+public class WebServiceGeneratorTestCase extends JBossWSTest
+{
+ public void testBasic() throws Exception
+ {
+ WebServiceGenerator gen = getGenerator();
+ File outputDir = new File("tools/wsgen/basic/out");
+ gen.setOutputDirectory(outputDir);
+ gen.generate(DocWrappedServiceImpl.class);
+
+ checkWrapperClasses(outputDir);
+
+ // There should be no source code
+ checkWrapperSource(outputDir, false);
+ }
+
+ private WebServiceGenerator getGenerator()
+ {
+ return WebServiceGenerator.newInstance();
+ }
+
+ private void checkWrapperSource(File outputDir, boolean shouldExist)
+ {
+ File file1 = new File(outputDir,
"org/jboss/test/ws/jaxws/jsr181/soapbinding/jaxws/SubmitPO.java");
+ File file2 = new File(outputDir,
"org/jboss/test/ws/jaxws/jsr181/soapbinding/jaxws/SubmitPOResponse.java");
+ assertEquals(shouldExist, file1.exists());
+ assertEquals(shouldExist, file2.exists());
+ }
+
+ private void checkWrapperClasses(File outputDir) throws MalformedURLException,
ClassNotFoundException, NoSuchMethodException
+ {
+ // Use a different loader each time to make sure the files exist
+ URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()},
Thread.currentThread().getContextClassLoader());
+
+ // Check request wrapper
+ Class wrapper =
JavaUtils.loadJavaType("org.jboss.test.ws.jaxws.jsr181.soapbinding.jaxws.SubmitPO",
classLoader);
+ wrapper.getMethod("setPurchaseOrder", PurchaseOrder.class);
+ assertEquals(PurchaseOrder.class.getName(),
wrapper.getMethod("getPurchaseOrder").getReturnType().getName());
+
+ // Check response wrapper
+ wrapper =
JavaUtils.loadJavaType("org.jboss.test.ws.jaxws.jsr181.soapbinding.jaxws.SubmitPOResponse",
classLoader);
+ wrapper.getMethod("setPurchaseOrderAck", PurchaseOrderAck.class);
+ assertEquals(PurchaseOrderAck.class.getName(),
wrapper.getMethod("getPurchaseOrderAck").getReturnType().getName());
+ }
+
+ public void testSource() throws Exception
+ {
+ WebServiceGenerator gen = getGenerator();
+ File outputDir = new File("tools/wsgen/source/out");
+ gen.setOutputDirectory(outputDir);
+ gen.setGenerateSource(true);
+ gen.generate(DocWrappedServiceImpl.class);
+
+ checkWrapperClasses(outputDir);
+ checkWrapperSource(outputDir, true);
+ }
+
+ public void testSourceDir() throws Exception
+ {
+ WebServiceGenerator gen = getGenerator();
+ File outputDir = new File("tools/wsgen/sourcedir/out");
+ File sourceDir = new File("tools/wsgen/sourcedir/source");
+
+ gen.setOutputDirectory(outputDir);
+ gen.setSourceDirectory(sourceDir);
+ gen.setGenerateSource(true);
+ gen.generate(DocWrappedServiceImpl.class);
+
+ checkWrapperClasses(outputDir);
+ checkWrapperSource(outputDir, false);
+ checkWrapperSource(sourceDir, true);
+ }
+
+ public void testWsdl() throws Exception
+ {
+ WebServiceGenerator gen = getGenerator();
+ File outputDir = new File("tools/wsgen/wsdl/out");
+ gen.setOutputDirectory(outputDir);
+ gen.setGenerateWsdl(true);
+ gen.generate(DocWrappedServiceImpl.class);
+
+ checkWrapperClasses(outputDir);
+
+ // There should be no source code
+ checkWrapperSource(outputDir, false);
+
+ File wsdlFile = new File(outputDir, "DocWrappedService.wsdl");
+ WSDLDefinitionsFactory wsdlFactory = WSDLDefinitionsFactory.newInstance();
+ wsdlFactory.parse(wsdlFile.toURL());
+ }
+
+ public void testResourceDir() throws Exception
+ {
+ WebServiceGenerator gen = getGenerator();
+ File outputDir = new File("tools/wsgen/resourcedir/out");
+ File wsdlDir = new File("tools/wsgen/resourcedir/wsdl");
+ gen.setOutputDirectory(outputDir);
+ gen.setResourceDirectory(wsdlDir);
+ gen.setGenerateWsdl(true);
+ gen.generate(DocWrappedServiceImpl.class);
+
+ checkWrapperClasses(outputDir);
+
+ // There should be no source code
+ checkWrapperSource(outputDir, false);
+
+ String wsdlName = "DocWrappedService.wsdl";
+ File wsdlFile = new File(outputDir, wsdlName);
+ assertFalse(wsdlFile.exists());
+
+ wsdlFile = new File(wsdlDir, wsdlName);
+ WSDLDefinitionsFactory wsdlFactory = WSDLDefinitionsFactory.newInstance();
+ wsdlFactory.parse(wsdlFile.toURL());
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jbossws-tests/src/main/java/org/jboss/test/ws/tools/jaxws/WebServiceGeneratorTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF