Axis2 contract-first web service


Installing Axis2 WAR Distribution

  1. Download the Axis2  WAR distribution from here: http://axis.apache.org/axis2/java/core/download.cgi
  2. Deploy it as an exploded directory in your preferred Servlet Container (JBoss, Tomcat, etc).
  3. axis2.war will be the container to hold multiple aar files, which independently are axis projects themselves
  4. Go to the axis2.war/WEB-INF/conf/axis2.xml file, and set the hotupdate parameter to true, as follows:
…<parameter name=”hotupdate”>true</parameter>Check that the Axis2 webapp was successfully deployed by going to this link http://localhost:8080/axis2/ and clicking on ‘Validate’.

Developing a contract-first web service

  1. Create a Maven project in eclipse.
  2. Copy your wsdl and xsd files to src/main/resourcesNote: This process assumes you already have an existing WSDL file with external xsd files for the messages definition (Contract-first approach)
  3. Copy the following to your pom.xml file:
<build><plugins>

<plugin>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-aar-maven-plugin</artifactId>

<version>1.4.1</version>

<extensions>true</extensions>

<configuration>

<servicesXmlFile>src/main/resources/services.xml</servicesXmlFile>

<wsdlFile>src/main/resources/<your-wsdl-file></wsdlFile>

<fileSets>

<fileSet>

<directory>src/main/resources</directory>

<outputDirectory>META-INF</outputDirectory>

<includes>

<include>**/*.xsd</include>

</includes>

</fileSet>

</fileSets>

</configuration>

</plugin>

</plugins>

</build>

<profiles>

<profile>

<id>codegen</id>

<build>

<plugins>

<plugin>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-wsdl2code-maven-plugin</artifactId>

<version>1.6.2</version>

<executions>

<execution>

<phase>generate-sources</phase>

<goals>

<goal>wsdl2code</goal>

</goals>

</execution>

</executions>

<configuration>

<classpathElements>${project.build.outputDirectory}</classpathElements>

<wsdlFile>src/main/resources/<your-wsdl-file></wsdlFile>

<databindingName>adb</databindingName>

<packageName><package-name></packageName>

<generateServerSide>true</generateServerSide>

<generateServerSideInterface>true</generateServerSideInterface>

<generateServicesXml>true</generateServicesXml>

</configuration>

</plugin>

</plugins>

</build>

</profile>

</profiles>

<dependencies>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-transport-http</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.apache.axis2</groupId>

<artifactId>axis2-transport-local</artifactId>

<version>1.6.2</version>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>json</artifactId>

<version>20090211</version>

</dependency>

</dependencies>

  1. To generate the java sources from the wsdl, run: mvn clean generate-sources -Pcodegen. This will create the input and output objects of every service, as well as the skeleton files and the services.xml file.
  2. Copy the files from target/generated-sources/axis2/wsdl2code/src to your src folder.
  3. Copy the services.xml file from target/generated-sources/axis2/wsdl2code/src to src/main/resources
  4. Edit the Skeleton class to include the logic you want.
  5. To generate the .aar file, run: mvn clean compile axis2-aar:aar
  6. Copy the generated .aar file from target to testws.war/WEB-INF/services
  7.  WSDL URLhttp://host:port/axis2/services/test-services?wsdl
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: