<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Mike Grogan&apos;s Blog</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mikeg/" />
<modified>2007-02-25T23:56:09Z</modified>
<tagline></tagline>
<id>tag:weblogs.java.net,2008:/blog/mikeg/332</id>
<generator url="http://www.movabletype.org/" version="3.01D">Movable Type</generator>
<copyright>Copyright (c) 2007, mikeg</copyright>
<entry>
<title>When to Use WSIT Reliable Messaging</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mikeg/archive/2007/02/when_to_use_wsi.html" />
<modified>2007-02-25T23:56:09Z</modified>
<issued>2007-02-25T23:56:02Z</issued>
<id>tag:weblogs.java.net,2007:/blog/mikeg/332.6680</id>
<created>2007-02-25T23:56:02Z</created>
<summary type="text/plain">The article discusses when the Reliable Messaging feature in WSIT should be used.</summary>
<author>
<name>mikeg</name>

<email>Mike.Grogan@Sun.COM</email>
</author>
<dc:subject>Web Services and XML</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mikeg/">
<![CDATA[<p>Reliable messaging is a feature of <a href="http://wsit.dev.java.net">WSIT</a>, which will be delivered through Glassfish V2.  Here is a link to the <a href="http://jax-ws.dev.java.net/servlets/ProjectDocumentList?folderID=5648&expandFolder=5648&folderID=5648">Milestone 3 build of WSIT</a>.<br />
 <br />
When the Reliable Messaging feature is used, it does its work automatically with almost no effort from  application developers.  This means that there is little to say about <i><b>how</b></i> to use the feature.  It is important, though, to understand <i><b>when</b></i> to use the feature.</p>

<p>The first thing to know is that an client application programmer does not get to choose whether to use Reliable Messaging.  If a Web Service endpoint uses it, it advertises the fact in a WS-Policy Assertion its WSDL.  A WSIT client invoking the endpoint will always use Reliable Messaging when the Policy assertion is present.  There are a few client-side Reliable Messaging configuration settings,  but they are fine-grained ones.  The default values  work fine in almost every case.  This means that the only special attention a client application programmer needs to pay to Reliable Messaging is the mechanism for closing a connection described <a href="http://weblogs.java.net/blog/mikeg/archive/2007/01/closing_wsit_re.html">here</a>.   In most cases, a client programmer does not need to know that Reliable Messaging is being used.</p>

<p>The developer of a WSIT endpoint only needs to choose whether to enable Reliable Messaging, and if it is enabled, must decide whether to enable the ordered delivery feature.  The decisions are reflected in Policy assertions in the WSDL of the endpoint.  These assertions can be edited using the NetBeans 5.5.1 IDE.  To make the decisions, it is important to understand some of the benefits and disadvantages of Reliable Messaging.</p>

<p><H2>Benefits</H2></p>

<p>Let's start with some benefits.  Reliable Messaging allows the WSIT Session support to work, but that is the subject of another article.  The benefits discussed here involve the delivery assurances that Reliable Messaging is designed to provide.  </p>

<p><H3>At least once delivery</H3></p>

<p>If Reliable Messaging is enabled, the client runtime will resend any messages that are lost in the network.  This saves the client application programmer the effort of doing this in application logic.  Arguably, this is mainly a service to the client, but there  might be business reasons for offering the service.</p>

<p><H3>At most once delivery</H3></p>

<p>Some distributed applications will not work correctly without this delivery assurance.  Consider a banking application with a payTo() method.  Suppose that this is a client program:</p>

<pre><b>
BankService service = new BankService();
CheckingAccount account = service.getCheckingAccountPort();

<p>received = false;<br />
while (!received) {<br />
     try {<br />
	account.payTo(“lucky recipient”, 1000.00);<br />
        received = true;<br />
     } catch (SocketTimeoutException e){}<br />
}<br />
</b></pre></p>

<p>Suppose that the request message for the call to payTo is received and processed, but the HTTP response is delayed and the connection times out.  In this case, the request will be resent and the payee will get a lucky windfall if the endpoint does not prevent the resent request from being processed by the business logic.</p>

<p>On the other hand, duplicate detection is not always as important.  Consider the code:</p>

<pre><b>
StockQuoteService service = new StockQuoteService();
StockQuotePort port = service.getStockQuotePort();
float price = port.getQuote(“SUNW”);
</b></pre>

<p>If the request message for the call to getQuote is processed several times, it will have no obvious ill effects.</p>

<p><br />
<H3>Ordered delivery</H3></p>

<p>Let's add a deposit() method to the CheckingAccount interface.  Consider the code:</p>

<pre><b>
BankService service = new BankService();
CheckingAccount account = service.getCheckingAccountPort();

<p>account.deposit(500.00);<br />
account.payTo(“possibly angry recipient”, 1000.00);<br />
</b></pre></p>

<p>If the request messages for the invocations of the deposit and payTo methods are processed out-of-order, the check will bounce if the initial balance was less than $500.00.  Since the messages might cross paths in the network, the application needs a way to ensure that they are processed in the order in which they were sent in order to work correctly.</p>

<p>In contrast, the StockQuote service in the example above will not malfunction if request messages for two quotes are processed out-of-order.</p>

<p>In summary, the cases where the Reliable Messaging delivery assurances are crucial to an endpoint application are ones where request messages to the endpoint have side-effects and different orderings or cardinalities of the messages leave the system in different (and possibly unpredictable) states.  On the other hand, for stateless services where invoking the operations has no side-effects, the benefits of the delivery assurances are not as compelling.</p>

<p><H2>Disadvantages</H2></p>

<p>There are  disadvantages to enabling Reliable Messaging.  Otherwise, it would be reasonable to enable it even in cases where there is no clear benefit.</p>

<p><H3>Performance</H3></p>

<p>This is the most frequently-mentioned disadvantage,but might not really matter that much to many users.  The Reliable Messaging protocol sends  its own messages and adds protocol headers to application messages, so both the number of messages and their sizes are increased if Reliable Messaging is enabled.  This increases processing times and decreases the number of requests that can be processed by a given endpoint.</p>

<p><H3>Interoperability</H3></p>

<p>This might be the main disadvantage.  Not all vendors of Web Services stacks support Reliable Messaging.  The implementations of vendors who do support it might not even  interoperate well, because of the looseness of the WS-RM Specification.  (The specification is being standardized and tightened by  <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=ws-rx">The OASIS WS-RX Technical Committee</a>.)  WSIT Reliable Messaging endpoints are designed to work with WSIT and WCF Reliable Messaging clients, but may not work as well with clients using other software stacks.  Therefore, enabling Reliable Messaging for a WSIT endpoint might limit the number of clients that are able to consume the service.</p>

<p><H2>Summary</H2></p>

<p>Using Reliable Messaging has real benefits.  Indeed, some Web Service applications will not work correctly without the delivery assurances it provides.  Not every application benefits from it however, and there are costs.  A WSIT developer should weigh the advantages against the disadvantages for each application before enabling the feature.</p>]]>

</content>
</entry>
<entry>
<title>Closing WSIT  Reliable Messaging Connections</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mikeg/archive/2007/01/closing_wsit_re.html" />
<modified>2007-01-24T20:37:48Z</modified>
<issued>2007-01-24T20:37:42Z</issued>
<id>tag:weblogs.java.net,2007:/blog/mikeg/332.6403</id>
<created>2007-01-24T20:37:42Z</created>
<summary type="text/plain">A discussion of how Reliable Messaging connections can be cleanly closed using the WSIT programming model. </summary>
<author>
<name>mikeg</name>

<email>Mike.Grogan@Sun.COM</email>
</author>
<dc:subject>Web Services and XML</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mikeg/">
<![CDATA[Most Reliable Messaging implementations in Web Services stacks, including the ones in Sun's <a href="http://wsit.dev.java.net">WSIT</a> and Microsoft's <a href="http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx">WCF</a> are designed to operate "under-the-hood" with little or no effort required from client or server application programmers.

There is one case where it is sometimes important for a client application programmer to communicate with the Reliable Messaging system.  A Reliable Messaging connection requires both a client and endpoint to maintain state related to the connection.  There is no automatic way for the runtime components to know when a client has finished using the connection, so an API (which I'll describe shortly) is provided for the purpose.  If the client programmer uses the API, it allows the client runtime to send a <b>WS-RM TerminateSequence</b> message to the endpoint, so both client and endpoint runtimes can do an orderly shutdown of the connection, and discard any resources associated with it.

This is analogous to the usual database programming model, where Connection objects have close() methods that perform a similar function.

The JAX-WS 2.1 interface with the close() method (it's only method) is <a href="http://fisheye5.cenqua.com/browse/~raw,r=1.1.2.1/jax-ws-sources/jaxws-ri/rt/src/com/sun/xml/ws/Closeable.java">com.sun.xml.ws.Closeable</a>.  Every instance of a JAX-WS 2.1 client, whether it is a Proxy or a Dispatch implements Closeable, so the code:


<pre><b>
((Closeable)client).close();
</b></pre>

always works, although it sometimes will have no effect.  Calling the method provides a way for WSIT components, such as Reliable Messaging and Secure Conversations to do clean-up activities related to the client instance.

Sometimes calling close() can be avoided without harmful effects.  Every RM endpoint has a timeout interval.  While a client is "still around", it will occasionally send messages to the endpoint to prevent a timeout, but if the client "goes away", the timeout will be reached, and the endpoint will assume that the connection is "closed".

There is another very important benefit to calling close, though.  Consider the program:

<pre><b>
public static void main(String[] args) {

	PingService service = new PingService();
	PingPortType port = service.getPingPort();

	port.ping();
}	
</b></pre>

Suppose that when this program is run,  the request message for port.ping() is lost in the network.  The way that a Reliable Messaging client does its job is to periodically check which messages have been acknowledged by the endpoint and and resend the ones that have not been.  In this case, however, the end of the program will be reached before this can happen!

This can be fixed by adding the call to close():

<pre><b>
public static void main(String[] args) {

	PingService service = new PingService();
	PingPortType port = service.getPingPort();

	port.ping();
	((Closeable)port).close();
}
</b></pre>

By default, the call to close() will not return until all messages have been acknowledged.  This means that the end of the main() method will not be reached until the request has been resent as many times as necessary for it to be acknowledged.

It is possible to override this default behavior.  WSIT has a client-side Reliable Messaging setting called <b><i>CloseTimeout</b></i>.
If non-zero, it is the interval (in milliseconds) that the client runtime will block waiting for a call to close() to
return.  When the timeout is reached, close() will return and a <b>SEVERE</b>  log message will be emitted announcing the likelihood that messages have been lost.

In summary.  There is <b>com.sun.xml.ws.Closeable</b> interface with a close() method that is implemented by every JAX-WS 2.1 client.
There is usually some benefit to using it and in a few cases, it is crucial.  It never hurts to call it, even if the client does not use Reliable Messaging, so to be safe, it is a good programming practice to always call it.]]>

</content>
</entry>
<entry>
<title>Reliable Messaging in WSIT Milestone 2</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mikeg/archive/2006/09/reliable_messag.html" />
<modified>2006-09-22T22:16:08Z</modified>
<issued>2006-09-22T22:10:14Z</issued>
<id>tag:weblogs.java.net,2006:/blog/mikeg/332.5611</id>
<created>2006-09-22T22:10:14Z</created>
<summary type="text/plain">A description of the Reliable Messaging features in the WSIT Milestone 2 Binary release.</summary>
<author>
<name>mikeg</name>

<email>Mike.Grogan@Sun.COM</email>
</author>
<dc:subject>Web Services and XML</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mikeg/">
<![CDATA[Other than the usual bug fixes and minor adjustments needed to adapt to changes between WCF versions, 
the new work for the milestone consists of implementing some configuration settings that may 
affect performance.  First some background:<p><p>

The WS-RM spec<Link> defines a SOAP-based protocol used by middleware components that exchange messages called 
the sender and receiver.  It defines a way for a sender of to ask the receiver 
which messages have arrived and a way for the receiver to answer.  The specification says little about how to 
use the protocol. Of course, the main use is that it allows the sender to ensure that all messages have arrived by 
periodically asking the receiver which ones have been delivered and resending the ones that haven't.<p><p>

A few variables affect the efficiency and performance of a system that does this.  Namely how often the sender asks 
the receiver to account for the received messages and how often the sender resends the un-accounted-for messages.
Imagine a scenario where almost no messages are lost.  "Correct" values for these variables depend very much on the 
frequency of lost messages and the length of time it takes to deliver a message.  We are exposing these variables 
as configuration settings, so end-users will be able to adjust them.<p><p>  

The configurations are client configurations, unlike the other RM configurations that only affect the endpoint.  As of 
Milestone 2, the settings are not exposed in the Netbeans UI, but it is possible to try them by manually editing the 
configuration files.  Each setting uses a proprietary PolicyAssertion.  They are:<p><p><p>

<code>
&lt;sun:ResendInterval Milliseconds="2000"/&gt;<p>
&lt;sun:AckRequestInterval Milliseconds="1000"/&gt;<p>
</code>
 
where sun==http://sun.com/2006/03/rm.  The namespace will change in the next release.<p><p><p>  

By default, retries happen every 2000 ms.  The Resend setting in the Policy assertion will be used if it is larger 
than 2000, unless the system detects an abnormal build-up of unacknowledged messages, in which it will revert 
to the default value.<p><p>

By default the client requests acknowledgements on every application message.  If a positive value is specified for
AckRequestInterval in the policy assertion, the system will always wait for that interval between requests for
acknowledgements, unless the system detects an abnormal build-up of unacknowledged messages, in which case it will
refert to the default behavior.<p><p>

As of Milestone 2, the settings are not exposed in the Netbeans UI.  However it is possible to experiment with the
settings by manually adding them to the PolicyAssertion for an endpoint's wsdl:binding.  Obviously, this is a 
temporary arrangement, since the settings ultimately need to be part of the client's configuration.  However, at the
moment, a client will use these settings if it finds them in the WSDL for the endpoint it is communicating with.


]]>

</content>
</entry>
<entry>
<title>WS-Reliable Messaging and Session Support (Part 2)</title>
<link rel="alternate" type="text/html" href="http://weblogs.java.net/blog/mikeg/archive/2006/08/wsreliable_mess.html" />
<modified>2006-08-16T19:35:23Z</modified>
<issued>2006-08-16T19:35:18Z</issued>
<id>tag:weblogs.java.net,2006:/blog/mikeg/332.5366</id>
<created>2006-08-16T19:35:18Z</created>
<summary type="text/plain">A discussion of Session support in project Tango and a comparison with the HTTP Sessions approach.</summary>
<author>
<name>mikeg</name>

<email>Mike.Grogan@Sun.COM</email>
</author>
<dc:subject>Web Services and XML</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.java.net/blog/mikeg/">
<![CDATA[<P STYLE="margin-bottom: 0in">This is Part 2 in a series of articles
on supporting sessions using <B><I>WS-ReliableMessaging</I></B>. In
my talk at Java One, I showed a demo of a Web Service endpoint that
needs Reliable Messaging to work properly. Like most endpoints that
benefit from Reliable Messaging, this one maintains state between
requests. In Part 1 of this series, Bhakti has written an <A HREF="http://weblogs.java.net/blog/bhaktimehta/archive/2006/08/ws_reliable_mes_1.html">article</A>
that describes the demo. 
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">The endpoint in the demo uses Session
Identifiers that happen to be implemented using Reliable Messaging.
These Session Identifiers are exposed as an experimental feature in
<A HREF="http://weblogs.java.net/blog/haroldcarr/archive/2006/02/an_overview_of_1.html">Tango</A>.
This is one way that the contents of SOAP Headers used by WS-*
protocols can be used to generate Session Identifiers. Secure
Conversation Tokens can also be used for this purpose. Microsoft uses
both mechanisms in <A HREF="http://microsoft.com/">Microsoft's
</A><A HREF="http://windowscommunication.net/">Windows Communication
Foundation </A>(WCF).</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">Like most demos, this one has problems
that would prevent it from being used in real-life applications.
Also, like most demos, there are ways to improve it by doing more
work. In this article, I'll try to indicate some of the advantages
and disadvantages of this approach to session management and compare
the approach with one that is an established feature of JAX-WS.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">This approach is the use of
<B><I>HttpSessions</I></B>. This article in <A HREF="http://weblogs.java.net/blog/ramapulavarthi/archive/2006/06/maintaining_ses.html">Rama's
Blog</A> illustrates the approach. Here are some comparisons of
<B><I>HttpSessions </I></B>and <B><I>Reliable Sessions</I></B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Transparency</B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">The <B><I>HttpSessions</I> </B>approach
requires that client application programmers explicitly enable
session support by setting the <B>javax.xml.ws.session.maintain</B>
BindingProvider property to <B>true</B>. The <B><I>Reliable Sessions</I></B>
approach is transparent to the client programmer.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Interoperability</B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">The  <A HREF="http://jcp.org/aboutJava/communityprocess/final/jsr224/index.html">JAX-WS
Specification </A> requires that every JAX-WS implementation support
<B><I>HttpSessions</I></B>. This means that in every implementation,
an endpoint can be deployed so that it supports <B><I>HttpSessions</I></B>,
and the session support will work correctly with JAX-WS clients whose
session support has been enabled.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in">The <B><I>Reliable Sessions</I></B>
approach requires that clients support implement the non-standard
WS-RM specification  and define RM Sequences so that all requests
belonging to the same session belong to the same sequence.  This will
always be the case with a Tango or WCF client, but may not be the
case with other Reliable Messaging implementations.  
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Protocol Independence</B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B><I>HttpSessions</I></B> require the
use of the HTTP Transport. <B><I>Reliable Sessions</I></B> do not.
With most current Web Services, this is not a significant limitation.
In the future, the increased use of other transports such as 
FastInfoset will make it more significant.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Security </B>
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in; font-weight: medium">Both approaches
are subject to attacks that tamper with parts of Request messages on
which Session Identifiers are based. For <B><I>HttpSessions</I></B>
this entails tampering with HTTP headers. For <B><I>Reliable Sessions</I></B>
it entails tampering with SOAP Headers. Both risks can be addressed
using transport-level security. In cases where message-level security
is required, <B><I>HttpSessions</I></B> are vulnerable. On the other
hand, <B><I>Reliable Sessions</I></B> can offer some defense in these
cases. In particular, in Tango or WCF, if a Reliable Messaging
endpoint is configured to use Secure Conversations, the same Secure
Conversation Token will be used to protect each request messaging
belonging to a given sequence.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in"><B>Resource Management</B></P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in; font-weight: medium">This is the
biggest problem with the demo. The demo endpoint maintains state for
each client, and does nothing to discard the state belonging to
clients that are no longer using the endpoint. This means that the
Hashtable that stores session state will grow uncontrollably. Of
course, we could improve the program by recording the last time each
key in the Hashtable is accessed, and periodically removing keys that
have not been accessed lately, but that is inconvenient. It would be
nice if there was another experimental feature in the infrastructure
to help us manage session lifetimes.</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>
<P STYLE="margin-bottom: 0in; font-weight: medium">This problem does
not exist for the <B><I>HttpSessions</I> </B>approach. This is
because HTTP Sessions expire if they are not accessed within a
specified interval. 
</P>
<P STYLE="margin-bottom: 0in"><BR>
</P>]]>

</content>
</entry>

</feed>