Wednesday, May 23, 2012

JavaScript Services in Action in WSO2 Mashup Server



WSO2 Mashup Server can be used to create and host JavaScript based mashups, acting as a hub for integrating your enterprise with rich information available on the web. Each mashup hosted in here is exposed as a new web service, and can be consumed by other mashups or web service clients.



In this post I'm going to show you how to get started with a JavaScript service, and consume that service inside another JavaScript (A client) embedded in an HTML page.

The scenario I'm going to cover is, developing a JavaScript based service for getting stock updates, which retrieve the stock information by invoking another external web service , and writing a JavaScript client inside an HTML, which invokes the JavaScript service. 


Writing the service

1. Download WSO2 Mashup Server binaries and extract into a convenient location (Hereafter referred to as MS_HOME ) 

2.  The JavaScript service should be written as a standard JavaScript file, as  mentioned below


3. This JavaScript file (stockQuote.js) needs to be placed in the following location
    <MS_HOME>/repository/deployment/server/jsservices/admin

4. Start the server ($ sh /bin/wso2server.sh )

5. If the StockQuote service is deployed successfully it should be logged as "Deploying Web service: stockQuote.js" and verify through Management Console (https://localhost:9443/carbon/service-mgt/index.jsp?region=region1&item=services_list_menu, or http://localhost:9763/services/admin/stockQuote?wsdl)

6. After successfully starting up the server, note that a folder is created in     <MS_HOME>/repository/deployment/server/jsservices/admin with the name stockQuote.resources.
Create a new folder with the name "www" if such a folder is not there already. Service client related code should be place in that folder.


Writing Client code and Installing a custom UI

JavaScript clients can invoke services via generated stubs. The generated stub is again a JavaScript file. It can viewed as follows,
http://localhost:9763/services/admin/stockQuote?stub

1. The sample code of StockQuote service client is listed below, note that it is embedded in an HTML file (which is the UI of your service) and in the top you can see a reference to the generated stub is included. Save this as index.html file into the "www" folder created above.
<MS_HOME>/repository/deployment/server/jsservices/admin/stockQuote.resources/www



2. Access the UI of the as follows to test the functionality
        http://localhost:9763/services/admin/stockQuote/
     In the text box, input a Stock symbol (eg: GOOG, IBM, VRTU .. etc) and check the results



Troubleshooting

In some situations, the generated JavaScript stubs are having some issues (which are already identified and will be fixed in the next release)

In such a scenario, as a hack you can do the following.

1. Access the stub (http://localhost:9763/services/admin/stockQuote?stub) and save the stub file in <MS_HOME>/repository/deployment/server/jsservices/admin/stockQuote.resources/www location as "stockQuoteStub.js"

2. The "bf2xml" function of the stub is the culprit here, so as a fix replace the relevant code related to bf2xml function with the code below


3. In index.html file modify the line which has the reference to the stub, so remove the line
  

and add the following line instead
 


Note that, now it is referenced the modified version of the stub, which is in the www directory

4. Now the issue should be fixed.

Friday, August 26, 2011

A Spontaneous Ad-hoc network to Share WWW Access (Raquel Lacuesta et al.)

This is a summary of the research paper A Spontaneous Ad-hoc network to Share WWW Access, done by Raquel Lacuesta et al. I chose this paper to present in my MSc course module, Mobile Computing.

In this paper, authors have proposed a secure spontaneous ad-hoc network, based on direct p2p interaction, in order to achieve a easy, quick and secure WWW access to the users. According to them, they are the first group of researches to come up with a design and a simulation of spontaneous ad-hoc networks.

Their paper is structured as follows
  1. An introduction to spontaneous ad-hoc networks and relevant literature
  2. The model they have proposed.
  3. Auto configuration procedures used in their model.
  4. A mathematical analysis.
  5. Security related things.
  6. The protocol procedure and messages
  7. Comparison of the proposal with some caching techniques
  8. Validation of the model through simulation
  9. Summary of the work and conclusion

Introduction

A mobile ad-hoc network can be briefly defined as a group of wireless nodes collaboratively form a network, which operates without the support of a fixed infrastructure. Several applications of such networks are; data collection in sensor arrays, communication in hostile or disaster stricken environments. Main challenges present in ad-hoc networking are that those should operate independent of an access point infrastructure, where nodes are unreliable and unpredictable. Also, the network should be able to provide administrative services need to support applications despite the fact that it operate independent of a pre-configured or centralized network management infrastructure. This is different from an infrastuctured networks, where those services like address allocation, name assignment are handled by a central authority of global scale. Name resolutions, file system management, mail and web services are centrally administered. Many general applications are server-based and hence preconfigured by human administrators and network tools. But in ad-hoc networks those services cannot be centralized and preconfigured because the network population and topology is not known in advance and also unpredictability of the network causes configuration needed to be changed rapidly.

A spontaneous ad hoc network is a type of ad-hoc network which is formed in a certain time during a period of time, with no dependence on a central server and without the intervention of expert users in order to carry out a specific task. The network is built by several independent nodes and the nodes are free to enter the network as well as leave the network whenever required. An example for a spontaneous network is when a group of people get together and use wireless computing devices for some computer based collaborative task. In spontaneous networks, users do not need to identify all the participating human and devices or don't need to configure their devices in advance.

Main features of ad-hoc networks can be described as follows.
  1. Network boundaries are poorly defined
  2. The network is not planned
  3. Hosts are not preconfigured
  4. No any central servers
  5. Users are not experts
Another important thing about spontaneous networks are that the participating nodes are limited in resources and power. Caching techniques have used in this model in order to avoid the nodes being overloaded.


Spontaneous Network Proposal Description

When a device joins a network following steps must be followed
  • Device should be integrated into the network
  • Service and Resource discovery
  • Accessing the services discovered
  • Collaborative tasks
A quick creation and configuration is very important for the performance of spontaneous networks, in the model described here authors have followed a way which requires minimum human intervention when setting up the network.


Saturday, March 5, 2011

My Research Areas

Workflow Engines - BPEL / Apache ODE / Web services orchestration


Friday, September 24, 2010

Quick fix for Eclipse Galileo GDK issue in Ubuntu Karmic Koala

Due to an incompatibility issue with GDK windows kit in Eclipse Galileo version in Ubuntu Karmic Kola environment, some buttons of Eclipse IDE are disabled, which blocks users from creating a simple Java project in Eclipse.

There is a quick fix for this issue.

Write a wrapper script (eclipse.sh) including following lines
export GDK_NATIVE_WINDOWS=1 # This line contains the fix.
/home/sajith/Dev/IDE/eclipse/eclipse # This line is for executing eclipse.

Setting Your Development Environment in Ubuntu (10.04)

Setting JAVA_HOME variable

If .bash_profile file is not in the ~ directory, use .bashrc file instead.

export JAVA_HOME variables and add those to PATH as follows.

export JAVA_HOME=/home/sajith/Software/jdk1.6.0_19
export PATH=$PATH:$JAVA_HOME/bin



Creating a symbolic link for Java

When you are trying to start up eclipse and then If you getting an error like this

"A Java Runtime Environment (JRE) or Jave Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations"

you have to create a symbolic link to java should be created in /usr/bin

For that excecute the following command
$ ln -s /home/sajith/Software/jdk1.6.0_19/bin/java /usr/bin/java


Tuesday, April 13, 2010

Solving screen resolution nightmare in Ubuntu 9.10

Have u ever spending days nights to figure out setting the best resolution for your screen in Ubuntu? Since i have had that nightmare, searching forums all over the internet, trying various methods, but were able to solve that only after wasting 2 days. :) My VGA supports resolutions like 1600x1200, but in Ubuntu, by default it comes with only 800x600 and 640x480 options.


So, thought of sharing how to configure those with you all.


The problem is that Ubuntu ( Im using 9.10 ) doesnt detect your monitor by default, compared to some other OSs like CentOS, where you can select the monitor easily, which is not the case in Ubuntu. ( Actually im quite new to Ubuntu, so may be there s a way for Guru s to select the monitor, but i couldnt find a way)


And my Graphic Adapter is Intel 82865G. You can check the type of your VGA by this command

$ lspci


Here s what i did. ( Many thanks to the folks who have documented various methods.. bt this i found most useful for mehttp://www.arunviswanathan.com/node/53 )


( In many forums they were talking about the xorg.conf in /etc/X11 . But in my machine i couldnt find that file under /etc/X11 )

Following command will display current display settings
$ xrandr

Output ( My default settings - only displays
800x600 and
640x480 )
---------
Screen 0: minimum 320 x 200, current 800 x 600, maximum 2048 x 2048
VGA1 connected 800x600+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
800x600 60.3*
640x480 59.9


Then u should add the resulotion you need as a new mode, but before that you need to get other parameters required for this, unless the new mode will not be added properly. Therefore, execute the following ( The resolution you need to achieve, here for me its 1600x1200 with the refresh rate 59.9)

$ gtf 1600 1200 59.9

It generates the following output :
# 1600x1200 @ 59.90 Hz (GTF) hsync: 74.40 kHz; pclk: 160.69 MHz
Modeline "1600x1200_59.90" 160.69 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +Vsync


Now add the new mode with above generated parameters as follows

$ xrandr --newmode"1600x1200_59.90" 160.69 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +Vsync

Then add the above mode to your desired output ( In my case its VGA1 , as given by executing xrandr command. For you it may be different, so first execute xrandr and verify your output and use that output to execute the following command)

$ xrandr --addmode VGA1 1600x1200_59.90

Thereafter chose that as your resolution
$ xrandr --output VGA1 --mode 1600x1200_59.90

If everything went successfully, above resolution must be selected automatically now. :)

Even if you are successful, you need to go thru one final step to persist the changes so that its available at system startup ( otherwise vanishes after you logoff)

$ sudo gedit /etc/gdm/Init/Default

Look for the following lines
PATH=/usr/bin:$PATH
OLD_IFS=$IFS

Add the following lines below them (The mode you created above)
xrandr --newmode "1600x1200_59.90" 160.69 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +Vsync
xrandr --addmode VGA1 "1600x1200_59.90"
xrandr --output VGA1 --mode "1600x1200_59.90"


Save and Exit. Logoff and Log in .. now you must be able to use your new resolution :)

Sunday, April 11, 2010

ADSL Connection setup in Ubuntu (9.10)

Have you ever came across with any issue in setting up ADSL connection in Ubuntu?
if so here s the solution.

PPPoE package should be installed before. To verify that the package is intalled, type
$ dpkg -s pppoeconf

If it is installed you should see the output on the package where two lines show this:

Package: pppoeconf
Status: install ok installed

If the package is not installed, insert your Ubuntu CD and in a terminal type:

sudo apt-get install pppoeconf

If the package cannot be found, you may have to add your Ubuntu CD to the list of software repositories. To add your CD, make sure it is inserted in your CD drive and in a terminal type:

sudo apt-cdrom add
After successfully installing PPPoE package,

$ sudo pppoeconf

And a text based interactive menu is prompted. Provide the relevant information, and your connection is
set up now.

To start your ADSL connection on demand, in a terminal type:

$ pon dsl-provider

To stop your ADSL connection, in a terminal type:

poff dsl-provider