Friday, September 13, 2013

Convert XML String to OMElement and extract values

A simple tip which saves a lot of your time...
You can simply convert XML string to an OMElement as below

      OMElement resultElement = AXIOMUtil.stringToOM(xmlString);


Extracting values from XML


Sample XML code


        Gambardella, Matthew
        XML Developer's Guide
        Computer
        44.95
        2000-10-01
        An in-depth look at creating applicationswith XML.
    
    
        Ralls, Kim
        Midnight Rain
        Fantasy
        5.95
        2000-12-16
        A former architect battles corporate zombies,an evil sorceress.
    
    
        Corets, Eva
        Maeve Ascendant
        Fantasy
        5.95
        2000-11-17
        After the collapse of a nanotechnologysociety in England.
    
    
        Corets, Eva
        Oberon's Legacy
        Fantasy
        5.95
        2001-03-10
        In post-apocalypse England, the mysteriousagent known only as Oberon.
    


Java code to retrieve values


OMElement resultElement = AXIOMUtil.stringToOM(xmlString);

        Iterator i = resultElement.getChildren();
        while (i.hasNext()) {
            OMElement book = (OMElement) i.next();
            Iterator properties = book.getChildren();
            System.out.println("====== book =======");
            while (properties.hasNext()) {
                OMElement property = (OMElement) properties.next();
                String localName = property.getLocalName();
                String value = property.getText();
                System.out.println(localName + ": " + value);
            }
        }


Result

====== book =======
author: Gambardella, Matthew
title: XML Developer's Guide
genre: Computer
price: 44.95
publish_date: 2000-10-01
description: An in-depth look at creating applicationswith XML.
====== book =======
author: Ralls, Kim
title: Midnight Rain
genre: Fantasy
price: 5.95
publish_date: 2000-12-16
description: A former architect battles corporate zombies,an evil sorceress.
====== book =======
author: Corets, Eva
title: Maeve Ascendant
genre: Fantasy
price: 5.95
publish_date: 2000-11-17
description: After the collapse of a nanotechnologysociety in England.
====== book =======
author: Corets, Eva
title: Oberon's Legacy
genre: Fantasy
price: 5.95
publish_date: 2001-03-10
description: In post-apocalypse England, the mysteriousagent known only as Oberon.

Sunday, July 21, 2013

Get started with WSO2 App Factory

AppFactory is an elastic and self-service enterprise DevOps platform to mange applications from cradle to grave. This is a 100% free and open source solution developed by WSO2 which covers the whole lifecycle of an application. You will be facilitated by all the required resources for the application created in one go. Just use ones, you will see the difference :)

Getting started is very simple. It is all online running on cloud. But I will go through step by step, so you do not miss anything.

Create an account

Click the 'Register' link in App Factory live URL
You need to fill the following form to get registered.


Do not worry about the phone number field, just give some number there if you do not like to put the actual number.

If your registration is successful you will be asked to check your email.

Change the default password

Using the URL sent to your email address given at register time, log in to the system and change password.
(Remember, that log in URL can be used only ones and you need to change the default password in that log in)


Then we will change the default password with the one you gave


 Log in to AF

Use this link and log into the system using your new password. You will see the following page just after the log in.



But wait for few seconds, we are creating a default application for you :)



When you navigate to the application that just now got created, you will see the set of features and the functionalities that are bound with your application. 



I will discuss about how to manage the applications with App Factory in a recent post.


















Thursday, November 1, 2012

Write your first Axis2 service


In this post I will describe on how to create a simple HelloWorld axis2 service by following three simple steps.
  1. Implement the service class
  2. Create the services.xml file
  3. Pack the service as .aar file archive
Implement the service class
    First we need to create the service class and the service methods. We will create HelloService.java service class and sayHello operation as shown below.


Create the services.xml file

    services.xml is a configuration file which all the axis2 web services must have.
    Create a META-INF directory and create the services.xml file inside the META-INF directory.
    You should define the service class as a parameter in services.xml

                 Your project structure will look like the following.



Pack the service as .aar file archive

    Compile your service class using javac command.
                  ie: javac HelloService.java -d ./ 
    
    Get a copy of your META-INF directory and the compiled .class file of the service to a temp
    directory. Now the tree structure of those should be as follows.


    Create an archive file with the META-INF directory and the compiled .class file of the service
    class and rename the archive to a .aar   
    
    Now you have a deployable axis2 service with you.












Friday, October 26, 2012

Get started with WSO2 Stratos Live and deploy your first axis2 service.


WSO2 Stratos Live is a complete open source PaaS and Cloud Middleware Platform.
To get a space in Stratos what you need is only an internet connection :)
By following the below mentioned steps you can have a your own service up and running in Stratos Live.

  1. Register to Stratos Live
    Visit WSO2 Stratos site and click on 'Get Started Now For FREE' button to create an account and a domain for your tenant. You have to fill the registration form with the relevant information.



    The admin username and the domain name is used as the login username.
    The e-mail address you enter should be a valid one. A verification e-mail is send to that email address and you have to verify your email address by following the instructions in the mail.

  2. After the verification you can log in to the Stratos manager page using the username and password given when registering.

    Now you have logged in to your domain in Stratos Live.

  3. The services provided in Stratos for your tenant can be seen there. Click on Application Server to deploy an axis2 service in Application Server.



  4. In the 'Main' tab of the left menu you can see the service types that you can add. Click on Axis2 Service under Web Services → Add



  5. Upload your service archive by choosing the .aar file.
    ( You can read on how to create a simple axis2 service from this article )

  6. Now you have deployed your axis2 service in Straots Live. You can access it by 'List' under Web Services in left menu.

  7. Click on 'Try this service' and you can try the deployed service.

Saturday, October 20, 2012

How to Deploy WSO2 Stratos Locally

WSO2 Stratos is a complete open source PaaS where you can use any of the WSO2 products as a service. This article describes how to set up WSO2 stratos locally by following few simple steps.


Prerequisites

mysql
following perl modules

  • File::Copy ( sudo apt-get install libfile-copy-recursive-perl )
  • File::Path (sudo apt-get install libfile-path-perl )
  • File::Basename (sudo apt-get install libfile-basedir-perl )
  • XML::LibXML (sudo apt-get install libxml-libxml-perl
    • You many need to install libxml2-dev first- sudo apt-get install libxml2-dev)
  • Archive::Zip ( sudo apt-get install libarchive-zip-perl )
  • Getopt::Std (sudo apt-get install libgetopt-declare-perl )
  • List::MoreUtils ( sudo apt-get install liblist-moreutils-perl )


Introduction


WSO2 Stratos is a complete open source Platform as a service (PaaS). You can use any WSO2 product through WSO2 Stratos Live which is the public online platform. And now you have the capability of deploying WSO2 Stratos in your personal computer by executing just a few simple steps. You can deploy WSO2 Stratos as a private cloud in your local machine with any of the WSO2 services required. Following are those service names with the terms that you can use to indicate them at the deployment time.


Service Name
term
WSO2 Stratos (Manager)
manager
WSO2 Business Process Server
bps
WSO2 Business Activity Monitor
bam
WSO2 Application Server
as
WSO2 Identity Server
is
WSO2 Enterprise Service Bus
esb
WSO2 Governance Registry
greg
WSO2 Data Service Server
dss
WSO2 Gadget Server
gs
WSO2 Mashup Server
ms
WSO2 Business Rules Server
brs
WSO2 Complex Event Processing Server
cep
WSO2 Message Broker
mb



Applies To

Service packs of version 1.5.2


Downloading Binaries

  • First you have to download the binaries of the services that is required to deploy as services. The binary files of WSO2 Stratos services can be found in WSO2 Stratos release page.
  • Download the required binary files listed under ‘Stratos Packs’.
  • By running the WSO2 Stratos setup script which can be downloaded from here

you can simply setup WSO2 Stratos in your machine in few minutes.


 Preparing to Setup WSO2 Stratos


  • Now you are ready to deploy WSO2 Stratos in your machine with the binary files that you have already downloaded. First copy all the binary files of the required services to one directory, e.g home/usr/stratos/packs.


Run the Script


  • Now by simply executing the setup script and following the instruction given you can deploy stratos. For that use terminal and navigate to the build directory that you have checked out now.
  • Give execute permission to the setup script by running chmod 755 ./stratos-setup.pl
  • Run the following command with the required fields filled.

./stratos-setup.pl -p -t -v "" -s -d -l "" -c -u -w

-p : path to stratos packs directory (here /home/usr/stratos/packs)

-t : path that you want to deploy stratos ( Note that you should give the location of an   empty directory. If not the script will delete all the files/directories inside that given directory )

-v : version of the packs. ( All the packs should have the same version)

-s : whether you want to enable single sign on
If you put '-s true' you must deploy IS pack and to start any other service, you need to start IS. The advantage is that you would be able to to access any other server that you have started, without entering user credentials.
-d : whether to create the database. (At the first time you deploy stratos you should set this to true to create the relevant database and the tables)

-l : names of services that you need to deploy. These names should be separated by a space. If you want to deploy IS,manager and greg put ‘-l is manager greg’

-c : path to stratos_config_min.xml ( It is in the checked out 'build' directory )

-u : database username

-w : database password

(ex : ./stratos-setup.pl -p /home/usr/stratos/packs -t /home/usr/stratos/deploy -v "1.5.2" -s false -d true -l "is manager greg" -c ./stratos_config_min.xml -u myusername -w mypassword )
This script will setup the services locally.


Adding Entries to /etc/hosts


You will be informed to add the following lines to /etc/hosts file.
127.0.0.1 cloud-test.wso2.com
127.0.0.1 identity.cloud-test.wso2.com
127.0.0.1 governance.cloud-test.wso2.com
127.0.0.1 appserver.cloud-test.wso2.com
127.0.0.1 monitor.cloud-test.wso2.com
127.0.0.1 data.cloud-test.wso2.com
127.0.0.1 process.cloud-test.wso2.com
127.0.0.1 rule.cloud-test.wso2.com
127.0.0.1 cep.cloud-test.wso2.com
127.0.0.1 esb.cloud-test.wso2.com
127.0.0.1 gadget.cloud-test.wso2.com
127.0.0.1  messaging.cloud-test.wso2.com
127.0.0.1 mashup.cloud-test.wso2.com

By adding the entries to /etc/hosts file you can complete the stratos local deployment process. The deployed services will be in the deployment directory. ( here in /home/usr/stratos/deploy )


Starting Services

  • You can start any service by navigating to the bin folder of that service ( /home/usr/stratos/deploy//bin ) and running the command ./wso2server.sh
  • To start all WSO2 Stratos services in one command, navigate to the deploy folder ( /home/usr/stratos/deploy/ ) and run ./stratos.sh start all and to stop ./stratos.sh stop all

Friday, April 22, 2011

Distributed Resource Broker

Hi friends, today I’m going to share about a very interesting project that I am currently involving with. It’s about developing a Distributed Resource Broker. This is an application that is useful in managing large volume of data in data intensive applications. The intension of this application is to store and manage huge number of large size files in a distributed system. The resource broker will handle all the tough part of the work including replica management and give an abstract view to the user where the user can simply upload, download, delete and search the files uploaded by him.

The network is a peer to peer (P2P) network and we are using an existing peer to peer substrate FreePastry for this purpose. We will be exposing an API with those above mentioned functionalities where a java client or a web client can use our API and customize our service.

I’ll present you some more details about this Distributed Resource Broker in future :)

Monday, April 18, 2011

Implementing a Lexical Analyzer and Parser

I recently involved in implementing a lexical analyzer and a parser. These were implemented to tokenize and parse a defined language “C-“ with specified conventions and grammar. For this I used JavaCC which is a lexical analyzer generator and a parser generator. The intension of the lexical analyzer was to tokenize the given input file. It will reject the input file if it is not according to the conventions of the C- language. The tokens generated in the lexical analyzer were used for parser. Parser will check the sequence of tokens and validate the grammar for C-.

Here I simply came with two files, LexAnalyzer.jj for tokenizing the input file and validate the generated tokens with C- specified tokens and MyParser.jjt file with the specified the grammar rules for the defined language and to validate whether the input file has been written in accordance with C- grammar. JavaCC which generates all the underline code, made my job much easy.

LexAnalyzer.jj
MyParser.jjt