1
votes

I've got an axis2 web-service generated from the WSDL file in a multi module maven project.

wsdl2java has generated the stubs and basic skeleton for me.

What's the best way to integrate those generated stubs into the exsisting business logic?

I've got several considerations:

  • The easiest way is to implement the business logic inside the stub. But I believe that will lead into trouble:
    • the stubs now are being generated as part of mvn clean install command. Maven clean deletes the generated source folder. I will have to protect the stub with the implemented business logic from deletion.
    • I don't want to commit anything from generated stubs into VCS. I'd like to keep it clean.
  • There is an option to extend the stub class in another source folder. This eliminates the cons of the previous approach, but brings something new to the stage:
    • As I understood from the AXIS2 docs, I have to specify the service class in the services.xml (and that's generated with maven-axis2 plugin). So again some parts of the generated stubs should be protected from modification.

Is there a way to somehow avoid this? Something like specifying the service class implementation in the web.xml? or anything similar?

2
I have more experience with JAX-WS than Axis2, but aren't you just implementing the generated interface in src/main/java (either by copying the implementation stub or creating it new) and copying the services.xml into src/main/resources (or wherever it's appropriate)? You could set up a Maven profile to turn the generation on and off, if you wanted.davidfmatheson
Let's leave the problem of Maven profiles for now. Assuming I want to generate the stubs each time the project is being built. Axis generates stubs, configs and implementation in /src/main/generated folder. If I want to extend the implemenation in my code, I have to provide the config (will be overriden by the next WS gen). So I'm forced to extend the stub implementation inside the generated folder and exclude the stub implementation from maven clean target.WeMakeSoftware
You want to generate the services.xml file every time, as well? I would just copy this to src/main/resources/META-INF/services.xml and edit it to point at an implementation class in src/main/java.davidfmatheson

2 Answers

1
votes

Axis2 is JAX-WS compliant, therefore you can use the wsimport tool instead of wsdl2java. I assume you've taken the contract first approach and you are generating the stubs from the WSDL file. Here is the doc to the wsimport maven plugin. A lot of things can be changed (destDir for instance).

Maven clean deletes the generated source folder. I will have to protect the stub with the implemented business logic from deletion.

You can actually generate the stubs to your regular package structure (perhaps to its own package) and add include (or exclude) the generated files in the maven clean plugin configuration. If you use this mvn plugin, your IDE should add the generated files to the project classpath.

If I were you, I would definitely try to do as much as possible as JAX-WS compliant, because if you do so, you won't be vendor locked-in to Axis2. But you can switch to CXF, Metro or Jboss WS in the future. The services.xml file is Axis2 specific.

So again some parts of the generated stubs should be protected from modification.

You can mark those resources as ignored by your SCM system. And mark them as derived in the Eclipse. Here is mvn plugin for it. If you do so, devs will be notified when trying to change them. There must be something similar in IntelliJ IDEA as well.

0
votes

What you have to do it is to configure maven pom, in order to let maven does the work.

First step

First of all you configure a maven properties, let's call it outputDirectory, the folder should be located inside the maven target folder, which I usually don't commit in the SCM.

Then you have to configure Axis maven plugin in order to generate stub sources into the target folder, as follow

<build>
   <plugins>
      ...
          <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        ... your configuration ..
                        <generateServerSide>true</generateServerSide>                                     
                        <generateServerSideInterface>true</generateServerSideInterface>
                        <outputDirectory>${outputDirectory}</outputDirectory>
                         ...
                    </configuration>
                </execution>
             </executions>
          </plugin>
          ...
      </plugins>
  </build>

with generateServerSideInterface to true the plugin generates an interface named XXXSkeleton that you can implement.

Second Step

Then you have to configure maven build helper plugin, in order to include the generated sources.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>add-source</id>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${outputDirectory}</source>
                </sources>
            </configuration>
        </execution>
    </executions>      
</plugin>

my personal opinion is that axis is not the better chioce for java Web Service, JAX-WS compliant framework are the best choice, here are the how with jax-ws maven plugin, the generate sources are far better and clean then axis sources.