Wednesday, 12 December 2012

Weblogic Server HTTP session replication ( JDBC database replication )


Weblogic Server HTTP session replication ( JDBC based database replication )

Assuming you have -

Oracle Databases  Installed
Weblogic Installed and two managed servers created in a cluster
Web server installed


Download the shoppingcart.war web application



1. Create a database user for jdbc session handling

connect with database
connect / as sysdba
sql> create user weblogic identified by webl0gic;
sql> grant connect,resource to weblogic;

Test user -

$ sqlplus weblogic/webl0gic
sql>
( if you got sql> prompt then you are good to go )

2. connect with weblogic user and create below table - 

create table wl_servlet_sessions
  ( wl_id VARCHAR2(100) NOT NULL,
    wl_context_path VARCHAR2(100) NOT NULL,
    wl_is_new CHAR(1),
    wl_create_time NUMBER(20),
    wl_is_valid CHAR(1),
    wl_session_values LONG RAW,
    wl_access_time NUMBER(20),
    wl_max_inactive_interval INTEGER,
   PRIMARY KEY (wl_id, wl_context_path) );


Run below command, it will give you 0 records

$ sqlplus weblogic/webl0gic

sql> select count(*) from WL_SERVLET_SESSIONS;

  COUNT(*)
----------
         0

3. Create a datasource with name  "dizzyworldDS"  from weblogic console and target to  
     your managed Servers.

Note : - Don't use XA driver


4. Configuring a Web Application for JDBC Replication

Edit the shoppingcart/WEB-INF/weblogic.xml file again, add <session-descriptor> element as follows:


<session-descriptor>

   <persistent-store-type>jdbc</persistent-store-type>


   <persistent-store-pool>dizzyworldDS</persistent-store-pool>


   <persistent-store-table>WL_SERVLET_SESSIONS</persistent-store-table>


</session-descriptor>


Re-create shoppingcart.war again or you can deploy shoppingcart folder in open exploded format.

5. Deploy shoppingcart application on your cluster ( on both managed servers )

6. Configure your webserver to redirect /shoppingcart request to your clustered managed 
     server

     Below is the configuration for apache httpd.conf file 

     <Location /shoppingcart>

     WLLogFile c:/temp/wlproxy.log

     SetHandler weblogic-handler

     WebLogicCluster localhost:40511,localhost:40512

     </Location>


( replace host and port according to your configuration ) 

restart your webserver after above configuration

Testing JDBC Replication


To validate your session replication settings, perform the following steps:

1. Access shoppingcart application

   http://webserver_host:webserevr_port/shoppingcart

   Example : http://localhost:80/shoppingcart

   2. Add several items to your shopping cart.
    3. Return to SQL Plus and inspect the latest contents of the WL_SERVLET_SESSIONS    
        table.

        SQL> select * from WL_SERVLET_SESSIONS;

    A row should exist and the value of the WL_CONTEXT_PATH column should be    
    shoppingcart.war.


    SQL> select * from WL_SERVLET_SESSIONS;

    WL_ID
    --------------------------------------------------------------------------------
    WL_CONTEXT_PATH
     --------------------------------------------------------------------------------
    W WL_CREATE_TIME W W WL_ACCESS_TIME WL_MAX_INACTIVE_INTERVAL
    - -------------- - - -------------- ------------------------
    1775QH9pFJy0MTpGcLTcN6TcVLhqQPm2ngvw0BFpDQnpTjKGWynp
    shoppingcart
    0     1.3553E+12 1 7     1.3553E+12                     3600

4. Use server output log file to determine which server is currently hosting the session. Kill    
    this server.

    in my case, session was create on first managed server, below are the logs

        within welcome.jsp
        within viewShoppingCart servlet
        Your shopping cart includes: 
Item: box of 12 pens (black) price: 4.99
Item: box of 12 pens (blue) price: 4.99
Item: leather adjustable chair price: 139.99
Item: 100 Post-It notes price: 7.99
Item: box of 12 pens (red) price: 4.99

       Once confirmed, I have killed this ( first ) managed server

      
5.  Again I went to same earlier accessed shoppingcart url and added few more items

     This time i have verified the logs of my second managed servers and confirmed further 
      items on same shippingcart was added via that server

      within shoppingcart.jsp
      within shopping cart servlet
      added new element: package of 5 legal pads
      within welcome.jsp
      within shoppingcart.jsp
      within shopping cart servlet
     added new element: corner computer desk
     within welcome.jsp
      within viewShoppingCart servlet
       Your shopping cart includes: 
Item: box of 12 pens (black) price: 4.99
Item: box of 12 pens (blue) price: 4.99
Item: leather adjustable chair price: 139.99
Item: 100 Post-It notes price: 7.99
Item: box of 12 pens (red) price: 4.99
Item: package of 5 legal pads price: 15.99
Item: corner computer desk price: 199.99

   and when I use the application to view your shopping cart again, and confirm that its    
   contents are still the same.



you are done, cheers!!!


My Blog Other Related Posts


In-Memory session replication
Managing User Sessions With Coherence 




Reference :- http://oracle.com






1 comment:

  1. Deploy same application as well as target same data source to that cluster.

    ReplyDelete