Wednesday, May 28, 2014

Call a web service from HTML

Goal :
The goal for this post is to know how exactly we call a web service in html page (Service and HTML should be hosted in the same server).

Pre-Requisites :

  • There should be a web service which is hosted in the server. 
  • One should have knowledge on what are the parameters to be sent to call a web service or at least know how to use a SOAP UI to call a web service.
  • Basic html knowledge.
Explanation :
  • Know the web service to be called
You have to know the parameters of the web service to be called. Below are the parameters which are to be known (Assuming the web service is in the same server where the html file is being developed),
1. End point
2. SOAP Request
3. Content Type

If the above parameters are not known these can be taken from soap UI or from Fiddler as shown below

Below picture gives a brief idea on how to get End Point and SOAP Request from SOAP UI

Below picture gives information on how to get End Point, SOAP Request and Content Type from Fiddler.

There are other ways of getting these information like network tab of chrome's developer tools etc., These are just few ways of getting these information. However the goal here is to get the parameters not how do we get. Once we have this information we go ahead by writing simple html page.
  • Write a simple HTML Page
Below is the sample page how do we write it.

  • Write a function which calls a web service and display it on the browser

function soap() {
            var xmlhttp = new XMLHttpRequest();
  'POST', 'http://dhl-hyd1024/cordys/com.eibus.web.soap.Gateway.wcp?', true);
            // build SOAP request
            var sr =             
                '<SOAP:Envelope xmlns:SOAP="">'+
                        '<sty:GetXMLObject xmlns:sty="">' +
                            '<sty:key version="isv">/OAuthIntegration/RedirectorContent.xml</sty:key>' +
                        '</sty:GetXMLObject>' +
' </SOAP:Body>'+
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
document.getElementById('responseXML').innerHTML = xml_to_string(xmlhttp.responseXML);
                        alert('done use firebug to see response');

Note : xml_to_string here is a function which is irrelevant here.

Highlighted sections are variable parameters (important variable parameters). These parameters should be replaced by the parameters what we have collected in the previous sections.

However this way of communication is not JQuery based which I would suggest to use in order to be in recent industrial terms.

Monday, May 26, 2014

Log from Java method in WSO2 Framework

Pre-Requisites :

Application server should be up and running.
   Ø  Should be able to write a simple java method using eclipse.
   Ø  One should have knowledge on how to deploy the service from java methods.
   Ø  Should be able to test the service after deployment.

Steps :

    Ø Write a simple Custom Java method by following syntax.

  import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;

 private static Log eventLogger = LogFactory.getLog(HelloDH.class);

   Ø  Create a jar and deploy it in the application server (Or Any other way of deploying the java methods onto application server).

   Ø  Test and check for the logs.

o   Test the service by searching for the web service and once tested,You can check for the log as shown in the below screenshot.

You can even find the logs in file system. For ex., "
E:\Kiran\Softwares DH\WSO2\WSO2\wso2as-5.2.1\wso2as-5.2.1\repository\logs"

Sunday, May 25, 2014

Execute a web service from JMeter

 How to fire a simple SOAP Request from JMeter:
Goal :

This document describes how do we fire a web service (SOAP) which are hosted in a server (in this scenario I have considered cordys service).

Pre-Requisites :

   Ø  We need to first have which service to be tested.
   Ø  JMeter to be up and Running so that service can be tested.

Steps :
Open JMeter UI (First step of testing will be done from here)

You can increase number of threads and all the configuration so as to test your load. For now I am going ahead with 1 thread which implies 1 user who is testing the service.

Give the details of HTTP Request as shown below. I have highlighted the necessary things to be filled in order to execute a SOAP request.

Once you have filled in all the parameters you have to click on the green button which is highlighted. But in order to view the results you need to have other artifacts.

View Results Tree Sample :

This is a failed scenario. The below one would be success scenario

This one is the success scenario (It is just a sample to show how the success and failed scenarios would be seen although I have modified the request so that the service is successful which is not the point of discussion here.) 

View Results in Table Sample :

Similarly there are many other ways of having the statistics using this tool. 

I hope this gives a kick off for how to start your exploration on using this tool. 

Friday, May 23, 2014

Learnings from WSO2 Framework : Application Server