Monday, July 14, 2008

How to access HTTP headers from an Axis2 service implementation class

I have seen some users in axis user mailing list ask the question on how to access HTTP headers of the request SOAP message using the service implementation class.
It's easy and straightforward with messageContext class.
Lets see with an example.

1. Create a service implementation class as follows

import javax.servlet.http.HttpServletRequest;

import org.apache.axis2.context.MessageContext;

public class TestService {

public String MyOperation(String s){

MessageContext msgCtx = MessageContext.getCurrentMessageContext();
HttpServletRequest obj =(HttpServletRequest)msgCtx.getProperty("transport.http.servletRequest");
System.out.println("Acceptable Encoding type: "+obj.getHeader("Accept-Encoding"));
System.out.println("Acceptable character set: " +obj.getHeader("Accept-Charset"));
System.out.println("Acceptable Media Type: "+obj.getHeader("Accept"));
return s;

}
}

As you can see in the highlighted statements, first we need to get the current messageContext. Then from the messageContext, we can get the HTTPServletRequest object from which we can get whatever HTTP headers we want.

2. Write service descriptor(services.xml) for the above service class and deploy the service in Axis2 (If you are not familiar with Axis2 deployment, please read Axis2 user's guide )

3. Invoke the service in RESTful manner
http://:/services/TestService/MyOperation?s=hi

You will see the following in Axis2 run time console.

Acceptable Encoding type: gzip,deflate
Acceptable character set: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Acceptable Media Type: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Saturday, July 12, 2008

How to monitor messages using tcpmon in Axis2 dual channel web service invocation

Apache Axis2 client API provides the necessary methods to utilize a service using two transport channels. You can even send request through one transport (e.g:- HTTP) and get the response back via a different transport such as TCP.

setUseSeperateListener(boolean) method of org.apache.axis2.client.Options
class can be used to utilize a separate listener for your response.
If two separate HTTP transport channels are used for request and response, Axis2 starts a new HTTP listener at the client side to receive the incoming response message.

As most of web service developers know, Apache tcpmon can be used to monitor message flow between web service invocations. In one way messaging, it is quite straightforward.
You just need to configure tcpmon to listen in some port and direct the messages to the port where the web service is hosted. In client, port of the endpoint reference has to be changed to tcpmonitor listen port. That's all you have to do for monitoring messages in single channel invocation.

In this post, you can see how tcpmonitor is configured to use in dual channel invocation.

1. If you have not done it yet, download Apache tcpmon from here
Unzip the downloaded file and run build/tcpmon.bat {sh}

2. As I stated before, Axis2 starts a http listener at the client in dual channel invocation. Therefore, you need to configure Axis2.xml to redirect messages to tcpmon as follows.

Open AXIS2_HOME/conf/axis2.xml and locate to the following section.

<!-- ============================================ -->
<!-- Transport Ins -->
<!-- ============================================ -->
<transportReceiver name="http"
class="org.apache.axis2.transport.http.SimpleHTTPServer">
<parameter name="port">8080</parameter>
<!-- Here is the complete list of supported parameters (see example settings further below):
port: the port to listen on (default 6060)
hostname: if non-null, url prefix used in reply-to endpoint references (default null)
------------
-->
<parameter name="hostname">http://localhost:8090</parameter>
<!-- <parameter name="originServer">My-Server/1.1</parameter> -->
----------
</transportReceiver>

3. Note the highlighted elements in the above axis2.xml configuration. First you have to uncomment the hostname paramter <parameter name="hostname"> and specify a port which is not already listened in your system (e.g:- 8090).

In tcpmon, create a new listener with 8090 as the listen port and 8080 as the target port. With this configuration, the response messages receive to the reply-to endpoint reference are directed to 8090 tcpmon port and then those will be targeted to client HTTP listener port, 8080.



Now, you should be able to monitor the response flow in dual channel invocation.

Monday, July 7, 2008

How to Deploy Apache Axis2 on IBM WebSphere

As I mentioned in a previous post, the flexible deployment mechanism of Axis2 allows you to install it on any application server with minimum configuration effort.
Lets see how Axis2 can be deployed on IBM WebSphere.

Pre-requisites:
Download and install IBM WebSphere 6.1
Create a profile as specified in the WebSphere installation steps

I will use Axis2-1.4 and WebSphere6.1 for demonstration purposes. But you should be fine with the other versions too.

Step 1
Download Axis2.war from here

Step 2
Start WebSphere server (In windows XP menu All programs--> IBM WebSphere-->Application Server 6.1 --> profiles --> YourProfile -->Start the Server)

Wait until start window closes.

Step3

Access WebSphere administration console
(In windows XP menu All programs--> IBM WebSphere-->Application Server 6.1 --> profiles --> YourProfile-->Administrative Console)

Log in to administration console (You should have configured username and password for admin console when creating WebSphere profile)

Step 4

In the left navigation menu of the WebSphere administrative console, select Install New Application
Enter the path of the Axis2.war file (Browse for axis2.war in your file system)
Enter 'axis2' as the context root for application (See the image below) and click on 'Next'



Step 5

In the Select installation options page, keep the default values and click.
Map modules to servers page will be displayed. Select Apache Axis2 module and click Next.
You will be directed to the Map virtual hosts for Web modules page. Select Apache-axis2 web module and click Next.
You should see a Summary page similar to the one given below. Click 'Finish' to complete installing Axis2.war on WebSphere.



You will get 'Application axis2_war installed successfully.' message in the next page. Click on Save to persist changes directly to the master configuration.

Step 6

Now we have to start the installed Axis2.war. Click on Enterprise Applications link in the left navigation menu.

Select Axis2.war and click on Start button. You will see the axis2.war started successfully message as in the following image.



Step 7

Now open a browser and go to http://localhost:<port>/axis2
Axis2 welcome page will be displayed.

Step 8

Verify the status of installation. Click on 'Validate' link. You should see the following 'Axis2 Happiness' page.



That's all!. If you encounter any issues with deployment, please drop a mail charitha@wso2.com


Friday, July 4, 2008

Why is quick learning ability extremely important for QA?

Quick Understanding of software product requirements and technologies around them are important qualities expected from any engineer. However, I believe
it is THE most important and must-have skill for a QA engineer. Why is that?

In theory, a QA cycle is supposed to start with test analysis and design. Requirements specifications/design specs are the ultimate references to derive test scenarios and
test cases in test analysis/design phase. But those reference materials are not always available in early stages of the development and in some projects you don't even see such docs.
Even if you have the documented requirements and design docs, you don't get the feel of actual business flow and scenarios until you play around with the
working instance of the product. There were thousands of test cases written by referring to functional specs, however the real business
scenarios may have missed due to the lack of understanding of the domain and nature of the product.

When the initial builds are released for QA testing, you will get a better knowledge of the product and its domain while you play around the features of product.
You will start to realize the functional flows documented in test scenarios (which were derived using requirement specs) and sudden requirements to aware of new technologies will arise.
However you don't get much time to learn every bits of business domain and related technologies with the frequent test build releases.

This is where your quick learning ability comes in to play. If QA engineer possesses;
-grasp things with minimum time
-eager to find out how it works
-Love to read
then I always believe such QA engineer is capable to move forward in a challenging environment.

Remember, QA is expected to act as user's advocates and should know what and how the product functions. Therefore catching the things as quickly as possible
and apply them in testing are key to deliver a successful QA outcome.

Thursday, July 3, 2008

WSDL2Code UI tool - Easy and efficient code generation utility

If you are an Apache axis2 user, you may already familiar with WSDL2Java code generation tool. WSO2 WSAS is powered by Apache Axis2 and includes a rich set of features to interact with web services. WSDL2Code is a UI based tool integrated with WSO2 WSAS which allows users to generate code from a WSDL hosted in a remote server or a local file system.
Lets see how WSDL2Code tool makes web service developement effort much easier and productive.

Step 1
Download and Install WSO2 WSAS

Step 2
Start wso2wsas. Go to WSAS_HOME/bin and run wso2wsas.bat{sh}

Step 3
Go to http://localhost:9762
Welcome page of the WSAS console will be displayed. Click on WSDL2Code at the left navigation menu. You will be directed to the following screen.



You can see multiple code generation options in the above screen. These code gen options are similar to the command line options available in WSDL2java tool.

Step 4
Lets generate client stub against default version service using the above tool.
Enter 'http://localhost:9762/services/version?wsdl' in the -uri option available on the top of the page.
Select -uw option and click on 'Generate'
It will prompt to save the generated zip file (e.g:- 1.2151049949841125E12.zip). Save it in a directory in your local file system.

Step 5
Unzip the generated file (You will see src folder, build.xml and pom.xml in the extracted directory) and go to the directory where you extracted the zip file.
Assuming your IDE is eclipse, enter the following command to export the generated code in to eclipse and setting up WSAS libraries at once.

mvn eclipse:eclipse


(If you have not installed maven2, download it from here and add maven_home/bin to your PATH)

You will see 'BUILD SUCCESSFUL' message at the end of executing above command.

Step 6
Open eclipse and go to Window-->Preferences-->Java-->Build path-->Classpath variables
Create a new variable, M2_REPO and enter your maven2 repository path as the value. (maven2 repository is located at user home directory. e.g:- C:/Documents and Settings/Charitha/.m2/repository)
(Note that this step has to be done only once. If the M2_REPO variable is already defined, you can ignore this step)

Step 7
In eclipse, select File-->import-->Existing projects into workspace-->next
Browse root directory of the extracted zip file above. Click 'Finish'.
New project will be added to the workspace with an id like N10001-version. You should see that all the necessary WSAS libraries are added to the project.

Now the only remaining step is to write client to invoke version service as follows

public class VersionClient {

public static void main(String[] args)throws Exception {
VersionStub stub = new VersionStub();
System.out.println(stub.getVersion());
}

}

You may realize how WSO2 WSAS reduce the complexity of web service invocation with these kind of tools. Even if you are beginner to the world of SOA, WSO2 WSAS can be considered as the best paltform to get started with minimum effort.

Monday, June 30, 2008

How to deploy Apache Axis2 on Resin and JBoss application servers

Axis2 can be deployed very easily on most of the application servers. Lets see how we can deploy axis2 on JBoss and Resin application servers.

Deploying Axis2 on Resin application server

1. Download and install Resin from here

2. Download Axi2.war

3. Copy axis2.war to RESIN_HOME/webapps (i.e:- D:\resin-3.1.6\webapps)

4. Start Resin server
Go to RESIN_HOME/lib and enter the following command to start the server
java -jar resin.jar start

5. Open a browser and issue http://localhost:8080/axis2
Axis2 welcome page will be displayed.

6. Verify the status of installation. Click on 'Validate' link. You should see the following 'Axis2 Happiness' page.



Deploying Axis2 on JBoss

1. Download JBoss
(I used JBoss 4.2.2 GA but the same procedure can be applied for any version)

2. Download Axi2.war

3. Copy axis2.war to JBOSS_HOME/server/default/deploy

4. Start JBoss (Just execute JBOSS_HOME/bin/run.bat or run.sh)

5. Jboss will explode and deploy Axis2 when starting the server. Exploded directory can be found at JBOSS_HOME/server/default/tmp/deploy/tmpXXXXaxis2-exp.war (i.e:- D:\jboss-4.2.2.GA\server\default\tmp\deploy\tmp46684axis2-exp.war)

6. Open a browser and access http://localhost:8080/axis2
Axis2 welcome page will be displayed.

6. Check whether the installation is successful. Click on 'Validate' link. You should see the following 'Axis2 Happiness' page.

How to avoid "Unable to generate EPR for transport" error in Axis2

"Unable to generate EPR for transport: http" is a FAQ in Axis2 mailing list. You may have experienced this when invoking a service using generated stubs.

Solution:

It's really simple. When creating the instance of stub, pass the actual service end point (epr) to the constructor as follows.

YourserviceStub stub = new YourserviceStub("http://<IP>:<PORT>/axis2/services/YourService")


Ideally when u generate a stub for a service it will pick up the Endpoint reference from the WSDL. So just instantiating stub with YourserviceStub stub = new YourserviceStub() could send the request to the address defined in the WSDL. In case you get the "Unable to generate EPR for transport: http" error, give a try with the above as well.