<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Michael Gilfix Online</title>
  <link rel="alternate" type="text/html" href="http://michaelgilfix.com"/>
  <link rel="self" type="application/atom+xml" href="http://michaelgilfix.com/atom/feed"/>
  <id>http://michaelgilfix.com/atom/feed</id>
  <updated>2007-01-27T20:30:00-07:00</updated>
  <entry>
    <title>Starting From Scratch</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2008/02/24/starting-from-scratch" />
    <id>http://michaelgilfix.com/techblog/2008/02/24/starting-from-scratch</id>
    <published>2008-02-24T19:49:36-07:00</published>
    <updated>2008-02-24T19:49:36-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Code" />
    <category term="Design" />
    <summary type="html"><![CDATA[<p>I have a friend who recently joined a startup in San Fransisco, where they are looking to start development on a product in addition to their consulting business. This prompted a good conversation on what technologies to use when starting a product from scratch with a wide open playing field on choices. There's definitely no one-size-fits-all answer here; the technology choices will be influenced both by the needs/goals of the business and the nature of the application.</p>
<p>The interesting part of the conversation was identifying the questions / criteria to use in guiding the decision making. The answers to these questions definitely vary depending on the growth plans of the business (e.g., is the goal to scale to a big development shop? Is this a small auxiliary effort to a core business like consulting?). Technology choice is about investment. It's the foundation for building something that must be evolved and supported. In my friend's case, time-to-market, cost, productivity, and agility were necessities of the startup environment.</p>
<p>The following questions seem pretty helpful in guiding the decision making, regardless of the particulars of the technology:</p>
<p><UL><br />
<LI>What skills do I have available right now?<br />
<LI>Do I have confidence that my technology choices will be able to meet the evolution of the business?<br />
<UL><br />
<LI>Will the application be able to scale?</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>I have a friend who recently joined a startup in San Fransisco, where they are looking to start development on a product in addition to their consulting business. This prompted a good conversation on what technologies to use when starting a product from scratch with a wide open playing field on choices. There's definitely no one-size-fits-all answer here; the technology choices will be influenced both by the needs/goals of the business and the nature of the application.</p>
<p>The interesting part of the conversation was identifying the questions / criteria to use in guiding the decision making. The answers to these questions definitely vary depending on the growth plans of the business (e.g., is the goal to scale to a big development shop? Is this a small auxiliary effort to a core business like consulting?). Technology choice is about investment. It's the foundation for building something that must be evolved and supported. In my friend's case, time-to-market, cost, productivity, and agility were necessities of the startup environment.</p>
<p>The following questions seem pretty helpful in guiding the decision making, regardless of the particulars of the technology:</p>
<p><UL><br />
<LI>What skills do I have available right now?<br />
<LI>Do I have confidence that my technology choices will be able to meet the evolution of the business?<br />
<UL><br />
<LI>Will the application be able to scale?<br />
<LI>How will the application be managed, monitored, upgraded, etc.?<br />
<LI>Can the technology base be supported going forward? If an open source library is being used, is their a vibrant community supporting the software to help resolve defects?<br />
<LI>How easy can I morph the application into a direction that we didn't anticipate form the start?<br />
</UL><br />
<LI>How comfortable are the target customers that I will be selling it to with that technology base if the application must be deployed on premise or installed by an end user?<br />
<LI>How big is the ecosystem of libraries, add-on technologies, that can be leveraged -even if these capabilities do not seem immediately relevant?<br />
<LI>What development tools are available and what productivity do they promise?<br />
</UL></p>
<p>The answers to these questions can definitely be taken in a lot of directions, even once a programming language choice is made.</p>
<p>Here's a common Java-based technology platform that I've seen for rapid, low-cost development. Java's large ecosystem means ready access to a wide range of add-on open source (Apache has plenty) or commercial technologies.</p>
<p><UL><br />
<LI>Tomcat, Geronimo, or Glassfish as an app server base<br />
<LI>iBatis, Hibernate, or OpenJPA for persistence<br />
<LI>Axis2 for Web Services support<br />
<LI>Google Web Toolkit (GWT) or DOJO for a web-based app. I'm a big fan of GWT as a way to rapidly develop complex AJAX apps.<br />
<LI>Eclipse-based development environment<br />
<LI>Eclipse Equinox w/ web bridge as a component model for assembling an extensible platform<br />
<LI>SVN for source control. I'd buy services from <a href="http://cvsdude.com">cvsdude.com</a> for source control, bug tracking, and backup to get up and running quickly<br />
<LI>Maven for build automation<br />
</UL></p>
    ]]></content>
  </entry>
  <entry>
    <title>URI Templates and REST URL Matching</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2008/01/22/uri-templates-and-matching-REST-URLs" />
    <id>http://michaelgilfix.com/techblog/2008/01/22/uri-templates-and-matching-REST-URLs</id>
    <published>2008-01-22T20:36:45-07:00</published>
    <updated>2008-01-22T20:36:45-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="REST" />
    <summary type="html"><![CDATA[<p>OK, so I haven't posted in a long time. Figure I'll ease in with an issue that I wanted to write about a while back. Oh yeah, and I turned off comments because the spam was out of control :)</p>
<p>For those watching the REST space, I'm sure <A href="http://bitworking.org/news/">Joe Gregorio</A>'s work on the IETF URI templates draft is interesting. The initial draft (<A href="http://tools.ietf.org/html/draft-gregorio-uritemplate-01">draft-gregorio-uritemplate-01.txt</A>) took a simple approach to describe URIs with variable parts. The idea was that parameterized variable parts would have <CODE>{ var name }</CODE> within the URI to indicate the variable parts. A simple example would look like this:</p>
<p>http://foo.com/accounts/{accountID}</p>
<p>where the account ID could be substituted with an appropriate ID in an instance of the REST URI:</p>
<p>http://foo.com/accounts/9991234</p>
<p>This approach was simple enough. It could be used in a straightforward manner when calling a REST service by substituting the variables parts with values prior to the invocation. It could also be used somewhat for matching inbound requests by transforming the template into a regular expression, replacing the variables with non-greedy matches.</p>
<p>In the process of updating the template specification, and despite many questions about matching inbound requests on the mailing list, Joe Gregorio stated that he never intended for URI templates to be used for matching but only for substitution. Indeed, the next version of the specification (<A href="http://tools.ietf.org/html/draft-gregorio-uritemplate-02">draft-gregorio-uritemplate-02.txt</A> introduced a bunch of new operators aimed at the substitution. The primary use cases that Mr. Gregario was interested in solving where client-side: simplifying the process of making a RESTful request from a JSP input form, for example, which would substitue the input form variables into their respective places in the REST request.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>OK, so I haven't posted in a long time. Figure I'll ease in with an issue that I wanted to write about a while back. Oh yeah, and I turned off comments because the spam was out of control :)</p>
<p>For those watching the REST space, I'm sure <A href="http://bitworking.org/news/">Joe Gregorio</A>'s work on the IETF URI templates draft is interesting. The initial draft (<A href="http://tools.ietf.org/html/draft-gregorio-uritemplate-01">draft-gregorio-uritemplate-01.txt</A>) took a simple approach to describe URIs with variable parts. The idea was that parameterized variable parts would have <CODE>{ var name }</CODE> within the URI to indicate the variable parts. A simple example would look like this:</p>
<p>http://foo.com/accounts/{accountID}</p>
<p>where the account ID could be substituted with an appropriate ID in an instance of the REST URI:</p>
<p>http://foo.com/accounts/9991234</p>
<p>This approach was simple enough. It could be used in a straightforward manner when calling a REST service by substituting the variables parts with values prior to the invocation. It could also be used somewhat for matching inbound requests by transforming the template into a regular expression, replacing the variables with non-greedy matches.</p>
<p>In the process of updating the template specification, and despite many questions about matching inbound requests on the mailing list, Joe Gregorio stated that he never intended for URI templates to be used for matching but only for substitution. Indeed, the next version of the specification (<A href="http://tools.ietf.org/html/draft-gregorio-uritemplate-02">draft-gregorio-uritemplate-02.txt</A> introduced a bunch of new operators aimed at the substitution. The primary use cases that Mr. Gregario was interested in solving where client-side: simplifying the process of making a RESTful request from a JSP input form, for example, which would substitue the input form variables into their respective places in the REST request.</p>
<p>This was and continues to be a shame. Matching of inbound URIs comes up frequently on the server-side application, and there may be middleware processing an inbound request and determining where to dispatch it. In the cases of bridging legacy interfaces to REST-style interactions, this dispatching process is very mechanical, but there needs to be a description that's consumable by a runtime. The original URI templates spec seemed to provide almost enough for a simple approach to specifying this the URI to match, but not quite:</p>
<p><UL><br />
<LI>URI parameters, query parameters, and fragments may have parameters that appear out of order<br />
<LI>Parameters may not have values, but are simply just present. Their presence is a boolean variable<br />
<LI>The URI templates let variables be anywhere in the template. This doesn't work so well for key-value pairs, when ordering is uncertain<br />
</UL></p>
<p>So, applying a few restrictions gives a fairly simple but powerful matching template, which can be automated by infrastructure fairly easily:</p>
<p><UL><br />
<LI>Any variable that appears in a parameter, query, or fragment slot as a single variable with no key-value pair can be considered a boolean. An example is <CODE>http://foo.com;{mybool}</CODE>, where <CODE>mybool</CODE> would be true for the match <CODE>http://foo.com;mybool</CODE>.<br />
<LI>Parameter keys can't be variables, just their values. Out of order problem solved.<br />
<LI>Also, any matching engine should ignore specific delimiters in parameter/query/fragment sections of the URI. This is just robustness.<br />
<LI>Matching in paths shouldn't be too greedy; the match should stop at the next path '/' element.<br />
</UL></p>
<p>With these restrictions, the basic concept of URI templates can be applied to matching. This is powerful enough to handle the majority of RESTful URI constructions that are commonly used. While the second draft of URI templates took the focus of URI templates in the direction of substitution, there's no reason that these approaches couldn't be combined and strengthened to address the matching problem. This would require some changes to how substitution operators are specified today or a flavor matching operators could be introduced.</p>
    ]]></content>
  </entry>
  <entry>
    <title>DOJO Client-Side Debugging Through Server-Side Trace</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/04/06/dojo-debugging" />
    <id>http://michaelgilfix.com/techblog/2007/04/06/dojo-debugging</id>
    <published>2007-04-06T12:51:28-06:00</published>
    <updated>2007-04-06T12:57:18-06:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="AJAX" />
    <category term="Code" />
    <category term="DOJO" />
    <category term="Java" />
    <summary type="html"><![CDATA[<p>Here's a cool trick for structuring debugging of <A href="http://dojotoolkit.org/">DOJO</A> applications. This technique originated from <A href="http://agentzlerich.blogspot.com/index.html">Rhys Ulerich</A>, who work in <A href="http://www-306.ibm.com/software/pervasive/serviceserver/">WebSphere Telecom Web Services Server</A> development. Rhys is working on an interactive web-based console on top of WAS 6.1 for the much improved Service Policy Management Console in our upcoming release (targeted around October time frame). This technique allows you to enable debugging from the server side (via the app server facilities) of DOJO logic that executes client-side.</p>
<p>The technique has two elements to it that are embedded into the JSPs that render the console contents. These JSPs also render the appropriate DOJO widgets, JavaScript, and UI contents. First, the following is used to determine the trace logging:</p>
<p><CODE></p>
<p>&lt;%@page import="java.util.logging.Level"%&gt;<br />
&lt;%@page import="java.util.logging.Logger"%&gt;<br />
&lt;%!<br />
    //  "this" is the compiled JSP class for either<br />
    //  a) ScriptPreamble.jspf if using jsp:include<br />
    //  b) including JSP page, if using @include<br />
    final Logger logger = Logger.getLogger(this.getClass().getName());<br />
%&gt;<br />
</CODE></p>
<p>As part of deployment, JSP contents are compiled into corresponding Java classes that are used to output the JSP contents. This can be done as part of deployment or through pre-compilation. This code snippet creates an instance of the Java logger class as part of the JSP generated class. As a byproduct, this will register the logger instance with the WAS trace logging subsystem as part of class loading.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Here's a cool trick for structuring debugging of <A href="http://dojotoolkit.org/">DOJO</A> applications. This technique originated from <A href="http://agentzlerich.blogspot.com/index.html">Rhys Ulerich</A>, who work in <A href="http://www-306.ibm.com/software/pervasive/serviceserver/">WebSphere Telecom Web Services Server</A> development. Rhys is working on an interactive web-based console on top of WAS 6.1 for the much improved Service Policy Management Console in our upcoming release (targeted around October time frame). This technique allows you to enable debugging from the server side (via the app server facilities) of DOJO logic that executes client-side.</p>
<p>The technique has two elements to it that are embedded into the JSPs that render the console contents. These JSPs also render the appropriate DOJO widgets, JavaScript, and UI contents. First, the following is used to determine the trace logging:</p>
<p><CODE></p>
<p>&lt;%@page import="java.util.logging.Level"%&gt;<br />
&lt;%@page import="java.util.logging.Logger"%&gt;<br />
&lt;%!<br />
    //  "this" is the compiled JSP class for either<br />
    //  a) ScriptPreamble.jspf if using jsp:include<br />
    //  b) including JSP page, if using @include<br />
    final Logger logger = Logger.getLogger(this.getClass().getName());<br />
%&gt;<br />
</CODE></p>
<p>As part of deployment, JSP contents are compiled into corresponding Java classes that are used to output the JSP contents. This can be done as part of deployment or through pre-compilation. This code snippet creates an instance of the Java logger class as part of the JSP generated class. As a byproduct, this will register the logger instance with the WAS trace logging subsystem as part of class loading.</p>
<p>Next, the follow is included to enable DOJO widget debugging:</p>
<p><CODE><br />
&lt;!-- Enable client-side dojo debug by enabling server-side tracing --&gt;<br />
&lt;!-- for at least Level.FINE on &lt;%= logger.getName() %&gt; --&gt;</p>
<p>&lt;%-- Prepare the djConfig object for DOJO bootstrapping --%&gt;<br />
&lt;script type="text/javascript"&gt;<br />
    djConfig = {    isDebug:<br />
        &lt;%= logger.isLoggable(Level.FINE) %&gt;<br />
    };<br />
&lt;/script&gt;<br />
</CODE></p>
<p>Based on the selected debugging level, this enables client-side debugging in the browser, using the same tracing subsystem as is typically used in WAS. This gives a familiar way to introduce debugging of this capability without having to introduce an additional mechanism to configure debugging.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Double-Checked Locking in Java</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/03/16/double-checked-locking" />
    <id>http://michaelgilfix.com/techblog/2007/03/16/double-checked-locking</id>
    <published>2007-03-16T15:03:12-06:00</published>
    <updated>2007-03-16T15:03:12-06:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Code" />
    <category term="Java" />
    <summary type="html"><![CDATA[<p>Double checked locking is a useful paradigm for avoiding the cost of unnecessary synchronization and is often used in the context of avoiding synchronization during lazy initialization. The basic idea behind double checked locking is that you check variable condition first, and if the condition is not met, then synchronize, perform the check again, and adjust the condition. The second check inside the synchronized block typically serves to avoid repeating the actions that were used to satisfy the condition in the first time. There are quite a few articles on the web on this topic. However, some are incorrect, provide only partial information, or are quite complicated. This is an older, but enduring topic. So here's an attempt to distill it down.</p>
<p>The basic problem that double checked locking is trying to alleviate are conditions like this:</p>
<p><CODE></p>
<p>public class Foo {</p>
<p>  private static Foo instance = null;</p>
<p>  public static Foo getInstance() {<br />
    synchronized(Foo.class) {<br />
      if (instance == null) {<br />
        instance = new Foo();<br />
      }<br />
    }<br />
    return instance;<br />
  }</p>
<p>}</p>
<p></CODE></p>
<p>Here, synchronization needs to occur for every fetching of an instance. This same pattern applies to any other lazy execution of static initialization that is undesirable to be repeated. The often cited and incorrect solution to this problem is code that looks as follows. This code implements a double-check locking approach to avoid synchronization of the typical execution path:</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Double checked locking is a useful paradigm for avoiding the cost of unnecessary synchronization and is often used in the context of avoiding synchronization during lazy initialization. The basic idea behind double checked locking is that you check variable condition first, and if the condition is not met, then synchronize, perform the check again, and adjust the condition. The second check inside the synchronized block typically serves to avoid repeating the actions that were used to satisfy the condition in the first time. There are quite a few articles on the web on this topic. However, some are incorrect, provide only partial information, or are quite complicated. This is an older, but enduring topic. So here's an attempt to distill it down.</p>
<p>The basic problem that double checked locking is trying to alleviate are conditions like this:</p>
<p><CODE></p>
<p>public class Foo {</p>
<p>  private static Foo instance = null;</p>
<p>  public static Foo getInstance() {<br />
    synchronized(Foo.class) {<br />
      if (instance == null) {<br />
        instance = new Foo();<br />
      }<br />
    }<br />
    return instance;<br />
  }</p>
<p>}</p>
<p></CODE></p>
<p>Here, synchronization needs to occur for every fetching of an instance. This same pattern applies to any other lazy execution of static initialization that is undesirable to be repeated. The often cited and incorrect solution to this problem is code that looks as follows. This code implements a double-check locking approach to avoid synchronization of the typical execution path:</p>
<p><CODE></p>
<p>public class Foo {</p>
<p>  private static Foo instance = null;</p>
<p>  public static Foo getInstance() {<br />
    if (instance != null) {<br />
      synchronized(Foo.class) {<br />
        if (instance == null) {<br />
          instance = new Foo();<br />
        }<br />
       }<br />
    }<br />
    return instance;<br />
  }</p>
<p>}</p>
<p></CODE></p>
<p>This code is broken, because the JVM does not provide atomicity guarantees on non-primitive 32-bit values such as object references, and 64-bit values such as longs or doubles. However, the JVM memory model does provide atomicity for 32-bit primitives, such as ints, floats, or booleans. Double-checked locking will work with these. So, you should be able to write the code above as follows:</p>
<p><CODE></p>
<p>public class Foo {</p>
<p>  private static boolean initialized = false;</p>
<p>  private static Foo instance = null;</p>
<p>  public static Foo getInstance() {<br />
    if (!initialized) {<br />
      synchronized(Foo.class) {<br />
        if (!initialized) {<br />
          if (instance == null) {<br />
            instance = new Foo();<br />
          }<br />
          initialized = true;<br />
       }<br />
    }<br />
    return instance;<br />
  }</p>
<p>}</p>
<p></CODE></p>
<p>This approach works on hardware architectures like Intel, Solaris, etc. All these platforms have stronger memory model guarantees than Java's. However, there is still a theoretical concern that some future processor architecture may not provide sufficient read coherency to support this memory model. This is discussed <A href="http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html?page=3">here.</A>.</p>
<p>Now, as of <A href="http://www-128.ibm.com/developerworks/library/j-jtp02244.html">JSR133</A>, which you should definitely have if you're running on Java 1.5, you should be able to use the volatile keyword to achieve this more simply. In addition, the adjustment to the Java memory model should fix any of the theoretical doubts of the approach above.</p>
<p><CODE></p>
<p>public class Foo {</p>
<p>  private static volatile Foo instance = null;</p>
<p>  public static Foo getInstance() {<br />
    if (instance != null) {<br />
      synchronized(Foo.class) {<br />
        if (instance == null) {<br />
          instance = new Foo();<br />
        }<br />
       }<br />
    }<br />
    return instance;<br />
  }</p>
<p>}</p>
<p></CODE></p>
<p>The volatile keyword causes writes/reads to go directly to main memory, rather than the cache. This avoids the cache coherency problem that prevented the double checked locking from working on multi-processor systems. While this approach fixes the double locking technique to work with instances, it still comes with some overhead: the value of the instance variable can no longer be cached and must be fetched from memory every time. This is similar in cost to a partial synchronization.</p>
<p>Of course, the fastest thing is just to do static eager initialization, which gets run once in a single thread by the class loader when loading the class. However, this approach may not always be possible, particularly in an application server environment where certain resources may need to be bound to at runtime. Of course, you can't go wrong with synchronization. But in many casts, this technique can be used to achieve cost savings for critical code paths when run on the usual platforms.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Pull Based APIs with Iterators and Streams</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/03/07/pull-based-design" />
    <id>http://michaelgilfix.com/techblog/2007/03/07/pull-based-design</id>
    <published>2007-03-07T22:46:47-07:00</published>
    <updated>2007-03-07T22:46:47-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Design" />
    <summary type="html"><![CDATA[<p>The use of iterators and streams in the design of an API/interface can be a powerful way to structure APIs for improved system performance, while maintaining simplicity for code that uses the API. These can be used to implement a design methodology, called "Pull Based" or "Pull" APIs. The basic idea behind a pull methdology is, rather than presenting the application code with an object model or a collection of state to be navigated or processed by the application, the application code asks for the data a piece at a time. Some variants of this design methodology allow the application to specify what kinda of data it is interested in, which can be used to push filtering into lower layers to improve performance.<br />
The <A href="http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html">StAX</A> (Streaming API for XML) is an example of a pull based API, which realizes significant performance gains. In the Telecom Web Services Server (TWSS) product, a pull based API was used to implement <A href="http://publib.boulder.ibm.com/infocenter/wtelecom/v6r1/topic/com.ibm.twss.javadoc.doc/attachmentspublicjavadoc/index.html?noframes=true">SOAP attachment extensions</A> to the WebSphere ESB product. This approach was modeled after the pull based <A href="http://java.sun.com/j2ee/1.4/docs/api/javax/xml/soap/AttachmentPart.html">SAAJ SOAP attachment APIs</A>.<br />
The basic idea behind improving performance is to hide the I/O (network or disk) behind the abstraction of the iterator and stream objects. Application code can begin processing in parallel with reading from the network. This is done through the implementation of the API or underlying platform. Each call of the application code to the iterator will block until the data becomes available. As soon as a chunk of data is available, the application can process in parallel while the next chunk is read. If the application code is performing writing, then this mode of processing will form a pipeline. Output can be written as soon as input has been processed. For network based applications, this can be a useful means of processing large amounts of data with limited memory requirements, by pushing the stream of data into the network.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>The use of iterators and streams in the design of an API/interface can be a powerful way to structure APIs for improved system performance, while maintaining simplicity for code that uses the API. These can be used to implement a design methodology, called "Pull Based" or "Pull" APIs. The basic idea behind a pull methdology is, rather than presenting the application code with an object model or a collection of state to be navigated or processed by the application, the application code asks for the data a piece at a time. Some variants of this design methodology allow the application to specify what kinda of data it is interested in, which can be used to push filtering into lower layers to improve performance.</p>
<p>The <A href="http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html">StAX</A> (Streaming API for XML) is an example of a pull based API, which realizes significant performance gains. In the Telecom Web Services Server (TWSS) product, a pull based API was used to implement <A href="http://publib.boulder.ibm.com/infocenter/wtelecom/v6r1/topic/com.ibm.twss.javadoc.doc/attachmentspublicjavadoc/index.html?noframes=true">SOAP attachment extensions</A> to the WebSphere ESB product. This approach was modeled after the pull based <A href="http://java.sun.com/j2ee/1.4/docs/api/javax/xml/soap/AttachmentPart.html">SAAJ SOAP attachment APIs</A>.</p>
<p>The basic idea behind improving performance is to hide the I/O (network or disk) behind the abstraction of the iterator and stream objects. Application code can begin processing in parallel with reading from the network. This is done through the implementation of the API or underlying platform. Each call of the application code to the iterator will block until the data becomes available. As soon as a chunk of data is available, the application can process in parallel while the next chunk is read. If the application code is performing writing, then this mode of processing will form a pipeline. Output can be written as soon as input has been processed. For network based applications, this can be a useful means of processing large amounts of data with limited memory requirements, by pushing the stream of data into the network.</p>
<p>In addition to hiding I/O, iterators can also be used for generation of data as needed. Rather than corresponding to an actual collection of data, each call to the iterator's next method computes the data to be returned. This data may be based on the state of the iterator itself (for example, a key stream), or may be based on other server state. I/O may also be viewed as generational in nature, where each advancement of the iterator pulls more input. The idea being that only the input that's needed is kept in memory (although read ahead would be needed for performance). This is the approach taken in the JDBC APIs for processing result sets. This concept is closely tied to parallelization of I/O.</p>
<p>The abstraction of the iterator and streams approach allows for staged development. The first version of the API need not implement parallelization or generation. It can be added later, transparent to the application. It may also turn out that the particular use case for the API does not warrant such implementation complexity. Still, a pull based design can serve as a point of future extensibility should the performance gains become worth it.</p>
<p>A decision point may be the size of the chunks of data being processed. For example, the SOAP attachment support extensions that were included with the TWSS product assume a certain range of SOAP attachment sizes that correspond to typical service provider usage around Multimedia Messaging Service (MMS). Such attachment sizes are typically on the order of 150-300k, as they are destined to mobile devices with limited bandwidth, memory, and processing. Thus, the implementation complexity for parallelization wasn't worth it for the first round of the API. However, as service provider use cases evolve and attachment sizes grow, such as in support of full blown MP3s, parallelization can have significant benefits for attachment processing.</p>
<p>So the caveat for this design approach is that it is not a substitute for the power of asynchronous APIs. However, all this can occur without the application being aware of this fancy parallelization using a straight-forward synchronous processing logic. Then to scale in throughput, you can scale up in terms of processing threads, where each thread can handle a different data stream simultaneously. Clearly this approach scales nicely on multi-processor and multi-core systems for heavily multi-threaded apps.</p>
<p>It used to be that a disadvantage to this approach is that type safety was lost. The object returned by the iterator would need to be cast to the appropriate type, and this could only be specified by contract in the API. For some, this could be deemed a liability. Support for generics in Java 1.5 solves this problem by allowing for incorporating typing into the interface -a feature that makes the use of iterators in an API much more attractive.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Patterns for Proper Web Service Interface Design</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/02/25/web-service-interface-design" />
    <id>http://michaelgilfix.com/techblog/2007/02/25/web-service-interface-design</id>
    <published>2007-02-25T19:16:28-07:00</published>
    <updated>2007-02-25T19:35:51-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Design" />
    <category term="SOA" />
    <category term="Web Services" />
    <summary type="html"><![CDATA[<p>Using proper Web Service interface design can greatly improve application responsiveness and simplify integration logic. Poor design will not only bog down logic, but actually increase the complexity of both client and server-side implementation by requiring both to handle a larger number of possible error cases. This post attempts to capture three key patterns for designing/improving Web Service interfaces. While this article approaches the problem from the perspective of Web Services, many of these principles apply to Web Service design.</p>
<p>Appropriate Granularity:</p>
<p>The traditional interface design paradigms that folks are used to using in OOP and functional languages are often inappropriate for remote interfaces. They favor having many different methods that can be used to query information or state about an objects internals. This is particularly true for data objects. Since each query results in a remote interface invocation, querying information can quickly add up. A better approach is to use the Data Transfer Object (DTO) pattern that is heavily talked about in the concept of remote EJBs. The DTO is a data object that contains all queriable information in a single data object, which is transferred once. The cost of transferring more data in a single shot is marginal compared to the latency cost of going back and forth. This is particularly true for interfaces that allow you to create/update/query/delete data objects.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Using proper Web Service interface design can greatly improve application responsiveness and simplify integration logic. Poor design will not only bog down logic, but actually increase the complexity of both client and server-side implementation by requiring both to handle a larger number of possible error cases. This post attempts to capture three key patterns for designing/improving Web Service interfaces. While this article approaches the problem from the perspective of Web Services, many of these principles apply to Web Service design.</p>
<p>Appropriate Granularity:</p>
<p>The traditional interface design paradigms that folks are used to using in OOP and functional languages are often inappropriate for remote interfaces. They favor having many different methods that can be used to query information or state about an objects internals. This is particularly true for data objects. Since each query results in a remote interface invocation, querying information can quickly add up. A better approach is to use the Data Transfer Object (DTO) pattern that is heavily talked about in the concept of remote EJBs. The DTO is a data object that contains all queriable information in a single data object, which is transferred once. The cost of transferring more data in a single shot is marginal compared to the latency cost of going back and forth. This is particularly true for interfaces that allow you to create/update/query/delete data objects.</p>
<p>As an example, consider a piece of data that identifies a customer. The customer has the following attributes:</p>
<p>- <STRONG>ID:</STRONG> The customer identity. This uniquely identifies the customer.<br />
- <STRONG>name:</STRONG> The customer's name.<br />
- <STRONG>balance:</STRONG> The customer's balance.<br />
- <STRONG>enabled:</STRONG> Whether this customer is enabled/disabled.</p>
<p>Consider a set of interactions that allow you to create, update, query, and delete a customer. Often times, a temptation is to design the interface as follows, trying to duplicate the smaller methods for a Java interface (Java syntax used below for convenience in expressing operation signatures):</p>
<p>void createCustomer(String id, String name, String contact, String balance);<br />
void updateName(String id, String name);<br />
void updateBalance(String id, int balance);<br />
void setEnabled(String id, boolean status);<br />
String getName(String id);<br />
int getBalance(String id);<br />
boolean getEnabled(String id);<br />
void deleteCustomer(String id);</p>
<p>Here's how that can be converted to using the DTO pattern and simplifying the interface using WSDL/schema. Consider a schema type for customer that looks as follows:</p>
<p>&lt;xsd:complexType name="Customer"&gt;<br />
  &lt;xsd:sequence&gt;<br />
    &lt;!-- ID is never optional --&gt;<br />
    &lt;xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1"/&gt;<br />
    &lt;!-- Name is optional --&gt;<br />
    &lt;xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1"/&gt;<br />
    &amp;lt!-- Balance is optional --&gt;<br />
    &lt;xsd:element name="balance" type="xsd:int" minOccurs="0" maxOccurs="1"/&gt;<br />
    &lt;!-- Enabled is optional --&gt;<br />
    &lt;xsd:element name="enabled" type="xsd:string" minOccurs="0" maxOccurs="1"/&gt;<br />
  &lt;/xsd:sequence&gt;<br />
&lt;/xsd:complextType&gt;</p>
<p>The ID is always needed to identify the customer, so it is non-optional in data object. We can now rewrite the operation signatures as follows with the implied contracts:</p>
<p>// All optional fields are filled in during creation, unless they<br />
// are meant to be null on the data object<br />
void createCustomer(Customer data);</p>
<p>// The non-optional ID uniquely identifies the customer. If any of the other<br />
// elements are present, then they are updated in the underlying object.<br />
void updateCustomer(Customer data);</p>
<p>// Fetch all customer information<br />
Customer getCustomer(String id);</p>
<p>// Deletes a customer<br />
void deleteCustomer(String id);</p>
<p>This simplifies the number of operations that are needed to interact with a customer and minimizes the number of request response changes. This approach also allows the client to reuse object instances. The output of a get can be fed back into an update with a single field changed. The update is also flexible, providing the equivalent of updating multiple fields simultaneously when appropriate. While this step may seem somewhat obvious to some folks, it is an important predecessor to the next pattern.</p>
<p>Do More at Once:</p>
<p>It's better to batch multiple operations in a single call, rather than performing an invocation for each individual customer object. This amortizes the cost of the remote hop over multiple operations, improving throughput and responsiveness. First, we add an additional useful operation to our running customer example: the ability to validate customer information against what's stored in the underlying service. This operation looks as follows:</p>
<p>boolean validateCustomer(Customer somebody);</p>
<p>Typically these operation signatures would also have exceptions -or in WSDL parlance "faults" -that are raised in the advent of error while executing the operation. Let's assume each of the above methods throw an exception like this:</p>
<p>boolean validateCustomer(Customer somebody) throws MyServiceException;</p>
<p>To enable batching, we allow each operation to take in an array of customer data objects to operate on. But we can't leave our exception/fault scheme as-is. Raising a single fault from the Web Service invocation means that we have an ambiguous situation to resolve: what happens to the items that were updated while traversing the list when we stopped? Were they rolled back or persisted up to that point? And how do we identify where we succeeded? This can be resolved by introducing a new data object:</p>
<p>&lt;xsd:complexType name="FaultStatus"&gt;<br />
  &lt;!-- A container for our service exception fault --&gt;<br />
  &lt;xsd:element name="fault" type="somens:MyServiceException" minOccurs="0" maxOccurs="1"/&gt;<br />
&lt;/xsd:complexType&gt;</p>
<p>Now we change our previous methods to return a list of fault status objects instead of raising a single fault exception. We need a container object for our fault so as to preserve the position of the result in the returned list. This pattern looks as follows for each of our method signatures:</p>
<p>FaultStatus[] createCustomers(Customer[] data);</p>
<p>FaultStatus[] updateCustomers(Customer[] data);</p>
<p>Customer[] getCustomers(String[] id) throws MyServiceException;</p>
<p>FaultStatus[] deleteCustomers(String[] id);</p>
<p>Boolean[] validateCustomers(Customer[] somebodies) throws MyServiceException;</p>
<p>Note that getCustomers() and validateCustomers still throw the single exception. This is because they don't update anything and thus do not suffer from the ambiguous situation. This is also what we want from the interface, which is to return the appropriate type.</p>
<p>Reuse Data Object:</p>
<p>Finally, where possible, reuse common data as sub-objects in larger objects. Ultimately this will improve cohesiveness of your interface, making it easier to supply information from one part to another. Schema makes these easy to do by embedding types as elements within larger types. Suppose in our example above that each balance had associated with it an account. Then we would have been better off using the following data model:</p>
<p>&lt;xsd:complexType name="Balance"&gt;<br />
  &lt;xsd:element name="account" type="xsd:string"&gt;<br />
  &lt;xsd:element name="amount" type="xsd:int"/&gt;<br />
&lt;/xsd:complexType&gt;</p>
<p>&lt;xsd:complexType name="Customer"&gt;<br />
  &lt;xsd:sequence&gt;<br />
    &lt;!-- ID is never optional --&gt;<br />
    &lt;xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1"/&gt;<br />
    &lt;!-- Name is optional --&gt;<br />
    &lt;xsd:element name="name" type="xsd:string" minOccurs="0" maxOccurs="1"/&gt;<br />
    &lt;!-- Enabled is optional --&gt;<br />
    &lt;xsd:element name="enabled" type="xsd:string" minOccurs="0" maxOccurs="1"/&gt;<br />
    &amp;lt!-- Balance is optional --&gt;<br />
    &lt;xsd:element name="balance" type="somens:Balance" minOccurs="0" maxOccurs="1"/&gt;<br />
  &lt;/xsd:sequence&gt;<br />
&lt;/xsd:complextType&gt;</p>
<p>Now consider we had an operation with the following operation signature that updates account balances:</p>
<p>FaultStatus[] updateBalance(Balance[] balances);</p>
<p>We could now call getCustomers() to get a list of customer information. We can then reuse the object instances in each customer's balance as input to the updateBalance() method, whereby we could tweak balances before updating. The client-side logic would then be simple: it would iterate through customers looking for balances to update and append updated balance objects to a list. This list would service as the input to the update balance operation.</p>
<p>Wrapping it up</p>
<p>Use of these three guidelines greatly simplifies Web Service interacts. The patterns in these guidelines can be repeatedly applied during interface design in order to achieve the minimum number of interactions and the best cohesiveness between different operations. A side effect of applying these patterns is that this will also simplify client-side (and even possibly server-side) code. A lot of error cases disappear when it is no longer possible to prove partial updates or provide recovery for each fine grained operation.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Essence of Web 2.0</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/02/14/essence-web-2.0" />
    <id>http://michaelgilfix.com/techblog/2007/02/14/essence-web-2.0</id>
    <published>2007-02-14T21:45:23-07:00</published>
    <updated>2007-02-14T21:45:23-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Business Models" />
    <summary type="html"><![CDATA[<p>Incorporating Web 2.0 principles into application and service design is all the rage these days. A lot of people are still trying to wrap their head around what the whole Web 2.0 movement means. The short version is that Web 2.0 refers to a collection of technologies, architectural principles, and business principles. Some of the hottest items on the technology side seem to be <A href="http://en.wikipedia.org/wiki/Ajax_(programming)">Asynchronous Javascript</A> (AJAX) based interfaces, <A href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">Representational State Transfer</A> (REST) architecture, <A href="http://en.wikipedia.org/wiki/Wiki">Wiki's</A>, blogs, and <A href="http://en.wikipedia.org/wiki/Web_syndication">syndication</A>. On the business side, the notion of combining existing assets in novel ways through <A href="http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)">Mashups</A>, user driven content, and new models of product development. Still this hodgepodge that is Web 2.0 means many things to different people.<br />
While online startups have adopted this model with great success, traditional businesses are still looking at defining and implementing their Web 2.0 strategy. Things just move a bit slower. The telecom service providers seem to be aggressively joining the fray. The problem is that amidst the shmorgasboard of things that are Web 2.0, it's difficult to find a simple, succinct explanation for what problems Web 2.0 really tries to solve that go beyond just the technology and just user driven content.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Incorporating Web 2.0 principles into application and service design is all the rage these days. A lot of people are still trying to wrap their head around what the whole Web 2.0 movement means. The short version is that Web 2.0 refers to a collection of technologies, architectural principles, and business principles. Some of the hottest items on the technology side seem to be <A href="http://en.wikipedia.org/wiki/Ajax_(programming)">Asynchronous Javascript</A> (AJAX) based interfaces, <A href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">Representational State Transfer</A> (REST) architecture, <A href="http://en.wikipedia.org/wiki/Wiki">Wiki's</A>, blogs, and <A href="http://en.wikipedia.org/wiki/Web_syndication">syndication</A>. On the business side, the notion of combining existing assets in novel ways through <A href="http://en.wikipedia.org/wiki/Mashup_(web_application_hybrid)">Mashups</A>, user driven content, and new models of product development. Still this hodgepodge that is Web 2.0 means many things to different people.</p>
<p>While online startups have adopted this model with great success, traditional businesses are still looking at defining and implementing their Web 2.0 strategy. Things just move a bit slower. The telecom service providers seem to be aggressively joining the fray. The problem is that amidst the shmorgasboard of things that are Web 2.0, it's difficult to find a simple, succinct explanation for what problems Web 2.0 really tries to solve that go beyond just the technology and just user driven content.</p>
<p>Here's my shot at what I think is a simple way to explain the value of a Web 2.0 strategy to a business. The essence of Web 2.0 is about three things:</p>
<ol>
<li><strong>Consumability:</strong> All the technology and architecture movements in Web 2.0 are really about making it easier to interact with, combine, and consume services in novel ways. At the heart of REST-ful architectures is a simple, yet powerful paradigm for exposing service capability, getting those capabilities to scale, and making it easy for others to integrate with those services. The syndication concept is about dissemination information or service content in an easy to consume form (one only need to look at the explosion of ATOM &amp; RSS on the net to be convinced). Wikis, blogs, AJAX: these are all about improving the consumability of content and information.
<li><strong>Marketability:</strong> Web 2.0 is about exposing services and information such that they can be combined in novel ways. Whether it's originated by a business selling those services or user driven content, it comes down to a more agile form of marketing: coming up with new creative ways to sell or exploit a myriad of existing content.
<li><strong>User experience:</strong> In the end, what's being marketed really comes down to a novel user experience. That's what's fueled the popularity of the Web 2.0 movement: whether it's from snappier Web experiences via AJAX, the ability to better sift through content, the enabling of self expression, or the new time saving or convenient gimick. The culmination of this is the mashup. What defines the mashup is the novel user experience they get from interacting with content in new ways, whether via a novel combination of services or even a better presentation of existing information. The appeal of Web 2.0 is the ability to rapidly create new user experiences, without the traditional overhead of product development.
</ol>
<p>So that's it. Cutting through all the technology, hype, and jargon, those three words seem to capture what Web 2.0 is all about. And of course, they build on one another. The consumability serves to enable more agile marketing. Once the shift of control is in the hands of the marketing folks, they are free to be creative and create new user experiences. It's the user experience that people pay for.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Sitting at the Nexus: Fixed Mobile Convergence</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/02/04/fixed-mobile-convergence" />
    <id>http://michaelgilfix.com/techblog/2007/02/04/fixed-mobile-convergence</id>
    <published>2007-02-04T22:59:22-07:00</published>
    <updated>2007-02-04T22:59:22-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Business Models" />
    <category term="Telecom" />
    <summary type="html"><![CDATA[<p>Fixed (to) Mobile Convergence (FMC) solution is a hot strategic item in today's telecommunications industry. Fixed Mobile Convergence refers to providing uninterrupted, continuous service while users switch between mobile and fixed line infrastructure access. The ability to offers converged fixed/mobile services is the key to conquering the increasing proliferation of 802.11 enabled mobile devices, hunger for high-bandwidth applications, ever-continuous demand of consumers for fair and efficient pricing, availability of communication services over plain old IP, etc. Basically, it's about enabling service delivery irrespective of location, access capability, and end device.<br />
From a business perspective for the service provider, it's about keeping control of a customer's entire communication experience. The longer the service provider maintains control over that experience, the more revenue opportunity. While this may sound a bit alarming for the customer at first, the customer also stands to gain in terms of convenience through seamless service and more flexible pricing (typically, based on the economics of the access technology). Here are some observations along those lines:</p>
<ul>
<li><strong>Emergence of 802.11 enabled devices:</strong> 802.11 is really only the tip of the iceberg, since WiMax and other larger area wireless technologies are on their way. This puts pressure on mobile operators and traditional fixed line providers, who now could be bypassed through pure data channels.<br />
    ]]></summary>
    <content type="html"><![CDATA[<p>Fixed (to) Mobile Convergence (FMC) solution is a hot strategic item in today's telecommunications industry. Fixed Mobile Convergence refers to providing uninterrupted, continuous service while users switch between mobile and fixed line infrastructure access. The ability to offers converged fixed/mobile services is the key to conquering the increasing proliferation of 802.11 enabled mobile devices, hunger for high-bandwidth applications, ever-continuous demand of consumers for fair and efficient pricing, availability of communication services over plain old IP, etc. Basically, it's about enabling service delivery irrespective of location, access capability, and end device.</p>
<p>From a business perspective for the service provider, it's about keeping control of a customer's entire communication experience. The longer the service provider maintains control over that experience, the more revenue opportunity. While this may sound a bit alarming for the customer at first, the customer also stands to gain in terms of convenience through seamless service and more flexible pricing (typically, based on the economics of the access technology). Here are some observations along those lines:</p>
<ul>
<li><strong>Emergence of 802.11 enabled devices:</strong> 802.11 is really only the tip of the iceberg, since WiMax and other larger area wireless technologies are on their way. This puts pressure on mobile operators and traditional fixed line providers, who now could be bypassed through pure data channels.
<li><strong>Different pricing models for different access technologies:</strong> Minutes of airtime pricing versus fixed monthly cost for Internet access. The internet pricing scheme has been a boon to Internet-based VoIP competitors like Skype for free regional calling and cheap long distance. People expect different pricing schemes for fixed line services versus paying extra for the convenience of mobility. Long distance costs in the US are a good example of this: mobile phone long distance rates are typically higher than their landline equivalents.
<li><strong>Maximizing communication:</strong> This whole convergence thing is about opening up communication possibilities and we have more ways than ever to communicate. If I'm sitting at work, I want to get my call on my work phone, not on my cell phone where I might have bad reception in my building or burn unnecessary minutes. Maybe I have no cellular reception but only Internet connectivity. People call other people, not a place or particular number. Each of these different communication points represents a possibility for substitution of my provider, switching to my most convenience communication mechanism.
<li><strong>Integration with collaborative software:</strong> Collaborative software plays an important part of business productivity and at its heart is enabling effective communication. More and more the lines between collaborative software and telecommunications are blurring. To that end, seamless communication ability regardless of access technology or  location is key -particularly for mobile workers. For example, the ability to seamlessly transfer between desktop web conferencing to a mobile device and back-again.
</ul>
<p>Each of these points is a potential point for substitution of service. Based on pricing, location, terminal capabilities, a customer may decide to switch   from the current service provider -and customers are finding themselves more than ever presented with choice. As such, Fixed Mobile Convergence ends up being a key unification of all the recent disruptions to the telecommunications industry and thus, sits at the nexus.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Converged HTTP/SIP Web Services in Webphere</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/02/01/web-service-and-SIP" />
    <id>http://michaelgilfix.com/techblog/2007/02/01/web-service-and-SIP</id>
    <published>2007-02-01T20:00:45-07:00</published>
    <updated>2007-02-01T20:02:09-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="Application Servers" />
    <category term="JSRs" />
    <category term="SIP" />
    <category term="Web Services" />
    <summary type="html"><![CDATA[<p>Work's been keeping me very busy lately. So, I plan on writing about a commonly asked question around the new converged HTTP/SIP capabilities in WebSphere Application server (WAS) V6.1. So first, what is a converged service? A converged service is an application that spans communication over multiple protocols to provide higher level function. In the case of the HTTP &amp; SIP protocols, a converged service joins together session information from both protocols, allowing interactions over one protocol to influence communication over the other (subjects to the constraints of the protocol). WAS provides a Servlet programming model for both HTTP &amp; SIP. Unification of those protocols is achieved though a converged web container solution, whereby sessions for both protocols may live in a single parent "application session" instance under the covers -the application session concept being first introduced as a <code>SIPApplicationSession</code> concept in the JSR116 SIP Servlet programming model.</p>
<p>The basic benefit to converged services? For SIP enabled applications, HTTP provides an ideal control protocol for communication with SIP signaling logic, which may participate in many different sessions, and may be constantly sending and receiving signaling messages asynchronously out the back-end. However, SIP also supports the notion of a basic request and response exchange, so what makes HTTP so ideal? First, you don't have to deal with the unreliability in SIP in a situation where decisive action is needed. But then enter Web Services. Central to Web Services is the notion of a Web Service Definition Language (WSDL) document that describes the structure of the request being issued. While you can always stuff a bunch of XML into an HTTP or SIP request to communicate with the application, WSDL provides the formal structure to allow you to communicate that interface to others. This approach also provides a path to interoperability with other programming stacks.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Work's been keeping me very busy lately. So, I plan on writing about a commonly asked question around the new converged HTTP/SIP capabilities in WebSphere Application server (WAS) V6.1. So first, what is a converged service? A converged service is an application that spans communication over multiple protocols to provide higher level function. In the case of the HTTP &amp; SIP protocols, a converged service joins together session information from both protocols, allowing interactions over one protocol to influence communication over the other (subjects to the constraints of the protocol). WAS provides a Servlet programming model for both HTTP &amp; SIP. Unification of those protocols is achieved though a converged web container solution, whereby sessions for both protocols may live in a single parent "application session" instance under the covers -the application session concept being first introduced as a <code>SIPApplicationSession</code> concept in the JSR116 SIP Servlet programming model.</p>
<p>The basic benefit to converged services? For SIP enabled applications, HTTP provides an ideal control protocol for communication with SIP signaling logic, which may participate in many different sessions, and may be constantly sending and receiving signaling messages asynchronously out the back-end. However, SIP also supports the notion of a basic request and response exchange, so what makes HTTP so ideal? First, you don't have to deal with the unreliability in SIP in a situation where decisive action is needed. But then enter Web Services. Central to Web Services is the notion of a Web Service Definition Language (WSDL) document that describes the structure of the request being issued. While you can always stuff a bunch of XML into an HTTP or SIP request to communicate with the application, WSDL provides the formal structure to allow you to communicate that interface to others. This approach also provides a path to interoperability with other programming stacks.</p>
<p>So back to getting up and running with converged web services. Today's most common paradigm for having Web Services in a J2EE environment is based on JSR109 JAX RPC specification. Some tooling parses the WSDL (WAS provides a tool called WSDL2JAVA) and generates either client-side or server-side stubs for packaging in the application. The service developer then inserts his or her code into the "BindingImpl" piece of the server-side stub. The goal of JSR109 was to isolate the developer from the details of Web Service interactions and provide them with an environment that looks a little more like Java. So, a little extra knowledge is required to enable a JSR109 binding to work with converged HTTP/SIP communications.</p>
<p>The following is a code example that shows you how to get access to SIP facilities and converged information from a JSR109 Web Service stub.</p>
<p><code><br />
...<br />
import javax.xml.rpc.server.ServiceLifecycle;<br />
import javax.xml.rpc.server.ServletEndpointContext<br />
...</p>
<p>public class MyServiceBindingImpl<br />
  implements MyService, // This is base interface that represents the WSDL interface in Java<br />
             ServiceLifecycle { // This allows you to access container information</p>
<p>  private ServletEndpointContext endptCtx = null;</p>
<p>  private SipFactory sipFactory = null;</p>
<p>  /**<br />
   * This method is called before each invocation by the JAX RPC runtime as part of the<br />
   * ServiceLifecycle interface. The API says to cast the context to a<br />
   * ServletEndpointContext object inside init. This lets you get at web container facilities.<br />
   */<br />
  public void init(Object context) throws ServiceException {<br />
    endptCtx = (ServletEndpointContext)context;<br />
    ServletContext srvCtx = endptCtx.getServletContext();<br />
    sipFactory = (SipFactory)srvCtx.getAttribute(SipServlet.SIP_FACTORY);<br />
  }</p>
<p>  /**<br />
   * Also part of ServiceLifecycle interface.<br />
   */<br />
  public void destroy() {</p>
<p>  }</p>
<p>  /**<br />
   * This gets you access to the shared application session parent object of the<br />
   * HTTP session and corresponding SIP sessions.<br />
   */<br />
  private IBMApplicationSession getIBMApplicationSession() {<br />
    IBMSession session = (IBMSession)endptCtx.getHttpSession();<br />
    IBMApplicationSession appSession = session.getIBMApplicationSession();<br />
    return appSession;<br />
  }</p>
<p>  /**<br />
   * This may seem a little more familiar.<br />
   */<br />
  private SipApplicationSesion getSipApplicationSession() {<br />
    return (SipApplicationSession)getIBMApplicationSession();<br />
  }</p>
<p>  public void myOperation(String someArg) {</p>
<p>    // Access the SIP factory if needed via the private member. This lets you<br />
    // create new SIP messages.</p>
<p>    // Get at the SIP application session to see inter-protocol state information<br />
    SipApplicationSession appSession = getSipApplicationSession();</p>
<p>    // Do good things</p>
<p>  }</p>
<p>}<br />
</code></p>
<p>This code example shows how to do two things from the Web Service side: (1) Get at the <code>SipFactory</code> object which is one entry point into the SIP Servlet API function. (2) Access application level information from within the SipApplicationSession. In addition, the SipApplicationSession lets you find session instances from both HTTP &amp; SIP protocols.</p>
<p>However, a caveat: converged services require that the Web Service client maintain some state information in order to refer to the converged session (this makes sense - you have to find the session somehow). There are two ways of doing this: maintaining the HTTP session information between Web Service calls using cookies or URL rewriting, and encoding Web Service URIs with application session IDs. Maintaining HTTP session information can be accomplished by setting the <code>javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY</code> property on the client-side stub. URI encoding requires that the converged service return a the original endpoint URI of the Web Service with a special identifier encoded as a parameter in the URI. The Web Service client then needs to know to set that URI as the subsequent endpoint for its communications.</p>
<p>Some folks dislike this approach because it breaks the stateless model that is traditionally Web Services and increases complexity at the client. One way to get around this is to introduce a correlator within the Web Service interface. Then a fronting Web Service server stub can receive the request, extract the correlator, and use the correlator to determine the appropriate encoded URI to use to find the appropriate converged session. This last approach comes at the cost of increased latency for each invocation of the service. Such an approach may even require a database lookup to find the appropriate information to dispatch the request to the real handler of the service. Regardless of the approach used, there still has to be some tidbit of information that relates the request to the session.</p>
    ]]></content>
  </entry>
  <entry>
    <title>Using AJAX for JSR168 Inter-Portlet Communication</title>
    <link rel="alternate" type="text/html" href="http://michaelgilfix.com/techblog/2007/01/27/ajax-and-portlets" />
    <id>http://michaelgilfix.com/techblog/2007/01/27/ajax-and-portlets</id>
    <published>2007-01-27T20:27:45-07:00</published>
    <updated>2007-01-27T20:30:00-07:00</updated>
    <author>
      <name>Michael Gilfix</name>
    </author>
    <category term="AJAX" />
    <category term="Design" />
    <category term="Portlets" />
    <summary type="html"><![CDATA[<p>Most articles around use of AJAX and JSR168 Portlets tend to focus on how AJAX techniques can be used to provide more dynamic visual display capabilities to Portlets. However, AJAX techniques (particularly the use of <code>XMLHttpRequest</code> calls can be used effective to provide inter-Portlet communication in a portable manner. Let me explain what I mean by portable: Full Portlet containers, such as <A href="http://www.ibm.com/websphere/portal">WebSphere Portal Server</A> provide additional APIs beyond the JSR168 Portlet standard to enable inter-Portlet communications. These contains offer a lot of function, but come at the cost of heavier weight infrastructure. Increasingly, support for JSR168 Portlets are appearing in lighter-weight containers. For example, the release of <A href="http://www-306.ibm.com/software/webservers/appserv/was/">WebSphere Application Server</A> V6.1 last year included support for JSR168 Portlets embedded in web modules (WAR files) in J2EE applications. WAS supports a bare-bones Portlet container, sticking only to the JSR168 specification, and providing no means for inter-Portlet communication. Portlets that are written for WAS 6.1 are considered forward compatible, in that they can be deployed in WebSphere Portal. The converse is typically not true, since WebSphere Portal contains many features that go beyond the JSR. Use of AJAX techniques can provide a design that is both forward compatible between lighter and heavier weight Portlet contains, and should allow for portability between different Portlet containers.</p>
    ]]></summary>
    <content type="html"><![CDATA[<p>Most articles around use of AJAX and JSR168 Portlets tend to focus on how AJAX techniques can be used to provide more dynamic visual display capabilities to Portlets. However, AJAX techniques (particularly the use of <code>XMLHttpRequest</code> calls can be used effective to provide inter-Portlet communication in a portable manner. Let me explain what I mean by portable: Full Portlet containers, such as <A href="http://www.ibm.com/websphere/portal">WebSphere Portal Server</A> provide additional APIs beyond the JSR168 Portlet standard to enable inter-Portlet communications. These contains offer a lot of function, but come at the cost of heavier weight infrastructure. Increasingly, support for JSR168 Portlets are appearing in lighter-weight containers. For example, the release of <A href="http://www-306.ibm.com/software/webservers/appserv/was/">WebSphere Application Server</A> V6.1 last year included support for JSR168 Portlets embedded in web modules (WAR files) in J2EE applications. WAS supports a bare-bones Portlet container, sticking only to the JSR168 specification, and providing no means for inter-Portlet communication. Portlets that are written for WAS 6.1 are considered forward compatible, in that they can be deployed in WebSphere Portal. The converse is typically not true, since WebSphere Portal contains many features that go beyond the JSR. Use of AJAX techniques can provide a design that is both forward compatible between lighter and heavier weight Portlet contains, and should allow for portability between different Portlet containers.</p>
<p>For those not familiar with Portlets, think of a Portlet as providing the graphical content for a portion, or visual unit, of a web page. The Portlet's sole responsibility is to render that unit of display for the page. Page content is assembled through a process called <em>aggregation</em>; each page has a notion of layout (typically expressed either as a JSP or in XML format) and a Servlet-like method on each Portlet is invoked by the container in order to render each piece of the aggregated page. The bare-bones Portlet container provided with WAS 6.1 does not provide aggregation capabilities. This must be done by a fronting JSP or Servlet. More advanced Portlet containers provide other capabilities, such as navigation between pages of content, filtering of content according to user roles, and even personalization of content.</p>
<p>The basic idea behind Portlet approach (as for many other similar systems, including the <A href="http://www.drupal.org">Drupal</A> system used for this blog</A> is a sort of UI componentization, allowing reuse of visual content and function, and promoting separation in the backing code. Portlets are intended to be mixed and matched to construct page content, either directly by the users or by the administrators of the page. Sometimes, Portlets are provided in groups that are intended to work together to provide more advanced visual display. This approach still allows the user to have control of layout and visual elements via the Portlet container, and still promotes reuse of content and capability in the code.</p>
<p>So, how to enable AJAX techniques with JSR168 Portlets? The best article I've found on the subject is from the a Sun Developer Network <A href="http://developers.sun.com/prodtech/portalserver/reference/techart/ajax-portlets.html">article</A>. Here's a summary of the technique described in the article: each Portlet has an associated HTTP Servlet component that handles the AJAX communication. On load of the page, content is aggregated or generated using the usual Portlet techniques. The generated content typically has some visual element, such as a button, or Javascript code that calls the AJAX function which makes an XML HTTP request to the Servlet. The Servlet then typically sets some context information in the HTTP session based on the Javascript request before dispatching the request directly to the JSR168 Portlet code in order to render the dynamic content. The implementation architecture looks like this:</p>
<p>Reproduced from Greg Ziebold and Jai Suri's article</p>
<p>This technique is an excellent way to approach inter-Portlet communication in a Portable manner. It pushes the coupling of the Portlets out to the client, rather than relying on non-standardized Portlet techniques. In addition, it avoids requiring a page refresh when one Portlet updates another. An example of inter-Portlet communication might be when you have one Portlet that serves a filter for the content in another. Perhaps this was done to allow reuse of the filter UI on multiple pages. When the user updates the filter, it can result in an AJAX request that applies the new filter to the other portlet on the page, without requiring a page refresh. In addition, it also preserves portability between containers.</p>
    ]]></content>
  </entry>
</feed>
