Axis 2 Tomcat Setup
Download Axis 2 war distribution from http://axis.apache.org/axis2/java/core/download.cgiNow install it to Tomcat by copying the axis2.war file to webapps directory of tomcat installation. Axis2 folder should be created automatically if tomcat is up and running.
We can conclude this part if http://localhost:8080/axis2 is ok. Validate link in the page shouldn't show any errors.
Implementation
create simple maven project in eclipse using create simple project option in the first window. name myHelloService2Use following as the wsdl for our web service
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="SayHelloRequest">
<part name="firstName" type="xsd:string"/>
</message>
<message name="SayHelloResponse">
<part name="greeting" type="xsd:string"/>
</message>
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>
<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/"/>
</port>
</service>
</definitions>
Save it as HelloService.wsdl at myHelloService2\src\main\resources\wsdl\
Now update your pom.xml file as following.
<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>com.nuwan.services</groupId>
<artifactId>myHelloService2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>target/generated-sources/axis2/wsdl2code/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.1</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>com.nuwan.ws</packageName>
<wsdlFile>src/main/resources/wsdl/HelloService.wsdl</wsdlFile>
<databindingName>xmlbeans</databindingName>
<syncMode>sync</syncMode>
<unpackClasses>true</unpackClasses>
<generateServerSide>true</generateServerSide>
<generateServicesXml>true</generateServicesXml>
<generateServerSideInterface>true</generateServerSideInterface>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<configuration>
<servicesXmlFile>${basedir}/src/main/resources/services.xml</servicesXmlFile>
<wsdlFile>${basedir}/src/main/resources/wsdl/HelloService.wsdl</wsdlFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>aar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<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>
</dependencies>
</project>
Now execute mvn generate-sources and refresh it, you will find new files created under target folder. look for the service.xml must be located at myHelloService2/target/generated-sources/axis2/wsdl2code/resources/services.xml
copy it to /myHelloService2/src/main/resources/
Now execute mvn eclipse:eclipse
Service Implementation
Now we must implement Hello_ServiceSkeletonInterface.javaCreate a new class MyHello_ServiceSkeleton.java
run mvn generate-sources
package com.nuwan.ws;Update service.xml to point to this new class at below line
import helloservice.examples.SayHelloDocument;
import helloservice.examples.SayHelloResponseDocument;
import helloservice.examples.SayHelloResponseDocument.SayHelloResponse;
public class MyHello_ServiceSkeleton implements Hello_ServiceSkeletonInterface {
public SayHelloResponseDocument sayHello(SayHelloDocument sayHello) {
SayHelloResponseDocument responseDocument = SayHelloResponseDocument.Factory.newInstance();
SayHelloResponse response = SayHelloResponse.Factory.newInstance();
response.setGreeting("Hi Nuwan How Are You?");
responseDocument.setSayHelloResponse(response);
return responseDocument;
}
}
<parameter name="ServiceClass">com.itcuties.ws.MyHighScoreServiceSkeleton</parameter>
Deploying
we can run mvn clean generate-sources package to create the aar package will be used at tomcat server. Now you should see a target\myHelloService2-0.0.1-SNAPSHOT.aar file created which should be copied to Tomcat 7.0\webapps\axis2\WEB-INF\services
Tomcat will automaticaly deploy it. Our new servive should be listing at http://localhost:8080/axis2/services/listServices
Testing
Testing can be done with the help of SoapUI which can be download free. Open SoapUI. Create a new soap project with http://localhost:8080/axis2/services/Hello_Service?wsdl url. Look for the Request in the side panal tree and hit run in the openned window. You will see <greeting>Hi Nuwan How Are You?</greeting>as the response.
mvn clean generate-sources package
run mvn generate-sources
http://axis.apache.org/axis2/java/core/download.cgi,#sthash.EwsFeSby.dpuf
http://axis.apache.org/axis2/java/core/download.cgi,#sthash.EwsFeSby.dpuf
http://axis.apache.org/axis2/java/core/download.cgi,#sthash.EwsFeSby.dpuf
http://axis.apache.org/axis2/java/core/download.cgi,#sthash.EwsFeSby.dpuf
http://axis.apache.org/axis2/java/core/download.cgi,#sthash.EwsFeSby.dpuf
Comments
Post a Comment