Tuesday Oct 04, 2011

Coherence*Web Session clustering between WebSphere and WebLogic

Briefly describing the needed steps to share session information between WebSphere 6.x and WebLogic 10.x

Steps for WLS 

1. java -cp coherence.jar;coherence-web.jar com.tangosol.coherence.servlet.WebPluginInstaller [WLS_HOME] -install

2. java -jar webInstaller.jar SessionTest.war -inspect -server:WebLogic/10.x

3. Modify coherence-web.xml 
    <param-name>coherence-session-cookie-domain</param-name>
    <param-value>.test.com</param-value>

<param-name>coherence-session-cookie-path</param-name>
    <param-value>/</param-value>

<param-name>coherence-servletcontext-clustered</param-name>
    <param-value>true</param-value>

    <param-name>coherence-enable-sessioncontext</param-name>
    <param-value>true</param-value>

<param-name>coherence-scopecontroller-class</param-name>
    <param-value>
       com.tangosol.coherence.servlet.AbstractHttpSessionCollection$GlobalScopeController
    </param-value>
<param-name>coherence-session-id-length</param-name>
    <param-value>32</param-value>

3. java -jar webInstaller.jar SessionTest.war -install

4. Insert those two classes(MyCookieHelper, MyDefaultFactory) into the SessionTest.war file.
----------------------------------------------------
package com.tangosol.coherence.servlet.weblogic81;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import com.oracle.FileLogWriter;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.cache.LocalCache;

public class MyCookieHelper extends CookieHelper {
// protected static final char SUFFIX_SEPARATOR = 46;
private LocalCache m_cacheFailover;
private String m_sConfiguredJvmRoute;
private FileLogWriter fileWriter;
public MyCookieHelper(
com.tangosol.coherence.servlet.SessionHelper.Factory factory,
ServletContext ctx) {
this(factory, ctx, null);
}

public MyCookieHelper(
com.tangosol.coherence.servlet.SessionHelper.Factory factory,
ServletContext ctx, String sJvmRoute) {
super(factory, ctx);
fileWriter = new FileLogWriter();
m_cacheFailover = new LocalCache(128);
m_sConfiguredJvmRoute = sJvmRoute;
}

public String decodeCookie(HttpServletRequest req) {
String sSessionId = super.decodeCookie(req);
CacheFactory.log("before :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
// WebLogic Session
if (sSessionId != null) {
int ofSeparator = sSessionId.indexOf('!');
if (ofSeparator >= 0) {
String sServerSuffix = getWebLogicAffinitrySuffix();
String sSessionSuffix = sSessionId.substring(ofSeparator);
sSessionId = sSessionId.substring(0, ofSeparator);
if (!sSessionSuffix.equals(sServerSuffix))
m_cacheFailover.put(sSessionId, sSessionSuffix);
}
}

// WebSphere Session
if ((sSessionId != null) && (sSessionId.length() > 4) &&(sSessionId.startsWith("0000"))) {
sSessionId = sSessionId.substring("0000".length());

int ofSeparator = sSessionId.indexOf(getWebSphereAffinitySuffix());
if (ofSeparator >= 0) {
String sServerSuffix = getWebSphereAffinitySuffix();
String sSessionSuffix = sSessionId.substring(ofSeparator);
sSessionId = sSessionId.substring(0, ofSeparator);

if (!sSessionSuffix.equals(sServerSuffix)) {
this.m_cacheFailover.put(sSessionId, sSessionSuffix);
}
}
}
CacheFactory.log("after :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
return sSessionId;
}

public String decodeUrl(HttpServletRequest request) {
String sSessionId = super.decodeUrl(request);
CacheFactory.log("before :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
if (sSessionId != null) {
int ofSeparator = sSessionId.indexOf('!');
if (ofSeparator >= 0)
sSessionId = sSessionId.substring(0, ofSeparator);
}
   if ((sSessionId != null) && (sSessionId.length() > 4) && (sSessionId.startsWith("0000")))
   {
     sSessionId = sSessionId.substring("0000".length());

     int ofSeparator = sSessionId.indexOf(getWebSphereAffinitySuffix());
     if (ofSeparator >= 0)
     {
       sSessionId = sSessionId.substring(0, ofSeparator);
     }
   }
   CacheFactory.log("after :" + sSessionId);
   fileWriter.writeToFile("before :" + sSessionId);
return sSessionId;
}

public String getWebSphereAffinitySuffix() {
return ":";
}

public String getWebLogicAffinitrySuffix() {
return "!";
}
}
----------------------------------------------------
package com.tangosol.coherence.servlet.weblogic103;

import com.tangosol.coherence.servlet.SessionHelper;
import com.tangosol.coherence.servlet.weblogic81.MyCookieHelper;
import javax.servlet.ServletContext;
import com.tangosol.net.CacheFactory;

public class MyDefaultFactory  extends DefaultFactory {

    public SessionHelper instantiateSessionHelper(ServletContext ctx) {
        CacheFactory.log(toString() + ": creating SessionHelper");
        azzert(ctx != null);
        azzert(getServletContext() == null && getSessionHelper() == null);
        String sJvmRoute = System.getProperty("jvmRoute", (String)ctx.getAttribute("coherence-jvmroute"));
        MyCookieHelper helper = new MyCookieHelper(this, ctx, sJvmRoute);
        setServletContext(ctx);
        setSessionHelper(helper);
        return helper;
    }
}
----------------------------------------------------

5. Modify the web.xml.
<param-name>coherence-factory-class</param-name>
    <param-value>com.tangosol.coherence.servlet.weblogic103.MyDefaultFactory</param-value>

Steps for WebSphere

Basically steps are very similar with WebLogic part except helper classes.

1. java -jar webInstaller.jar SessionTest.war -inspect -server:WebSphere/6.x

2. Modify coherence-web.xml
    <param-name>coherence-session-cookie-domain</param-name>
    <param-value>.test.com</param-value>

<param-name>coherence-session-cookie-path</param-name>
    <param-value>/</param-value>

<param-name>coherence-servletcontext-clustered</param-name>
    <param-value>true</param-value>

    <param-name>coherence-enable-sessioncontext</param-name>
    <param-value>true</param-value>

<param-name>coherence-scopecontroller-class</param-name>
    <param-value>
       com.tangosol.coherence.servlet.AbstractHttpSessionCollection$GlobalScopeController
    </param-value>
<param-name>coherence-session-id-length</param-name>
    <param-value>32</param-value>

3. java -jar webInstaller.jar SessionTest.war -install

4. Insert those two classes(MyCookieHelper, MyDefaultFactory) into the SessionTest.war file.
----------------------------------------------------
package com.tangosol.coherence.servlet.websphere60;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import com.oracle.FileLogWriter;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.cache.LocalCache;

public class MyCookieHelper extends com.tangosol.coherence.servlet.websphere60.CookieHelper {
protected static final char SUFFIX_SEPARATOR = 46;
private LocalCache m_cacheFailover;
private String m_sConfiguredJvmRoute;
private FileLogWriter fileWriter;
public MyCookieHelper(
com.tangosol.coherence.servlet.SessionHelper.Factory factory,
ServletContext ctx) {
this(factory, ctx, null);
}

public MyCookieHelper(
com.tangosol.coherence.servlet.SessionHelper.Factory factory,
ServletContext ctx, String sJvmRoute) {
super(factory, ctx);
fileWriter = new FileLogWriter();
m_cacheFailover = new LocalCache(128);
m_sConfiguredJvmRoute = sJvmRoute;
}

public String decodeCookie(HttpServletRequest req) {
String sSessionId = super.decodeCookie(req);
CacheFactory.log("before :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
// WebLogic Session
if (sSessionId != null) {
int ofSeparator = sSessionId.indexOf('!');
if (ofSeparator >= 0) {
String sServerSuffix = getWebLogicAffinitrySuffix();
String sSessionSuffix = sSessionId.substring(ofSeparator);
sSessionId = sSessionId.substring(0, ofSeparator);
if (!sSessionSuffix.equals(sServerSuffix))
m_cacheFailover.put(sSessionId, sSessionSuffix);
}
}

// WebSphere Session
if ((sSessionId != null) && (sSessionId.length() > 4) && (sSessionId.startsWith("0000"))) {
sSessionId = sSessionId.substring("0000".length());

int ofSeparator = sSessionId.indexOf(getWebSphereAffinitySuffix());
if (ofSeparator >= 0) {
String sServerSuffix = getWebSphereAffinitySuffix();
String sSessionSuffix = sSessionId.substring(ofSeparator);
sSessionId = sSessionId.substring(0, ofSeparator);

if (!sSessionSuffix.equals(sServerSuffix)) {
this.m_cacheFailover.put(sSessionId, sSessionSuffix);
}
}
}
CacheFactory.log("after :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
return sSessionId;
}

public String decodeUrl(HttpServletRequest request) {
String sSessionId = super.decodeUrl(request);
CacheFactory.log("before :" + sSessionId);
fileWriter.writeToFile("before :" + sSessionId);
if (sSessionId != null) {
int ofSeparator = sSessionId.indexOf('!');
if (ofSeparator >= 0)
sSessionId = sSessionId.substring(0, ofSeparator);
}
   if ((sSessionId != null) && (sSessionId.length() > 4) && (sSessionId.startsWith("0000")))
   {
     sSessionId = sSessionId.substring("0000".length());

     int ofSeparator = sSessionId.indexOf(getWebSphereAffinitySuffix());
     if (ofSeparator >= 0)
     {
       sSessionId = sSessionId.substring(0, ofSeparator);
     }
   }
   CacheFactory.log("after :" + sSessionId);
   fileWriter.writeToFile("before :" + sSessionId);
return sSessionId;
}

public String getWebSphereAffinitySuffix() {
return ":";
}

public String getWebLogicAffinitrySuffix() {
return "!";
}
}
----------------------------------------------------
package com.tangosol.coherence.servlet.websphere60;

import javax.servlet.ServletContext;

import com.tangosol.coherence.servlet.SessionHelper;
import com.tangosol.coherence.servlet.websphere60.DefaultFactory;
import com.tangosol.coherence.servlet.websphere60.MyCookieHelper;
import com.tangosol.net.CacheFactory;

public class MyDefaultFactory   extends com.tangosol.coherence.servlet.websphere60.DefaultFactory {
public MyDefaultFactory() {
}
    public SessionHelper instantiateSessionHelper(ServletContext ctx) {
        CacheFactory.log(toString() + ": creating SessionHelper");
        azzert(ctx != null);
        azzert(getServletContext() == null && getSessionHelper() == null);
        String sJvmRoute = System.getProperty("jvmRoute", (String)ctx.getAttribute("coherence-tomcat-jvmroute"));
        MyCookieHelper helper = new MyCookieHelper(this, ctx, sJvmRoute);
        setServletContext(ctx);
        setSessionHelper(helper);
        return helper;
    }
}
----------------------------------------------------

5. Modify the web.xml. 
    <param-name>coherence-factory-class</param-name>
    <param-value>com.tangosol.coherence.servlet.websphere60.MyDefaultFactory</param-value>


Thursday Jun 03, 2010

JRockit Virtual Edition Debug Key

There are a few keys that can help the debugging of the JRVE env in console. you can type in each keys in JRVE console to see what's happening under the hood.

key '0' : System information
key '5' : Enable shutdown
key '7' : Start JRockit Management Server (port 7091)
key '8' : Statistics Counters
key '9' : Full Thread Dump
key '0' : Status of Debug-key

Below is the sample out from each keys.

Debug-key '1' pressed

============ JRockitVE System Information ============
JRockitVE version : 11.1.1.3.0-67-131044
Kernel version : 6.1.0.0-97-131024
JVM version : R27.6.6-28_o-125824-1.6.0_17-20091214-2104-linux-ia32
Hypervisor version : Xen 3.4.0
Boot state : 0x007effff
Uptime : 0 days 02:04:31
CPU : uniprocessor @2327 Mhz
CPU usage : 0% ctx/s: 285 preempt/s: 0 migrations/s: 0
Physical pages : 82379/261121 (321/1020 MB)
Network info : 10.179.97.64 (10.179.97.64/255.255.254.0)
GateWay : 10.179.96.1
MAC address : 00:16:3e:7e:dc:78
Boot options :
vfsCwd : /application/user_projects/domains/wlsve_domain
mainArgs : java -javaagent:/jrockitve/services/sshd/sshd.jar -cp /jrockitve/jrockit/lib/tools.jar:/jrockitve/lib/common.jar:/application/patch_wls1032/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/application/wlserver_10.3/server/lib/weblogic.jar -Dweblogic.Name=WlsveAdmin -Dweblogic.Domain=wlsve_domain -Dweblogic.management.username=weblogic -Dweblogic.management.password=welcome1 -Dweblogic.management.GenerateDefaultConfig=true weblogic.Server
consLog : /jrockitve/log/jrockitve.log
mounts : ext2 / dev0;
posixLocale : en_US
posixTimezone : Asia/Seoul
posixEncoding : ISO-8859-1
Local disk : Size: 1024M, Used: 728M, Free: 295M
========================================================

Debug-key '5' pressed
Shutdown enabled.

Debug-key '7' pressed
[JRockit] Management server already started. Ignoring request.

Debug-key '8' pressed
Starting stat recording
Debug-key '8' pressed
========= Statistics Counters for the last second =========
dev.eth0_rx.cnt : 22 packets
dev.eth0_rx_bytes.cnt : 2704 bytes
dev.net_interrupts.cnt : 22 interrupts
evt.timer_ticks.cnt : 123 ticks
hyper.priv_entries.cnt : 144 entries
schedule.context_switches.cnt : 271 switches
schedule.idle_cpu_time.cnt : 997318849 nanoseconds
schedule.idle_cpu_time_0.cnt : 997318849 nanoseconds
schedule.total_cpu_time.cnt : 1000031757 nanoseconds
time.system_time.cnt : 1000 ns
time.timer_updates.cnt : 123 updates
time.wallclock_time.cnt : 1000 ns
=======================================

Debug-key '9' pressed

===== FULL THREAD DUMP ===============
Fri Jun 4 08:22:12 2010
BEA JRockit(R) R27.6.6-28_o-125824-1.6.0_17-20091214-2104-linux-ia32

"Main Thread" id=1 idx=0x4 tid=1 prio=5 alive, in native, waiting
-- Waiting for notification on: weblogic/t3/srvr/T3Srvr@0x646ede8[fat lock]
at jrockit/vm/Threads.waitForNotifySignal(JLjava/lang/Object;)Z(Native Method)
at java/lang/Object.wait(J)V(Native Method)
at java/lang/Object.wait(Object.java:485)
at weblogic/t3/srvr/T3Srvr.waitForDeath(T3Srvr.java:919)
^-- Lock released while waiting: weblogic/t3/srvr/T3Srvr@0x646ede8[fat lock]
at weblogic/t3/srvr/T3Srvr.run(T3Srvr.java:479)
at weblogic/Server.main(Server.java:67)
at jrockit/vm/RNI.c2java(IIIII)V(Native Method)
-- end of trace

"(Signal Handler)" id=2 idx=0x8 tid=2 prio=5 alive, in native, daemon

Open lock chains
================
Chain 1:
"ExecuteThread: '0' for queue: 'weblogic.socket.Muxer'" id=23 idx=0x50 tid=20 waiting for java/lang/String@0x630c588 held by:
"ExecuteThread: '1' for queue: 'weblogic.socket.Muxer'" id=24 idx=0x54 tid=21 (active)

===== END OF THREAD DUMP ===============

Debug-key '0' pressed

Debug-keys enabled


Happy Cloud Walking :)

About

Solution & Technology Architect, Asia Pacific

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today