Skip to main content

Axis 2 WSDL to Java Approach

Axis 2 Tomcat Setup

Download Axis 2 war distribution from http://axis.apache.org/axis2/java/core/download.cgi

Now 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 myHelloService2

Use 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.java

Create a new class MyHello_ServiceSkeleton.java
run mvn generate-sources

package com.nuwan.ws;

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;
    }

}
Update service.xml to point to this new class at below line
<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

Popular posts from this blog

Oracle Database 12c installation on Ubuntu 16.04

This article describes how to install Oracle 12c 64bit database on Ubuntu 16.04 64bit. Download software  Download the Oracle software from OTN or MOS or get a downloaded zip file. OTN: Oracle Database 12c Release 1 (12.1.0.2) Software (64-bit). edelivery: Oracle Database 12c Release 1 (12.1.0.2) Software (64-bit)   Unpacking  You should have following two files downloaded now. linuxamd64_12102_database_1of2.zip linuxamd64_12102_database_2of2.zip Unzip and copy them to \tmp\databases NOTE: you might have to merge two unzipped folders to create a single folder. Create new groups and users Open a terminal and execute following commands. you might need root permission. groupadd -g 502 oinstall groupadd -g 503 dba groupadd -g 504 oper groupadd -g 505 asmadmin Now create the oracle user useradd -u 502 -g oinstall -G dba,asmadmin,oper -s /bin/bash -m oracle You will prompt to set to password. set a momorable password and write it down. (mine is orac

DBCA : No Protocol specified

when trying to execute dbca from linux terminal got this error message. now execute the command xhost, you probably receiving No protocol specified xhost:  unable to open display ":0" issue is your user is not allowed to access the x server. You can use xhost to limit access for X server for security reasons. probably you are logged in as oracle user. switch back to default user and execute xhost again. you should see something like SI:localuser:nuwan solution is adding the oracle to access control list xhost +SI:localuser:oracle now go back to oracle user and try dbca it should be working

Java Head Dump Vs Thread Dump

JVM head dump is a snapshot of a JVM heap memory in a given time. So its simply a heap representation of JVM. That is the state of the objects. JVM thread dump is a snapshot of a JVM threads at a given time. So thats what were threads doing at any given time. This is the state of threads. This helps understanding such as locked threads, hanged threads and running threads. Head dump has more information of java class level information than a thread dump. For example Head dump is good to analyse JVM heap memory issues and OutOfMemoryError errors. JVM head dump is generated automatically when there is something like OutOfMemoryError has taken place.  Heap dump can be created manually by killing the process using kill -3 . Generating a heap dump is a intensive computing task, which will probably hang your jvm. so itsn't a methond to use offetenly. Heap can be analysed using tools such as eclipse memory analyser. Core dump is a os level memory usage of objects. It has more informaiton t