You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2004/05/10 19:25:43 UTC

cvs commit: ws-axis/java/tools/org/apache/axis/tools/ant/wsdl Wsdl2javaAntTask.java

dims        2004/05/10 10:25:43

  Modified:    java/docs reference.html
               java/docs/ant axis-wsdl2java.html
               java/src/org/apache/axis/i18n resource.properties
               java/src/org/apache/axis/wsdl WSDL2Java.java
               java/src/org/apache/axis/wsdl/toJava Emitter.java
                        JavaBindingWriter.java JavaDeployWriter.java
                        JavaImplWriter.java JavaSkelWriter.java
               java/tools/org/apache/axis/tools/ant/wsdl
                        Wsdl2javaAntTask.java
  Added:       java/test/wsdl/webref DoubleBack.java
                        DoubleBackServiceTestCase.java build.xml
  Log:
  Fix for AXIS-1314 - Custom name for implementation class, WSDL2Java
  from M�ns T�nneryd
  
  Revision  Changes    Path
  1.36      +13 -0     ws-axis/java/docs/reference.html
  
  Index: reference.html
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/docs/reference.html,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- reference.html	1 Apr 2004 20:47:51 -0000	1.35
  +++ reference.html	10 May 2004 17:25:43 -0000	1.36
  @@ -122,6 +122,10 @@
   &lt;argument&gt; <br>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   password to access the WSDL-URI <br>
  +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -c, --implementationClassName
  +&lt;argument&gt; <br>
  +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  +use this as the implementation class <br>
   &nbsp; </p>
   <h4> -h, --help</h4>
   Print the usage statement and exit
  @@ -272,6 +276,15 @@
   This password is used in resolving the WSDL-URI provided as the input
   to WSDL2Java. &nbsp;If the URI contains a password, this will override
   the command line switch.&nbsp; <br>
  +<h4> -c, --implementationClassName &lt;argument&gt;</h4>
  +<p>Set the name of the implementation class.Especially useful when
  +exporting an existing class as a web service using java2wsdl 
  +followed by wsdl2java.&nbsp;If you are using the skeleton deploy option you must make sure, after generation, 
  +that your implementation class implements the port type name interface generated
  +by wsdl2java.&nbsp;You should also make sure that all your exported methods throws
  +java.lang.RemoteException.
  +</p>
  +<br>
   <h3><a name="Java2WSDL"></a>Java2WSDL Reference</h3>
   <p>Here is the help message generated from the current tool: </p>
   <p><font color="#993366">
  
  
  
  1.8       +14 -3     ws-axis/java/docs/ant/axis-wsdl2java.html
  
  Index: axis-wsdl2java.html
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/docs/ant/axis-wsdl2java.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- axis-wsdl2java.html	26 Mar 2004 17:56:54 -0000	1.7
  +++ axis-wsdl2java.html	10 May 2004 17:25:43 -0000	1.8
  @@ -94,7 +94,7 @@
           <td bgcolor="#eeeeee" valign="top" align="left">
             <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
           </td>
  -        <td bgcolor="#eeeeee" valign="top" align="left" rowspan="21">
  +        <td bgcolor="#eeeeee" valign="top" align="left" rowspan="22">
             <font color="#000000" size="-1" face="arial,helvetica,sanserif">Optional</font>
           </td>
       </tr>
  @@ -338,8 +338,19 @@
             <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
           </td>
       </tr>
  -
  -
  +    
  +    <!-- Attribute -->
  +    <tr>
  +        <td bgcolor="#eeeeee" valign="top" align="left">
  +          <font color="#000000" size="-1" face="arial,helvetica,sanserif">implementationClassName</font>
  +        </td>
  +        <td bgcolor="#eeeeee" valign="top" align="left">
  +          <font color="#000000" size="-1" face="arial,helvetica,sanserif">Set the name of the implementation class. Especially useful when exporting an existing class as a web service using java2wsdl followed by wsdl2java.</font>
  +        </td>
  +        <td bgcolor="#eeeeee" valign="top" align="left">
  +          <font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
  +        </td>
  +    </tr>
           </table>
         </blockquote></td></tr>
   
  
  
  
  1.86      +1 -1      ws-axis/java/src/org/apache/axis/i18n/resource.properties
  
  Index: resource.properties
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/i18n/resource.properties,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- resource.properties	10 May 2004 08:23:44 -0000	1.85
  +++ resource.properties	10 May 2004 17:25:43 -0000	1.86
  @@ -940,7 +940,7 @@
   optionNSInclude=include namespace in generated code
   optionNSExclude=exclude namespace from generated code
   optionQuiet=do not print any informational or debug messages (except errors)
  -
  +implementationClassName=custom name of web service implementation
   cantCreateBean00=Unable to create JavaBean of type {0}.  Missing default constructor?  Error was: {1}.
   faultDuringCleanup=AxisEngine faulted during cleanup!
   
  
  
  
  1.49      +18 -7     ws-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java
  
  Index: WSDL2Java.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/WSDL2Java.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- WSDL2Java.java	8 Apr 2004 13:09:07 -0000	1.48
  +++ WSDL2Java.java	10 May 2004 17:25:43 -0000	1.49
  @@ -84,8 +84,11 @@
       /** Field namespace include */
       protected static final int NS_INCLUDE_OPT = 'i';
       
  -    /** Filed namespace exclude */
  -    protected static final int NS_EXCLUDE_OPT = 'x';
  +	/** Filed namespace exclude */
  +	protected static final int NS_EXCLUDE_OPT = 'x';
  +	
  +	/** Field IMPL_CLASS_OPT */
  +	protected static final int IMPL_CLASS_OPT = 'c';
   
       /** Field emitter */
       private Emitter emitter;
  @@ -162,11 +165,15 @@
                           + CLOptionDescriptor.ARGUMENT_REQUIRED,
                           NS_INCLUDE_OPT,
                           Messages.getMessage("optionNSInclude")),
  -                new CLOptionDescriptor("nsExclude",
  -                        CLOptionDescriptor.DUPLICATES_ALLOWED
  -                        + CLOptionDescriptor.ARGUMENT_REQUIRED,
  -                        NS_EXCLUDE_OPT,
  -                        Messages.getMessage("optionNSExclude"))
  +				new CLOptionDescriptor("nsExclude",
  +						CLOptionDescriptor.DUPLICATES_ALLOWED
  +						+ CLOptionDescriptor.ARGUMENT_REQUIRED,
  +						NS_EXCLUDE_OPT,
  +						Messages.getMessage("optionNSExclude")),
  +				new CLOptionDescriptor("implementationClassName",
  +						CLOptionDescriptor.ARGUMENT_REQUIRED,
  +						IMPL_CLASS_OPT,
  +						Messages.getMessage("implementationClassName"))
               };
   
       /**
  @@ -298,6 +305,10 @@
                   exclude.setNamespace(option.getArgument());
                   emitter.getNamespaceExcludes().add(exclude);
                   break;
  +
  +			case IMPL_CLASS_OPT:
  +				emitter.setImplementationClassName(option.getArgument());
  +				break;
   
               default :
                   super.parseOption(option);
  
  
  
  1.69      +26 -1     ws-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java
  
  Index: Emitter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/Emitter.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- Emitter.java	9 Apr 2004 18:37:04 -0000	1.68
  +++ Emitter.java	10 May 2004 17:25:43 -0000	1.69
  @@ -124,7 +124,14 @@
        * that can be used by custom JavaGeneratorFactories.
        */
       protected List properties = new ArrayList();
  -
  +    
  +    /**
  +     * Field implementationClassName - defines a non default classname for the actual
  +     * implementation class. Particularly useful when exporting a webservice directly
  +     * from the java implementation.
  +     */
  +	private String implementationClassName = null;
  +	
       /**
        * Default constructor.
        */
  @@ -900,4 +907,22 @@
       public void setTypeCollisionProtection(boolean value){
           this.typeCollisionProtection = value;
       }
  +    
  +	/**
  +	 * Get an implementation classname to use instead of the default.
  +	 * @return
  +	 */
  +	public String getImplementationClassName() {
  +		return implementationClassName;
  +	}
  +
  +	/**
  +	 * Set an implementation classname to use instead of the default.
  +	 * 
  +	 * @param implementationClassName 
  +	 */
  +	public void setImplementationClassName(String implementationClassName) {
  +		this.implementationClassName = implementationClassName;
  +	}
  +
   }
  
  
  
  1.25      +7 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java
  
  Index: JavaBindingWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaBindingWriter.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- JavaBindingWriter.java	12 Apr 2004 18:17:31 -0000	1.24
  +++ JavaBindingWriter.java	10 May 2004 17:25:43 -0000	1.25
  @@ -187,8 +187,13 @@
                               symbolTable);
                   }
   
  -                String fileName = Utils.getJavaLocalName(bEntry.getName())
  -                        + "Impl.java";
  +                // Use custom implementation classname if available
  +                String fileName = emitter.getImplementationClassName(); 
  +                if ( fileName == null)
  +					fileName = Utils.getJavaLocalName(bEntry.getName())
  +                    	    + "Impl.java";
  +				else
  +					fileName = Utils.getJavaLocalName(fileName) + ".java";
   
                   try {
                       if (Utils.fileExists(fileName,
  
  
  
  1.83      +10 -5     ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java
  
  Index: JavaDeployWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaDeployWriter.java,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- JavaDeployWriter.java	3 May 2004 20:04:10 -0000	1.82
  +++ JavaDeployWriter.java	10 May 2004 17:25:43 -0000	1.83
  @@ -388,11 +388,16 @@
           Binding binding = bEntry.getBinding();
           String className = bEntry.getName();
   
  -        if (emitter.isSkeletonWanted()) {
  -            className += "Skeleton";
  -        } else {
  -            className += "Impl";
  -        }
  +		if (emitter.isSkeletonWanted()) {
  +			 className += "Skeleton";
  +		 } else 
  +		 {
  +			 String customClassName  = emitter.getImplementationClassName();
  +			 if ( customClassName != null )
  +				 className = customClassName;
  +			 else
  +				 className += "Impl";
  +		 }
   
           pw.println("      <parameter name=\"className\" value=\"" + className
                   + "\"/>");
  
  
  
  1.36      +7 -5      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java
  
  Index: JavaImplWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaImplWriter.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- JavaImplWriter.java	25 Feb 2004 14:02:52 -0000	1.35
  +++ JavaImplWriter.java	10 May 2004 17:25:43 -0000	1.36
  @@ -54,11 +54,13 @@
        * @param symbolTable 
        */
       protected JavaImplWriter(Emitter emitter, BindingEntry bEntry,
  -                             SymbolTable symbolTable) {
  -
  -        super(emitter, bEntry.getName() + "Impl", "templateImpl");
  -
  -        this.binding = bEntry.getBinding();
  +                             SymbolTable symbolTable) 
  +    {
  +        super(emitter, ( emitter.getImplementationClassName() == null ? 
  +        		bEntry.getName() + "Impl" :
  +				emitter.getImplementationClassName()), "templateImpl");
  +		
  +		this.binding = bEntry.getBinding();
           this.symbolTable = symbolTable;
           this.bEntry = bEntry;
       }    // ctor
  
  
  
  1.61      +8 -2      ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java
  
  Index: JavaSkelWriter.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/toJava/JavaSkelWriter.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- JavaSkelWriter.java	1 Apr 2004 20:47:51 -0000	1.60
  +++ JavaSkelWriter.java	10 May 2004 17:25:43 -0000	1.61
  @@ -329,10 +329,16 @@
           pw.println("    }");
           pw.println();
   
  -        // Skeleton constructors
  +        // Skeleton constructors 
           pw.println("    public " + className + "() {");
  -        pw.println("        this.impl = new " + bEntry.getName() + "Impl();");
  +
  +		// Use custom implementation class if available.
  +		String implementationClassName = emitter.getImplementationClassName(); 
  +		if ( implementationClassName == null)
  +			implementationClassName = bEntry.getName() + "Impl";
  +        pw.println("        this.impl = new " + implementationClassName + "();");
           pw.println("    }");
  +        
           pw.println();
           pw.println("    public " + className + "(" + implType + ") {");
           pw.println("        this.impl = impl;");
  
  
  
  1.1                  ws-axis/java/test/wsdl/webref/DoubleBack.java
  
  Index: DoubleBack.java
  ===================================================================
  package test.wsdl.webref;
  /**
   * Test the wsdl2java option implementationClassName
   *
   * @author Mans Tanneryd (mans@tanneryd.com)
   */
  
  public class DoubleBack
  {
  	public String echo(String message)
  	{
  		return message+message;    
  	}
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/webref/DoubleBackServiceTestCase.java
  
  Index: DoubleBackServiceTestCase.java
  ===================================================================
  /**
   * DoubleBackPortTypeServiceTestCase.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis 1.2beta May 06, 2004 (03:41:36 CEST) WSDL2Java emitter.
   */
  
  package test.wsdl.webref;
  
  public class DoubleBackServiceTestCase extends junit.framework.TestCase {
      public DoubleBackServiceTestCase(java.lang.String name) {
          super(name);
      }
  
      public void testDoubleBackServiceWSDL() throws Exception {
          javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
          java.net.URL url = new java.net.URL(new test.wsdl.webref.DoubleBackPortTypeServiceLocator().getDoubleBackServiceAddress() + "?WSDL");
          javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.webref.DoubleBackPortTypeServiceLocator().getServiceName());
          assertTrue(service != null);
      }
  
      public void test1DoubleBackServiceEcho() throws Exception {
          test.wsdl.webref.DoubleBackServiceSoapBindingStub binding;
          try {
              binding = (test.wsdl.webref.DoubleBackServiceSoapBindingStub)
                            new test.wsdl.webref.DoubleBackPortTypeServiceLocator().getDoubleBackService();
          }
          catch (javax.xml.rpc.ServiceException jre) {
              if(jre.getLinkedCause()!=null)
                  jre.getLinkedCause().printStackTrace();
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
          }
          assertNotNull("binding is null", binding);
  
          // Time out after a minute
          binding.setTimeout(60000);
  
          // Test operation
          java.lang.String value = null;
          value = binding.echo( "hello" );
         	assertEquals( "hellohello", value);
      }
  
  }
  
  
  
  1.1                  ws-axis/java/test/wsdl/webref/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
     
     The purpose of this test is to verify the option implementationClassName
     in the wsdl2java emitter.
     
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Matt Seibert mseibert@us.ibm.com
    Mans Tanneryd mans@tanneryd.com
  
  Copyright:
    Copyright (c) 2002-2004 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
  <property name="axis.home" location="../../.." />
  <property name="componentName" value="test/wsdl/webref" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
          &targets;
  
  <target name="clean">
      <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}" />
      <delete dir="${build.dir}/classes/${componentName}"/>
      <delete dir="${build.dir}/work/${componentName}"/>
  </target>
  
  <!-- main target, always start from scratch -->
  <target name="compile" depends="setenv, clean">
      <echo message="Compiling test.wsdl.webref"/>
    
      <!-- Compile the implementation class for Java2WSDL -->
      <javac srcdir="${axis.home}/${componentName}" 
             destdir="${build.dest}" 
             fork="${javac.fork}"
             nowarn="${nowarn}" 
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="DoubleBack.java" />
      </javac>
      
      <mkdir dir="${build.dir}/work/${componentName}"/>
      
      <!-- Generate WSDL from java -->
      <java2wsdl output="${build.dir}/work/${componentName}/DoubleBackService.wsdl"
                 className= "test.wsdl.webref.DoubleBack"
                 location="http://localhost:8080/axis/services/DoubleBackService"
                 porttypename="DoubleBackPortType"
                 style="DOCUMENT"
                 namespace="http://webref.wsdl.test/DoubleBack">
      	<mapping package="test.wsdl.webref" namespace="http://webref.wsdl.test/DoubleBack" />
      </java2wsdl>
          
      <!-- Generate skeletons and stubs for client and server with custom implementation class -->
      <wsdl2java url="${build.dir}/work/${componentName}/DoubleBackService.wsdl"
                 output="${axis.home}/build/work"
                 all="yes"
                 serverside="yes"
                 skeletondeploy="no"
                 verbose="no"
                 testcase="no"
                 implementationClassName="test.wsdl.webref.DoubleBack">
          <mapping namespace="http://webref.wsdl.test/DoubleBack" package="test.wsdl.webref"/>
      </wsdl2java>
  
      <copy todir="${build.dir}/work/${componentName}" overwrite="yes">
        <fileset dir="${axis.home}/${componentName}">
          <include name="DoubleBack.java"/>
          <include name="DoubleBackServiceTestCase.java"/>
        </fileset>
      </copy>
  
      <!-- Compile it all -->
      <javac srcdir="${build.dir}/work" destdir="${build.dest}" nowarn="${nowarn}" fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="${componentName}/*.java" />
      </javac>
  
  </target>
  
  <target name="run" >
    <antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.18      +17 -3     ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java
  
  Index: Wsdl2javaAntTask.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/tools/org/apache/axis/tools/ant/wsdl/Wsdl2javaAntTask.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Wsdl2javaAntTask.java	12 Apr 2004 18:17:31 -0000	1.17
  +++ Wsdl2javaAntTask.java	10 May 2004 17:25:43 -0000	1.18
  @@ -102,7 +102,7 @@
       private List nsIncludes = new ArrayList();
       private List nsExcludes = new ArrayList();
       private List properties = new ArrayList();
  -
  +	private String implementationClassName = null;
   
       /**
        * do we print a stack trace when something goes wrong?
  @@ -177,7 +177,8 @@
           log("\tnamespaceMappingFile:" + namespaceMappingFile, logLevel);
           log("\tusername:" + username, logLevel);
           log("\t:password" + password, logLevel);
  -        log("\t:noWrapped" + noWrapped, logLevel);
  +		log("\t:noWrapped" + noWrapped, logLevel);
  +		log("\t:implementationClassName" + implementationClassName, logLevel);
           log("\t:classpath" + classpath, logLevel);
           traceNetworkSettings(logLevel);
       }
  @@ -233,7 +234,8 @@
               if (namespaceMappingFile != null) {
                   emitter.setNStoPkg(namespaceMappingFile.toString());
               }
  -            emitter.setTimeout(timeout);
  +			emitter.setTimeout(timeout);
  +			emitter.setImplementationClassName(implementationClassName);
   
               Authenticator.setDefault(new DefaultAuthenticator(username, password));
               if (classpath != null) {
  @@ -510,6 +512,18 @@
       public void setNoWrapped(boolean noWrapped) {
           this.noWrapped = noWrapped;
       }
  +
  +	/**
  +	 * Set the name of the class implementing the web service.
  +	 * This is especially useful when exporting a java class
  +	 * as a web service using Java2WSDL followed by WSDL2Java.
  +	 * 
  +	 * @param implementationClassName
  +	 */
  +	public void setImplementationClassName(String implementationClassName) {
  +		this.implementationClassName = implementationClassName;
  +	}
  +
   
       /**
        * set the classpath