WeMakeSoftware
WeMakeSoftware

Reputation: 9162

Axis2 web-service in a multi module maven project

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:

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

Upvotes: 1

Views: 1776

Answers (2)

landal79
landal79

Reputation: 1520

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.

Upvotes: 0

Jiri Kremser
Jiri Kremser

Reputation: 12847

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.

Upvotes: 1

Related Questions