0

I'm trying to clusterize http session using hazelcast-wm 3.0, hazelcast-spring 3.0, spring 3.2.2 and servlet-api 3.0.

web.xml:

<listener>
    <listener-class>com.company.PropertiesListener</listener-class>
</listener>
...
<filter>
    <filter-name>hazelcast-filter</filter-name>
    <filter-class>com.hazelcast.web.WebFilter</filter-class>
    <!-- Name of the distributed map storing your web session objects -->
    <init-param>
        <param-name>map-name</param-name>
        <param-value>my-sessions</param-value>
    </init-param>
    <!-- How is your load-balancer configured? stick-session means all requests  
        of a session is routed to the node where the session is first created. This  
        is excellent for performance. If sticky-session is set to false, when a session  
        is updated on a node, entry for this session on all other nodes is invalidated.  
        You have to know how your load-balancer is configured before setting this  
        parameter. Default is true. --> 
    <init-param>
        <param-name>sticky-session</param-name>
        <param-value>false</param-value>
    </init-param>
    <!-- Name of session id cookie --> 
    <init-param>
        <param-name>cookie-name</param-name>
        <param-value>hazelcast.sessionId</param-value>
    </init-param>
    <!-- Should cookie only be sent using a secure protocol? Default is false. --> 
    <init-param>
        <param-name>cookie-secure</param-name>
        <param-value>false</param-value>
    </init-param>
    <!-- Should HttpOnly attribute be set on cookie ? Default is false. -->
    <init-param>
        <param-name>cookie-http-only</param-name>
        <param-value>false</param-value>
    </init-param>
    <!-- Are you debugging? Default is false. --> 
    <init-param>
        <param-name>debug</param-name>
        <param-value>false</param-value>
    </init-param>
    <!-- Configuration xml location; * as servlet resource OR * as classpath  
        resource OR * as URL Default is one of hazelcast-default.xml or hazelcast.xml  
        in classpath. --> 
    <init-param>
        <param-name>config-location</param-name>
        <param-value>hazelcast-context.xml</param-value>
    </init-param>
    <!-- Do you want to use an existing HazelcastInstance? Default is null. -->
    <init-param>
        <param-name>instance-name</param-name>
        <param-value>hz.session.instance</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>hazelcast-filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

<listener>
    <listener-class>com.hazelcast.web.SessionListener</listener-class>
</listener>

hazelcast-context.xml

<hz:hazelcast id="hz.session.cluster" depends-on="hazelcast.properties">
    <hz:config>
        <hz:instance-name>hz.session.instance</hz:instance-name>
        <hz:group name="${cluster.name:my-sessions}" password="${cluster.password:mypass}" />
        <hz:properties>
            <hz:property name="hazelcast.logging.type">slf4j</hz:property>
            <hz:property name="hazelcast.version.check.enabled">false</hz:property>
            <hz:property name="hazelcast.jmx">true</hz:property>
        </hz:properties>
        <hz:network port="${cluster.network.port:5701}"
            public-address="${cluster.member.address:127.0.0.1}"
            port-auto-increment="${cluster.network.port-auto-increment:true}">
            <hz:join>
                <hz:multicast enabled="${cluster.network.multicast.enabled:false}"
                    multicast-group="${cluster.network.multicast.group:224.2.2.3}"
                    multicast-port="${cluster.network.multicast.port:54327}" />
                <hz:tcp-ip enabled="${cluster.network.tcpip:true}">
                    <hz:members>${cluster.members:127.0.0.1}</hz:members>
                </hz:tcp-ip>
            </hz:join>
        </hz:network>
    </hz:config>
</hz:hazelcast>

PropertiesListener set System.properties: cluster.members, cluster.member.address, etc, depending on the machine where is running.

If I create hazelcast instance using Application's Spring Context, it works great:

@Configuration
@ImportResource("classpath:hazelcast-context.xml")
public class HazelcastConfig {

} 

It works great! Hazelcast instance is bound to the correct network interface.

But the problem is when I use WebFilter (previously, I deleted HazelcastConfig class so not to create Hazelcast instance twice.

These are the messages that appears in the log:

Oct 13, 2013 9:09:28 PM com.hazelcast.config.UrlXmlConfig
INFO: Configuring Hazelcast from 'file:/home/neuquino/springsource/vfabric-tc-server-developer-2.9.2.RELEASE/my-app/wtpwebapps/my-app-web/WEB-INF/classes/hazelcast-context.xml'.
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.name:my-sessions' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.password:mypass' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.port:5701' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.port-auto-increment:true' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.member.address:127.0.0.1' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.multicast.enabled:false' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.multicast.group:224.2.2.3' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.multicast.port:54327' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.network.tcpip:true' on node: null
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find a value for property  'cluster.members:127.0.0.1' on node: null
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[10.8.254.133]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true
Oct 13, 2013 9:09:29 PM com.hazelcast.system
INFO: [10.8.254.133]:5701 [dev] Hazelcast Community Edition 3.0.2 (20130906) starting at Address[10.8.254.133]:5701
Oct 13, 2013 9:09:29 PM com.hazelcast.system
INFO: [10.8.254.133]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.Node
INFO: [10.8.254.133]:5701 [dev] Creating MulticastJoiner
Oct 13, 2013 9:09:29 PM com.hazelcast.core.LifecycleService
INFO: [10.8.254.133]:5701 [dev] Address[10.8.254.133]:5701 is STARTING
Oct 13, 2013 9:09:34 PM com.hazelcast.cluster.MulticastJoiner
INFO: [10.8.254.133]:5701 [dev] 


Members [1] {
    Member [10.8.254.133]:5701 this
}

Oct 13, 2013 9:09:34 PM com.hazelcast.core.LifecycleService
INFO: [10.8.254.133]:5701 [dev] Address[10.8.254.133]:5701 is STARTED

The correct IP should be 11.1.0.133 (${cluster.member.address} value ), Hazelcast is picking one of the network interfaces of my PC, but not using ${cluster.member.address} value.

How can I use WebFilter with System Properties?

Thanks in advance!

Neuquino
  • 11,580
  • 20
  • 62
  • 76

1 Answers1

0

You can try to read the properties yourself and modify the Config instance created from the XML or you can create the Config instance yourself. XmlConfigBuilder should do the trick for you. Maybe I'll add a way to register post-creation listeners to the Spring module.

noctarius
  • 5,979
  • 19
  • 20