Thursday, December 15, 2011

Using WSO2 Registry Eventing for notification through an Executor

We will gonna do this through an Executor associated to a registry LC (Life Cycle) .

What we gonna do: We are going to create a simple registry LC associate a resource to it and write an Executor class which notify via email when that resource promote to its next state. To send email we use registry eventing functionality.

Executors are one of the facilitators which helps to extend the WSO2 GReg functionality. Here an Executor is associated to a registry life cycle. Life Cycle is basically a set of pre-defined states which can be associated to a registry Resource and allows that associated resource to evolve through that LC as defined. There users can basically do "Promote" and "Demote" a resource from one state to another.

You can write your own WSO2 GReg Executor class by implementing the org.wso2.carbon.governance.registry.extensions.interfaces.Execution interface. There you can override the execution method.

public class LCStateChangeNotificationExecutor implements Execution {
public void init(Map map) { }
public boolean execute(RequestContext requestContext, String s, String s1) {
// DO what you want to do when the resource change its LC state. Here we try to send an email notification to a subscriber.
sendEmail(requestContext);
return true;
}
}
Now lest see how to achieve the notification through registry eventing. Here we create a ResourceUpdateEvent and send that event to a subscriber resource which is a dummy resource where we manually subscribed to its update mode via my email. ( when state change happens to a resource, the executor gets HIT and it will send a Update Event to a dummy resource to which user is subscribed via email.)

UserRegistry registry registry = (UserRegistry) requestContext.getSystemRegistry();
ResourceUpdatedEvent resourceUpdatedEvent = new ResourceUpdatedEvent(CUSTOM_EMAIL_MESSAGE);

resourceUpdatedEvent.setResourcePath(SUBSCRIPTION_RESOURCE_PATH);
if (registry != null) {
resourceUpdatedEvent.setTenantId(registry.getTenantId());
}


Now Event instance is ready and only needs to sent it through registry NotificationService.

 org.wso2.carbon.registry.common.eventing.NotificationService.notify(resourceUpdatedEvent);

NOTE: Notification service is exposed as an OSGi service where that service included component class has getters and setters so that you can call the getRegistryNotificationService() method on that class which will return the NotificationService set by the eventing service.


Then you are done with the Executor class. Please add an entry inside to a LC state from which you want the Executor to be HIT when state change takes place.

So to define reference to Executor.
Now we have to define the Executor in our LC. Find the EventLifeCycle.xml.xml LC file under GREG_HOME/samples/sportmeet-scenario/src/resources.
(In the EventLifeCycle.xml.xml file we have added an entry for our executor inside the first state, because here, we want the executor to hit as soon as LC state promote from its initial state).
Here is the sample LC XML.
<aspect name="WSO2SportMeetEventHandler" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle">
<configuration type="literal">
<lifecycle>
<scxml xmlns="http://www.w3.org/2005/07/scxml"
version="1.0"
initialstate="Create">
<state id="Create">
<datamodel>
<data name="checkItems">
<item name="Created the Event" forEvent="Promote">
</item>
<item name="Announced the Event" forEvent="Promote">
</item>
</data>
<data name="transitionValidation">
<validation forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.validators.PromoteValidator">
</validation>
</data>
<data name="transitionExecution">
<execution forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.executors.LCStateChangeNotificationExecutor">
</execution>
</data>
</datamodel>
<transition event="Promote" target="Edit"/>
</state>
<state id="Edit">
<datamodel>
<data name="checkItems">
<item name="Add participants" forEvent="Promote">
</item>
<item name="Collect participant details" forEvent="Promote">
<validations>
<validation forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.validators.ParticipantValidator">
</validation>
</validations>
</item>
</data>
<data name="transitionValidation">
<validation forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.validators.PromoteValidator">
</validation>
</data>
<data name="transitionExecution">
<execution forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.executors.LCStateChangeNotificationExecutor">
</execution>
</data>
</datamodel>
<transition event="Promote" target="Review"/>
<transition event="Demote" targedt="Create"/>
</state>
<state id="Review">
<datamodel>
<data name="checkItems">
<item name="Not eligible participants removed" forEvent="Promote">
</item>
<item name="Extra participants removed(if maximum number exceeds)" forEvent="Promote">
</item>
<item name="All the participhants are not eligible for the Event" forEvent="Demote">
</item>
</data>
<data name="transitionExecution">
<execution forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.executors.LCStateChangeNotificationExecutor">
</execution>
</data>
<data name="transitionValidation">
<validation forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.validators.PromoteValidator">
</validation>
</data>
</datamodel>
<transition event="Promote" target="Accept"/>
<transition event="Demote" target="Edit"/>
</state>
<state id="Accept">
<transition event="Demote" target="Review"/>
<datamodel>
<data name="transitionExecution">
<execution forEvent="Promote"
class="org.wso2.carbon.registry.samples.sportmeet.executors.LCStateChangeNotificationExecutor">
</execution>
</data>
</datamodel>
</state>
</scxml>
</lifecycle>
</configuration>
</aspect>



For the notification part you must enable the axis2 TransportSender in GREG_HOME/reposiroty/conf/axis2.xml.


1. Now everything is ready and start the server.

2. Go to admin console.

3.Add a resource (which you provided as SUBSCRIPTION_PATH) and subscribe to it via email under update resource mode.

4 . Now add another resource and associate the service LC to it and do a promote.

5 When promoted, an email notification will be sent to your previously
subscribed email address.


References:





Monday, June 27, 2011

Configuring Eclipse to use OpenCV



This is how I figured out and which was succeeded in getting eclipse to work with Eclipse. This is a bit tedious, but can do this in 15 min :).





1. If you are not already installed Eclipse, first you have to install Eclipse. If you installing eclipse for the first time, better to install a version which supports C++. Instead, if you already have eclipse, only need to do is install the CDT C/C++ plugin for eclipse.

To install CDT plugin use the name as CDT and give an available source repository link. But I could only found "http://download.eclipse.org/releases/ganymede/" available as most of them are not available.

2. Now you have to install OpenCV if not yet installed. So there are few steps to follow to accomplish this.

Because Prebuilt binaries for Linux are not included with the Linux version of OpenCV owing to the large variety of versions of GCC and GLIBC in different distributions (SuSE,Debian, Ubuntu, etc.). If your distribution doesn’t offer OpenCV, you’ll have to build it from sources.

Follow these steps to download the source and build OpenCV.
There are some prerequisite packages to be installed

a) GCC 4.x or later.. you can install it from the following command
sudo apt-get install build-essential
b) And things like pkgconfig , subversion, cmake and etc.

2.1 First download the source. Go to http://sourceforge.net/projects/opencvlibrary and download the tar ball and unzip it to build. Else easiest way is to checkout the src from opencv svn repo .You can do it by simply following command, or choose a latest tag from the svn.

svn co https://code.ros.org/svn/opencv/trunk

2.2 Now have to build this by cmake. So go to your opencv source directory and make a directory to put generated make files.
i.e
mkdir binary
cd binary
cmake ../

2.3 Now go to that binary directory
make
sudo make install

3. Now everything is fine and you can create a C++ project and use opencv.
But before that there is one other thing to do. We have to tell our project where opencv headers and libraries are located in.

3.1 For that purpose, go to Project > Properties goto C/C++ Build and goto Settings > Tool Setting tab.
3.2 There in GCC C++ Compiler in "Includes" or "Directories" you will find an option "-l" to fill. 3.3 Add the path where you installed the opencv in above steps.
3.4 Now go to GCC C++ Linker and set the opencv distribution lib to "Library Search path -L".
3.5 Also in the Libraries -l , add the libraries you want to use. Following are useful set of libraries.
  • opencv_core
  • opencv_imgproc
  • opencv_highgui
  • opencv_ml
  • opencv_video
  • opencv_features2d
  • opencv_calib3d
  • opencv_objdetect
  • opencv_contrib
  • opencv_legacy
  • opencv_flann
4. And now ITS ALL FINE....:-) Happy coding with OpenCV..

For more information please visit

Wednesday, June 8, 2011

How to create a Apache Tuscany SCA component for Apache PhotArk



Apache PhotArk is an open source rich photo gallery application where you can do many things what a typical photo gallery app can do as well as some additional features such as it contains a Google app engine to function in cloud. Apache Tuscany is what PhotArk uses for message passing bridge between front and and back end under Service Component Architecture. This is how you do $Title.

  • Step-1
In Tuscany way first you have to put and SCA component entry to the Tuscany composite, which is in photark, named as web.composite.xml.

 













  • Step2
In Photark web app, there is a sca-contribution.xml file for each of your PhotArk module. So There you have to define the packages you use externally as well as you own package name. So suppose I dont have any dependent external packages to import my service component implementation class. Then your sca-contribution.xml file can be something similar to this.









NOTE : If you are using a brand new PhotArk module, make sure you add the dependency of it not only to the parent pom, but also to the pom inside photark-webapp as well, because in deploying it on tomcat, maven can't find your dependency if you don't add it to this pom.
  • Step 3
Now everything is ready. Make sure you use proper annotations for your service component interface and its implementation. For instance, @Scope("COMPOSITE") for the impl and @Remotable for the interface.
  • Step 4

Call your service through JSON, in PhotArk we make JSON calls through DOJO. So to use the service use the absolute binding url (in composite you define the relative path only..visit constant.js file in PhotArk and you will find the absolute path..)

i.e add PhotArk context root to your tuscany binding url.

In this example it should be /photark/FaceRecognitionService?smd . NOTE : make sure you add "smd" param as well.


I think now its done :) Enjoy Apache products.





Sunday, May 29, 2011

How to obtain a Facebook access token to use face.com functionality

This is simple and here are the steps to follow.

1. Go to http://www.facebook.com/developers/apps.php/ page and create a new app and obtain your FB appID, api key and api secret.

2. If not, you have to create a face.com account and obtain a face.com API key, secret pair.

3. And register this FB api key and secret with your face.com API key. You can go to edit account settings in face.com and apply this.

Use app ID to fill client_id(i.e client_id=appID) to follows with redirect url and get the auth token. AND SKIP THE expire time variable also.
NOTE: Redirect_url should be in the same domian you specified your app in FB.

https://graph.facebook.com/oauth/authorize?
type=user_agent&
client_id=your_FB_APPID&
redirect_uri=http://abc.com/&
scope=user_photos,email,user_birthday,user_online_presence,offline_access

Out put of redirect url can be something like this and obtain the access token and use this to access the API.

http://face.com/about.php/#access_token=2242657575991sadasdasf1faf9%7C2.%7CYwds6rrGtfpOi7c&expires_in=0

Tuesday, July 6, 2010

Configuration to mount MySQL data sources on a standalone tomcat server

There are loads of google searches for $Title.So following steps will guide you ,how to do that with a sample testing web app.

1. Gather requirements :
  • Tomcat 5.5 or above
  • MySQL database server
  • Connector: mysql-connector-java-3.1.7-bin.jar
2. Place the mysql connector in CATALINA_HOME/common/lib

3. Create your own sample web app say "myApp".

4. Then place this XML Context tag entry in server.xml (CATALINA_HOME/conf/server.xml) inside .........



Note that ,the username ,password are your MySQL credentials.

5.Then we have to tell the server container where is our jdbc data source is , when running our web app.So for that we have to enter the following resource ref tag entry in your web.xml.


6. Then you only have to do is make a datasource and get a connection with a MySQL DB in your webapp ,say inside a jsp and call it.Here is the code

/**


*/

THATS IT.SIMPLE............ENJOY J2EE.......!


Wednesday, June 23, 2010

Webservices and Axis

These days web services are becoming so popular and used in a wide area.Putting up a web service is not something like rocket science. Basically what it does is exchanging data through the Internet in a XML based format which we call "SOAP" (Simple Object Access Protocol).SOAP is meant for exchanging data in a distributed environment, and SOAP is built on XML

So we can say SOAP is a mechanism for inter-application communication between systems written in arbitrary languages, across the Internet. SOAP usually exchanges messages over HTTP.These SOAP messages exchange structured information between SOAP systems and they consist of one or more SOAP elements inside an envelope, Headers and the SOAP Body.So here Axis is an Open Source SOAP server and client which is an Apache project.

Axis implements the JAX-RPC API, one of the standard ways to program Java services.Here we will be talking more about JWS which stands for Java Web Services.

For instance lets say ,a java class which has a method "adder" to add two supplied values.At the end of this article you will find it really easy to expose this adder as a web service.

Lets get in to the action :Now we are going to deploy a web service with Axis.

Step-1:

You need to download and install Axis.For this please follow the install.html under docs directory in your binary distribution of axis.In brief what you have to do is that , copy the axis directory inside your Axis downloaded distribution in to your current web server's webapp directory (it is recommended to have a Apache Tomcat web server)

Step-2:

Also you have to copy any XML parser in to the axis/WEB-INF/lib directory .It is also recommended that to use Apache Xerces parcer and you can download it from here.

Step-3:

Start your web server.And you can simply check whether the installation has succeeded by simply requesting for http://localhost:8080/axis .

Thats it for now.

Above steps are to setup the axis environment.But how we deploy our web service.

Lets take a look at this sample Adder class .

public class Adder {

public int adder(int a, int b) {

return a+b;
}
}

Only you have to do here is that , create this class and name it as Adder.java and copy it in to axis directory and rename it as Adder.jws.This is how your "adder" method becomes a web service under axis framework.

Lets implement a small client to connect to the web service and invoke it.Here is a simple client class for you to run and test how this works.


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

import java.net.*;

public class AdderServiceClient {
public static void main(String [] args) throws Exception {

Service service = new Service();
Call call = (Call)service.createCall();

String endpoint = "http://localhost:8080/axis/Adder.jws";
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName("getCount"));

int a = 12;
int b = 13;
int count = 0;

int total = (Integer)call.invoke(new Object [] {new Integer(a), new Integer(b)});

System.out.println("Got result : " + total);
}
}


Please note that ,what we need to specify is the URL of the jws-file and the name of the method to invoke. Of course we also need to give the two strings with the division and team names. The convention is that they must be given as an Object array.

Now you will see the result as "Got result : 25"

This is a very simple demonstration of how JWS works.

Regards
/subash

Thursday, May 20, 2010

Compiz keyboard short cuts

Desktop Effects1 Keyboard Shortcuts
Rotate Cube Mousewheel on Desktop
Switcher2 Alt + Tab
Shift Switcher3 Super + Tab (2 modes: flip and cover)
Ring Switcher Super + Tab – overrides Shift Switcher
Expo Super + E (toggle)
Film Effect Ctrl + Alt + Down Arrow4
Rotate Cube Manually Ctrl + Alt + Left Mouse Button
Scale Windows Alt + Shift + Up Arrow
Show/Clear Desktop Ctrl + Alt + D (toggle)
Snapping Windows Move a window across workspaces5
Screenshot Super + Left Mouse Button
Zoom In/Out Super + Mousewheel
Transparent Window Alt + Mousewheel
Resize Window Alt + F8
Move Window Alt + F7
Add Helper Super + P
Widget Layer F9 (toggle)
Water Effects Shift + F9 (toggle)
Fire Effects: On Super + Shift + Left Mouse Button
Fire Effects: Clear Super + Shift + C
Annotate: Draw Super + Left Mouse Button
Annotate: Start Super + 1
Annotate: End Super + 3
Group: Select Window(s) Super + S
Group: Group Windows Super + T
Group: Ungroup Windows Super + U
Group: Flip Windows Super + Right or Left Arrow