会话属性未在tomcat 7群集中正确复制

时间:2014-01-20 08:53:46

标签: java xml session tomcat serialization

我在struts2.3 ::

中有以下代码
SessionEvent se = new SessionEvent();

se.setSessionID(session.getId());

se.setUserID(user.getUserId());

session.setAttribute("SessionEvent", se);**


Map attributes = ActionContext.getContext().getSession();

attributes.put("USER", user);  // user is a serialized object

attributes.put("ID", 0);

ActionContext.getContext.setSession(attributes);

CustomSessionManager cst = new CustomSessionManager();

cst.setUserID(user.getUserId());

cst.setUserMachineIP(req.getRemoteHost());

cst.setUsersessionId(session.getId());

session.setAttribute("boundUnboundUser", cst);


SessionEvent And CustomSessionManager are Serialized Listener classes ::

public class SessionEvent implements HttpSessionBindingListener, Serializable
{

     public void valueBound(HttpSessionBindingEvent arg0)
     {

     }
     public void valueUnbound(HttpSessionBindingEvent arg1)
     {
     }
}




public class CustomSessionManager implements HttpSessionBindingListener, Serializable
{

     public void valueBound(HttpSessionBindingEvent arg0)
     {

     }
     public void valueUnbound(HttpSessionBindingEvent arg1)
     {
     }
}

现在的问题是,在复制时,DeltaManager能够复制SessionEvent和CustomSessionManager对象,但无法重新复制用户对象。现在,如果我更改代码序列并将会话代码放在会话事件之上,则会复制用户对象,但自定义会话管理器不会。不确定这是否是我的代码中的问题或者tomcat 7中Delta Manager的行为存在问题。我也标记了我的Web应用程序。我的tomcat接收器端口也不同。我正在使用粘性会话。以下是群集的server.xml配置 我还在server.xml文件中的Engine标记内指定了jvmRoute属性。我使用mod_proxy_balancer进行负载均衡

  <!--For clustering, please take a look at documentation at:
      /docs/cluster-howto.html  (simple how to)
      /docs/config/cluster.html (reference documentation) -->
  <!--
  <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  -->
  <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" 
                     channelSendOptions="8">



         <Channel className="org.apache.catalina.tribes.group.GroupChannel">

         <Membership className="org.apache.catalina.tribes.membership.McastService"
         address="228.0.0.4"
         port="45569"
         frequency="500"
         dropTime="3000"/>

          <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
         <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
         </Sender>

         <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
         address="auto"
         port="4001"
         autoBind="100"
         selectorTimeout="5000"
         maxThreads="6"/>

         <Interceptor  
                                          className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

         <Interceptor 
                          className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

         </Channel>



         <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>

         <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

         <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>

         <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>

</Cluster>

  <!-- Use the LockOutRealm to prevent attempts to guess user passwords
       via a brute-force attack -->
  <Realm className="org.apache.catalina.realm.LockOutRealm">
    <!-- This Realm uses the UserDatabase configured in the global JNDI
         resources under the key "UserDatabase".  Any edits
         that are performed against this UserDatabase are immediately
         available for use by the Realm.  -->
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           resourceName="UserDatabase"/>
  </Realm>

        <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true" deployXML="true">
    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>
</Engine>

0 个答案:

没有答案