Apache Axis2, the third generation Web services engine is more
efficient, more modular and more XML-oriented than its predecessor
Apache Axis. It is
carefully designed to support the easy addition of plug-in modules
that extend its functionality for features such as security and
increased reliability On the other hand, Eclipse is a project aiming to provide a universal
tool set for development. It is an open source IDE that is mostly
provided in Java, but the development language is independent and not
limited in any way. It is the most widely used IDE for most computer
languages, especially for JAVA.
Using Web Services we can publish our application's functions to
everyone. This tutorial provides step by step instructions to develop
Web Services using Axis2 Web Services / SOAP / WSDL engine and Eclipse
IDE. Let's start. In Order to Develop a Web Services We need to Configure our working Environment for Development. here we are going to Develop a Web Service Using Axis2 So we need Setup for that
System Requirement
System Requirement
These are the tools used in the tutorial.
1) Java Development Kit (Download)
2) WSO2 Developer Studio (Download)
3) Apache Tomcat (Download)
First We need to Configure
Java_HOME
and TOMCAT_HOME
and Path also
JAVA_HOME :- Set the value to jdk directory (
export JAVA_HOME=/home/rajjaz/Documents/jdk1.8.0_45
)
TOMCAT_HOME :- Set the value to top level directory of your Tomcat install (export
TOMCAT_HOME=/home/rajjaz/Documents/apache-tomcat-6.0.44
)
PATH :- Set the value to bin directory of your jdk (e
export PATH=$JAVA_HOME/bin:$PATH
)
After our Environment Setup We need to create a Dynamic Web Project in Eclipse in Order to Run the Samples of Axis2 Engine. Here is the Point WSO2 Studio Going to Help us. in WSO2 Developer Studio Many Plug-In's are already integrated for Web Services Development and Its have more Features
So First Go to New-->Dynamic web Project or New-->Other..-->Dynamic web Project Because We are going to Run Server Client Communication so its want to be an Dynamic web Project Then we will get the window like Below one
So in the New Dynamic web Project Window Select the Target runtime as Apache Tomcat and in Configuration click Modify and we will get the Project Facets window
In Above option panel select Axis2 Web Services also for the Project and Click OK and FINISH
Now we are Created a Java Dynamic Web Project Successfully
Now Copy the Sample Folder in axis2-1.6.2 --> samples --> servicelifecycle --> src --> sample and Copy the files with the folder and past it into the our project java Resources --> src folder it will become like below one
Then we need to add web services to our Project so select the project and as same as Earlier New-->Other..-->web services
select server runtime as Tomcat and web Service runtime as Apache Axis2 and Click Next
In the Above window its show as we are going to Develop our Service in Bottom up java bean web Services type . In Web services terminology, Bottom Up (Code First) is used where the developer starts with the business logic, which is the code, and then develop and deploy the code as a Web service. The Top Down (Contract First) approach starts from the Web service descriptions, which is the WSDL, and then goes on to expose the Web service R
Then we need to create a Service.xml file for the Project in this scenario Let's choose default Service.xml file but this is the important point we need to node in the activity .The description of services are specified using services.xml. Each service archive file needs to have a services.xml in order to be a valid service and it should be available in the META-INF directory of the archive file.
Sample Services.xml file
<service name="name of the service" scope="name of the scope" class="full qualifide name the service lifecycle class" targetNamespace="target namespase for the service"> <Description> The description of the service </Description> <transports> <transport>HTTP</transport> </transports> <schema schemaNamespace="schema namespace"/> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <parameter name="ServiceClass" locked="xsd:false">org.apache.axis2.sample.echo.EchoImpl</parameter> <operation name="echoString" mep="operation MEP"> <actionMapping>Mapping to action</actionMapping> <module ref=" a module name "/> <messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/> </operation> </service>
So in our Project we just created new Services.xml file so it's doesn't know about about project so need to copy our own Services.xml file into this project
axis2-1.6.2/samples/servicelifecycle/src/META-INF/services.xml
After Replace the Services.xml file Successfully Now Run the Server Project As Run on Server If it's Deployed Successfully we will get the Below output on Browser with the Name LibraryService with available services Then Click LibraryService Link and get it's URL http://localhost:8080/LibraryServiceCycle/services/Library?wsdl it will need when we create the Client for this project
This is the Wsdl File Created From out Source Code and it will Contain all the information about our Services and End Point Reference also
Now create New Dynamic Web Project For the Client Service as well as we created earlier in the same way create new Project but with the Different name. here we can add client part also in the same project but for the better understand and experience I'm developing both as separate projects. Now here copy the Client Folder in axis2-1.6.2 --> samples --> servicelifecycle --> src --> Client and Paste it into Java Resources --> src after it will be look like below one
Now we will get the new window. in that window it will ask the Service definition our service definition is in our wsdl file so here we need to add our wsdl URL. our Service definition url is we already copied from web browser http://localhost:8080/LibraryServiceCycle/services/Library?wsdl Type or Paste it in given space and as same as earlier one select server runtime as Tomcat and web Service runtime as Apache Axis2 and Click FINISH
Until Now we setup the Running Environment now time to Run the Sample Project So here Select the Client package and run it as java application but here we can run the project from the project folder it will ask the running class so we can directly run from the client package
Now Client Works Correctly .if it's correctly then in console now Type the End point Reference Address That will be the same as Wsdl addres except ?wsdl http://localhost:8080/LibraryServiceCycle/services/Library
Now Client Program Will ask the Service we need from the Library Service Server. Let's try to list all books are available in the library then we need to press 1 if our system work properly we will get the below output
Now We are Successfully Running the Server Client Web Services using Axis2 and Tomcat in Eclipse IDE
Source Code
1.Client
2.Service
References
No comments:
Post a Comment