Nov 26, 2010

Apache Camel

" Apache Camel is a powerful open source integration framework based on known Enterprise Integration Patterns with powerful Bean Integration ".

So what is Enterprise Integration Patterns? In an enterprise they may use different software to do there task easily. But those software should interact with others and will not be isolated. Therefore, software must communicate with each other. But as an enterprise software, its communication is not so easy. To overcome this problem people use a common set of instructions or patterns when they implementing an enterprise solution. Most people use "Enterprise Integration Patterns" book and it describe about 65 categorise of integration patterns which was collected since 2002. Most of these patterns use asynchronous messaging architectures with the help of EAI, SOA, or ESB platforms such as  IBM WebSphere MQ, TIBCO, Vitria, SeeBeyond, WebMethods, BizTalk, Sonic, Fiorano, Mule ESB, ActiveMQ.

Beans Integration is, it provides a general purpose mechanism for processing messages using arbitrary Java objects. By using a bean reference into a route, you can call an arbitrary method on a Java object. From that you can access and modify the incoming exchange. So this bean binding mechanism is used in Apache Camel.

Then why we need camel? When you are designing an enterprise solution you need to use integration patterns and to implement that thing you may need to  use messaging modules like HTTP, ActiveMQ, JMS, JBI, SCA, MINA, etc. Camel create an easy environment to use these things, such as a pluggable data format option which can interact with other modules. It is a small library with less dependencies for easy embedding in any Java application. Camel can be used as a routing mechanism for Apache ServiceMix which is a powerful ESB and JBI container. So Camel can be used in complex enterprise integration solutions to do the job with less effort. 

Nov 25, 2010

Develop a BPEL project using Eclipse and Apache ODE.

To do this thing you need to install these software.
 Apache ODE on Apache Tomcat server and Eclipse IDE with BPEL designer plugin. 
First you should download and install tomcat web server.
http://tomcat.apache.org/download-connectors.cgi

Then you can download the ODE war file from this link;
http://www.apache.org/dyn/closer.cgi/ode/apache-ode-war-1.3.4.zip

Unzip this file and put that into the webapps folder in the tomcat.
Then you must restart the tomcat server.

After that you must install the Eclipse IDE (Eclipse IDE for Java EE Developers). You can download it from this website.
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/heliossr1

The run the Eclipse IDE and go to,
Help -> Install new software
Then in the window, add this URL to the space called "work with": http://download.eclipse.org/technology/bpel/update-site/

Then it will provide some plugins and you should install those things to your Eclipse IDE.

Now you need to setup the IED to communicate with the ODE. TO do that you must go to,
File -> New -> Other
and select "Server " in the server directory.
This will pop-up a new window,in that you must select,
apache -> Ode v1.x Server

This will ask some details according to your Apache-Tomcat and JDK setting of your machine.  Mainly you must give the path to the ODE field as;
path_to_tomcat/webapps/ode/


Then try to start the server from the IDE, first stop it from console if the server is running. 


Now you can try to design a project. First  go to, New -> Projects;
And there you should select BPEL -> BPEL Project
Then in the wizard you must select "Apache Ode v1.x Runtime" and in the configurations section select "BPEL2.0 Facets".


Then this will open a project folder, right click on that and select new -> other and in the wizard select BPEL -> New BPEL Process file.


Now you can see  some file like <something>.bpel, double click on it. It will open a graphical flow chart kind of a thing. In the right side  of that you can see some tools which can be use to design the process. Try these tools, but I will explain how to get a output from an input String. To do that thing;
You must insert "Assign" part in between the input and output. Then go to its properties by right clicking on it.
Then go to details and add a new. it  will show two fields to fill. In the first select input and click on "input:string", on the other select output and do the same. Then perss the save button. At this time it will ask some thing  like "Variable output doesn't have initializer. Should it be generated? ", In this, press "Yes" 
This step will create a file like <something>.wsdl, double click on it. It will view a network kind of a thing. You must edit the URL in the <project_name>Port to;
http://localhost:8080/ode/processes/<project_name>
And also you must select the protocol as "SOAP".


Save the project and right click on the main project folder. Go to  New -> Other and select "Apache ODE deployment Descriptor". This will generate a XML file called deploy.xml. You must double click and open it. In that select inbound Interface -> Associated Port and give the "<project_name>Port" in the drop down menu. If it does not excise, you  must restart the Eclipse IDE and all file names and project names must be equal. If there is no error you can try to run it.
To do that you must go to the Server, right click on it and select add/remove project. In the wizard you must add the project to the server and run it. If the server in not running, run it from the IDE by clicking the run button while the server is selected. 

Now  you can go to the project explore, select and right click on the  <project_name>.wsdl and go to;
web services -> Test with web service explore.
That action will view a web browser kind of an environment. In that you can see your project file, click on that and it will view a file call "process". Double click on that. In the next window you can insert a value and press go, you will see the same output from the below frame.


Our process was get a string and return it. So this done that thing. We can do more thing  by changing the process flow with the graphical aid. It is the amin advantage of this thing and this is a web based system, therefore it's more easy to manage and use.

Nov 23, 2010

Haskell for web development - web server for haskell

There are many web frameworks which use to develop web applications by using Haskell programming language. I will talk about "SNAP Framework".

Snap is a simple web development framework.It is very easy to install. To install this web framework you need to install GHC and Cabal-installer. Important thing is Cabal-installer must compatible with the GHC version. If both work correctly it will reduce lots of issues while installing the framework.

First you must update the cabal database by;
cabal update
Then try to install snap by;
cabal install snap-server

This will install all dependent packages which need by the snap-server. This may take some time to complete. If there is an error try to read and understand it. Most of the time those errors occur when the system is missing some dependent package and it should me manually installed. To get these packages try this website as possible as you can.
http://hackage.haskell.org/packages/archive/pkg-list.html

Then you need to install "expat library" which use in developments.
Use yum to install it.
yum install  expat-devel.i686

Now you should check if the path to the ~/.cabal/bin is in your path.
Then create a folder and do these steps.
mkdir test-snap
cd test-snap
snap init

This  will create a src directory and a file called test-snap.cabal. You may see three files in the src directory.

Now you can try to view this in your web browser. To do that, you need to run these command within the project root (inside the test-snap directory where you can see the.cabal file).

cabal install
test-snap 8000

Now you can visit the url http://localhost:8000/ to view he web page.

If you need to stop the server just press Ctrl+c.

Note:- When you are  creating a folder to build the project try to use a unique name like  [somethilng]-snap  or likewise. Because after the installation of the web site in will create an executable file in the ~/.cabal/bin, and that place is also available in the path variable.

Nov 16, 2010

visualizing the way we communicate over a digital network.

These days we are using internet and other small digital networks as a common media to communicate. Sending a short message from your mobile phone to a VoIP conference call, it use a digital network. There are various methods each technology use to communicate each other. But most of these technologies use a common method to pass their message from one place to another through a digital network.
Data cannot travel through a network as a hole. It should know its destination, and how to get there. So to do these things service need to add some more information to the original data. So now this combined data set is called as a "packet" (also as a datagram, a frame, ect.). 
Many data packets contain more information according to the technology (protocol) that it use to communicate. There is a software to view these information of a packet called as "Wireshark".
First of all you must install wireshark on your machine. You may need root permission to do this. Download it from their website http://www.wireshark.org/ and install it.
Then try to run it as root. Running wireshark as a root or a supper user is the best way to capture packets. At least you should grant sudo  permission to run the wireshark.
Now you can run the wireshark. In that window you will see 4 main rows. First row contain all tools, second will display the live packets which a communicating with the interface, next will display details of a selected data packet and the last will display it's hex value. In the initial step you will see an empty rows but to view information you must select some thing.
As the  first time we are using wireshark we can try with our localhost  interface.
To select an interface you must click the button called "List available interfaces" and it will display a list of available interfaces. Select  "lo" or "localhost" and apply. Then open a terminal and type;
$ping localhost

what you can see on the wireshark, It should be like this;

5    2.001518    127.0.0.1    127.0.0.1    ICMP    Echo (ping) request
6    2.001601    127.0.0.1    127.0.0.1    ICMP    Echo (ping) reply

Now select a single packet and see the 3rd row of the wireshark.
In that field you can see the information that carry by a packet.

Now you can try this also;
$ssh localhost

Now you can see how many packets should involve to make an ssh connection. Try to use some other things also. To start another capture you should stop the ongoing thing first. You can save the captured information if you need. Then you can try some other interface like "usbmon2 usb bus number 2". In my computer the mouse is connected into this interface so i can see the packets exchange between the machine and the mouse.

So now you can try the ethernet interface which commonly use to connect to the internet. Select the interface  which you connect to the internet if you do not use a ethernet port.(if you use a usb modem or else). You can see many number of packets are travelling without any action from you. It happens due to DHCP, automatic updating software things and so on.
If you know about protocols you can get a filtered output from this software. Think if you need to see the details of sctp packets, you can use the filter in the first row. If you use the filter you will only get the live sctp packets.
Think if you did not  use a filter, but wireshark will display each packet type in a different background colour. Most of the known harmful packets will highlighted in dark colours.
Always wireshark gives a user interface, but there is a tool to do the same thing without the GUI. Its also shiped with wireshark and you can run it by typing "tshark" in the console. This command also required the superuser permission.
You can try this by typing;
tshark -i eth0

Nov 2, 2010

Important things when installing Haskell ghc and packages

Haskell is not like other programming languages. Even when it is installing the compilers installing person must manually install each and every module if he/she needs. I will tell some points that you may need when you are going to use Haskell.
These thing may change in future, but for now it may be the best way.

First thing, do not use "yum install ghc" . This will install " ghc 6-10. " or some old thing. You will be able to download the latest ghc from the website.
link : http://www.haskell.org/ghc/index.html 

If you had install an old version of ghc from yum, you can erase it and install new ghc manually.
$yum erase ghc

Installing ghc from the tar file ease easy. Only you need to do extract the tar file and reat the INSTALL file. You can use the default configurations which will install ghc in /usr/local. To do that you can; (You may need root permission)

$ ./configure
$ make install



Next thing is when you need to install any module, first search it from the http://hackage.haskell.org/  website. This will give all relevant details of the package.

Old version of ghc use a package installation program called Cabal-installer. But the new version is not working with that program. May be in future they will make it, but for now you can't use cabal.

Do not download the package as soon as you see the package downloading link. Go through the web page. You may many important details like;

*  Versions -
            Gives the version information. Very important when you are finding a dependent file. You must use the relevant version of the dependent package.

*  Dependencies -
           Gives information about packages which need to run the current selected package. You can not install, if a single package is missing. This thing also very important. There are words like "or" , "(>2.0)" which you must think before downloading or selecting a dependent file.

*  Built on / Built failure - This will tell if the package will install correctly or not, considering on the ghc version. Some files can only work properly on some ghc versions. Some packages give errors on some ghcs.

Selection the working file may be too hard, but this will help you a lot. Think when you installing a package and you got a error message as you need to install a dependent package, read it correctly and try to install only that dependent package, even if you got a new package if the old one is stable.

Connect to a MySQL database from a Java program

In a program, it may need to store and organise data. To do that in a secure way it must use a database service. MySQL is a good database which can this task by communicating with a Java program. MySQL supports other languages also but for now we only talk about the MySQL-Java combination.

If the Java program need to communicate with the database, the program need to convert instructions into a language which MySQL can understand. To do this Java need a special connector called Jconnector. You need to download and install it.
Link : http://www.mysql.com/downloads/connector/j/

After downloading you may get a  file like "mysql-connector-java-5.1.13.tar.gz"
Unzip this file. Now you can see a file call "mysql-connector-java-5.1.13-bin.jar". You should move this file to the jre/lib/ext, to do that;

$ mv mysql-connector-java-5.1.13-bin.jar   $JAVA_HOME/jre/lib/ext
( "$JAVA_HOME" is where the JDK is installed.)



Now you can try to communicate with the database. You need to create a database in MySQL and if you need create a new user and a password. Then run the MySQL server. After the server is completely up run the Java program. A simple Java program to check the db connection;

/* File name :-  Connect.java



 *
 *
*/

import java.sql.*;

   public class Connect
   {
       public static void main (String[] args)
       {
           Connection conn = null;

           try
           {
               String userName = "root";
               String password = "";
               String url = "jdbc:mysql://localhost/test";
               Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, password);
               System.out.println ("Database connection established");   }
           catch (Exception e) {
               System.err.println ("Cannot connect to database server"); }
           finally {
               if (conn != null) {
                   try {   conn.close ();
                             System.out.println ("Database connection terminated");}
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
       }
   }

Installing JKD in fedora

Java development kit is the Java environment which supports to run and compile Java based programs. JDK is containing everything in  Java Runtime (JRE) as well as java compilers  debuggers. Most of the time fedora will contain openJDK but it's better to install Sun micro system JDK. You can download it from there website;

link : http://www.oracle.com/technetwork/java/javase/downloads/index.html
Note - download the JDK not the JRE.

For Fedora it is a file like jdk-6u22-linux-i586-rpm.bin. You need to convert this bin file to an executable file. To do that you can type;

chmod a+x jdk-6u18-linux-i586-rpm.bin

Now we can simply run this file. But this bin file will extract all the file in the current directory. So if you need to install JDK in "/usr/local/", first you must change your directory to that location which you need to install it.

(To install in this location you may need root permission. If you haven't got it you can install it in your home directory.)

$cd /usr/local
(or $cd ~/)
Then you can execute the bin file,

$ ./jdk-6u18-linux-i586-rpm.bin

This will extract files in to a file like "jdk1.6.0_22".

Note - JDK is a rapidly developing thing, there for you may need to install the latest JDK in order to get the maximum from Java. To do these updates you can use this kind of method.

Now you are in /urs/local/,

$ ln  -s    jdk1.6.0_22    jdk
This will create  a soft link in /usr/local/ called jdk which points to the "jdk1.6.0_22" directory. In this way you only need to update the link when ever you need to update/downgrade the JDK in the system.

Now you need to add the bin file in JDK to the PATH variable. To do that you must edit the .bash_profile (or .bashrc)  which contains the PATH variable.

Update the variable into;

       export JAVA_HOME=/usr/local/jdk
       PATH=$PATH:$JAVA_HOME/bin:$HOME/bin
       export PATH

then type;
$source .bash_profile

Now you can try
$java -version
This should give the correct version information. If this thing gives wrong information type;
$whereis java
This will give like
/usr/bin/java
Then type;
$ls -la /usr/bin/java
If it  gives like this;
  lrwxrwxrwx. 1 root root 23 2010-11-01 14:42 /usr/bin/java -> /usr/local/jdk/bin/java
If this is the matter you can unlink the java file  in /usr/bin by;
$unlink /usr/bin/java
($unlink /usr/bin/java*  this will unlink all java, javac, javawp)

Then again check the Java version. Make sure all paths and spelling are correct.