Thursday, May 27, 2010

Enabling JMS Transport in WSO2 BPS

As I highlighted in my previous blog post, WSO2 BPS is a powerful open source BPEL engine.Here i am going to enable JMS Transport in WSO2 BPS.  You can use any JMS provider as you preferred. I'm going to use Apache ActiveMQ-5.2.0 for this example.


1. You can download WSO2BPS (version 1.1.1) from here. then you can extract in to a directory in your file system. Lets call as BPS_HOME

2. Start ActiveMQ message broker. Go to (ActiveMQ_Install_directory)/bin and run activemq.sh (or activemq.bin in DOS)

3. Copy ActiveMQ libraries to BPS_HOME/repository/components/lib directory

activemq-core-5.2.0.jar and geronimo-j2ee-management_1.0_spec-1.0

4. Enable JMS Transport in WSO2 BPS.  Uncomment following parameters in axis2.xml (BPS_HOME/conf directory) Here I have configured it for ActiveMQ environment.

For Receiver

<parameter name="myTopicConnectionFactory">
            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
            <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter>
        </parameter>


        <parameter name="myQueueConnectionFactory">
            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
            <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
        </parameter>


        <parameter name="default">
            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
            <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
        </parameter>

For Sender
    <transportSender name="jms"
                     class="org.apache.axis2.transport.jms.JMSSender"/>

5. Start BPS server running  the wso2server.sh (in unix) or wso2server.bat (in windows)
You can see following Logs when starting if you have correctly configured

[2010-05-27 22:19:55,019]  INFO -  JMS ConnectionFactory : default initialized
[2010-05-27 22:19:55,021]  INFO -  JMS ConnectionFactory : myTopicConnectionFactory initialized
[2010-05-27 22:19:55,022]  INFO -  JMS ConnectionFactory : myQueueConnectionFactory initialized
[2010-05-27 22:19:55,022]  INFO -  JMS Transport Receiver/Listener initialized...

We can see JMS endpoint has been added to BPEL service (See the wsdl also)


Note:-

Step 4,   You can enable JMS and configure it using UI.




But there are some issues when disabling  JMS from UI. So i recommended to use axis2.xml configure JMS in WSO2BPS version 1.1.1. This will be fixed in next WSO2BPS release.....!!!

Thursday, May 13, 2010

WSO2 BPS in Cluster


Clustering is one of a major requirement for web servers which are in production environment. because these servers have to fulfill two basic needs, high availability and scalability.

WSO2 carbon based web products comes with the clustering functionality (Please refer this article for more information on WSO2 carbon clustering) Here I am going to introduce to configure the WSO2BPS in a clustering environment.
 

1. You can download WSO2BPS (version 1.1.1) from here.

2. All nodes in BPS cluster would share the  same persistence storage (BPS datasource) and same registry. So Each node must be connected to external datasource and external registry. This Post is described configuration of  external BPS datasource. Use same configuration for all nodes, But don't forget to use different provider port for each node, if you are starting all nodes in same machine (same url).

3. Then registry.xml and user-mgt.xml (Both are in WSO2BPS/conf directory)must be configured to use a one central registry. Use same configuration for all nodes.

Sample configuration of registry.xml for Mysql database

        <dbConfig name="wso2registry">
            <url>jdbc:mysql://10.100.1.1:3306/regdb</url>
            <userName>regadmin</userName>
            <password>regadmin</password>
            <driverName>com.mysql.jdbc.Driver</driverName>
            <maxActive>80</maxActive>
            <maxWait>6000</maxWait>
            <minIdle>5</minIdle>
       </dbConfig>

Sample configuration of user-mgt.xml

 <Database>
         <URL>jdbc:mysql://10.100.1.1:3306/regdb</URL>
         <UserName>regadmin</UserName>
         <Password>regadmin</Password>
         <Dialect>mysql</Dialect>
         <Driver>com.mysql.jdbc.Driver</Driver>
          <maxActive>30</maxActive>
          <maxWait>60000</maxWait>
          <minIdle>5</minIdle>
    </Database>


4. Then One BPS node must be started as the group management node. you can simply do this by configuring following basic parameters in axis2.xml (WSO2BPS/conf directory)

# Enable clustering for this node

<clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true"> 
  
# Clustering domain/group

<parameter name="domain">bps</parameter>

# Enable the group Management

<groupManagement enable="true">
            <applicationDomain name="bps" description="BPS group" agent="org.apache.axis2.clustering.management.DefaultGroupManagementAgent"/>
</groupManagement>

5.  Other BPS nodes also should be started with enabling the clustering (Can enable or disable node management, but there is no effect for BPS. So here i did not use it)

# Enable clustering for this node

<clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true">
  
# Clustering domain/group

<parameter name="domain">bps</parameter>


6. Start every BPS node running  the wso2server.sh (in unix) or wso2server.bat (in windows) file in the WSO2BPS/bin directory.  Don't forget to use different http and https port for each node, if you are starting all nodes in same machine (same url). Configuration can be found in transport.xml and axis2.xml

By looking at Debug and INFO message you can understand what is happening there.

But WSO2BPS (version 1.1.1) have some limitations when setting on clustering ( Retiring of BPEL process not propagate to other node, Managing BPEL packages and processes should be disable for member nodes) which would be resolved in next BPS release.........!!!

Sunday, February 7, 2010

How to create a Password Callback class

Most of web services have been secured using various WS security  methods. Therefore we need to implements clients that support WS-Security to invoke these web services.

If you are using Rampart or WSS4J for WS-Security for processing in client side,  you may need to create a password callback class for following

1) Get the password to build the username token

2) Get the private key password for signture or decryption


It is very easy to write a Password callback. Following Java code is for simple Password callback class

package org.wso2.samples.pwcb;

import org.apache.ws.security.WSPasswordCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;

public class PWCBHandler implements CallbackHandler {

        public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {

            for (int i = 0; i < callbacks.length; i++) {
                WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];
                String id = pwcb.getIdentifer();
                int usage = pwcb.getUsage();


                   if (usage == WSPasswordCallback.USERNAME_TOKEN) {
                   // Logic to get the password to build the username token
                        if ("admin".equals(id)) {pwcb.setPassword("admin");}
                } else if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
                // Logic to get the private key password for signture or decryption
                        if ("client".equals(id)) {pwcb.setPassword("apache");}
                        if ("service".equals(id)) {pwcb.setPassword("apache");}
                }

            }
        }
}

Lets see how you can use this password class back class with the WSO2 products such as ESB and BPS. For ESB, we need a class back class to invoke a secured BE services where ESB Proxy service would act as client for BE service.  Also when external partner service is invoked by a BPEL is act as a client to the external web service.

Therefore we need to create a jar file ... 

Step1 : Creating a jar file 

Note :  If you are familiar with maven. Please find the maven project of callback class from here 

1. Copy sample Password callback in to text file and save it as PWCBHandler.java

2. Create a directory called "temp"  ...any where you like,

3. Go in to temp directory and create following directory structure   org/wso2/samples/pwcb

4. Copy PWCBHandler.java in to pwcb directory

5. Download wss4j.jar from here (http://ws.apache.org/wss4j/) and copy it to temp directory

6. Compile PWCBHandler.java pointing classpath to wss4j.jar from pwcb directory

Ex:-
#javac PWCBHandler.java -classpath /home/asela/temp/PWC/org/wso2/samples/pwcb/wss4j-1.5.8.jar

7. Go in to temp directory and create a jar file issuing following

#jar cf PWCBHandler.jar org/wso2/samples/pwcb/*.class

Step2 : Adding jar file in to classpath

1. Now you have created your  PWCBHandler.jar and Copy jar in to <CARBON_HOME> /repository/components/lib

2. Restart Server


That All........!!!

Saturday, January 30, 2010

How Install PostgreSQL database in Ubuntu 9.04

It is very simple to install postgreSQL in Ubuntu. Just run the following command in the command prompt

sudo apt-get install postgresql

This will install the latest postgreSQL and Now your are ready to use it.

But lets do some important configurations (that I did). The PostgreSQL configuration files are stored in the /etc/postgresql//main directory. In my case, I install PostgreSQL 8.3.  So there are in /etc/postgresql/8.3/main

1. Enable TCP/IP connections

By default, connection via TCP/IP is disabled. PostgreSQL supports multiple client authentication methods. By default, IDENT authentication method is used for postgres and local users

To enable TCP/IP connections, edit the file /etc/postgresql/8.3/main/postgresql.conf

Locate the line #listen_addresses = 'localhost'  and uncomment it.

To allow other computers to connect to your PostgreSQL server replace 'localhost' with the IP Address of your server.

2. Set a password for the postgres user


Run the following command at a terminal prompt to connect to the default PostgreSQL template database

 sudo -u postgres psql template1

Then run following SQL command at the psql prompt to configure the password for the user postgres. 

ALTER USER postgres with encrypted password 'your_password';

Remember to restart the PostgreSQL service to initialize the new configuration

Enter the following to restart
 

sudo /etc/init.d/postgresql-8.3 restart

How to Deploy Axis2 services in WSO2 BPS

Wso2bps is powerful bpel engine which allows you to easily deploy and manage bpel services,  can be download from here.

Also we can deploy Axis2 services in Wso2bps (But not from remotely).  It is easy , Just copy your *.aar file in to repository/services directory in the extracted Wso2bps

After few second, your service will be list in the Deployed service page. You can configure QoS accessing Service Dashboard.