Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Externalize HTTP Session Data to the JBoss Data Grid

November 23, 2015
Guna Vijayaratnam
Related products:
Red Hat JBoss Enterprise Application Platform

    Introduction

    This article aims to provide a step by step guide for setting up a remote Red Hat JBoss Data Grid (JDG) cluster as an HTTP session store for your state-full web applications running on Red Hat JBoss Enterprise Application Platform (EAP). I had recently explored this setup for another customer and figured it would be helpful to put together a set of detailed instructions for replicating this. This feature was recently released with the GA of JDG 6.5.

    Benefits of this Solution

    Here are some of the reasons why you might want to consider this solution:

    1. Increased application scalability and elasticity. By offloading the session data off to a remote Data Grid, the application tier itself can be more scalable and elastic. Adding a new EAP instance to the cluster will not require a rehash process which could be problematic especially when we are dealing with a lot of session data.

       

    2. Session Persistence. By offloading session data to a remote data grid, the application itself will be able to survive EAP node failures since the a JVM failure will not cause the session data to be lost. In addition, additional cache persistence policies can be set up on the remote data grid so the session data is persisted to a user defined persistence medium.

       

    3. Session Data Sharing. If you have a requirement for multiple applications to be able to share session data, this solution might be able to solve that use case as well.

    Detailed Configuration

    Configuring JBoss EAP Cluster

    First we need to configure the Infinispan subsystem of the EAP server(s) to write session data to the remote JDG cluster. In order to do this, we will execute a set of EAP Command Line Interface (CLI) commands to configure the underlying cache container to preform this remote write of the Http Session data. All these commands can also be batched up and executed as a script they are going to be executed individually in this example.

    1. Create a new Cache Container which is going to be holding the definition for the session data cache.
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container:add(default-cache=remote-http-cache, module=org.jboss.as.clustering.web.infinispan)
    2. Create a remote cache inside the parent cache container. This is going to be referenced from the web application to externalize the session data.
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache:add(mode=ASYNC, batching=true)
      
    3. Add a new transport setting
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/transport=TRANSPORT:add(lock-timeout=60000)
      
    4. Define the remote Data Grid cluster to persist the session data
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:add(remote-servers=[{"outbound-socket-binding" => "remote-jdg-server1"}])
      
    5. Set the properties for the remote cache store:
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=cache, value=remote-http-cache)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=socket-timeout, value=60000)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=shared, value=true)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=passivation, value=false)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=purge, value=false)
      
    6. Define the Socket Binding profile with the actual address for the remote JDG servers
      [standalone@localhost:9999 /] /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-jdg-server1:add(host=localhost,port=11222)
      

    Configuring JBoss JDG Cluster

    1. Create a new cache store on the remote Data Grid Cluster to define the external cache that we are going to be persisting our session data to.
      [standalone@localhost:9999 cache-container=clustered] ./distributed-cache=remote-http-cache:add(mode=SYNC, start=EAGER)
      {"outcome" => "success"}
      
    2. You should also see the following confirmation on your JDG console
      INFO  [org.jboss.as.clustering.infinispan] (MSC service thread 1-7) JBAS010281: Started remote-http-cache cache from clustered container
      

    Now we are ready to test this solution!

    Verifying the Setup

    In order to verify this configuration, we first need a state full web application that is going persist data into the HttpSession object.

    You can access a sample stateful application from here.

      1. Deploy the above application into a JBoss EAP Cluster.
      2. You should notice that the application is not configured to write the session data to the remote JDG cluster. We need to make an update to the jboss-web.xml to define the cache-name for the session replication configuration.
        <?xml version="1.0" encoding="UTF-8"?>
        <jboss-web>
         <context-root>/counter</context-root>
         <replication-config>
              <replication-trigger>SET_AND_GET</replication-trigger>
              <replication-granularity>SESSION</replication-granularity>
              <cache-name>jboss.infinispan.remote-http-container.remote-http-cache</cache-name>
         </replication-config>
        
        </jboss-web>
        
      3. Access the application from one of the servers where it is deployed to. You should notice that the counter will increase.
      4. Now use the JDG cli to connect to the remote JDG server to verify that the session information has indeed been written to the data grid cluster.
        [standalone@localhost:9999 cache-container=clustered]  cd /subsystem=infinispan/cache-container=clustered/distributed-cache=remote-http-cache
        [standalone@localhost:9999 distributed-cache=remote-http-cache] stats
        Statistics: {
          removeHits: 0
          stores: 3
          numberOfEntries: 1
          hitRatio: 0.0
          removeMisses: 0
          averageRemoveTime: 0
          elapsedTime: 1060
          evictions: 0
          hits: 0
          misses: 8
          statisticsEnabled: true
          averageWriteTime: 0
          readWriteRatio: 2.6666666666666665
          averageReadTime: 0
          timeSinceReset: 1060
        }
        .
        .
        .
        

    The session data has been externalized successfully! You can also test the persistent aspect of this solution by shutting down the EAP server and then bring it back and access the application with the previous session id - this time EAP should be able to use the session id and query the cache for the session data and pick up from where it left off.

    Last updated: February 26, 2024

    Recent Posts

    • Protect data offloaded to GPU-accelerated environments with OpenShift sandboxed containers

    • Case study: Measuring energy efficiency on the x64 platform

    • How to prevent AI inference stack silent failures

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.