Seam 2.2.1 fails in cluster on Weblogic 10.3.0
robertus May 4, 2011 11:07 PMI have tried to deploy the JPA sample project to Weblogic 10.3.0 for testing the clustering. I just put some configuration in weblogic.xml as follows:
<session-descriptor> <sharing-enabled>true</sharing-enabled> <persistent-store-type>file</persistent-store-type> <persistent-store-dir>C:/newss/session</persistent-store-dir> </session-descriptor>
And the clustering is working fine.
But till now I'm still facing clustering problem in my project, seems the stored session from 1st server couldn't be picked up by the 2nd server.
So, the 2nd server always goes to login page (login.seam). When I debug the User object in the session, the value of username and password attribute are NULL, and I got some errors in the log as follows:
####<May 5, 2011 9:55:30 AM SGT> <Error> <HTTP Session> <PSD-NB-5302> <newss1> <[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <> <1304560530264> <BEA-100018> <An error occurred while loading serialized session data for session QQXpNBrVn1G4LJGh02WNyhwcc5fpPLpvjybpmXF9322ywTjgXn1s. java.lang.RuntimeException: java.lang.IllegalStateException: No application context active at org.jboss.seam.intercept.JavaBeanInterceptor.readResolve(JavaBeanInterceptor.java:219) at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1061) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1761) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at java.util.Hashtable.readObject(Hashtable.java:859) at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at weblogic.servlet.internal.session.SessionData.readExternal(SessionData.java:960) at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at weblogic.servlet.internal.session.FileSessionContext.loadSession(FileSessionContext.java:538) at weblogic.servlet.internal.session.FileSessionContext.getSessionInternal(FileSessionContext.java:687) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator.cleanupExpiredSessions(SessionContext.java:838) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator$1.run(SessionContext.java:794) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator.timerExpired(SessionContext.java:788) at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) java.lang.IllegalStateException: No application context active at org.jboss.seam.ScopeType.getContext(ScopeType.java:145) at org.jboss.seam.Component.getInstance(Component.java:2002) at org.jboss.seam.Component.getInstance(Component.java:1997) at org.jboss.seam.Component.getInstance(Component.java:1970) at org.jboss.seam.Component.getInstance(Component.java:1965) at org.jboss.seam.international.LocaleConfig.instance(LocaleConfig.java:109) at com.fms.newss.web.UserBean.<init>(UserBean.java:70) at com.fms.newss.web.UserBean_$$_javassist_seam_1.<init>(UserBean_$$_javassist_seam_1.java) at sun.reflect.GeneratedConstructorAccessor199.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.jboss.seam.Component.wrap(Component.java:1507) at org.jboss.seam.intercept.JavaBeanInterceptor.readResolve(JavaBeanInterceptor.java:214) at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1061) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1761) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at java.util.Hashtable.readObject(Hashtable.java:859) at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at weblogic.servlet.internal.session.SessionData.readExternal(SessionData.java:960) at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1791) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at weblogic.servlet.internal.session.FileSessionContext.loadSession(FileSessionContext.java:538) at weblogic.servlet.internal.session.FileSessionContext.getSessionInternal(FileSessionContext.java:687) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator.cleanupExpiredSessions(SessionContext.java:838) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator$1.run(SessionContext.java:794) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.servlet.internal.session.SessionContext$SessionInvalidator.timerExpired(SessionContext.java:788) at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Followings are some codes and configurations in my project:
1. AuthenticationAction.java
package com.myproject.authc.action; import ................. @Name("authenticator") public class AuthenticationAction { @Logger private Log log; @In private Credentials credentials; @In private Identity identity; @Out(required = false, scope = ScopeType.SESSION) private UserBean userBean; /** * Commented by Robertus (20110429) Reason: Not being used BEGIN { * * @In(value = "acl", create = true) * @Out(value = "acl") private AclUtil aclUtil; } END */ @In(value = "authentication", create = true) private IAuthentication authenticationMgr; @In(create = true) private Actor actor; @In(value = "groupManager", create = true) private IGroup grpMgr; @In(value = "roleManager", create = true) private IRole roleMgr; @In(value = "aclManager", create = true) private IAcl aclMgr; @In(value = "userActivityLog", create = true) private IUserActivityLog userActLogMgr; @In(value = "organizationUnitManager", create = true) private IOrganizationUnit orgUnitMgr; @In(value = "groupUserManager", create = true) private IGroupUser groupUserMgr; @In(value = "organizationUnitRecordTypeManager", create = true) private IOrganizationUnitRecordType orgUnitRecordTypeMgr; public boolean authenticate() { log.info("authenticating #0", credentials.getPassword()); // ROBERTUS-START if (userBean == null) { userBean = new UserBean(); } // ROBERTUS-END log.info("--- before transfering username and password from credentials --- "); log.info("inside authenticate() userBean.username = " + userBean.getUserName()); log.info("inside authenticate() userBean.password = " + userBean.getPassword()); // Put username and password to UserBean userBean.setUserName(credentials.getUsername()); userBean.setPassword(credentials.getPassword()); log.info("--- after transfering username and password from credentials --- "); log.info("inside authenticate() userBean.username = " + userBean.getUserName()); log.info("inside authenticate() userBean.password = " + userBean.getPassword()); // To populate upfront before UsrActivityLog is not updated with the // latest login date. populateLoginInfo(userBean.getUserName()); boolean exist; exist = authenticationMgr.authenticateUser(credentials.getUsername(), credentials.getPassword()); log.info("inside authenticate() credentials = " + credentials); log.info("Is user '#0' exist? #1", credentials.getUsername(), exist); if (!exist) return exist; // no need to continue because the user not exist postAuthenticated(); return exist; } private void printUserBeanDetails() { log.debug("-------------------------------------------------------------------------------"); log.debug("\t\t\t Displaying getOuStateId"); log.debug("-------------------------------------------------------------------------------"); log.debug("\tuserBean.getOuStateId() = " + userBean.getOuStateId()); log.debug("-------------------------------------------------------------------------------"); log.debug("\t\t\t Displaying getNotManagedOuDistrictIds"); log.debug("-------------------------------------------------------------------------------"); List<Integer> notManagedOuDistrictIds = userBean .getNotManagedOuDistrictIds(); for (Integer notManagedOuDistrictId : notManagedOuDistrictIds) { log.debug("\tnotManagedOuDistrictId = " + notManagedOuDistrictId); } log.debug("-------------------------------------------------------------------------------"); log.debug("\t\t\t Displaying getManagedOuDistrictIds"); log.debug("-------------------------------------------------------------------------------"); List<Integer> managedOuDistrictIds = userBean.getManagedOuDistrictIds(); for (Integer managedOuDistrictId : managedOuDistrictIds) { log.debug("\tmanagedOuDistrictId = " + managedOuDistrictId); } } public void doLogout() { userActLogMgr.updateLogoff(userBean.getUserId(), userBean.getSessionId()); } private void populateLoginInfo(String userName) { userBean.setLastAccessDate(userActLogMgr.findLastSuccessDate(userName)); } private void populateUserOrgUnitIds() { userBean.getUserOrgUnitIds().clear(); List<GroupUser> groupUserList = groupUserMgr .findGroupUserByUserId(userBean.getUserId()); if (groupUserList.size() != 0) { List<String> orgUnitIds = new ArrayList<String>(); for (GroupUser groupUser : groupUserList) { String orgUnitId = groupUser.getId().getOrgUnitId(); if (!orgUnitIds.contains(orgUnitId)) { orgUnitIds.add(orgUnitId); } } userBean.setUserOrgUnitIds(orgUnitIds); } orgUnitMgr.setUserBean(userBean); int linkId = -1; List<Object[]> firstOrgUnitByType = orgUnitMgr .findUserFirstOrgUnitByType(null); if (!firstOrgUnitByType.isEmpty()) { Object[] orgUnit = firstOrgUnitByType.get(0); userBean.setFirstOrgUnitId((String) orgUnit[0]); userBean.setUserOrgType(((java.math.BigDecimal) orgUnit[3]) .intValue()); Object oLinkId = orgUnit[2]; if (oLinkId != null) linkId = ((java.math.BigDecimal) orgUnit[2]).intValue(); } if (userBean.getUserOrgType() == 2) { // means state id (JPN) userBean.setOuStateId(linkId); userBean.setOuDistrictId(-1); userBean.getManagedOuDistrictIds().add(-1); userBean.getManagedOuDistrictIds().addAll( OrgUnitUtil.getManagedDistrictId(userBean .getFirstOrgUnitId())); } else if (userBean.getUserOrgType() == 3) { userBean.setOuStateId(-1); userBean.setOuDistrictId(linkId); userBean.getManagedOuDistrictIds().add(-1); userBean.getManagedOuDistrictIds().addAll( OrgUnitUtil.getManagedDistrictId(userBean .getFirstOrgUnitId())); } else { userBean.setOuStateId(-1); userBean.setOuDistrictId(-1); userBean.getManagedOuDistrictIds().add(-1); userBean.getNotManagedOuDistrictIds().add(-1); } } /** * To populate user group id for JBpm to initialize the task list. */ private void populateUserBpmInfo() { actor.setId(userBean.getUserId()); List<GroupUser> groupUserList = groupUserMgr .findGroupUserByUserId(userBean.getUserId()); if (groupUserList.size() != 0) { for (GroupUser ug : groupUserList) { System.out.println("JBPM USER GROUP => " + ug.getId().getOrgUnitId() + ":" + ug.getId().getGroupId()); actor.getGroupActorIds().add( ug.getId().getOrgUnitId() + ":" + ug.getId().getGroupId()); } } actor.getGroupActorIds().add(userBean.getUserId()); } private void populateUserGroup() { List<Object[]> objects = new ArrayList<Object[]>(); List<String> userGrpIds = new ArrayList<String>(); List<String> userGrpNames = new ArrayList<String>(); // populate user group details. objects.clear(); objects = grpMgr.findGroupByUserId(credentials.getUsername()); for (Object[] usrGrp : objects) { userGrpIds.add((String) usrGrp[0]); userGrpNames.add((String) usrGrp[1]); } userBean.setUserGroupIds(userGrpIds); userBean.setUserGroupNames(userGrpNames); log.info("authenticate(): user group: " + userBean.getUserGroupIds()); log.info("authenticate(): user orgId: " + userBean.getUserOrgId()); } private void populateUserRole() { List<String> strings = new ArrayList<String>(); List<String> userRoleIds = new ArrayList<String>(); // populate user role details. strings.clear(); if (userBean.getUserGroupIds().size() > 0) { strings = roleMgr.findRoleByGroupId(userBean.getUserGroupIds()); for (String usrRole : strings) { userRoleIds.add(usrRole); } } userBean.setUserRoles(userRoleIds); log.info("authenticate(): user role: " + userBean.getUserRoles()); } private void populateModule() { List<String> strings = new ArrayList<String>(); List<String> moduleIds = new ArrayList<String>(); // populate module details. strings.clear(); strings = aclMgr.findModuleByRoleId(userBean.getUserRoles()); for (String module : strings) { moduleIds.add(module); } userBean.setModule(moduleIds); log.info("authenticate(): module: " + userBean.getModule()); } private void populateModuleItem() { userBean.setAccessibleModuleItems(aclMgr.findByRoleIds(userBean .getUserRoles())); if (log.isDebugEnabled()) log.info("authenticate(): module item: " + userBean.getModuleItems()); } private void populateOrgUnitRecordType() { userBean.getOrgUnitRecordTypeIds().clear(); orgUnitRecordTypeMgr.setUserBean(userBean); userBean.getOrgUnitRecordTypeIds().addAll( orgUnitRecordTypeMgr.findOrgUnitByGroupOrgUnit()); } public boolean _authenticate() { boolean bool = false; log.info("authenticating #0", credentials.getUsername()); if (StringUtils.equals(credentials.getUsername(), "superuser")) { userBean.setUserId(credentials.getUsername()); userBean.setUserName("Super User"); userBean.setEmail("superuser@fms.psd.com"); identity.addRole("super-user"); bool = true; } else if (StringUtils.equals(credentials.getUsername(), "admin")) { userBean.setUserId(credentials.getUsername()); userBean.setUserName("Administrator"); userBean.setEmail("admin@fms.psd.com"); identity.addRole("admin"); bool = true; } else if (StringUtils.equals(credentials.getUsername(), "manager")) { userBean.setUserId(credentials.getUsername()); userBean.setUserName("Manager"); userBean.setEmail("manager@fms.psd.com"); identity.addRole("manager"); bool = true; } else if (StringUtils.equals(credentials.getUsername(), "jack")) { userBean.setUserId(credentials.getUsername()); userBean.setUserName("Jack Sparrow"); userBean.setEmail("jack@fms.psd.com"); identity.addRole("user"); identity.addRole("admin"); userBean.getModuleItems().add("USER_GROUP:buttonNew"); userBean.getModuleItems().add("USER_GROUP:buttonUpdate"); userBean.getModuleItems().add("USER_GROUP:buttonDelete"); bool = true; } else if (StringUtils.equals(credentials.getUsername(), "william")) { userBean.setUserId(credentials.getUsername()); userBean.setUserName("William Shakespear"); userBean.setEmail("william@fms.psd.com"); identity.addRole("user"); identity.addRole("admin"); userBean.getModuleItems().add("USER_GROUP:buttonUpdate"); bool = true; } return bool; } private void postAuthenticated() { User usr = authenticationMgr.getUser(); // populate user details userBean.populate(usr); populateUserOrgUnitIds(); // tempPopulateUserOrgUnitIds(); // Temporary fix that works (traverse // orgUnit trees) populateUserGroup(); populateUserRole(); populateModule(); populateModuleItem(); populateUserBpmInfo(); populateOrgUnitRecordType(); printUserBeanDetails(); } public void autoLogin() { log.info("inside autoLogin()........................."); Redirect redirect = (Redirect) Component.getInstance(Redirect.class, false); log.info("current viewid: " + redirect.getViewId()); log.info("inside autoLogin() credentials = " + credentials); log.info("inside autoLogin() credentials.username = " + credentials.getUsername()); userBean = (UserBean) Component.getInstance(UserBean.class, false); log.info("--- after getting UserBean from Seam Component ---"); log.info("inside autoLogin() userBean.username = " + userBean.getUserName()); log.info("inside autoLogin() userBean.password = " + userBean.getPassword()); log.info("inside autoLogin() principals = " + identity.getSubject().getPrincipals()); if (userBean != null) { log.info("UserBean is not null, force inject the credentials from userBean..."); credentials.setUsername(userBean.getUserName()); credentials.setPassword(userBean.getPassword()); log.info("After injecting the credentials from userBean..."); log.info("credentials.username: " + credentials.getUsername()); log.info("credentials.password: " + credentials.getPassword()); } identity.tryLogin(); log.info("after tryLogin()........................." + identity.isLoggedIn()); if (identity.isLoggedIn() && authenticationMgr.authenticateIdentity(identity)) { postAuthenticated(); } log.info("leaving autoLogin()........................."); } public boolean getAuthencationService() { if (PropertiesUtil.getInstance().getString("authc.service") .equals("oid")) { return true; } else { return false; } } }
2. UserBean.java
package com.myproject.web; import ......................... @Name("userBean") @Scope(ScopeType.SESSION) public class UserBean extends UserBeanBase implements Mutable { private static final long serialVersionUID = 1L; @Logger private static Log logger; // USER SECURITY private String isAccountDisabled; private Date accountExpiryDate; private Date passwordExpiryDate; private String isPasswordReset; private String isPasswordNearExpire; private String accountConcurrentSession; private int loginAttempt; private Date currentLoginDate; private long currentLoginTime; private Date lastAccessDate; private Date lastFailedAccessDate; // USER ORGANIZATION private String userOrgName; private String firstOrgUnitId; private String countryId; private String userOrgGroupId; private Integer ouStateId; private Integer ouDistrictId; private Integer messagePreference; private int userOrgType = 0; private List<String> userOrgUnitGroup = new ArrayList<String>(); // deprecated private List<String> userOrgUnitIds = new ArrayList<String>(); private List<Integer> orgUnitRecordTypeIds = new ArrayList<Integer>(); private List<Integer> notManagedOuDistrictIds = new ArrayList<Integer>(); private List<Integer> managedOuDistrictIds = new ArrayList<Integer>(); // for testing purpose (clustering) private String password; // USER GROUP private List<String> userGroupNames; // USER LOCALE private String currentLocale = LocaleConfig.instance().getDefaultLocale(); // private String currentLocale = FacesContext.getCurrentInstance() // .getApplication().getDefaultLocale().toString(); // DETERMINE IF APP CALLED FROM PORTAL private String isFromPortal; // USED TO HIDE LEFT MENU ON KMS POP-UPS private boolean fromKmsPortal = false; public UserBean() { HttpSession session = (HttpSession) FacesContext.getCurrentInstance() .getExternalContext().getSession(false); this.setSessionId(session.getId()); } public void populate(User user) { this.setUserId(user.getUserId()); this.setUserName(user.getUserName()); this.setEmail(user.getEmail()); this.setIsAccountDisabled(user.getDisabledFlag().toString()); this.setAccountConcurrentSession(user.getConcurrentSessionFlag() .toString()); this.setAccountExpiryDate(user.getExpiryDate()); this.setIsPasswordReset(user.getPasswordResetFlag().toString()); this.setUserOrgId(user.getOrgId()); // HttpSession session = (HttpSession) // FacesContext.getCurrentInstance().getExternalContext().getSession(false); // this.setSessionId(session.getId()); } ................ /** * Getter and setter */ ................ /** * Get and clear the dirty flag. * * @return true if the instance is dirty and requires replication */ @Override public boolean clearDirty() { return true; } }
3. weblogic.xml
<?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd"> <session-descriptor> <!--<cookie-name>NEWSS_ISSF</cookie-name>--> <sharing-enabled>true</sharing-enabled> <persistent-store-type>file</persistent-store-type> <persistent-store-dir>C:/newss/session/</persistent-store-dir> </session-descriptor> <library-ref> <library-name>jsf-12_12</library-name> <specification-version>1.2</specification-version> <implementation-version>1.2_12-b01-FCS</implementation-version> <exact-match>false</exact-match> </library-ref> </weblogic-web-app>
Thanks in advance