Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for Axis2 with Maven

I'm a novice both to Maven and Axis2. My project consists of three modules: client, interface and server. Service is POJO-based. WSDL is being built at the server module. Interface module contains common stuff like service interface and beans.

Should I generate (or copy manually) the WSDL into the interface module? Should I generate client code at the client module? Is the modules structure ok? All I wish to do is make the build process automated but strictly structured.

like image 436
no id Avatar asked May 16 '12 06:05

no id


1 Answers

it doesn't result clear the component that you call 'interface'. for web service construction there are two main approaches:

  • start with the wsdl (that is the contract / or service interface descriptor)
  • start with the code (maybe a java interface)

I suggest the first approach because not always you can control both sides of the development. you can use the second one approach to start with a wsdl definition (java2wsdl) or built the wsdl with a tool as altova xmlspy.

Having the wsdl you can use the axis2-maven wsdl2code plugin to develop the WSS (web service server-side). This plugin in the version 2.6.0 only generates the source code of your server, but you need to host this code inside an axis2-war distribution or as an aar component.

Having the wsdl you can use again the axis2-maven wsdl2code plugin to generate the WSC (web service client-side). You can specify in the plugin instruction that you want to generate the test code. You can use mvn generate-sources to generate the client stub, move the generated sources and modify the test.

In both cases, you need to built the initial pom (ath this time I haven't found an official and unified or recommended pom). You can search in google for some pom.xml axis examples (i.e: http://wso2.org/library/90 ).

Below i have some xml that you can use to build the pom (WSC):

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>your_group_id</groupId>
      <artifactId>your_artifact_id</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>your_artifact_id</name>
      <url>http://your_url</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.1</version>
          <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
          <version>2.5</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.1</version>
          <scope>provided</scope>
        </dependency>

        <!-- axis2/axiom: dependencies -->
        <dependency>
              <groupId>org.apache.axis2</groupId>
              <artifactId>axis2</artifactId>
              <version>${axis2.version}</version>
        </dependency>
        <dependency>  
           <groupId>org.apache.axis2</groupId>  
           <artifactId>axis2-transport-local</artifactId>  
           <version>${axis2.version}</version>  
        </dependency>
        <dependency>  
           <groupId>org.apache.axis2</groupId>  
           <artifactId>axis2-transport-http</artifactId>  
           <version>${axis2.version}</version>  
        </dependency>         
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-codegen</artifactId>
            <version>${axis2.version}</version>
            <scope>provided</scope>
        </dependency>   

        <!-- axis2-rampart: dependencies -->
        <dependency>
            <groupId>org.apache.rampart</groupId>
            <artifactId>rampart-core</artifactId>
            <version>${axis2.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- slf4j: dependencies -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>${slf4j.version}</version>
          <!-- 
          <scope>runtime</scope>
          -->
          <exclusions>
            <exclusion>
                <artifactId>log4j</artifactId>
                <groupId>log4j</groupId>
            </exclusion>
          </exclusions>
        </dependency> 
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <!-- log4j: dependencies -->
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j.version}</version>
          <exclusions>
            <exclusion>
                <artifactId>jmxtools</artifactId>
                <groupId>com.sun.jdmk</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jmxri</artifactId>
                <groupId>com.sun.jmx</groupId>
            </exclusion>
            <exclusion>
                <artifactId>mail</artifactId>
                <groupId>javax.mail</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jms</artifactId>
                <groupId>javax.jms</groupId>
            </exclusion>
          </exclusions>
        </dependency>

        <!-- other: dependencies -->
      </dependencies>


      <build>
        <plugins>
          <plugin>
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>maven-jetty-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
              <warName>${project.artifactId}</warName>
            </configuration>
          </plugin>

          <plugin>
              <groupId>org.apache.axis2</groupId>
              <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
              <version>${axis2.version}</version>
              <executions>
                  <execution>
                    <id>wsc_01</id>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        <wsdlFile>${codegen.wsc_01.wsdl-uri}</wsdlFile>
                        <packageName>${codegen.wsc_01.package-name}</packageName>
                        <namespaceToPackages>${codegen.wsc_01.namespace-map}</namespaceToPackages>
                        <outputDirectory>${codegen.wsc.target-dir}</outputDirectory>
                        <databindingName>adb</databindingName>
                        <syncMode>sync</syncMode>
                        <generateServerSide>false</generateServerSide>
                        <generateServicesXml>true</generateServicesXml>
                        <generateTestcase>true</generateTestcase>
                        <language>java</language>
                    </configuration>
                  </execution>
                  <!-- other wsc-generation params -->
              </executions>
          </plugin> 

        </plugins>

      </build>

        <properties>
            <slf4j.version>1.6.3</slf4j.version>  
            <log4j.version>1.2.15</log4j.version>
            <axis2.version>1.6.0</axis2.version>
            <rampart.version>1.6.0</rampart.version>

            <!-- codegen.client.properties -->

            <codegen.wsc_01.wsdl-uri>wsdl_relative_path_or_url</codegen.wsc_01.wsdl-uri>
            <codegen.wsc_01.package-name>your_root_package</codegen.wsc_01.package-name>
            <codegen.wsc_01.namespace-map>http://your_url_namespace=your_java_namespace_mapped</codegen.wsc_01.namespace-map>

            <codegen.wsc.target-dir>target/generated-sources/axis2/wsdl2code</codegen.wsc.target-dir>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-jdk14</artifactId>
                    <version>1.5.2</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
like image 108
ANDRES HURTADO Avatar answered Sep 28 '22 22:09

ANDRES HURTADO