Powered By Blogger

Oct 14, 2013


Developer Studio - Tutorial

Let's consider a scenario of a Health Care Organization. This organization provides some facilities as a service to the customer who is consuming the services via a Mobile Application. Customer wants to find the details of the nearest health care center/facilities based on his/her geographical coordinates (longitude and latitude). Let's assume that there is no direct mapping between the coordinates and the Healthcare facilities. Apparently, the organization has 3 different services namely 'Geo Service' , 'HC Facility Locator Service' and 'Health Care center Information Service' which are exposed as SOAP services. So, this is a typical service integration scenario, where we need to integrate these 3 services and expose the integrated business functionality as a single service.  

Considering the incremental development, our goal is to resolve the coordinates which sent by the customer and find-out the matching Healthcare Center details, so the message sends to the 'Geo Service' to resolve the zip code from the given coordinate. This example shows the implementation of a customer sends a message which goes through a proxy service to the Geo Service and sending back the response to the customer.

Creating a New ESB Project 

  • Open Developer Studio Dashboard and select 'ESB Config Project' under the Enterprise Service Bus category.
  • If you want to create this ESB project from existing configuration files, select 'Point to Existing Synapse-configs Folder'. Otherwise select 'New ESB Config Project.
  • Give a unique name for the project. (If you select the option to point to an existing Synapse-configs folder, then give a name and click Browse to navigate to the folder containing the configuration files) Optionally specify the location where you want to save the project (or leave the default location specified). You can optionally specify the working set, if any, that you want to include in this project. 
  • A Maven POM file will be generated automatically for this project. If you want to include parent POM information in the file from another project in this workspace, click Next, click the Specify Parent from Workspace check box, and then select the parent project.
  • Click Finish.
  • If you specified a folder with existing configuration files, specify whether you want to open those files now 


The new ESB project has been created in the workspace. If you browse inside the project, you will see a project structure as below, with folders created for different resources such as endpoints, local entries, proxy services, and sequences.



Message Mediation

  • Create a new custom proxy by right click on the created ESB config project( new -> proxy service -> Create a new Proxy Service) and name it as 'HCCProxyService'. Select the Proxy Service Type as 'Custom Proxy'.

  • Since the original request from the client comes to the 'InSequence' of the proxy service, let's consider the implementation of the inSequence. First from the tool pallet drag and drop a 'Property Mediator' for longitude to the inSequence of the proxy service.



  • Then change its properties. When editing the Value Expression it will pop up a Namespace Property Editor and insert the namespace property, namespace as follows and then click Add and then OK.


  • The properties window will displays as follows 

  • Create another property mediator to extract the value of latitude as well.
  • Then drag and drop a 'Log Mediator' to verify that the values are properly extracted

  • Then edit its properties . When editing the 'Properties' property it will pop up a Log Mediator Configuration window and edit it as follows



  • Now we have extracted the required values, in order to create a new Geo Service request we may use XSLT, PayloadFactory or Enrich mediators. We have used Enrich mediators in this example. Drag and drop three Enrich Mediators and edit its properties. The source will look like this

            <enrich>
                <source clone="true" type="inline">
                    <geo:getZipCode xmlns:geo="http://geo.wso2">
                        <geo:longitude>0</geo:longitude>
                        <geo:latitude>0</geo:latitude>
                    </geo:getZipCode>
                </source>
                <target action="replace" type="body"/>
            </enrich>
            <enrich>
                <source clone="true" property="longitude" type="property"/>
                <target action="replace" type="custom"
                        xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:longitude/text()"/>
            </enrich>
            <enrich>
                <source clone="true" property="latitude" type="property"/>
                <target action="replace" type="custom"
                        xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:latitude/text()"/>
            </enrich>






  • Then drag and drop Log Mediators for verification.
  • Finally modify the HCCProxyService's inSequence by specifying the send mediator with 'GeoEP' and the receiving sequence as 'hcfrequest.


  • This is the full configuration of the inSequence of the HCCProxyService

         <inSequence>
                <property action="set"
                          expression="//heal:getHealthcareCenterInfo/heal:longitude/text()"
                          name="longitude" scope="default" type="STRING" xmlns:heal="http://healthcare.wso2"/>
                <property action="set"
                          expression="//heal:getHealthcareCenterInfo/heal:latitude/text()"
                          name="latitude" scope="default" type="STRING" xmlns:heal="http://healthcare.wso2"/>
                <log category="INFO" level="custom" separator=",">
                    <property expression="$ctx:longitude" name="Longitude"/>
                    <property expression="$ctx:latitude" name="Latitude"/>
                </log>
                <enrich>
                    <source clone="true" type="inline">
                        <geo:getZipCode xmlns:geo="http://geo.wso2">
                            <geo:longitude>0</geo:longitude>
                            <geo:latitude>0</geo:latitude>
                        </geo:getZipCode>
                    </source>
                    <target action="replace" type="body"/>
                </enrich>
                <enrich>
                    <source clone="true" property="longitude" type="property"/>
                    <target action="replace" type="custom"
                            xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:longitude/text()"/>
                </enrich>
                <enrich>
                    <source clone="true" property="latitude" type="property"/>
                    <target action="replace" type="custom"
                            xmlns:geo="http://geo.wso2" xpath="//geo:getZipCode/geo:latitude/text()"/>
                </enrich>
                <log category="INFO" level="custom" separator=",">
                    <property name="MessageFlow" value="===== Sending Request To : GeoWS ========="/>
                </log>
                <log category="INFO" level="full" separator=","/>
                <send receive="hcfRequest">
                    <endpoint key="GeoEP"/>
                </send>
            </inSequence>
 
  • Since we are describing only the message sending to the Geo Service in this example just drag and drop an empty send mediator without an en endpoint for the outsequence




Oct 10, 2013

Developer Studio - Getting Started


Accessing Developer Studio

You can access Developer Studio features by using the Developer Studio Dashboard. From the Eclipse Welcome page, you can click 'Open Dashboard', or if you are already in the workbench, click the Developer Studio menu and select Open Dashboard.When the dashboard appears, you can scroll down to view the available links to all features of Developer Studio. 



Additionally you can choose File -> New -> Other and select an item from the WSO2 category.






If you have an existing project, you can right-click on the project, choose New, and then choose one of the WSO2 options from the menu.







Quick Start Guide

This includes fundamentals of Developer Studio to develop WSO2 projects in Eclipse.
  • Creating New Projects
  • Importing Existing Projects
Creating New Projects
Let's assume AcmeSuper is a shopping complex with branches in the cities of Colombo, Galle, and Kandy, and you want to create a different SOA application for each of the different locations. You have folders on your local file system, one for each location, that are synched with branches in your source control system (such as SVN), so you want to create the SOA application projects in those folders.

First, to follow along with this example, create a folder called AcmeSuper anywhere on your file system with three subfolders: Colombo, Galle, and Kandy. These folders represent the location where your source code is checked out.
Next, create an Apache Axis2 Service in the Colombo branch by following these steps:
  1. In Eclipse, choose Developer Studio -> Open Dashboard to display the dashboard (if it's not already visible), and then click the Axis2 Service Project link.
  2. In the Axis2 Service wizard, specify whether you want to create the service manually (the first option) or from a WSDL. For this example, leave the first option selected.
  3. Click Next, and then specify the following:
    • Unique names for the project, package, and class you are creating for this service.
    • Clear the check box and specify the path to the Colombo folder followed by the project name. This will ensure that you're creating the project in the same directory as your existing source code and will make it easier to check the files into your source control system.
    • If you want to add this project to any working sets, select the check box and specify the working sets. For this example, we won't specify any working sets.

  1. Click Next if you want to view the Maven-related information, which is filled in for you automatically, or just click Finish.
Now you can see the new project has been created in the workspace.


All the relevant files have created in the Colombo folder in your local file system, which makes it easy to check the changes to your source control system.

You can create a container project at the root level, and all the projects underneath it, will be displayed under that project. For example, you might create a general project called AcmeSuper at the root level and make sure you clear 'use default location' check box and specify the path to the AcmeSuper folder.



When the project is created, it includes the AcmeConsumerServiceColombo service which we already created.




You can now create additional applications in the folder structure by right-clicking a folder and choosing 'New' followed by the type of application you want to create. For example, to create a data service inside the Kandy branch, right-click the Kandy folder in the project explorer and choose New -> Data Service Project.


After you create your applications, you can group them by creating Carbon Application Projects. Choose File -> New -> Other and select Carbon Application Project. Depending on your requirements, you could create separate Carbon Application Projects for each and every branch such as one for Colombo, one for Galle, and one for Kandy, or you could create a single Carbon Application Project for your root project such as AcmeSuper. You can then generate Carbon Application Archives (CAR), which can be deployed to Carbon Servers.


Importing Existing Projects

If you want to create a project within a hierarchy of existing projects created by another developer, you must import those projects. For example, assume one of your developers created a project called Parent with several sub projects under it and checked it into your source control system. If you want to add projects under the Parent project, first make sure you have the latest version of this source code, and then do the following:
  1. Right-click the Project Explorer in Eclipse and choose Import -> Import.
  2. In the Import dialog box, expand the WSO2 category, select Existing WSO2 Projects in to workspace, and click Next.
  3. In the Import Projects dialog, click Browse, select the directory where the Parent project resides on your local file system, and click OK.
  4. The Import Projects dialog now displays all the WSO2 projects in the Parent project you selected. Select the projects you want to import into your workspace and click Finish.
The projects are now imported into your workspace, and you can create projects within this hierarchy as described in the previous section.

Building from Source

WSO2 invites you to contribute by checking out the source from the Subversion (SVN) source control system using the following commands, building the product and making changes, and then committing your changes back to the source repository. For information on using Subversion, see http://svnbook.red-bean.com.
  • Checking out the source
    • Access through a proxy
  • Building the product
  • Committing your changes
Checking out the source

You can use the svn checkout command to download the trunk or a specific branch of Developer Studio to the directory you specify. For example:

Trunk: svn checkout https://svn.wso2.org/repos/wso2/trunk/tools/ide/eclipse/ wso2devstudio
3.2.0 branch: svn checkout https://svn.wso2.org/repos/wso2/branches/tools/eclipse/developer-studio/3.2.0/ wso2devstudio320

Access through a proxy

The Subversion client can be configured to access through a proxy. Specify the proxy to use in the "servers" configuration file in: 
  • "~/.subversion" directory for Linux/Unix
  • "%APPDATA%\Subversion" hidden directory for Windows. (Try "echo %APPDATA%")
The comments in the file explain what to do. If you don't have this file, get the latest Subversion client and run any command. It will create the configuration directory and template files.
For example, edit the 'servers' file and add something similar to the following:

[global]
http-proxy-host = your.proxy.name
http-proxy-port = 3128
Building the product


Following are the commands you can run to create complete release artifacts of WSO2 Developer Studio, including the binary and source distributions.

Before you build:
  • Install Maven and JDK.
  • Set the environment variable MAVEN_OPTS="-Xms768m -Xmx3072m -XX:MaxPermSize=1200m" to avoid the Maven OutOfMemoryError.
  • Make sure the build server has an active Internet connection to download dependencies while building.
  • Switch to the directory where you checked out Developer Studio before entering these commands.

Committing your changes

If you are a committer, you can commit your changes using the following command (SVN will prompt you for your password):

$ svn commit --username your-username -m "A message"

May 1, 2013

More Tech Tips !!!: JADE MessagesWhen concerning a multi- agent syste...

More Tech Tips !!!: JADE Messages
When concerning a multi- agent syste...
: JADE Messages When concerning a multi- agent system we can see that individual agents are communicating and interact with each other....

JADE Messages


When concerning a multi- agent system we can see that individual agents are communicating and interact with each other. Basically this happens through exchanging messages between agents. It is essential that agents should agree on a format and semantics of the messages. Jade follows FIPA standards so that Jade agents could interact with agents written in other languages and running on other platforms.

The intended recipients, the sender, the message type and content are some basic parts of a message. In JADE, messages are strictly stick to the ACL (Agent Communication Language) standard. JADE also supports FIPA's SL (Semantic Language), which allows the content to be serialized Java objects.

Structure of a JADE Message:

  • Performative: FIPA message type:
            INFORM      - One agent gives another agent some useful information
            QUERY        - To ask a question.
REQUEST    - To ask the other to do something.
PROPOSE    - To start bargaining.
AGREE        -  For positive answers.
REFUSE      -  For negative answers. 

  • Addressing:
            Receiver
Sender
  • Content - Main content of the message.
  • ConversationID - Used to link messages in same conversation.
  • Language - Specifies which language is used in the content.
  • Ontology - Specifies which ontology is used in the content.
  • Protocol - Specifies the protocol.
  • ReplyWith - Another field to help distinguish answers.
  • InReplyTo - Sender uses to help distinguish answers.
  • ReplyBy - Used to set a time limit on an answer.

When you create a message, you have to indicate its type, its performative you have to and set the content:

ACLMessage msg = new ACLMessage( ACLMessage.INFORM );
msg.setContent("Hello Seller Agent…" );

Mar 22, 2013


Functions in Python



Functions of Python performs specific task. By using functions we can reduce the duplication of code and can also increase the clarity of the code.  Functions can be assigned into variables, stored in collections or can pass as arguments.

Built-in functions and user defined functions are the two basic types.  Some of the examples of built-in functions are dir(), len() and abs().  The user defined functions are functions created with the ‘def ’  keyword.

The ‘def ’ keyword is followed by the function name with round brackets and a colon.  You can include the indented statements inside the body of the function.

def function_one():
    return ("hello")

When we call the function as function_one()the statements inside the function’s body are executed and gives the output as ‘hello’.

Functions can be defined inside a class those functions are known as ‘methods’.  A function can be defined inside the module (the file which we put the Python code) also the function can be defined inside another function and it’s called an “inner function”.

Methods:
class First_Class:
        @staticmethod
        def f():
        print “f() is a method”

Functions inside the Module:
def f():
        print “f() is a function”

Inner Functions:
def g():
        def f():
        print “f() is an inner function”
        f()


           

Mar 1, 2013


Behaviours 


When concerning the job done by agents it is basically carried out within “behaviours”.  Behaviours are created by extending the jade.core.behaviours.Behaviour class. If you want to make the agent execute a task then you should create an instance of the corresponding Behaviour subclass and call the addBehaviour() method of the Agent class. Each Behaviour subclass must implement following methods.
  •   public void action():  what the behaviour actually does
  •    public boolean done(): Whether the behaviour is finished or not

 There are some Behaviour types as listed below.

  •  “One shot” behaviours.

The class is jade.core.behaviours.OneShotBehaviour . This completes immediately and the action() method is executed only once. Their done() method simply returns true.

  • “Cyclic” behaviours.

The class is jade.core.behaviours.CyclicBehaviour. This never completes and their action() method executes the same operation each time it is invoked. Their done() method simply returns false.

  • “Complex” behaviours.

This completes when a given condition is met.  Embed a state and execute in their action() method, different operation depending on their state.

Feb 27, 2013


What is JADE?

JADE or Java Agent Development Framework is a free software which is completely implemented using Java language and the minimum requirement is version 1.4 of JAVA. This basically simplifies debug and development process of multi agent systems since this uses a middle-ware and a set of graphical tools.  The configuration can be controlled through a remote GUI. Another advantage is the configuration can be changed at run time when moving agents between machines.

Jade creates containers for agents and those containers can be either on same system or different systems. Platform is a collection of containers. Each platform should have a Main Container which has two specialized agents called AMS agent and DF agent.

  • AMS (Agent Management System) - This is the only agent who can create and kill other agents, it can kill containers and also shut down the platform.
  • DF (Directory Facilitator) - This implements yellow pages service which advertises the services of agents in the platform, therefore other agents requiring those services can find them.