Stateful JAX-WS with Coherence*Web

We describe a stateful JAX-WS web service with high availability provided by Coherence*Web [1]. Deployed to two separate WebLogic managed servers, the web service stores its state in http session cookies. Coherence*Web distributes and synchronizes http session data between both managed servers. As a result, two endpoints with synchronized web service state provide high availability. With one endpoint down, another could continue to serve the service request with current web service state.

Note that WebLogic clustering can also provide highly available http sessions. However, we want to demonstrate Coherence*Web as an alternative to clustering for high availability. Therefore, we do not use clustering here. Instead, we use Coherence*Web.

Setting up the stateful web service with Coherence*Web involves the following steps.

  • start Coherence*Web cache server 
  • create and configure managed servers
    • deploy Coherence*Web as a shared library to the managed servers
  • create and deploy the web service
    • stores state in http session
    • instrument the web service using Coherence*Web
    • deploy the web service to both managed servers
Start Coherence*Web Cache Server

Start Coherence*Web cache server using the command below [2].

java -server -Xms512m -Xmx512m 
-cp coherence/lib/coherence.jar:coherence/lib/coherence-web-spi.war

Create and Configure Managed Servers

Copy coherence/lib/coherence.jar [2] to $DOMAIN_HOME/lib.

Start WebLogic AdminServer using


Create two managed servers Server-2 at port 7012 and Server-3 at port 7013 using the admin console. Start both servers using the commands below.

$DOMAIN_HOME/bin/ Server-2
$DOMAIN_HOME/bin/ Server-3

Deploy coherence\lib\coherence-web-api.war [2] to the servers as a shared library. 

Create and Deploy the Web Service

Install Oracle Enterprise Pack for Eclipse (OEPE) on Eclipse Galileo [4]. In Eclipse, create a web service using the following WSDL and implementation.

<xsd:import namespace=""
 schemaLocation="http://localhost:7001/Stateful_WS_Coherence/StatefulWSService?xsd=1" />
<message name="addItem">
<part name="parameters" element="tns:addItem" />
<message name="addItemResponse">
<part name="parameters" element="tns:addItemResponse" />
<portType name="StatefulWS">
<operation name="addItem">
<input message="tns:addItem" />
<output message="tns:addItemResponse" />
<binding name="StatefulWSPortBinding" type="tns:StatefulWS">
<soap:binding transport=""
style="document" />
<operation name="addItem">
<soap:operation soapAction="" />
<soap:body use="literal" />
<soap:body use="literal" />
<service name="StatefulWSService">
<port name="StatefulWSPort" binding="tns:StatefulWSPortBinding">
 location="http://localhost:7001/Stateful_WS_Coherence/StatefulWSService" />
</definitions> and

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.*;
import javax.annotation.Resource;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*
public class StatefulWS {
WebServiceContext ctx;
public int addItem(String name) {
HttpServletRequest req = (HttpServletRequest)
HttpSession session = req.getSession(true);
if (session == null)
throw new WebServiceException("No HTTP Session found");
System.out.println("httpsession: id="+session.getId());

//Get the cart object from the HttpSession
List<Item> cart = (List<Item>)session.getAttribute("myCart");
if (cart == null)
{ cart = new ArrayList(); }
// Add the item to the cart
cart.add(new Item(name));
// Save the updated cart in the HTTPSession
session.setAttribute("myCart", cart);
// return the number of items in the stateful cart
return cart.size();
public class Item implements {
public String name;public Item(String name){ = name;

Add coherence-web-api library into weblogic.xml [2].


Deploy the web service to both managed servers.


Run the test.

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;

public class StatefulWSClient {
public static void main(String[] args) throws Exception {
StatefulWSService service =
 , new QName("", "StatefulWSService"));
StatefulWS port = service.getStatefulWSPort();

.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);


System.out.println("calling " +
for (int j=0; j<5; j++) {
try {
int response = port.addItem("abc");
System.out.println("Got " + response);
} catch (Exception ex) {}

System.out.println("calling " +
for (int j=0; j<5; j++) {
try {
int response = port.addItem("abc");
System.out.println("Got " + response);
} catch (Exception ex) {}

The test invokes the web service five times for each endpoint.  The output shows that the returned count increases, indicating synchronized web service state across both endpoints.

Got 1
Got 2
Got 3
Got 4
Got 5
Got 6
Got 7
Got 8
Got 9
Got 10

Both managed servers output the same http session id's.

httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfs14fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923

  1. Coherence*Web and WebLogic Server
  2. Installing Coherence*Web on the WebLogic Server 10.3
  3. Stateful JAX-WS
  4. Oracle Enterprise Pack for Eclipse

Thanks for taking the top out to write this interesting post.

Posted by Leoma Ohle on February 19, 2010 at 01:06 PM PST #

Thank you for a great post

Posted by Watch Eclipse on April 20, 2010 at 03:34 PM PDT #

I agree with you. Things sweet the taste prove in digestion sour. ~William Shakespeare, King Richard the Second, 1595

Posted by sites like chat roulette on May 14, 2010 at 07:32 PM PDT #

What an outstanding job you have done. You have served many people by creating this post. Hats off to you. Thank you and looking more like these posts.

Posted by Silver Bullion on August 14, 2010 at 10:12 PM PDT #

This site seems to get a large ammount of visitors. How do you promote it? It gives a nice individual twist on things. I guess having something real or substantial to talk about is the most important factor.

Posted by Hermina Smoldt on October 30, 2010 at 08:17 PM PDT #

I’m having a little issue I cannot make my reader pick up your feed, I’m using google reader by the way.

Posted by hurtige hjemmesider on November 02, 2010 at 04:23 PM PDT #

Hmm i don't know if i quite agree with your point here. I did a little research on the subject but yahoo hasn't much information on the subject! So thanks for providing us with information.

Posted by Mohammad Brothern on November 21, 2010 at 08:53 AM PST #

I love reading websites like these. It has been an great source of info. I could not stumble on sites like these. Thanks once again.

Posted by Karole Benz on December 30, 2010 at 08:03 AM PST #

I would probably use this info mate, but where do you get this one?

Posted by Lee Saile on January 01, 2011 at 11:49 PM PST #

Apple now has Rhapsody as an app, which is a great start, but it is currently hampered by the inability to store locally on your iPod, and has a dismal 64kbps bit rate. If this changes, then it will somewhat negate this advantage for the Zune, but the 10 songs per month will still be a big plus in Zune Pass' favor.

Posted by Haine on January 03, 2011 at 11:36 PM PST #

My friend and I were just having a debate about the topic you referred to in your blog and apparently, I win the discussion! Thank you for clearing it out.

Posted by leukemia on January 06, 2011 at 09:18 AM PST #

I groked this post of yours, over at facebook and figured that you might well want to hear about it. Should you eventually get my notation down here, please send a short PM to the email box shown (for safety) and I will try to send the address for you. Great post and TY in advance…

Posted by Keira Haukaas on January 26, 2011 at 01:34 PM PST #

GO on !!!!! ,.....I will save all that for future use.

Posted by Sam Mook on February 01, 2011 at 11:50 PM PST #

thanks 1

Posted by Fanny on March 01, 2011 at 10:13 AM PST #

This is my second visit to this blog!! We are starting a brand new initiative in the same category as this blog? You definitely answered all the questions!! Thanks very much! I really enjoyed reading this.? Valuable information and excellent design you got here!!! I really like what you had to say.I thought it was going to be some boring old post, but it really compensated for my time. This is very nice one and gives indepth information.? Where else could I get this kind of information written in such a perfect way?!!

Posted by Cherry Cubbage on March 05, 2011 at 05:02 AM PST #

I am going to go ahead and bookmark this post for my brother for the study project for school. This is very interesting! This post truly made my day suknie na ślub. Interesting blog. This is a really good read for me! The illustrations you have made, the easy website menu, the relationships your site give support to create - it's got mostly impressive! Use a good day!

Posted by przygotowania na wesele on March 05, 2011 at 11:40 AM PST #

I am impressed, your writing skills and the layout on your blog is most informative.

Posted by Buy Backlinks on March 05, 2011 at 12:23 PM PST #

Hi there! opening your post i think it is great. This is very nice topic If you like you should check my post at my wesele blog! where you find a lot of post about weeding jewelery and much more flowers organization questions. Thanks for this opinion I married nine years ago and what better to know about this best day. Wesele blog contain much more information about it

Posted by moda na ślub 2011 on March 14, 2011 at 12:20 PM PDT #

They recently are playing, for me too for awile YouTube wasn"t working here on tipb. I was wonderin g the same.Never knew about this. Sounds great since I constantly buy iTunes gift cards to replenish funds in my account.Oh, i meant what is the name of the iphone case in the podcast picture above, with the pink – blue color case.Never knew about this. Sounds great since I constantly buy iTunes gift cards to replenish funds in my account.Oh, i meant what is the name of the iphone case in the podcast picture above, with the pink – blue color case.Airplay doesn"t show up on my iPhone 4 not even in YouTube. Do you have to have an apple tv for it to show up.

Posted by mts to avi converter on March 16, 2011 at 08:08 AM PDT #

amount of sperm to get pregnant low sperm count pregnant how to increase sperm motility naturally average sperm count in one ejaculation cure for low sperm count increase sperm amount build up sperm how to ejaculate more frequently ejaculate without sperm how to make your sperm shoot farther sperm production process increase sperm count in men low sperm count natural treatment sperm motility iui how to generate sperm faster ejaculate volume pills zero sperm motility sperm increase pills better sperm production sperm count in older men

Posted by sex toys on April 06, 2011 at 11:02 AM PDT #

Great info. This just what I've been looking for. I know additional people who'll find this useful too so, I be sure to pass this along for them as well. Many thanks.

Posted by kopfschmerzen hausmittel on April 26, 2011 at 08:29 PM PDT #

Just what exactly I'm trying to say, is that all through history we did not need a mechanical product to pass around music, but you did need to have a mechanical device to pass on text (not speaking - writing). This tool was some kind of real mark upon a flat substrate of some kind. Hence, this has been with us a long time as the standard of living increased. One important thing people accomplished was convey that experience in to our lives early as possible.

Posted by Merlin Treinen on April 29, 2011 at 08:13 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

The official blog for Oracle WebLogic Server fans and followers!

Stay Connected


« April 2014