Archive for category Axis2

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

Leave a comment

Axis2: Deploying webservice onto Axis2


1. Download Apache Axis2 war distribution and Axis2 Binary distribution as well. Axis2 can be downloaded from

http://axis.apache.org/axis2/java/core/download.cgi In this case, i used Axis2 1.6.1.

2. Download latest tomcat from http://tomcat.apache.org/ and unzip onto c:\tomcatx. Lets assume it is c:\tomcat7

3. Unzip Axis2 war distribution, and copy axis2.war onto C:\tomcat7\webapps

4. open run command and navigate to C:\tomcat7\bin and start the tomcat by typing startup.bat

5. Upon starting the tomcat, you can notice that the axis2.war file that was copied earlier, gets exploded into directory structure. Later on, we want .aar file to be copied to C:\tomcat7\webapps\axis2\WEB-INF\services to deploy a webservice onto the tomcat server

6. Now lets start to build .aar file to be deployed onto the above directory. For this unzip the Axis2 binary distribution and extract it to a directory lets say, c:\axis2161 (i downloaded axis2-1.6.1-bin and named it accordingly)

7. Now, do not forget to set AXIS2_HOME environmental variable to point to C:\axis2161\ and also add %AXIS2_HOME%  to the path.

8. Our goal is to deploy the quickstart sample app that gets shipped with Axis2, onto application server.

9. If you do not have ant installed on your machine, download ant from http://ant.apache.org/bindownload.cgi, in our case it is ant apache-ant-1.8.2-bin.zip

10. Set the environmental variable for ant, NOTE: Ant 1.8.2 has an issue with environmental variable setup, setup the system path variable directly as ;C:\ant182\bin;

11. Open run command, cd to c:\axis2161\samples\quickstart

12. quickstart example comes with ant build.xml, run the command ant generate.service. You should see build successful

c:\axis2161\samples\quickstart>ant generate.service
Buildfile: c:\axis2161\samples\quickstart\build.xml

compile.service:
[mkdir] Created dir: c:\axis2161\samples\quickstart\build\classes
[javac] c:\axis2161\samples\quickstart\build.xml:42: warning: ‘includeantrun
time’ was not set, defaulting to build.sysclasspath=last; set to false for repea
table builds
[javac] Compiling 1 source file to c:\axis2161\samples\quickstart\build\clas
ses
[javac] Note: c:\axis2161\samples\quickstart\src\samples\quickstart\service\
pojo\StockQuoteService.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

generate.service:
[copy] Copying 1 file to c:\axis2161\samples\quickstart\build\classes
[jar] Building jar: c:\axis2161\samples\quickstart\build\StockQuoteService
.aar
[copy] Copying 1 file to c:\axis2161\repository\services

BUILD SUCCESSFUL
Total time: 9 seconds

13. Navigate to URL http://127.0.0.1:8080/axis2/axis2-admin/ and login with admin as login and axis2 as password

14. Under upload services at http://127.0.0.1:8080/axis2/axis2-admin/upload, upload the aar file generated in above step.

15. upon successful deployment of service, you should see the service under available services. If you are seeing the service to be in FAULT status, check my other post regarding version mismatch to resolve the issue.

16. Click on the service name, to get the WSDL

17. If you have SOAP UI or any other client, you can now test the generated WSDL and the services using the URL

http://127.0.0.1:8080/axis2/services/StockQuoteService?wsdl

 

 

 

 

Leave a comment

Error: org.apache.axis2.deployment.DeploymentException: The following error occurred during schema generation


Problem: Upon trying to deploy an aar file onto Axis2, service will be in fault status and the error log shows

Error: org.apache.axis2.deployment.DeploymentException: The following error occurred during schema generation: samples.quickstart.service.pojo.StockQuoteService at org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:150) at org.apache.axis2.deployment.ServiceDeployer.deploy(ServiceDeployer.java:82) at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136) at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:813) at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144) at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:370) at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:254) at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:364) at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:73) at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:94) at org.apache.axis2.deployment.scheduler.Scheduler$SchedulerTimerTask.run(Scheduler.java:93) at java.util.TimerThread.mainLoop(Timer.java:512) at java.util.TimerThread.run(Timer.java:462) Caused by: org.apache.axis2.deployment.DeploymentException: The following error occurred during schema generation: samples.quickstart.service.pojo.StockQuoteService at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:433) at org.apache.axis2.deployment.repository.util.ArchiveReader.buildServiceGroup(ArchiveReader.java:101) at org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:143) … 12 more Caused by: org.apache.axis2.deployment.DeploymentException: The following error occurred during schema generation: samples.quickstart.service.pojo.StockQuoteService at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:397) … 14 more Caused by: org.apache.axis2.AxisFault: samples.quickstart.service.pojo.StockQuoteService at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at org.apache.axis2.util.Utils.getServiceClass(Utils.java:804) at org.apache.axis2.deployment.util.Utils.fillAxisService(Utils.java:430) at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:389) … 14 more Caused by: java.lang.ClassNotFoundException: samples.quickstart.service.pojo.StockQuoteService at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:169) at org.apache.axis2.util.Loader.loadClass(Loader.java:261) at org.apache.axis2.util.Loader.loadClass(Loader.java:229) at org.apache.axis2.util.Utils.getServiceClass(Utils.java:801) … 16 more

Solution:

This is a problem with the java version being used and initially i was setting my java home to jdk1.7, upon setting JAVA_HOME environmental variable to point to jdk1.6 version instead, recreate the aar file and deploy on AXIS2, service will be deployed without any issues and will not be in fault status

1 Comment

Axis2M


Axis2M is a utility projects that simplify Axis2 web service development along with Maven. axis2M provide set of Maven artifacts and promote usage of j2ee web application project layout for axis2 development:

Axis2mhas following features.

  • quickstart archetype
    • provide easy start for Hello world axis2 web service only using few number of Maven commands . Also this genarate standred j2ee project layout for axis 2 peoject, and provide WAR pacakgeing option for both services and modules.
  • axis2m:run goal to to run Axis2 simple Http server
    • This Maven plug-in facilitates to run Axis2’s simple Http server with Maven, those who familiar with axis2 standard distribution can use same server.
  • axis2m:WSDL2Java goal to simplfy code genaration under Maven project
    • This is a customized version of Axis2 WSDL2Code maven plug-in; this will generate java codes with minimum number of configuration options and garneted code are compatible with Maven project structure.
  • Pre-configuration of axis2 ARR, MAR plug-ins for quickstart archetype.
    • Once the project is created using axis2m quickstart archetype axis2 AAR and axis2 MAR maven plug-ins are configured with project layout so that users not required configure POM file again.

This tutorial briefs the steps involved for Hello world axis2 web service only using few number of Maven command. Before running the below steps, it is assumed that maven is available on your path, if not set up maven on your environmental path.

1. Run maven archetype generate

mvn archetype:generate -DarchetypeCatalog=http://axis2m.sourceforge.net/repo

2. Choose options

3. From eclipse, select IMPORT EXISTINGECTS -> MAVEN -> Exiting Maven Projects

4.Click next, select quickstart:1.0:war

5.

6.

7.

thats it…it was a breeze to get started and see Axis2 in action in a short time..Run the client.java to hit the service.

Leave a comment

Axis2 + Log4j


Problem: How to enable Log4j logging inside Axis2

Solution: When application is deployed as .aar (axis archive) file, even if log4j settings are done properly and logging is enabled, there are cases where log file is either not generated or logging is not happening.

This can be resolved by checking out the Axis2 source code from apache website (instead of checking out the axis2.war)  and replacing the log4j.properties file with the custom log4j.xml and log4j.dtd and then build the  axis2.war using maven

1. Check out the axis2 source code distribution

2. Navigate to src/main/webapp/WEB-INF/classes

3. Locate and replace log4j.properties with your log4j.xml and log4j.dtd

4. Inside log4j.xml , FileAppender shall  look like this

<appender name=”FileAppender”>

<param name=”File” value=”logs/newlog.log”/>

<!–Other Params goes here –>

</appender>

5.  Now build the axis2.war and package the app as war file (using maven or so) to deploy axis2 inside
application container as a webapp. When the application container is started, axis2.war is exploded to axis2
directory

6. Upon the application is accessed, newlog.log will be created and the generated logs can be viewed, provided log statements
are available and set to appropriate levels like Debug for debugging.

,

Leave a comment