Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Are Your Handhelds Safe in J2EE Hands?

Are Your Handhelds Safe in J2EE Hands?

As J2EE usage proliferates into new domains, software engineers are realizing that out-of-the-box components cannot be used to solve problems for which they were not designed. One such example is state and session management (SSM) for applications serving wireless devices. We'll look at why traditional techniques don't work and how you can create your own scalable, fault-tolerant SSM solution.

Despite what your stock portfolio says, there is life out there in the high-tech world. One such example is all the software being created for wireless operator consumption. It's becoming more of a wireless world out there and new specifications are emerging. One example is the Wireless Village initiative created by Nokia, Ericsson, and Motorola. Essentially, this joint venture has created a specification for wireless devices. With its emphasis on interoperability, it addresses instant messaging and presence services (IMPS). This feeds into the expanding universe of mobile information appliances and their associated protocols, paradigms, and policies. Now more than ever, software engineers must think beyond the browser-based client.

J2EE is at a crossroads and facing increasing competition from .NET. Which one of these platforms will dominate the wireless frontier? Is J2EE up to the challenge?

Browser-Based SSM
What's so different about architecting an application serving wireless devices vs. one serving browsers? The big difference is state and session management - or what I like to call "SSM." To fully appreciate this, let's look at how SSM works for good old browsers.

To communicate with servers, browsers use HTTP, which is by nature a connectionless and stateless protocol. With HTTP alone, the server cannot maintain a relationship among the series of requests originating from a browser. There are times, of course, when stateful connections are needed, as in the case of a shopping cart in an online store. Each browser must be identified on subsequent requests in order to access its own shopping cart stored as an object in the server. Browser identity is commonly achieved through the use of HTTP cookies. When a browser visits a Web site, the server's response can include a cookie that contains a unique session ID. The browser will automatically pass this back on subsequent requests. If a browser does not accept cookies for security reasons, the server can use URL rewriting. Essentially, this means that the session ID is encoded right into the URL.

Whichever technique is used, ultimately a stateful connection is established via a session ID, which should have the following properties:

  • Be a long alphanumeric string (80-100 characters)
  • Be randomly generated (nonsequential)
These properties lead to session IDs that are difficult to guess and make it challenging for a hacker to masquerade as legitimate user. This requires the attacker to hijack the session, by guessing and using someone else's session ID, to gain access to the system.

Once this is in place, we have a mechanism that allows the server to establish browser identification, create a session, and hold state (i.e., the shopping cart) on behalf of its client. These are the fundamentals of SSM. On a small-scale application, SSM can be fairly straightforward. However, on a big-time, highly available, fault-tolerant, and scalable application, this is quite another matter. Let's take a look at some techniques that WebLogic (version 6.0 or higher) uses to fulfill these big-time requirements.

Performance and Scalability
No matter how much CPU power, memory, or disk space is available, a host has a finite load capacity. If the load increases beyond that point, a cluster of hosts is needed to achieve further scalability. This, of course, adds complexity to SSM. Let's look at how this works in a clustered environment. (Note that this is just one of the various configurations supported by WebLogic.)

In Figure 1, the application is hosted by a cluster composed of four identical and interchangeable hosts - meaning a request can be served by any host. Each is a WebLogic server hosting a servlet and EJB container. The cluster is accessed by a dedicated Web server (such as an Apache HTTP server or Microsoft Internet information server) that serves static content. Dynamically generated content, on the other hand, is dispatched to the WebLogic cluster. The Web server contains a WebLogic-specific plug-in (a.k.a. HttpClusterServlet) that load balances each request to a cluster member. Note that a client's session state is stored in only one particular server. Therefore, load-balancing algorithms, such as round-robin, can cause the request to be sent to a host that does not contain the session state. How will session state be accessed in this situation?

Session state could be accessed using network calls (via RMI) but this would incur extra network traffic and reduce performance. Alternatively, replicating the session state on every host so that it is available everywhere would also be nonviable because as the cluster grows, replication becomes more and more costly. N-host replication hinders scalability.

WebLogic has a clever solution. The session ID, stored in the cookie, has an embedded host name representing the session's home host. The plug-in uses this information to route the request to the home host. This guarantees that accessing the state will be a local, non-RMI call. Typically, processing requests requires many read/writes to session state. When you compare remote calls to local calls, which are 100 times more expensive, this is a key design advantage.

Fault-tolerance and state replication
Another benefit of clustered hosts is their inherent fault-tolerant quality. When one host fails, another one steps in to serve the request. All this happens transparently from the client's perspective. Let's look at how SSM fits into this.

In actuality, a particular session's state is stored on exactly one host (on whichever host the session was created), but is constantly being replicated on exactly one backup host (see Figure 2). Each time an element in the session state is created, updated, or deleted, WebLogic automatically replicates the state on a backup host. Furthermore, to minimize network traffic, only the state delta is replicated.

If the primary (home) host fails, the plug-in will transparently route the request to a secondary (backup) host. Conveniently, all of the session's state will be available and up-to-date right on that host. The secondary will now become the session's primary host and a new secondary will be assigned.

In an effort to avoid n-host state replication, WebLogic employs a one-host replication scheme, or what is referred to as "in-memory replication." As the cluster grows, scalability is not hindered by state replication since there is still only one secondary. The only drawback is that if both primary and secondary fail simultaneously, session data will be lost. WebLogic does offer alternatives, such as database replication, but to the detriment of performance. According to tests, this can represent an 83% drop in performance. In reality, the odds of having two hosts simultaneously fail and losing both session replicas are indeed slim. So in-memory replication is sufficient for most applications.

In retrospect, this is quite powerful functionality. It's all available in J2EE through Sun's servlet specification classes and WebLogic's load-balancing and fail-over mechanisms. Now that I've exposed the inner working of a browser-based client serving, let's see how this relates to wireless clients.

Why Out-of-the-Box Components Won't Do
Unlike the Web browser in the desktop world, there is no ubiquitous counterpart in the wireless world. Wireless devices come in many shapes and sizes and communicate using various protocols. Some are HTTP-based, some are not. All use proprietary networks and all client-to-server communication is mediated by a device-specific gateway. Furthermore, wireless devices must be served differently due to their inherent limitations in screen size, bandwidth, memory, and processing power.

Suffice it to say that despite efforts to make wireless devices behave like desktop browsers (WAP and HDML come to mind), they are a different kind of animal. As far as SSM is concerned, out-of-the-box Web components were specifically designed for HTTP clients. Until the specification addresses this, engineers can choose between two platform-leveraging solutions:

  • Solution 1: Create an adapter component that converts from the native protocol to HTTP - and get all the goodies J2EE has to offer
  • Solution 2: Build upon the platform and roll a custom solution

    These can be viewed as "poor man's solution" vs. "rich man's solution" respectively. Don't get me wrong, I'm not passing any judgements in terms of the affluence of these solutions. The first may be adequate for applications that don't require stateful connections. It can also be good enough if the adapter's performance is not an issue. There are caveats, though, and we'll examine them in detail. We'll also look at a best-of-breed solution.

    Creating an Adapter Component (Solution 1)
    To put things in perspective, let's say you're designing a server-side application that supplies content to SMS-based cell phones upon request. Assume that a stateful connection between client and server is required. The application would most likely use short message peer-to-peer (SMPP) protocol - the most widely used SMS gateway protocol. As Figure 3 demonstrates, the adapter component would convert every request from SMPP to HTTP.

    So where do the problems lurk? First, processing requests incurs the extra costs associated with piping requests across two network connections; one between gateway and adapter and another between adapter and application. Second, and more important, there would be two levels of SSM to maintain: the servlet-based SSM in the servlet container and the custom, adapter-based SSM. Essentially, since SMS gateways have no concept of HTTP cookies, this solution requires the adapter to emulate a browser. That is, save cookies and pass them back to the application. However, unlike the browser, which stores cookies for only one user, the adapter would need to store cookies for every connected client.

    So, how can we do this? A simple solution is to leverage your database's powerful storage and lookup features to store cookies. Naturally, extra costs would be incurred with database lookups on every request. Furthermore, the adapter would also be responsible for garbage collection. A custom eviction policy would need to be designed and implemented.

    There is another potential side effect. Transactions do not propagate across HTTP boundaries. Therefore, components on either side of the divide could not participate in the same transaction. Consequently, if the adapter would read and lock database tables needed by other components, database deadlocks would ensue. Transactions need to be carefully demarcated.

    Alternatively, memory could be used to store cookies. However, with memory, fault-tolerance and replication are now the main concern. If the host fails, the cookie cache must be replicated and available elsewhere.

    In summary, this solution can be sufficient for some applications but clearly falls short of servlet-based SSM.

    Rolling Your Own (Solution 2)
    The custom solution will have the following design ideals:

  • Maximize the amount of functionality that can be leveraged from the platform (write as little code as possible)
  • Have all the features and performance of servlet-based SSM

    Since servlet-based SSM will serve as a model, let's review the major players involved:

  • HttpSession: Holder of session state. Any serializable object can be stored. WebLogic automatically replicates state to a secondary host.
  • Servlet container: Manages the HttpSession cache including the accessibility of HttpSession and garbage collection.
  • Plug-in: Load-balances requests and manages fail over.
  • Cookie: Used by the plug-in to route requests. Contains the primary and secondary hosts for routing.

    The solution will consist primarily of moving these responsibilities to other J2EE components and writing custom code where this is not possible. In place of the HttpSession will be a stateful session bean (SFSB) in the EJB container. All that's needed is a custom bean class that allows clients to get and set any serializable object representing session state. Note that SFSBs and HttpSessions share the same replication mechanisms. When their hosts fail, and in-memory replication is enabled, their state is available on a secondary host. Unlike HttpSessions, however, SFSBs state replication is controlled by the transactional context. This gives SFSBs a net advantage in keeping session state cohernt across the cluster.

    In managing the cache of SFSBs, the EJB container is far more flexible than its servlet counterpart. The EJB specification defines the bean life cycle but allows vendors to implement their own cache management schemes. In WebLogic, you can control how aggressively the trash is taken out. First, define a timeout value for the bean. This tells WebLogic when an unused SFSB can be removed either temporarily (via passivation) or permanently (via eviction). Second, choose a cache management policy. Under the not-recently-used (NRU) policy, SFSBs are only passivated when the cache is running out of space. Conversely, the least-recently-used (LRU) policy will passivate upon timeout even if the cache is not full. The timeout value also affects the time of eviction.

    As for fail over and load balancing, this will be managed by SFSB's remote stub object. Remote stubs are objects that act as proxies to the actual session bean. Clients invoke methods on these stubs, which in turn invoke on the actual session bean. In WebLogic, stubs are "replica-aware" objects capable of routing the request to the host containing the SFSB. Similar to cookies, they also contain primary and secondary host data used for routing. When a primary host fails, they automatically route to the secondary host and update themselves to reflect the change. If a host fails during a request, however, the remote stub will throw an exception. The client need only retry and the stub will automatically adjust itself and subsequently function correctly.

    Like HttpSessions, EJB stubs must be cached and made accessible to clients. Caching can be done by retrieving the "handle" from the EJB stub and storing it in its serialized form. The stub can be re-created at anytime by deserializing the handle. However, since SFSB instances and their corresponding stub objects have different life cycles, the stub cache may not be in sync with the SFSB to which they refer. Making use of the SFSB's call-back methods (ejbActivate, ejbPassivate, ejbCreate, ejbRemove) is the key to keeping the cache in sync with the SFSBs. Figure 4 shows the complete solution using the same application shown earlier.

    Implementation Caveats
    The EJB specification states that a SFSB instance must not be accessed concurrently or an exception is thrown by the container. WebLogic has extended the spec and allows concurrent client invocations via the <allow-concurrent-calls> element in the WebLogic deployment descriptor. When activated, access is serialized at the bean level. This feature only works for SFSBs whose transactions are container-managed.

    Notice that as in solution 1, you still need to manage your own cache sessions (containing EJB headless rather than HTTP cookies).

    This can be implemented in a variety of ways. The simplest is to make it a database cache. If performance is an issue, you can purchase a third-party hardware cache box which can give you better performance, since these tend to be memory-based caches. The Java Community Process is addressing caching through its jcache component; this will certainly fill a void in J2EE if and when it becomes standard.

    Accessing State Locally
    One of the keys to this design is that, as with servlets, request processing is sent to the data rather than vice-versa. The goal is to access session state locally. To achieve this, the SFSB mediates all communications between the client (protocol adapter) and the application (a collection of EJBs replicated in the cluster). Each coarse-grain service offered by the application can only be accessed by a Java object whose sole purpose is to call the service on behalf of the client. This object is called the service executor and employs a "Strategy design pattern." The client creates an instance of the service-specific executor and passes it to the SFSB. In turn, the SFSB invokes a generic method on the executor which ultimately calls the back-end service. Using this framework guarantees that the request made from the protocol adapter will be processed on the host that contains the session's state.

    Whichever solution you choose, much can be leveraged from WebLogic and J2EE. This can make a big difference in delivering your product faster using dependable, out-of-the-box components.


  • Gridley, Michael; Woolen, Rob; Emerson, Sandra L. (2002). J2EE Applications and BEA Weblogic Server. Prentice-Hall.
  • Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John. (1994). Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
  • Failover and replication in a cluster: http://e-docs.bea.com/wls/docs70/cluster/failover.html
  • Wireless Village and the IMPS initiative: www.wireless-village.org
  • The SMS forum: http://smsforum.net
  • More Stories By Nick Maiorano

    Nick Maiorano is a Sun-certified J2EE architect with over 10 years of experience in software development. He is currently a senior developer and co-architect of a wireless, instant messaging application built atop J2EE WebKogic technology.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    @ThingsExpo Stories
    BnkToTheFuture.com is the largest online investment platform for investing in FinTech, Bitcoin and Blockchain companies. We believe the future of finance looks very different from the past and we aim to invest and provide trading opportunities for qualifying investors that want to build a portfolio in the sector in compliance with international financial regulations.
    A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
    Imagine if you will, a retail floor so densely packed with sensors that they can pick up the movements of insects scurrying across a store aisle. Or a component of a piece of factory equipment so well-instrumented that its digital twin provides resolution down to the micrometer.
    In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settle...
    Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
    Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    "IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
    When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy high-performance Java applications that use Java 3D and/or Jogl without having to run an installer. We are subject to the constraint that the applications be signed and deployed so that they can be run in a trusted environment (i.e., outside of the sandbox). Further, we seek to do this in a way that does not depend on bundling a JRE with our applications, as this makes downloads and installations rat...
    Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
    DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
    In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
    Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
    "Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
    The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...