AXIS 2 Sample web service Client with maven and eclipse
-
Create maven project in eclipse
-
Put the WSDL file
- Copy the CalculatorService.wsdl
- Put the wsdl file inside the src/main/resurce folder
-
Edit the pom.xml
- add the cxf-codegen-plugin
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cxf.version>2.2.3</cxf.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.7</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlRoot>${basedir}/src/main/resources</wsdlRoot>
<includes>
<include>*.wsdl</include>
</includes>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- add the maven dependencies
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
-
Generate the code
- Execute maven goal generate-sources
- Execute maven goal eclipse:eclipse to create project structure
- Client code will be generated in target/generated/cxf folder
-
Implment the Client code
- Creat new package com.cal.client
- Add java class named CalculatorClient.java
- Add the below code to CalculatorClient.java
package com.cal.client;
import com.ruks.services.CalculatorService;
import com.ruks.services.CalculatorServicePortType;
public class CalculatorClient {
public static void main(String[] args) {
// TODO Auto-generated method stub
CalculatorService service=new CalculatorService();
CalculatorServicePortType client= service.getCalculatorServiceHttpSoap11Endpoint();
client.setX(100);
client.setY(200);
System.out.println("Sum is: "+client.getSum());
}
}
-
Run the Client
- Run the CalculatorClient.java
- You get the output of the getSum operation
Add Comment
Comments (0)