<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; Web Servers</title>
	<atom:link href="http://www.javabeat.net/category/web-servers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Mon, 13 May 2013 20:10:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Oracle Weblogic 10.3.2 Campaign</title>
		<link>http://www.javabeat.net/2011/04/oracle-weblogic-10-3-2-campaign/</link>
		<comments>http://www.javabeat.net/2011/04/oracle-weblogic-10-3-2-campaign/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 00:01:58 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=657</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction This post is to present the steps for creating a Campaign in Weblogic Portal that illustrates some vague points about it. The campaign target is to show an advertisement in a placeholder, within some interval (start &#38; end dates), with some goals to be reached before the end date of the campaign. Campaign Goals [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><h2>Introduction</h2>
<p>This post is to present the steps for creating a <em>Campaign</em> in <strong>Weblogic Portal</strong> that illustrates some vague points about it.</p>
<p>The campaign target is to show an advertisement in a placeholder, within some interval (start &amp; end dates), with some goals to be reached before the end date of the campaign.</p>
<h2>Campaign Goals</h2>
<p>Campaign goals are set against content clicks or impressions (views) count. This count can be calculated based on the <strong><span style="text-decoration: underline;">clicks/views</span></strong> of the specific content that is displayed in the campaign, or if the content is <strong><span style="text-decoration: underline;">viewed/clicked</span></strong> outside the campaign. Also, the count is checked for each content count or the <span style="text-decoration: underline;">summation</span> of the contents&#8217; count in the goal.</p>
<h2>Example Scenario</h2>
<p>For example, a campaign is to show some advertisements on the ads area of the portal, on IPhone should display 5 different contents. Each content is displayed in its place based on the queries defined in the placeholders in the portal, content selectors or Content Presenter Portlet. The goal of the campaign is to reach 1,000,000 clicks on the 5 contents/ads. So, the goal is to check on the summation of the 5 content paths added to the campaign goal.</p>
<h2>Campaign Target</h2>
<p>The campaign should target females only. So in the data sync project, we create a gender property in the default profile, GroupSpace profile, and make it restricted multi-value property, with two values (male or female). Then, define a user segment that filters the users based on the gender profile property to equal &#8220;female&#8221;.</p>
<h2>Campaign Content Action</h2>
<p>We can now add a new scenario to the campaign, and drag the segment condition on it, then assign it to be the &#8220;females&#8221; segment. Now, we need to define the action. Here we create two actions to be performed. First, we need to place a specific content on a placeholder (suppose that the place holder by default shows the logo of the company). We drag the &#8220;place content&#8221; action, and assign a query to this action that retrieve the content to be placed and then select the place holder, that to be replaced its content with the content retrieved.</p>
<h2>Campaign Calling Method Action</h2>
<p>Second, we need to call a static method in a Class. When I tried this, I created a class in the Web project and I was getting an exception that the class is not found. I didn&#8217;t read carefully that I need to make this class &#8220;application-scoped&#8221; class by creating a Library Project (JAR) and add it to the EAR project, to expose all the classes in this library to the portal project. Then, we drag the &#8220;call static method&#8221; action on the campaign, then enter both the method name &amp; the type of the class.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>The campaign works fine, but there is something bothered me. When I made the campaign has a <span style="text-decoration: underline;">goal of X clicks on a content</span>, I didn&#8217;t notice that the count is not resting when I redeploy, <span style="text-decoration: underline;">the count persisted in the database</span>. But I needed someway to monitor how many clicks so far on the content and debug if the campaign goal is reached successfully or not.</p>
<h2>Database Tables</h2>
<p>I used PointBase console and looked around the tables in the &#8220;weblogic&#8221; scheme, till I found the table named <strong><span style="text-decoration: underline;">&#8220;AD_COUNT&#8221;</span></strong>. It contains the column <strong><span style="text-decoration: underline;">&#8220;AD_ID&#8221;</span></strong> which represents the path of the ad, a column that represents the Portal Application, a column for the view count, and another for the clicks count. Also, I found that the whole content in the WLP Repository goes in the table <strong><span style="text-decoration: underline;">CM_NODE &amp; CM_PROPERTY</span></strong>. The funny thing about PointBase console that it interprets the binary column and display the content image inside it. Check figure 1</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2011/04/115.jpg"><img class="aligncenter size-medium wp-image-1200" title="1" src="http://www.javabeat.net/wp-content/uploads/2011/04/115-300x155.jpg" alt="" width="300" height="155" /></a><strong><span style="color: red;">Figure 1 Shows the image appears in the PointBase database console as it interpreted its binary content</span></strong></center></p>
<h2>Conclusion</h2>
<p>Weblogic Portal Campaigns is a powerful feature that lets you provide personalized content on the portal, with predefined goals, targeting specific segment(s) of users. It enables the portal to be dynamic to adapt with market changes by changing the parameters of the campaigns in run-time, choosing which content to be displayed to which segment till the campaign goal is reached or the campaign due date comes. It integrates with Weblogic Virtual Content repository.</p>
<p>A feature it lacks is enabling the campaign to end based on goals other than content views/clicks only, like checking against an inventory of the limited product items(which may require calling some back-end method or web service) to flag the campaign as ended. Also the documentation lacks many details about features found in the development IDE (Eclipse packed with OEPE) which make it hard to exploit all the features of Weblogic Portal Campaigns.</p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fweb-servers%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/web-servers/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/web-servers/feed/" data-count="vertical" data-text="Web Servers" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2011/04/oracle-weblogic-10-3-2-campaign/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weblogic Interview Questions</title>
		<link>http://www.javabeat.net/2010/08/weblogic-interview-questions/</link>
		<comments>http://www.javabeat.net/2010/08/weblogic-interview-questions/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:44:21 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=462</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Weblogic Interview Questions &#8211; 1 1)How do I provide user credentials for starting a server? When you create a domain, the Configuration Wizard prompts you to provide the username and password for an initial administrative user. If you create the domain in development mode, the wizard saves the username and encrypted password in a boot [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Weblogic Interview Questions &#8211; 1</h2>
<h3>1)How do I provide user credentials for starting a server?</h3>
<p>When you create a domain, the Configuration Wizard prompts you to provide the<br />
username and password for an initial administrative user. If you create the<br />
domain in development mode, the wizard saves the username and encrypted password<br />
in a boot identity file. A WebLogic Server instance can refer to a boot identity<br />
file during its startup process. If a server instance does not find such a file,<br />
it prompts you to enter credentials.</p>
<p>If you create a domain in production mode, or if you want to change user<br />
credentials in an existing boot identity file, you can create a new boot<br />
identity file.</p>
<h3>2)Can I start a Managed Server if the Administration Server is unavailable?</h3>
<p>By default, if a Managed Server is unable to connect to the specified<br />
Administration Server during startup, it can retrieve its configuration by<br />
reading a configuration file and other files directly. You cannot change the<br />
server&#8217;s configuration until the Administration Server is available. A Managed<br />
Server that starts in this way is running in Managed Server Independence mode.</p>
<h3>3)What is the function of T3 in WebLogic Server?</h3>
<p>T3 provides a framework for WebLogic Server messages that support for<br />
enhancements. These enhancements include abbreviations and features, such as<br />
object replacement, that work in the context of WebLogic Server clusters and<br />
HTTP and other product tunneling. T3 predates Java Object Serialization and RMI,<br />
while closely tracking and leveraging these specifications. T3 is a superset of<br />
Java Object. Serialization or RMI; anything you can do in Java Object<br />
Serialization and RMI can be done over T3. T3 is mandated between WebLogic<br />
Servers and between programmatic clients and a WebLogic Server cluster. HTTP and<br />
IIOP are optional protocols that can be used to communicate between other<br />
processes and WebLogic Server. It depends on what you want to do. For example,<br />
when you want to communicate between a browser and WebLogic Server-use HTTP, or<br />
an ORB and WebLogic Server-IIOP.</p>
<h3>4)How do you set the classpath?</h3>
<p>WebLogic Server installs the following script that you can use to set the<br />
classpath that a server requires:</p>
<p>WL_HOME\server\bin\setWLSEnv.cmd (on Windows)</p>
<p>WL_HOME/server/bin/setWLSEnv.sh (on UNIX)</p>
<h3>5)How do stubs work in a WebLogic Server cluster?</h3>
<p>Clients that connect to a WebLogic Server cluster and look up a clustered object<br />
obtain a replica-aware stub for the object. This stub contains the list of<br />
available server instances that host implementations of the object. The stub<br />
also contains the load balancing logic for distributing the load among its host<br />
servers.</p>
<p>What happens when a failure occurs and the stub cannot connect to a WebLogic<br />
Server instance?</p>
<p>When the failure occurs, the stub removes the failed server instance from its<br />
list. If there are no servers left in its list, the stubb uses DNS again to find<br />
a running server and obtain a current list of running instances. Also, the stub<br />
periodically refreshes its list of available server instances in the cluster;<br />
this allows the stub to take advantage of new servers as they are added to the<br />
cluster.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h3>6)How does a server know when another server is unavailable?</h3>
<p>WebLogic Server uses two mechanisms to determine if a given server instance is<br />
unavailable.</p>
<p>Each WebLogic Server instance in a cluster uses multicast to broadcast regular<br />
&#8220;heartbeat&#8221; messages that advertise its availability. By monitoring heartbeat<br />
messages, server instances in a cluster determine when a server instance has<br />
failed. The other server instances will drop a server instance from the cluster,<br />
if they do not receive three consecutive heartbeats from that server instance</p>
<p>WebLogic Server also monitors socket errors to determine the availability of a<br />
server instance. For example, if server instance A has an open socket to server<br />
instance B, and the socket unexpectedly closes, server A assumes that server B<br />
is offline.</p>
<h3>7)How are notifications made when a server is added to a cluster?</h3>
<p>The WebLogic Server cluster broadcasts the availability of a new server instance<br />
each time a new instance joins the cluster. Cluster-aware stubs also<br />
periodically update their list of available server instances.</p>
<h3>8)How do clients handle DNS requests to failed servers?</h3>
<p>If a server fails and DNS continues to send requests to the unavailable machine,<br />
this can waste bandwidth. For a Java client application, this problem occurs<br />
only during startup. WebLogic Server caches the DNS entries and removes the<br />
unavailable ones, to prevent the client from accessing a failed server twice.</p>
<p>Failed servers can be more of a problem for browser-based clients, because they<br />
always use DNS. To avoid unnecessary DNS requests with browser-based clients,<br />
use a third-party load-balancer such as Resonate, BigIP, Alteon, and<br />
LocalDirector. These products mask multiple DNS addresses as a single address.<br />
They also provide more sophisticated load-balancing options than round-robin,<br />
and they keep track of failed servers to avoid routing unnecessary requests.</p>
<h3>9)How many WebLogic Servers can I have on a multi-cpu machine?</h3>
<p>There are many possible configurations and each has its own advantages and<br />
disadvantages. BEA WebLogic Server has no built-in limit for the number of<br />
server instances that can reside in a cluster. Large, multi-processor servers<br />
such as Sun Microsystems, Inc. Sun Enterprise 10000, therefore, can host very<br />
large clusters or multiple clusters.</p>
<p>In most cases, WebLogic Server clusters scale best when deployed with one<br />
WebLogic Server instance for every two CPUs. However, as with all capacity<br />
planning, you should test the actual deployment with your target web<br />
applications to determine the optimal number and distribution of server<br />
instances.</p>
<h3>10)How can I set deployment order for applications?</h3>
<p>WebLogic Server allows you to select the load order for applications. WebLogic<br />
Server deploys server-level resources (first JDBC and then JMS) before deploying<br />
applications. Applications are deployed in this order: connectors, then EJBs,<br />
then Web Applications. If the application is an EAR, the individual components<br />
are loaded in the order in which they are declared in the application.xml<br />
deployment descriptor.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/08/weblogic-interview-questions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tomcat Interview Questions</title>
		<link>http://www.javabeat.net/2010/08/tomcat-interview-questions/</link>
		<comments>http://www.javabeat.net/2010/08/tomcat-interview-questions/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 00:42:03 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Apache Tomcat]]></category>
		<category><![CDATA[Interview Questions]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=457</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Tomcat Interview Questions &#8211; 1 How do you create multiple virtual hosts? If you want tomcat to accept requests for different hosts e.g., www.myhostname.com then you must 0. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/www.myhostname.com 1. add a host entry in the server.xml file 1 &#60;Host appBase=&#34;www/appBase&#34; name=&#34;www.myhostname.com&#34;/&#62; 2. Create the the following file under conf/Catalina/www.myhostname.com/ROOT.xml [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Tomcat Interview Questions &#8211; 1</h2>
<h3>How do you create multiple virtual hosts?</h3>
<p>If you want tomcat to accept requests for different hosts e.g., www.myhostname.com then you must 0. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/www.myhostname.com</p>
<p>1. add a host entry in the server.xml file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">  &lt;Host appBase=&quot;www/appBase&quot; name=&quot;www.myhostname.com&quot;/&gt;</pre></td></tr></table></div>

<p>2. Create the the following file under conf/Catalina/www.myhostname.com/ROOT.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Context
    path=&quot;/&quot;
    docBase=&quot;www/deploy/mywebapp.war&quot;
    reloadable=&quot;true&quot; antiJARLocking=&quot;true&quot;&gt;
&lt;/Context&gt;</pre></td></tr></table></div>

<p>Add any parameters specific to this hosts webapp to this context file</p>
<p>3. put your war file in ${catalina.home}/www/deploy</p>
<p>When tomcat starts, it finds the host entry, then looks for any context files and will start any apps with a context</p>
<p>To add more sites just repeat and rinse, all webapps can share the same war file location and appbase</p>
<h3>How will you load properties file?</h3>
<p>* Use a ResourceBundle. See the Java docs for the specifics of how the ResourceBundle class works. Using this method, the properties file must go into the WEB-INF/classes directory or in a jar file contained in the WEB-INF/lib directory.</p>
<p>* Another way is to use the method getResourceAsStream() from the ServletContext class. This allows you update the file without having to reload the webapp as required by the first method. Here is an example code snippet, without any error trapping:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">// Assuming you are in a Servlet extending HttpServlet
                    // This will look for a file called &quot;/more/cowbell.properties&quot; relative
                    // to your servlet Root Context
                   InputStream is = getServletContext().getResourceAsStream(&quot;/more/cowbell.properties&quot;);
                   Properties  p  = new Properties();
                   p.load(is);
                 is.close();</pre></td></tr></table></div>

<h3>Can I set Java system properties differently for each webapp?</h3>
<p>No. If you can edit Tomcat&#8217;s startup scripts, you can add &#8220;-D&#8221; options to Java. But there is no way to add such properties in web.xml or the webapp&#8217;s context.</p>
<h3>How do I configure Tomcat to work with IIS and NTLM?</h3>
<p>Follow the standard instructions for when the isapi_redirector.dll Configure IIS to use &#8220;integrated windows security&#8221;</p>
<p>In server.xml, make sure you disable tomcat authentication:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;Connector port=&quot;8009&quot; enableLookups=&quot;false&quot; redirectPort=&quot;8443&quot; protocol=&quot;AJP/1.3&quot; tomcatAuthentication=&quot;false&quot; /&gt;</pre></td></tr></table></div>

<h3>How can I access members of a custom Realm or Principal?</h3>
<p>When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your webapp code, you&#8217;ll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server&#8217;s classloader, and you are trying to access it through you webapp&#8217;s classloader. While the classes maybe otherwise exactly the same, different (sibling) classloaders makes them different classes.</p>
<p>This assumes you created a My&#8220;Principal class, and put in Tomcat&#8217;s server/classes (or lib) directory, as well as in your webapp&#8217;s webinf/classes (or lib) directory. Normally, you would put custom realm and principal classes in the server directory because they depend on other classes there.</p>
<p>Here&#8217;s what you would like to do, but it throws ClassCastException:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">MyPrincipal p = request.getUserPrincipal();
String emailAddress = p.getEmailAddress();</pre></td></tr></table></div>

<p>Here are 4 ways you might get around the classloader boundary:</p>
<p>1) Reflection</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">Principal p = request.getUserPrincipal();
String emailAddress = p.getClass().getMethod(&quot;getEmailAddress&quot;, null).invoke(p, null);</pre></td></tr></table></div>

<p>2) Move classes to a common classloader</p>
<p>You could put your custom classes in a classloader that is common to both the server and your webapp &#8211; e.g., either the &#8220;common&#8221; or bootstrap classloaders. To do this, however, you would also need to move the classes that your custom classes depend on up to the common classloader, and that seems like a bad idea, because there a many of them and they a core server classes.</p>
<p>3) Common Interfaces</p>
<p>Rather than move the implementing custom classes up, you could define interfaces for your customs classes, and put the interfaces in the common directory. You&#8217;re code would look like this:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">public interface MyPrincipalInterface extends java.security.Principal {
  public String getEmailAddress();
}
&nbsp;
public class MyPrincipal implements MyPrincipalInterface {
...
  public String getEmailAddress() {
    return emailAddress;
  }
}
&nbsp;
public class MyServlet implements Servlet {
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    MyPrincipalInterface p = (MyPrincipalInterface)request.getUserPrincipal();
    String emailAddress = p.getEmailAddress();
...
}</pre></td></tr></table></div>

<p>Notice that this method gives you pretty much the webapp code you wanted in the first place</p>
<p>4) Serializing / Deserializing</p>
<p>You might want to try serializing the response of &#8216;request.getUserPrincipal()&#8217; and deserialize it to an instance of [webapp]MyPrincipal.</p>
<h3>How do I override the default home page loaded by Tomcat?</h3>
<p>After successfully installing Tomcat, you usually test it by loading http://localhost:8080 . The contents of that page are compiled into the index_jsp servlet. The page even warns against modifying the index.jsp files for this reason. Luckily, it is quite easy to override that page. Inside $TOMCAT_HOME/conf/web.xml there is a section called &lt;welcome-file-list&gt; and it looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
        &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
        &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;</pre></td></tr></table></div>

<p>The default servlet attempts to load the index.* files in the order listed. You may easily override the index.jsp file by creating an index.html file at $TOMCAT_HOME/webapps/ROOT. It&#8217;s somewhat common for that file to contain a new static home page or a redirect to a servlet&#8217;s main page. A redirect would look<br />
like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
&nbsp;
&lt;head&gt;
&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;URL=http://mydomain.com/some/path/to/servlet/homepage/&quot;&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>This change takes effect immediately and does not require a restart of Tomcat.</p>
<h3>How do I enable Server Side Includes (SSI)?</h3>
<p>Two things have to be done for tomcat to aknowledge SSI scripts:</p>
<p>1. Rename $CATALINA_BASE/server/lib/servlets-ssi.renametojar to $CATALINA_BASE/server/lib/servlets-ssi.jar.</p>
<p>2. Uncomment the section of web.xml found in $CATALINA_BASE/conf/web.xml that deals with SSI. it looks like this when it is uncommented:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;servlet&gt;
        &lt;servlet-name&gt;ssi&lt;/servlet-name&gt;
        &lt;servlet-class&gt;
          org.apache.catalina.ssi.SSIServlet
        &lt;/servlet-class&gt;
        &lt;init-param&gt;
          &lt;param-name&gt;buffered&lt;/param-name&gt;
          &lt;param-value&gt;1&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
          &lt;param-name&gt;debug&lt;/param-name&gt;
          &lt;param-value&gt;0&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
          &lt;param-name&gt;expires&lt;/param-name&gt;
          &lt;param-value&gt;666&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
          &lt;param-name&gt;isVirtualWebappRelative&lt;/param-name&gt;
          &lt;param-value&gt;0&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;4&lt;/load-on-startup&gt;
    &lt;/servlet&gt;</pre></td></tr></table></div>

<h3>How do I use DataSources with Tomcat?</h3>
<p>When developing J2EE web applications, the task of database connection management can be daunting. Best practice involves using a J2EE DataSource to provide connection pooling, but configuring DataSources in web application servers and connecting your application to them is often a cumbersome process and poorly documented.</p>
<p>The usual procedure requires the application developer to set up a DataSource in the web application server, specifying the driver class, JDBC URL (connect string), username, password, and various pooling options. Then, the developer must reference the DataSource in his application&#8217;s web.xml configuration file, and then access it properly in his servlet or JSP. Particularly during<br />
development, setting all of this up is tedious and error-prone.</p>
<p>With Tomcat 5.5, the process is vastly simplified. Tomcat allows you to configure DataSources for your J2EE web application in a context.xml file that is stored in your web application project. You don&#8217;t have to mess with configuring the DataSource separately in the Tomcat server.xml, or referencing it in your application&#8217;s web.xml file. Here&#8217;s how:</p>
<p>Install the JDBC Driver</p>
<p>Install the .jar file(s) containing the JDBC driver in Tomcat&#8217;s common/lib folder. You do not need to put them in your application&#8217;s WEB-INF/lib folder. When working with J2EE DataSources, the web application server manages connections for your application.</p>
<p>Create META-INF/context.xml</p>
<p>In the root of your web app directory structure, create a folder named META-INF (all caps). Inside that folder, create a file named context.xml that contains a Resource like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&nbsp;
&lt;Context&gt;
&nbsp;
  &lt;Resource name=&quot;jdbc/WallyDB&quot; auth=&quot;Container&quot;
            type=&quot;javax.sql.DataSource&quot; username=&quot;wally&quot; password=&quot;wally&quot;
            driverClassName=&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;
            url=&quot;jdbc:sqlserver://localhost;DatabaseName=mytest;SelectMethod=cursor;&quot;
            maxActive=&quot;8&quot;
            /&gt;
&nbsp;
&lt;/Context&gt;</pre></td></tr></table></div>

<p>This example shows how to configure a DataSource for a SQL Server database named mytest located on the development machine. Simply edit the Resource name, driverClassName, username, password, and url to provide values appropriate for your JDBC driver.</p>
<p>Access the DataSource in Your Application</p>
<p>From a Servlet</p>
<p>Here&#8217;s how you might access the data in a servlet:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">InitialContext ic = new InitialContext();
  DataSource ds = (DataSource) ic.lookup(&quot;java:comp/env/jdbc/WallyDB&quot;);
  Connection c = ds.getConnection();
  ...
  c.close();</pre></td></tr></table></div>

<p>Notice that, when doing the DataSource lookup, you must prefix the JNDI name of the resource with java:comp/env/</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/08/tomcat-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tomcat 6.0 Servlet Container Overview</title>
		<link>http://www.javabeat.net/2010/06/tomcat-6-0-servlet-container-overview/</link>
		<comments>http://www.javabeat.net/2010/06/tomcat-6-0-servlet-container-overview/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 00:10:52 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Apache Tomcat]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1888</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Tomcat 6.0 Developer&#8217;s Guide Current books on Tomcat are primarily focused on the application deployer or administrator. As a result, they invariably focus on the issues related to managing a Tomcat installation, configuring the runtime environment, and on deploying web applications. On the other hand, while books on servlet programming are targeted at Java web [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><H1><CENTER>Tomcat 6.0 Developer&#8217;s Guide</CENTER></H1><br />
<P>Current books on Tomcat are primarily focused on the application deployer<br />
or administrator. As a result, they invariably focus on the issues related to<br />
managing a Tomcat installation, configuring the runtime environment, and on<br />
deploying web applications.</P><br />
<P>On the other hand, while books on servlet programming are targeted at Java web<br />
developers, they often provide a container-agnostic view of the servlet specification.<br />
Tomcat is often a bit player in these books and has very few speaking lines.</P><br />
<P>This book fills the void between these two approaches.</P><br />
<P>It will take you on a guided tour of a living implementation of an industrial-strength<br />
servlet container.</P><br />
<P>Along the way, you will learn how various elements of the Servlet 2.5 specification as<br />
well as how the HTTP RFCs are implemented.</P><br />
<P>By the end of your journey, you will have acquired specialist grade skills in a range of<br />
technologies that contribute to the arena of Java server-side development.</P><br />
<P>This book intended to provide Tomcat administrators, deployers, and developers an<br />
introduction into the internal workings of the Tomcat servlet container.</P><br />
<P>At the same time, it provides Java web programmers with a deep appreciation of the<br />
Servlet APiby exploring its reference implementation—the Tomcat container.</P><br />
<P>While this book provides you with the conceptual background of all that is necessary to<br />
take your skills to the next level, it assumes that the reader has a general understanding of<br />
the Java programming language and Java web programming.</P><br />
<H1>What This Book Covers</H1><br />
<P><I>Chapter 1—Introduction to Tomcat</I> introduces you to the Tomcat container and provides<br />
you with the tools necessary to begin to take it apart. The key objective of this chapter is<br />
to allow you to make a current source distribution of Tomcat active in a development<br />
environment (Eclipse Galileo) so that you can trace the path that a request takes through<br />
the container&#8217;s code.</P><br />
<P><I>Chapter 2—Servlet APiOverview</I> provides the prerequisite information necessary to<br />
navigate the remainder of the book. It describes the Java Enterprise Edition Platform, the<br />
HTTP protocol, and the Servlet API, and serves as a refresher for those who are already<br />
familiar with Java EE web development.</P><br />
<P><I>Chapter 3—Servlet Container</I> Overview introduces the reader to the Tomcat container.<br />
This is the 10,000 foot overview of the container that provides a backdrop to the chapters<br />
that follow. All the components of Tomcat are described with just enough detail, so as<br />
not to overwhelm the reader with too much information, too early in the process.</P><br />
<P><I>Chapter 4—Starting up Tomcat</I> takes a closer look at the startup process for Tomcat. This<br />
is also where you will be first introduced to the Apache Digester project—a key<br />
component that we will revisit in later chapters. The chapter ends with an example that<br />
demonstrates how a web application can be deployed to a dissected Tomcat container<br />
living within an Integrated Development Environment.</P><br />
<P><I>Chapter 5—The Server and Service Components</I> discusses the Server component and<br />
investigates one of its key services—an implementation of the <B>Java Naming and<br />
Directory Interface (JNDI)</B> API. We are also introduced to the Lifecycle interface<br />
that almost every component within Tomcat implements in order to participate in a<br />
standardized event based listener mechanism. To show JNDiin action, our example<br />
considers connecting to a MySQL database to retrieve data.</P><br />
<P><I>Chapter 6—The Connector Component</I> introduces our first Tomcat luminary, the Coyote<br />
Connector. We take a closer look at the standard Java I/O implementation of an HTTP<br />
connector. In this chapter, we get a closer look at socket programming, advanced<br />
elements of the HTTP protocol, and the internals of the request processing mechanism.</P><br />
<P><I>Chapter 7—The Engine Component</I> describes the first request processing &#8216;Container&#8217;<br />
within Tomcat and gives us an inkling of things to come. We are also introduced to the<br />
Pipeline and its Valves, which are the standard request processing mechanism for<br />
Tomcat components.</P><br />
<P><I>Chapter 8—The Host Component</I> discusses the Tomcat implementation of a Virtual Host.<br />
This is the key component responsible for the deployment of web application contexts, as<br />
well as for the error page mechanism.</P><br />
<P><I>Chapter 9—The Context Component</I> is at the central core of this book. You get an upclose-<br />
and-personal look at how a Context is configured, how it accesses its resources,<br />
and how it implements its class loading magic.</P><br />
<P><I>Chapter 10—The Wrapper Component</I> takes us to the workhorse of the Tomcat<br />
component hierarchy. This component wraps an actual servlet, and as a result is close<br />
to a web developer&#8217;s heart. In addition to reviewing the mapping rules dictated by the<br />
Servlet API, we also look at the implementation of servlet filters and the request<br />
dispatcher mechanism.</P><br />
<P><I>Chapter 11—The Session Component</I> discusses how sessions are implemented in Tomcat<br />
to enable stateful behavior over the stateless HTTP protocol. In addition to looking at<br />
some core concepts, such as Java serialization and entropy gathering for random number<br />
generation, we look at the standard memory based session implementation, as well as an<br />
implementation that uses files to persist sessions.</P><br />
<H1><CENTER>Servlet Container Overview</CENTER></H1><br />
<P>In the last chapter, we noted that the Java Enterprise Edition can be considered to be<br />
nothing more than a set of specifications, or interfaces, for which service providers<br />
are required to provide implementations.</P><br />
<P>While it is the actual implementation that does all the work, these specifications<br />
ensure that each implementation can assume that all its other collaborating<br />
pieces work as described by their interfaces. In theory, this allows complex<br />
software platforms (such as application servers) to be assembled from<br />
constituent implementations, each of which is sourced from a different vendor.</P><br />
<P>In practice, it is highly unlikely that you will interface an EJB container from<br />
WebSphere and a JMS implementation from WebLogic, with the Tomcat servlet<br />
container from the Apache foundation, but it is at least theoretically possible.</P><br />
<P>Note that the term &#8216;interface&#8217;, as it is used here, also encompasses abstract classes.<br />
The specification&#8217;s APimight provide a template implementation whose operations<br />
are defined in terms of some basic set of primitives that are kept abstract for the<br />
service provider to implement. For instance, in Chapter 2, we noted that the servlet<br />
hierarchy is made up of the Servlet interface, and the GenericServlet and<br />
HttpServlet abstract classes within the javax.servlet package.</P><br />
<P>A service provider is required to make available concrete implementations of<br />
these interfaces and abstract classes. For example, the HttpSession interface<br />
is implemented by Tomcat in the form of org.apache.catalina.session.<br />
StandardSession.</P><br />
<P>Let&#8217;s return to the image of the Tomcat container that we saw in Chapter 1.</P><br />
<P><CENTER><IMG SRC="images/2010/06/Tomcat6.0/1.jpg"/></CENTER></P><br />
<P>As was stated in Chapter 1, the objective of this book is to cover the primary request<br />
processing components that are present in this image. Advanced topics, such as<br />
clustering and security, are shown as shaded in this image and are not covered.</P><br />
<P>In this image, the &#8216;+&#8217; symbol after the Service, Host, Context, and Wrapper<br />
instances indicate that there can be one or more of these elements. For instance, a<br />
Service may have a single Engine, but an Engine can contain one or more Hosts.<br />
In addition, the whirling circle represents a pool of request processor threads.</P><br />
<P>In this chapter, we will fl y over the architecture of Tomcat from a 10,000-foot<br />
perspective taking in the sights as we go.</P><br />
<H1>Component taxonomy</H1><br />
<P>Tomcat&#8217;s architecture follows the construction of a Matrushka doll from Russia. In<br />
other words, it is all about containment where one entity contains another, and that<br />
entity in turn contains yet another.</P><br />
<P>In Tomcat, a &#8216;container&#8217; is a generic term that refers to any component that can<br />
contain another, such as a Server, Service, Engine, Host, or Context.</P><br />
<P>Of these, the Server and Service components are special containers, designated as<br />
<B>Top Level Elements</B> as they represent aspects of the running Tomcat instance. All<br />
the other Tomcat components are subordinate to these top level elements.</P><br />
<P>The Engine, Host, and Context components are officially termed <B>Containers</B>, and<br />
refer to components that process incoming requests and generate an appropriate<br />
outgoing response.</P><br />
<P><B>Nested Components</B> can be thought of as sub-elements that can be nested inside<br />
either Top Level Elements or other Containers to configure how they function.<br />
Examples of n ested components include the Valve, which represents a reusable unit<br />
of work; the Pipeline, which represents a chain of Valves strung together; and a<br />
Realm which helps set up container-managed security for a particular container.</P><br />
<P>Other nested components include the Loader which is used to enforce the<br />
specification&#8217;s guidelines for servlet class loading; th e Manager that supports session<br />
management for each web application; the R esources component that represents the<br />
web application&#8217;s static resources and a mechanism to access these resources; and<br />
the Listener th at allows you to insert custom processing at important points in a<br />
container&#8217;s life cycle, such as when a component is being started or stopped.</P><br />
<P><PRE><CODE><br />
	Not all nested components can be nested within every container.<br />
</CODE></PRE></P><br />
<P>A final major component, which falls into its own category, is the <B>Connector</B>. It<br />
represents the connection end point that an external client (such as a web browser)<br />
can use to connect to the Tomcat container.</P><br />
<P>Before we go on to examine these components, let&#8217;s take a quick look at how they are<br />
organized structurally.</P><br />
<P><CENTER><IMG SRC="images/2010/06/Tomcat6.0/2.jpg"/></CENTER></P><br />
<P>Note that this diagram only shows the key properties of each container.</P><br />
<P>When Tomcat is started, the <B>Java Virtual Machine (JVM)</B> instance in which it<br />
runs will contain a singleton Server top level element, which represents the entire<br />
Tomcat server. A Server will usually containjust one Service object, which is a<br />
structural element that combines one or more Connectors (for example, an HTTP<br />
and an HTTPS connector) that funnel incoming requests through to a single<br />
Catalina servlet Engine.</P><br />
<P>The Engine represents the core request processing code within Tomcat and supports<br />
the definition of multiple <B>Virtual Hosts</B> within it. A virtual host allows a single<br />
running Tomcat engine to make it seem to the outside world that there are multiple<br />
separate domains (for example, www.my-site.com and www.your-site.com) being<br />
hosted on a single machine.</P><br />
<P>Each virtual host can, in turn, support multiple web applications known as<br />
<B>Contexts</B> that are deployed to it. A context is represented using the web application<br />
format specified by the servlet specification, either as a single compressed <B>WAR<br />
(Web Application Archive)</B> file or as an uncompressed directory. In addition, a<br />
context is configured using a web.xml file, as defined by the servlet specification.</P><br />
<P>A context can, in turn, contain multiple servlets that are deployed into it, each of<br />
which is wrapped in a Wrapper component.</P><br />
<P>The Server, Service, Connector, Engine, Host, and Context elements that<br />
will be present in a particular running Tomcat instance are configured using the<br />
server.xml configuration file.</P><br />
<P><PRE><CODE><br />
	Things are a bit more complicated than this. However, we&#8217;ll defer the<br />
	complexity until later chapters when we deal with each component in a<br />
	lot more detail.<br />
</CODE></PRE></P><br />
<H1>Architectural benefits</H1><br />
<P>This architecture has a couple of useful features. It not only makes it easy to manage<br />
component life cycles (each component manages the life cycle notifications for its<br />
children), but also to dynamically assemble a running Tomcat server instance that<br />
is based on the information that has been read from configuration files at startup.<br />
In particular, the server.xml file is parsed at startup, and its contents are used to<br />
instantiate and configure the defined elements, which are then assembled into a<br />
running Tomcat instance.</P><br />
<P><PRE><CODE><br />
	The server.xml file is read only once, and edits to it will not be picked<br />
	up until Tomcat is restarted.<br />
</CODE></PRE></P><br />
<P>This architecture also eases the configuration burden by allowing child containers<br />
to inherit the configuration of their parent containers. For instance, a Realm defines<br />
a data store that can be used for authentication and authorization of users who<br />
are attempting to access protected resources within a web application. For ease of<br />
configuration, a realm that is defined for an engine applies to all its children hosts<br />
and contexts. At the same time, a particular child, such as a given context, may<br />
override its inherited realm by specifying its own realm to be used in place of its<br />
parent&#8217;s realm.</P></p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/06/tomcat-6-0-servlet-container-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing Applications with JBoss, Hibernate and EJB 3.0</title>
		<link>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/</link>
		<comments>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 00:18:55 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1948</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>JBoss AS 5 DevelopmentThe JBoss Application Server is a Java EE-certified platform for developing and deploying Java Enterprise applications. JBoss Application Server provides the full range of J2EE 1.5 features as well as extended Enterprise services including clustering, caching, and persistence. This book will show Java EE developers how to develop their applications using the JBoss Application Server. It [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><center><strong>JBoss AS 5 Development</strong></center>The JBoss Application Server is a Java EE-certified platform for developing and deploying Java Enterprise applications. JBoss Application Server provides the full range of J2EE 1.5 features as well as extended Enterprise services including clustering, caching, and persistence. This book will show Java EE developers how to develop their applications using the JBoss Application Server. It covers topics such as:</p>
<ul>
<ul>
<li>Setting up a development environment</li>
</ul>
</ul>
<ul>
<ul>
<li>Customization</li>
</ul>
</ul>
<ul>
<ul>
<li>Java EE programming modules</li>
</ul>
</ul>
<ul>
<ul>
<li>Clustering</li>
</ul>
</ul>
<ul>
<ul>
<li>Security</li>
</ul>
</ul>
<p>All these features will be explored by developing sample and intuitive applications built using the friendly interface of Eclipse and JBoss Tools.</p>
<p><strong>What This Book Covers</strong></p>
<p>Chapter 1: <i>Installing Core Components</i> covers the installation of the key components that will be needed throughout the rest of the book. The installation process will be completed by using intuitive wizards that will lead even inexperienced users through it.</p>
<p>Chapter 2: <i>What&#8217;s New in JBoss AS 5.0</i> introduces the reader to the most significant changes brought by release 5.0 of the application server. The new server directory tree is analyzed in detail and possible variants in the server configuration are discussed in the latter part of this chapter.</p>
<p>Chapter 3: <i>Customizing JBoss Services</i> discusses the core configuration of the application server. The highlights of it include an introduction to JBoss AS monitoring services, the inner details about JBoss thread pool, how to configure logging services, and a detailed description of the transaction and Datasource service.</p>
<p>Chapter 4: <i>Developing EJB 3 Session Bean</i> introduces the reader to some concrete Java EE programming examples developed on JBoss AS 5. The focus of this chapter is on EJB 3 session Beans, including a section about their configuration for optimal results.</p>
<p>Chapter 5: <i>Developing JPA Entities</i> covers the development of an example based on the Java Persistence API (JPA). Here, we introduce an enterprise application named the Appstore, which will be a central theme of this book.</p>
<p>Chapter 6: <i>Creating a Web Application</i> is about developing and configuring web applications on JBoss AS 5.0 using the JSF cutting-edge technology. In the first part of this chapter we will enhance the Appstore Enterpirse application by adding a web layer to<br />
it. In the latter part, we explain in detail how to properly configure JBoss Web Server.</p>
<p>Chapter 7: <i>Developing Applications with JBoss Messaging Service</i> discusses JBoss Messaging provider by giving a short introduction to the new messaging system. The chapter then helps us set up some proof of concept programming examples.</p>
<p>Chapter 8: <i>Developing Applications with JBoss and Hibernate</i> covers the de facto standard object relational mapping tool, Hibernate, showing how to quickly set up a Hibernate project using the facilities provided by the JBoss tools interface.</p>
<p>Chapter 9: <i>Managing JBoss AS</i> covers the Java Management Extension (JMX), which still plays a vital role in the application server infrastructure. The chapter includes many examples that show how to write traditional MBeans services and the new POJO Services.</p>
<p>Chapter 10: <i>Developing Applications with JBoss Web Services</i> focuses on the JBoss Web Service implementation, JBossWS, showing how to create, deploy, and test Web Services on JBoss AS along with some advanced concepts such as Handler chains and SOAP debugging.</p>
<p>Chapter 11: <i>Clustering JBoss AS</i> covers the facts about JBoss AS clustering configuration, moving from cluster basics to detailed configuration of the individual services of the application server.</p>
<p>Chapter 12: <i>Developing a Clustered Application</i> continues the journey in the clustering arena by adding some concrete examples based on the abstract concepts covered in the earlier chapter.</p>
<p>Chapter 13: <i>JBoss AS Security</i> provides a systematic guide to JBoss security framework and the cryptographic interfaces available in the Java EE framework. This supplies the basis for concrete examples, which are delivered in the next chapter.</p>
<p>Chapter 14: <i>Securing JBoss AS Applications</i> continues the in-depth exploration of the JBoss security framework, adding concrete programming examples applied on the EJB and Web Services technologies.</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">Developing Applications with JBoss and Hibernate</span></span></h2>
<pre class="brush: java; title: ; notranslate">
	&lt;i&gt;Hibernation is a state of regulated hypothermia undergone by some animals to
	conserve energy during the winter&lt;/i&gt;. – Wikipedia</pre>
<p>In this chapter, we will introduce Hibernate, which is the <i>de facto</i> standard object-relational mapping framework for Java applications. The Hibernate galaxy is quite large and needs a book of its own to be fully explored. Our mission will be to take over one sector of this galaxy, especially where Hibernate applications are managed by JBoss AS.</p>
<p>In this chapter, we will cover the following topics:</p>
<ul>
<ul>
<li>A short introduction to Hibernate</li>
</ul>
</ul>
<ul>
<ul>
<li>Setting up our proof of concept for the Hibernate project</li>
</ul>
</ul>
<ul>
<ul>
<li>Reverse engineering a database schema into Hibernate POJOs and mapping files</li>
</ul>
</ul>
<ul>
<ul>
<li>Deploying the application to JBoss AS</li>
</ul>
</ul>
<ul>
<ul>
<li>Comparing the Hibernate technology with EJB 3 persistence (JPA)</li>
</ul>
</ul>
<h2>Introducing Hibernate</h2>
<p>Hibernate provides a bridge between the database and the application by persisting application objects in the database, rather than requiring the developer to write and maintain lots of code to store and retrieve objects.</p>
<p>The main configuration file, hibernate.cfg.xml, specifies how Hibernate obtains database connections, either from a JNDI DataSource or from a JDBC connection pool. Additionally, the configuration file defines the persistent classes, which are backed by mapping definition files.</p>
<p>This is a sample hibernate.cfg.xml configuration file that is used to handle connections to a MySQL database, mapping the com.sample.MySample class.</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-configuration&gt;
		&lt;session-factory&gt;
			&lt;property name=&quot;connection.username&quot;&gt;user&lt;/property&gt;
			&lt;property name=&quot;connection.password&quot;&gt;password&lt;/property&gt;
			&lt;property name=&quot;connection.url&quot;&gt;
				jdbc:mysql://localhost/database
			&lt;/property&gt;
			&lt;property name=&quot;connection.driver_class&quot;&gt;
				com.mysql.jdbc.Driver
			&lt;/property&gt;
			&lt;property name=&quot;dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/property&gt;
			&lt;mapping resource=&quot;com/sample/MyClass.hbm.xml&quot;/&gt;
		&lt;/session-factory&gt;
	&lt;/hibernate-configuration&gt;</pre>
<p>From our point of view, it is important to know that Hibernate applications can coexist in both the <b>managed</b> environment and the <b>non-managed</b> environment. An application server is a typical example of a managed environment that provides services to hosting applications, such as connection pooling and transaction.</p>
<p>On the other hand, a non-managed application refers to standalone applications, such as Swing Java clients that typically lack any built-in service.</p>
<p>In this chapter, we will focus on managed environment applications, installed on JBoss Application Server. You will not need to download any library to your JBoss installation. As a matter of fact, JBoss persistence layer is designed around Hibernate API, so it already contains all the core libraries.</p>
<h2>Creating a Hibernate application</h2>
<p>You can choose different strategies for building a Hibernate application. For example, you could start building Java classes and map files from scratch, and then let Hibernate generate the database schema accordingly. You can also start from a database schema<br />
and reverse engineer it into Java classes and Hibernate mapping files. We will choose the latter option, which is also the fastest. Here&#8217;s an overview of our application.</p>
<p>In this example, we will design an employee agenda divided into departments. The persistence model will be developed with Hibernate, using the reverse engineering facet of JBoss tools. We will then need an interface for recording our employees and<br />
departments, and to query them as well.</p>
<p>The web interface will be developed using a simple <b>Model-View-Controller (MVC) </b>pattern and basic JSP 2.0 and servlet features.</p>
<p>The overall architecture of this system resembles the AppStore application that has been used to introduce JPA. As a matter of fact, this example can be used to compare the two persistence models and to decide which option best suits your project needs. We have added a short section at the end of this example to stress a few important points about this choice.</p>
<h2>Setting up the database schema</h2>
<p>As our first step, we are going to create the necessary tables for our example. Launch a MySQL client and issue the following DDL:</p>
<pre class="brush: java; title: ; notranslate">	CREATE schema hibernate;
	GRANT ALL PRIVILEGES ON hibernate.* TO 'jboss'@'localhost' WITH GRANT
	OPTION;
	CREATE TABLE `hibernate`.`department` (
		`department_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
		`department_name` VARCHAR(45) NOT NULL,
		PRIMARY KEY (`department_id`)
	)
	ENGINE = InnoDB;
	CREATE TABLE `hibernate`.`employee` (
		`employee_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
		`employee_name` VARCHAR(45) NOT NULL,
		`employee_salary` INTEGER UNSIGNED NOT NULL,
		`employee_department_id` INTEGER UNSIGNED NOT NULL,
		PRIMARY KEY (`employee_id`),
		CONSTRAINT `FK_employee_1` FOREIGN KEY `FK_employee_1` (`employee_
	department_id`)
		REFERENCES `department` (`department_id`)
		ON DELETE CASCADE
		ON UPDATE CASCADE
	)
	ENGINE = InnoDB;</pre>
<p>With the first <b>Data Definition Language (DDL)</b> command, we have created a schema named Hibernate that will be used to store our tables. Then, we have assigned the necessary privileges on the Hibernate schema to the user jboss (created in Chapter 5, <i>Developing JPA Entities</i>).</p>
<p>Finally, we created a table named department that contains the list of company units, and another table named employee that contains the list of workers. The employee table references the department with a foreign key constraint.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-1.jpg"><img class="aligncenter size-full wp-image-6631" alt="jboss-hibernate-1" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-1.jpg" width="447" height="195" /></a></center></p>
<h2>A new Eclipse project</h2>
<p>Now start Eclipse. You don&#8217;t have a specific project for Hibernate applications, so a utility project (that simply packs the classes in an archive) will be enough. You can reach this option from the menu by going to <b>New | Other | Java EE | Utility Project</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-2.jpg"><img class="aligncenter  wp-image-6632" alt="jboss-hibernate-2" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-2.jpg" width="431" height="402" /></a></center>Name the project <b>HibernateProject</b> and target it to <b>JBoss AS 5.0 Runtime</b>. You can leave the default JBoss AS configuration and hit <b>Finish</b>.</p>
<p>Now, we are going to unleash the full potential of <b>Hibernate tools</b>. Select from the menu <b>New | Other | Hibernate | Hibernate Configuration File</b>. The Hibernate configuration contains all of the details for wiring your application to the database. You will be asked for the name and the parent folder of the configuration file. Accept the default hibernate.cfg.xml at the root of your project.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-3.jpg"><img class="aligncenter  wp-image-6633" alt="jboss-hibernate-3" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-3.jpg" width="437" height="272" /></a></center>Next , insert the details of your Hibernate configuration. Choose a name for your session factory, which will contain your MySQL connection facets. Remember to check the fl ag <b>Create a console configuration</b>, so that the wizard will complete the console configuration as the next step.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-4.jpg"><img class="aligncenter  wp-image-6634" alt="jboss-hibernate-4" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-4.jpg" width="409" height="357" /></a></center>A <b>console configuration</b> describes how the Hibernate plugin should interact with Hibernate and what configuration files (including the classpath) are needed to load the POJOs, JDBC drivers, and so on. This step is required to make use of query prototyping, reverse engineering, and code generation.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-5.jpg"><img class="aligncenter  wp-image-6635" alt="jboss-hibernate-5" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-5.jpg" width="456" height="460" /></a></center>The console wizard will look at the current selection in the IDE and will try to autodetect the settings, which you can approve or modify to suit your needs. For example, you don&#8217;t need to enter the <b>Configuration file</b> or the <b>Property file</b> if you have just one in your project; Eclipse will select it automatically.</p>
<p>One important selection is the <b>Type</b> option that lets you choose between the <b>Core </b>hibernate configuration (Java classes backed by mapping files), <b>Annotations</b>, or even <b>JPA</b> annotations. We will leave the selected <b>Core</b> option.</p>
<p>Before clicking <b>Finish</b>, select <b>MySQL (InnoDB)</b> as <b>Database dialect</b> in the <b>Options </b>tab. No other changes are required.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-6.jpg"><img class="aligncenter  wp-image-6636" alt="jboss-hibernate-6" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-6.jpg" width="446" height="338" /></a></center>Now verify that you have successfully linked to Hibernate by switching to <b>Hibernate Configuration</b>. This view will be composed by a tree of three objects: <b>Configuration, Session Factory,</b> and <b>Database</b>. Choose Database and verify that it expands correctly to show the database tables of your schema.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-7.jpg"><img class="aligncenter size-full wp-image-6637" alt="jboss-hibernate-7" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-7.jpg" width="298" height="263" /></a></center>If you fail to browse the database schema, check that you have correctly set up your Hibernate configuration.</p>
<h2>Reversing your schema into Java classes</h2>
<p>The next move will be reversing our database schema into Java classes and mapping files. This powerful feature is available from the menu: <b>File | New | Hibernate |Hibernate Reverse Engineering file</b>. You can place this file in a convenient location for your project and choose a name for it. The default name proposed is hibernate.reveng.xml, which looks rather the tile of another fiction movie from G. Lucas.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-8.jpg"><img class="aligncenter  wp-image-6638" alt="jboss-hibernate-8" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-8.jpg" width="367" height="191" /></a></center>On the next page, select your <b>Console configuration</b> and choose the tables that will be included in your reverse engineering process. (Hint: You have to hit <b>Refresh</b> first to show the database schema and then click <b>Include&#8230;.)</b></p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-9.jpg"><img class="aligncenter  wp-image-6639" alt="jboss-hibernate-9" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-9.jpg" width="421" height="236" /></a></center>What Eclipse has just created for you is a file named hibernate.reveng.xml that should resemble the following code snippet:</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-reverse-engineering&gt;
		&lt;table-filter match-catalog=&quot;hibernate&quot; match-name=&quot;department&quot;/&gt;
		&lt;table-filter match-catalog=&quot;hibernate&quot; match-name=&quot;employee&quot;/&gt;
	&lt;/hibernate-reverse-engineering&gt;</pre>
<p>If you are smart at noticing variations, you might have discovered a new icon in your toolbar. This is your gateway to the reverse engineering process. (Notice: this icon is visible only in the Hibernate Perspective, you will not be able to find it anywhere else.)</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-10.jpg"><img class="aligncenter  wp-image-6640" alt="jboss-hibernate-10" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-10.jpg" width="451" height="62" /></a></center>Click on Hibernate&#8217;s down arrow icon and select <b>Hibernate Code Generation Configurations</b>. In the next dialog, you will first have to create a new <b>Hibernate Code Generation Configuration</b> that will contain all the details of your reverse engineering process. Click on the <b>New</b> button located in the left corner of the wizard.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-11.jpg"><img class="aligncenter  wp-image-6641" alt="jboss-hibernate-11" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-11.jpg" width="456" height="200" /></a></center>Now, select your brand new configuration and carefully choose the following options. First, wire the <b>Console configuration</b> to your project (HibernateProject). Then, choose an output directory for your generated files. We would suggest you to point to your src folder. (Be aware that existing files will be overwritten, that&#8217;s why I just said you have to be <i>careful</i>!)</p>
<p>Just below, you will find the checkbox <b>Reverse engineer from JDBC Connection</b>. If enabled, the tools will reverse engineer the available database using the connection information in the selected Hibernate Console configuration. Check this option and enter the package name for the generated classes, which will be <b>com.packtpub. hibernate</b>. Leave the other text fields to the defaults and move to the tab <b>Exporters</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-12.jpg"><img class="aligncenter  wp-image-6642" alt="jboss-hibernate-12" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-12.jpg" width="365" height="341" /></a></center><br />
The <b>Exporters</b> tab menu is used to specify which type of code should be generated. Each selection represents an Exporter that is responsible for generating the code, hence the name.</p>
<p>In the upper area of the dialog, you will notice an interesting checkbox named <b>Generate EJB 3 annotations</b>. We will return to this useful option later. At the moment, what we need is just to check the <b>Domain code and Hibernate XML Mappings </b>options, which will generate the Java POJOs and mapping files respectively.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-13.jpg"><img class=" wp-image-6643 aligncenter" alt="jboss-hibernate-13" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-13.jpg" width="427" height="375" /></a></p>
<p>It took a bit of time to complete all of these steps; however, now your Java classes and configuration files are handy and waiting to be packaged.</p>
<h2>Adding Hibernate configuration to your project</h2>
<p>The advantage of embedding the Hibernate application in JBoss AS is that you can expose <b>Hibernate SessionFactory</b> through a JN DI tree and modify its configuration at runtime.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>This is indeed a great configuration advantage; before the new release of JBoss AS, you had to delegate to an MBean the creation of the Hibernate SessionFactory and its exposure through JNDI.</p>
<p>For example, if you wanted to configure a SessionFactory at the naming context hibernate/SessionFactory, you would have to package your Hibernate application with a file named xxx-service.xml in the META-INF folder. Here&#8217;s a sample of it:</p>
<pre class="brush: java; title: ; notranslate">	&lt;server&gt;
		&lt;mbean code=&quot;org.jboss.hibernate.jmx.Hibernate&quot;
			name=&quot;jboss.har:service=Hibernate&quot;&gt;
			&lt;attribute name=&quot;DatasourceName&quot;&gt;java:/ MySqlDS&lt;/attribute&gt;
			&lt;attribute name=&quot;Dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/attribute&gt;
			&lt;attribute name=&quot;SessionFactoryName&quot;&gt;
				java:/hibernate/SessionFactory
			&lt;/attribute&gt;
			&lt;attribute name=&quot;CacheProviderClass&quot;&gt;
				org.hibernate.cache.HashtableCacheProvider
			&lt;/attribute&gt;
		&lt;/mbean&gt;
	&lt;/server&gt;</pre>
<p>This configur ation is still valid for pre 5.0 releases of JBoss AS. With the introduction of the new <b>Virtual Deployment Framework (VDF)</b>, you now have to provide your <b>SessionFactory</b> configuration using the Hibernate XML schema. For example, if you want to link your SessionFactory to your MySQL database, you have to add the following service-hibernate.xml. (Be aware, the suffix is -hibernate.xml and not –service.xml.)</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-configuration xmlns=&quot;urn:jboss:hibernate-deployer:1.0&quot;&gt;
		&lt;session-factory name=&quot;java:/hibernate/SessionFactory&quot;
			bean=&quot;jboss.test.har:service=Hibernate,
			testcase=TimersUnitTestCase&quot;&gt;
			&lt;property name=&quot;datasourceName&quot;&gt;java:/MySqlDS&lt;/property&gt;
			&lt;property name=&quot;dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/property&gt;
			&lt;depends&gt;jboss:service=Naming&lt;/depends&gt;
			&lt;depends&gt;jboss:service=TransactionManager&lt;/depends&gt;
		&lt;/session-factory&gt;
	&lt;/hibernate-configuration&gt;</pre>
<p>The preceding configuration file needs to be stored in the META-INF folder of your <b>Hibernate archive (HAR)</b> file. The structure of the updated project from the <b>Package Explorer</b> is as shown in the following snapshot:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-14.jpg"><img class="aligncenter size-full wp-image-6644" alt="jboss-hibernate-14" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-14.jpg" width="478" height="424" /></a></center></p>
<h2>Adding a web client to your project</h2>
<p>There are seve ral ways to test our Hibernate application. The simplest of all is adding a web application, which is packaged in an Enterprise application along with the Hibernate application. Create a new dynamic web project named HibernateWeb.</p>
<p>The first step, before adding servlets and JSPs is linking the HibernateProject libraries to your web application, otherwise, you will not be able to reference the Hibernate POJOs. Right-click on your project and select <b>Properties</b>. Reach the <b>Java Build Path </b>option and select the tab <b>Projects</b>. From there add <b>HibernateProject</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-15.jpg"><img class="aligncenter  wp-image-6645" alt="jboss-hibernate-15" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-15.jpg" width="458" height="196" /></a></center>Let&#8217;s move on. This project will contain a main servlet that acts as a controller, and a few JPSs for the client view. We will start by adding com.packtpub.hibernateWeb. HibernateServlet to our project.</p>
<p>In the following snippet, you can see the core section of the servlet. Here, we will not detail the Controller logic, which is straightforward if you have some rudiments of the MVC pattern; rather we want to highlight the most interesting part of it, which is how to query and persist Hibernate objects.</p>
<pre class="brush: java; title: ; notranslate">	public class HibernateServlet extends HttpServlet {
		private SessionFactory getSessionFactory() {
			return (SessionFactory)getServletContext().
			getAttribute(&quot;sessionFactory&quot;);
		}
		public void init() { [1]
			if (getSessionFactory() != null) {
				return;
			}
			InitialContext ctx;
			try {
				ctx = new InitialContext();
				&lt;b&gt;factory = (SessionFactory)ctx.
					lookup(&quot;java:/hibernate/SessionFactory&quot;);
				getServletContext().setAttribute(&quot;sessionFactory&quot;, factory);&lt;/b&gt;
			}
			catch (NamingException e) {
				e.printStackTrace();
			}
		}
		private String saveEmployee(HttpServletRequest request) {
			Session hsession=null;
			String name=request.getParameter(&quot;name&quot;);
			String salary=request.getParameter(&quot;salary&quot;);
			String departmentId=request.getParameter(&quot;departmentId&quot;);
			try {
				hsession = getSessionFactory().openSession();
				hsession.beginTransaction();
				&lt;b&gt;Query query = hsession.createQuery(&quot;from Department d where
					d.departmentId = :departmentId&quot;); [2]&lt;/b&gt;
				query.setInteger(&quot;departmentId&quot;, new Integer(departmentId));
				Department dep = (Department) query.uniqueResult();
				Employee emp = new Employee();
				emp.setDepartment(dep);
				emp.setEmployeeName(name);
				emp.setEmployeeSalary(Integer.parseInt(salary));
				&lt;b&gt;hsession.save(emp); [3]&lt;/b&gt;
				hsession.getTransaction().commit();
			}
			catch (Exception e) {
				// TODO Auto-generated catch block e.printStackTrace();
				hsession.getTransaction().rollback();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return employeeList(request);
		}
		private String employeeList(HttpServletRequest request) {
			Session hsession=null;
			Department dep;
			try {
				hsession = getSessionFactory().openSession();
				&lt;b&gt;Query query = hsession.createQuery(&quot;select p from Employee p
					join fetch p.department c&quot;); [4]&lt;/b&gt;
				List &lt;Employee&gt;list = query.list();
				request.setAttribute(&quot;employee&quot;, list);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return &quot;/listEmployees.jsp&quot;;
		}
		private String saveDepartment(HttpServletRequest request) {
			String depName=request.getParameter(&quot;depName&quot;);
			Session hsession=null;
			Department dep;
			try {
				hsession = getSessionFactory().openSession();
				hsession.beginTransaction();
				dep = new Department();
				dep.setDepartmentName(depName);
				&lt;b&gt;hsession.save(dep); [5]&lt;/b&gt;
				hsession.getTransaction().commit();
			}
			catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				hsession.getTransaction().rollback();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return employeeList(request);
		}
	}</pre>
<p>As you can see from the preceding code, we recover the SessionFactory from the JNDI tree in the init() <b>[1]</b> method of the servlet. Instances of SessionFactory are thread-safe and typically shared throughout an application, so we store it in the ServletContext and share it among all servlet instances.</p>
<p>The SessionFactory is subsequently used to start a Hibernate session, which is not thread-safe and should only be used for a single transaction or unit of work in an application.</p>
<p>In order to store our Employee, in the saveEmployee method, we first retrieve the corresponding Department from our schema <b>[2]</b>, and finally the Employee is saved <b>[3]</b> and the transaction is committed.</p>
<p>The list of employees is fetched by the employeeList method. Notice we are using a join fetch statement to retrieve all the employees <b>[4]</b>, which will be routed to the listEmployees.jsp view. Why? The answer is that with the default fetch mode (Lazy), once the Hibernate session is closed, the client will not be able to navigate through the department field of the Employee. The common solution to this issue is switching to the EAGER fetch mode that reads the related fields (in our case department) in memory, as soon as we query the Employee table.</p>
<p>You have more than one option to achieve this. One possible solution, if you don&#8217;t want to change the default fetch mode for the Employee table, is to build an <i>ad hoc</i> query that forces Hibernate to read also those fields that are in relation with the Employee table.</p>
<pre class="brush: java; title: ; notranslate">	&quot;select p from Employee p join fetch p.department c&quot;</pre>
<p>If you prefer to use the XML class files to configure the fetch mode, you can also change the lazy=&#8221;true&#8221; attribute in the employee-department relationship.</p>
<p>The last method, saveDepartment <b>[5]</b> takes care to persist a new Department in the corresponding table. We complete our excursus on the web tier with the listEmployees.jsp that is used to display a tabular view of the employees:</p>
<pre class="brush: java; title: ; notranslate">	&lt;b&gt;&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&gt;&lt;/b&gt;
	&lt;html&gt;
		&lt;script language=&quot;JavaScript&quot;&gt;
			function doSubmit(url) {
				document.module.action = url;
				document.module.submit();
			}
		&lt;/script&gt;
		&lt;body&gt;
			&lt;table border=&quot;1&quot;&gt;
				&lt;tr&gt;
					&lt;th&gt;Name&lt;/th&gt;
					&lt;th&gt;Salary&lt;/th&gt; &lt;TH&gt;department&lt;/th&gt;
				&lt;/tr&gt;
				&lt;b&gt;&lt;c:forEach items=&quot;${employee}&quot; var=&quot;emp&quot;&gt;
					&lt;tr&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.employeeName}&quot;/&gt; &lt;/td&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.employeeSalary}&quot;/&gt;&lt;/td&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.department.departmentName}&quot;/&gt;&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/c:forEach&gt;&lt;/b&gt;
			&lt;/table&gt;
			&lt;form name=&quot;module&quot; method=&quot;POST&quot;&gt;
				&lt;input type=&quot;button&quot; value =&quot;New Employee&quot;
					onClick=&quot;doSubmit('actionServlet?op=newEmployee')&quot;&gt;
				&lt;input type=&quot;button&quot; value =&quot;New Department&quot;
					onClick=&quot;doSubmit('actionServlet?op=newDepartment')&quot;&gt;
			&lt;/form&gt;
		&lt;/body&gt;
	&lt;/html&gt;</pre>
<p>This page uses JSP 2.0 <b>Expression Language (EL)</b> to iterate through the list of employees, as highlighted in the last code snippet. We have also highlighted the taglib directive, at the beginning of the page. This directive will be used to resolve the JSTL core set of libraries that ships with JBoss AS in the server/xxx/deploy/ jbossweb.sar/jstl.jar library. (Eclipse does not contain references to this library when you create a web project; you have to add jstl.jar to your build path, otherwise Eclipse will mark it as an error. However, that&#8217;s only a visual annoyance because the JBoss web container has got everything it needs to run JSTL.)</p>
<p>The complete web application is available on the Packtpub website (http://www.packtpub.com) and includes two additional JSPs for entering the employee (newEmployee.jsp) and department (newDepartment.jsp) data, plus one placeholder index.jsp that merely forwards to the <b>HibernateServlet</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-16.jpg"><img class="aligncenter size-full wp-image-6646" alt="jboss-hibernate-16" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-16.jpg" width="387" height="306" /></a></center></p>
<h2>Packaging and deploying the application</h2>
<p>Your enterprise application is complete. We need to package it in an EAR archive so that the web application will be able to interact with the Hibernate POJOs. Create a new <b>Enterprise Application</b> project from the Java EE folder. You will be prompted to select the projects that will be included as modules. Select both the <b>HibernateProject</b> and the web application <b>HibernateWeb</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-17.jpg"><img class="aligncenter size-full wp-image-6647" alt="jboss-hibernate-17" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-17.jpg" width="503" height="537" /></a></center> If you have ever worked with JBoss AS and Hibernate, then you might argue that right now something is missing. You&#8217;re indeed right. Before release 5.0 of the JBoss Application Server, Hibernate classes and mapping files had to be packaged in a JBoss AS custom .har archive. The suffix was determinant, as JBoss AS was able to classify the package as a Hibernate resource.</p>
<p>As HAR archives are not Java EE standard components, you have to declare it in a JBoss AS-specific configuration file named jboss-app.xml that sits in the META-INF folder of our EAR.</p>
<pre class="brush: java; title: ; notranslate">	&lt;!DOCTYPE jboss-app PUBLIC &quot;-//JBoss//DTD J2EE Application 1.5//EN&quot;
		&quot;http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd&quot;&gt;
		&lt;jboss-app&gt;
			&lt;module&gt;
				&lt;har&gt;HibernateApplication.har&lt;/har&gt;
			&lt;/module&gt;
		&lt;/jboss-app&gt;</pre>
<p>While this approach is still advisable if you want to grant backward compatibility to your applications, with release 5.0 of the Application Server you now have a handy quicker solution. As the new VFS of JBoss AS is able to detect the nature of your application by scanning deployment descriptors, it&#8217;s enough to pack your Hibernate application in a plain <b>Java ARchive (JAR)</b>. JBoss AS will discover the .hbm.xml mapping files and look for the corresponding Java classes. If successful, the package will be deployed as a Hibernate application straightaway.</p>
<p>The corollary of this theorem is that you can leave out, as well, the JBoss AS configuration file jboss-app.xml, which is not necessary any more. The only update required is to your application.xml, where your Hibernate application is declared as a Java module in order to make it available to other enterprise modules.</p>
<pre class="brush: java; title: ; notranslate">	&lt;application&gt;
		&lt;module&gt;
			&lt;web&gt;
				&lt;web-uri&gt;HibernateWeb.war&lt;/web-uri&gt;
				&lt;context-root&gt;HibernateWeb&lt;/context-root&gt;
			&lt;/web&gt;
		&lt;/module&gt;
		&lt;b&gt;&lt;module&gt;
			&lt;java&gt;HibernateProject.jar&lt;/java&gt;
		&lt;/module&gt;&lt;/b&gt;
	&lt;/application&gt;</pre>
<p>This is how your Enterprise ARchive should look like before deploying it:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-18.jpg"><img class="aligncenter size-full wp-image-6648" alt="jboss-hibernate-18" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-18.jpg" width="388" height="288" /></a></center> Now deploy your application in the usual way, by adding the project to JBoss AS projects and then choosing <b>Full Publish</b>. The application server will then produce a few log pages; if the binding of classes is successful, you will find the following among your logs:</p>
<p><b>16:46:18,949 INFO [HbmBinder] Mapping class: com.packtpub.hibernate.</b></p>
<p>Employee -&gt;employee</p>
<p><b>16:46:19,261 INFO [HbmBinder] Mapping class: com.packtpub.hibernate.</b></p>
<p>Department -&gt; department</p>
<p><b>16:46:19,277 INFO [HbmBinder] Mapping collection: com.packtpub.hibernate.</b></p>
<p>Department.employees -&gt; employee</p>
<p>In order to test your application, simply recall your JSP default page, using the HibernateWeb context. In our example:</p>
<p>http://localhost:8080/HibernateWeb/</p>
<h2>Using the wizard to generate EJB 3</h2>
<p>Hibernate tool capabilities are not limited to Hibernate programming. By using the reverse engineering option, you can also generate EJB 3.0 classes in a matter of seconds. Recall the <b>Reverse Engineering Configuration:</b></p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-19.jpg"><img class="aligncenter  wp-image-6649" alt="jboss-hibernate-19" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-19.jpg" width="502" height="441" /></a></center> If you Check the <b>Generate EJB 3 annotations</b> checkbox along with <b>Domain code</b>, then the outcome of your reverse engineering process would be simple Java classes with entity annotations. That&#8217;s a huge saving of time, especially if your database schema is rather complex. You can still adjust your entity beans to your needs once they are generated.</p>
<h2>Hibernate and EJB: Friends or opponents?</h2>
<p>In Chapter 4, we introduced the EJB programming model, so at this stage, you might wonder when it&#8217;s more appropriate to use EJB from your projects and when it&#8217;s better to stay on the Hibernate framework.</p>
<p>The premise of this debate is that EJB and Hibernate are not fully comparable because they are semantically different. EJBs live in a container, which provides services, such as transactions, concurrent access control, security, instance pooling,and others. On the other hand, Hibernate is classified as an <b>object-relational mapping tool</b> and it is independent from a server container.</p>
<p>So, if comparing EJB and Hibernate is technically a mistake, you can actually compare the <b>Java Persistence API</b> and Hibernate, which are, in some ways, two <i>antagonist</i> technologies. The most important factor, which is in favor of JPA, is that it is a standard. Using industry-standard components allows the business comparatively more fl exibility when it&#8217;s necessary to change its business model, to reorchestrate itself, and to collaborate dynamically.</p>
<p>Technically speaking, it is also important to stress that an EJB-centric approach is the appropriate implementation technology for two types of applications:</p>
<ul>
<ul>
<li>Applications that use distributed transactions initiated by remote clients</li>
</ul>
</ul>
<ul>
<ul>
<li>Applications that are heavily message-oriented and need message-driven beans</li>
</ul>
</ul>
<p>On the other hand, Hibernate framework has reached a vast community of developers and it offers the benefit of peacefully coexisting in various deployment environments, from application servers to standalone applications.</p>
<p>At the end of the day, the choice between the two technologies might be to preserve your well-tested applications backed by Hibernate Persistence and to definitely consider switching to JPA when you are designing a new project from the ground up. What about using them together instead?</p>
<h2>Using Hibernate with EJB</h2>
<p>A plausible scenario is that some time ago, you designed the persistence layer of your application with Hibernate. Now you need to expose some functionalities of your application through RMI or Web Services.</p>
<p>The good news is that persistent classes that are mapped using Hibernate *.hbm. xml files are supported by JBoss AS EJB 3 implementation. The <b>EJB 3 deployer </b>will search the archive for any .hbm.xml files and add them to the definition of the underlying Hibernate SessionFactory. Let&#8217;s see how you can leverage Hibernate objects from the EJB environment.</p>
<h2>Injecting key Hibernate objects</h2>
<p>If you have been through the Hibernate web application carefully, you might advocate that it is not a pure MVC application, as we are accessing the persistence layer from within the servlet.</p>
<p>This approach can be useful for a learner who wants an easy-to-catch example of Hibernate. However, you can create a clean separation of roles between the controller and the model tier, also by introducing an EJB as intermediary.</p>
<p>From inside your Hibernate project, add another Stateless Session Bean named com.packtpub.hibernate.HibernateDAOBean implementing a local interface com.packtpub.hibernate.HibernateDAOLocal.</p>
<p>Following is a code snippet of the bean implementing the saveEmployee method:</p>
<pre class="brush: java; title: ; notranslate">	@Stateless
	@LocalBinding(jndiBinding=&quot;HibernateDAO/local&quot;)
	public class HibernateDAOBean implements HibernateDAO {
		&lt;b&gt;@PersistenceUnit(unitName=&quot;hibernateUnit&quot;) [1]
			SessionFactory factory;&lt;/b&gt;
		public void saveEmployee(String name,String salary,String
			departmentId) {
			Session hsession=null;
			try {
				hsession = factory.openSession();
				Query query = hsession.createQuery(&quot;from Department d where
				d.departmentId = :departmentId&quot;);
				query.setInteger(&quot;departmentId&quot;, new Integer(departmentId));
				Department dep = (Department) query.uniqueResult();
				Employee emp = new Employee();
				emp.setDepartment(dep);
				emp.setEmployeeName(name);
				emp.setEmployeeSalary(Integer.parseInt(salary));
				hsession.save(emp);
			}
			catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				throw new EJBException(e.getMessage());
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
		}</pre>
<p>The most interesting point in this example is that you have injected the Hibernate SessionFactory in your bean by means of the persistence unit named hibernateUnit. Therefore, you have to equip your application with a JPA persistence.xml file:</p>
<pre class="brush: java; title: ; notranslate">	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
		&lt;persistence version=&quot;1.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/
			persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
			xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://
			java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;&gt;
			&lt;b&gt;&lt;persistence-unit name=&quot;hibernateUnit&quot; transaction-type=&quot;JTA&quot;&gt;&lt;/b&gt;
				&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
				&lt;jta-data-source&gt;java:/MySqlDS&lt;/jta-data-source&gt;
				&lt;properties&gt;
					&lt;property name=&quot;hibernate.dialect&quot;
						value=&quot;org.hibernate.dialect.MySQLDialect&quot;/&gt;
				&lt;/properties&gt;
			&lt;/persistence-unit&gt;
		&lt;/persistence&gt;</pre>
<p>We leave as exercise to the reader to complete the EJB with all other methods. On the web tier, you will do a clear cut of all the persistence stuff, just taking care to invoke the EJB with the parameters collected from the request. Look how simple and effective your servlet method saveEmployee has become:</p>
<pre class="brush: java; title: ; notranslate">	&lt;b&gt;@EJB(mappedName = &quot;HibernateDAO/local&quot;)
	HibernateDAO hibernateDAO;&lt;/b&gt;
		private String saveEmployee(HttpServletRequest request) {
			Session hsession=null;
			String name=request.getParameter(&quot;name&quot;);
			String salary=request.getParameter(&quot;salary&quot;);
			String departmentId=request.getParameter(&quot;departmentId&quot;);
			try {
				hibernateDAO.saveEmployee(name,salary,departmentId);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			return employeeList(request);
		}</pre>
<p>A snapshot of the complete Hibernate EJB-driven project follows here:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-20.jpg"><img class="aligncenter size-full wp-image-6650" alt="jboss-hibernate-20" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-20.jpg" width="401" height="524" /></a></center> As you can see, using Hibernate API works much the same way as the EntityManager interface. This example reveals another difference with our former web application. Here the EJB must not attempt to manage the life cycle of the Hibernate session; this is done internally by the EJB container, which is in charge of committing or rolling back the transaction, following the EJB container&#8217;s policies.</p>
<h2>Summary</h2>
<p>Hibernate is a fl exible framework that can be used in any Java application environment. In our excursus, we have showed how to develop a sample application that is geared toward a managed environment. In the last two sections of the chapter, we have compared the Hibernate framework with the JPA persistence standard, showing how the two technologies can be coupled in a single application.</p>
<p>In the next chapter, we will learn JBoss AS JMX infrastructure, which was the backbone of earlier releases of JBoss. Even if it&#8217;s not the main kernel component anymore, the JMX API is still the glue around many JBoss AS services.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring JMS API and Weblogic JMS Integration</title>
		<link>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/</link>
		<comments>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 16:00:32 +0000</pubDate>
		<dc:creator>Sangeetha G</dc:creator>
				<category><![CDATA[JMS]]></category>
		<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=422</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>1)Introduction JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Spring provides support for JMS programming. Spring is a widely used framework to develop enterprise application. It is bundled with many APIs like AOP, IOC Spring MVC,Spring JMS [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>1)Introduction</h2>
<p>JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Spring provides support for JMS programming. Spring is a widely used framework to develop enterprise application. It is bundled with many APIs like AOP, IOC Spring MVC,Spring JMS etc. This article can be used by beginners to write simple programs using Spring API to integrate with Weblogic JMS .Here weblogic is used because it supports many features to provide communication between sender and receiver.It acts as a middleware for JMS application.</p>
<h2>2)Why do we need JMS?</h2>
<p>Enterprise Application is a software to solve enterprise problem. It has many business requirements to solve the problem. To have better modularity, the requirements will be developed as different software components and programmer will integrate these components to complete entire enterprise application. The programmer needs to consider many factors while integrating the components. The following scenarios will give the clear picture about the some factors with respect to component integration</p>
<h3>Scenario #1:</h3>
<p>Assume that there two components called OrderProcessing and CreditCardVerification. The OrderProcessing component needs to communicate to the CreditCardVerifcation but it is not having the interface of the CreditCardVerification.<br />
<strong>How it is going to communicate?</strong></p>
<h3>Scenario #2:</h3>
<p>Assume that there are two Components called TransactionBean and HistoryBean(to record each transaction). For each transaction, the TransactionBean is going to send information to the HistoryBean and it doesn?t want to wait till the HistoryBean completes the work.<br />
<strong>How to develop the TransactionBean to have asynchronous communication to HistoryBean?</strong></p>
<p>The solution is provided by JMS.</p>
<h2>3)Introduction to JMS API</h2>
<p>JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Messaging provides communication between software components or applications. A messaging component can send messages to, and receive messages from, any other component. This is achieved with help of JMS Provider. The JMSProvider is a MOM (Message Oriented Middleware); sitting between sender and receiver components for asynchronous communication i.e. if a sender sends a message, the same will be stored inside MOM. The MOM then forwards the message to receiver.</p>
<p>To achieve the communication, following components will be configured inside the MOM.</p>
<ul>
<li>Connectionfactoires:Provides the communication to client programs</li>
<li>Destination: Stores the messages.There are two types.
<ol>
<li>Queue:Message will be delivered to Only one receiver</li>
<li>Topic-Message will be delivered to more than one receiver</li>
</ol>
</li>
</ul>
<h2>4) Weblogic JMS Provider</h2>
<p>One of the widely used providers is Web logic. It is widely used because of following features.</p>
<ul>
<li>Provides messaging API.</li>
<li>Supports clustering.</li>
<li>Platform independent.</li>
<li>Resources can be configured using Web Logic Administration Console.</li>
<li>Supports XML message.</li>
<li>Supports multicasting delivery.</li>
</ul>
<h2>5) Spring JMS API</h2>
<p>Spring supports JMS framework that simplifies the complexity of the JMS implementation. The package org.springframework.jms.core provides the API for JMS core functionality. A JMS Programmer can write JMS application using Spring IOC and Spring JMS API easily. Using Spring JMS and Dependency injection, the JMS configuration details are migrated from Java code to xml file</p>
<p>The Spring JMS API supports a template mechanism to hide the details of Java APIs. Programmers can use JDBC Template and JNDI Template classes to use Web logic JMS resource. Spring supports the JMS Template, so developers don&#8217;t have to write the complex code for JMS implementation. Templates are helper classes used to reduce the complexity of JMS and handle the creation and release of JMS resources like connection factories, destinations, and sender/receiver objects.</p>
<p>We attempt to provide you, in this article, a step by step solution for Integrating Spring, JMS and Web logic. It is addressed to the audience who are aware of the basics of Spring IOC, Web logic and JMS. The article also provides the detailed information about the JMS implementation using Spring JMS. This article will help the programmer to write JMS application using Spring. Programmers can use the configuration file as basic setup for JMS application in addition they can develop application as well.</p>
<h2>6) Steps to integrate Spring JMS and Weblogic</h2>
<h3>Step 1:</h3>
<ul>
<li>Configure the following JMS resource inside the web logic server.</li>
<li>ConnectionFactory- jms/connectionFactory and<br />
Queue Destination- jms/testQueue</li>
</ul>
<h3>Step 2:</h3>
<p>Create dynamic web application in the Web logic workshop</p>
<h3>Step 3:</h3>
<p>Import Spring.jar,<br />
Commons-logging.jar and<br />
log4j-1.2.15.jar</p>
<h3>Step 4:</h3>
<p>Create the InvoiceQueueSender class in the package jms. The class InvoiceQueueSender is used to send messages. The JMSTemplate is injected into InvoiceQueueSender using IOC container. JMS Template is used for sending and receiving messages using Message Creator. The Message Creator is a call back interface which has createMessage to create messages. JMS Template has send method which takes the parameter, Queue name and message creator.</p>
<p><strong>Sample Code</strong></p>
<pre class="brush: java; title: ; notranslate">package jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class InvoiceQueueSender {
	private JmsTemplate jmsTemplate;
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public void sendMesage() {
		MessageCreator messageCreator=new MessageCreator() {
		public Message createMessage(Session session) throws
		JMSException {
		return session.createTextMessage(&quot;I am 
                               sending Invoice message&quot;);}
		};

		jmsTemplate.send(&quot;jms/testQueue&quot;, messageCreator);
	}
}</pre>
<h3>Step 5:</h3>
<p>Create the InvoiceMDB class in the package jms. It is a MessageDrivenBean. The InvoiceMDB is a MDB and it implements MessageListener interface. The onMessage will be executed automatically whenever message is delivered to the Queue or Topic.</p>
<p><strong>Sample Code</strong></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">package jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class InvoiceMDB implements MessageListener {
	public void onMessage(Message message) {
	 try {
	   System.out.println(((TextMessage) message).getText());
	   System.out.println(&quot;Hello&quot;);
	 } catch (JMSException ex) {
	   throw new RuntimeException(ex);
	 }
	}
}</pre>
<h3>Step 6:</h3>
<p>The following details will be configured inside spring configuration file. Here the file name is applicationContext.xml.</p>
<h5>JNDITemplate</h5>
<p>It helps us to perform JNDI operations. It has methods to do lookup and binding operation. The web logic context details are configured using this interface.</p>
<pre class="brush: java; title: ; notranslate">	
&lt;bean id=&quot;jndiTemplate&quot; class=&quot;org.springframework
       .jndi.JndiTemplate&quot;&gt;
&lt;property name=&quot;environment&quot;&gt;
 &lt;props&gt;
   &lt;prop key=&quot;java.naming.factory.initial&quot;&gt;
           weblogic.jndi.WLInitialContextFactory&lt;/prop&gt;
   &lt;prop key=&quot;java.naming.provider.url&quot;&gt;t3://localhost:7001&lt;/prop&gt;
 &lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>JndiObjectFactoryBean</h5>
<p>It is used to look up the JNDI object on startup and cache it. This interface is used to configure connection factory.</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;queueConnectionFactory&quot; 
      class=&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;jndiName&quot;&gt;
 &lt;value&gt;jms/connectionFactory&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>DestinationResolver</h5>
<p>It is used by JmsTemplate to resolve destination names</p>
<pre class="brush: java; title: ; notranslate">
&lt;bean id=&quot;jmsDestinationResolver&quot; 
       class=&quot;org.springframework.jms.support.destination
       .JndiDestinationResolver&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;cache&quot;&gt;
 &lt;value&gt;true&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>JMSTemplate</h5>
<p>It is used to send messages. This requires information about connection factory and destination resolver while configuring.</p>
<pre class="brush: java; title: ; notranslate">	
&lt;bean id=&quot;invoiceQueueTemplate&quot; class=&quot;org.springframework.jms
        .core.JmsTemplate&quot;&gt;
&lt;property name=&quot;connectionFactory&quot;&gt;
 &lt;ref bean=&quot;queueConnectionFactory&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;destinationResolver&quot;&gt;
 &lt;ref bean=&quot;jmsDestinationResolver&quot; /&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>Queue</h5>
<p>The destination details will be configured using JndiObjectFactoryBean</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;invoiceQueue&quot; class=&quot;org.springframework
            .jndi.JndiObjectFactoryBean&quot;&gt;
 &lt;property name=&quot;jndiTemplate&quot;&gt;
   &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
 &lt;/property&gt;
 &lt;property name=&quot;jndiName&quot;&gt;
   &lt;value&gt;jms/testQueue&lt;/value&gt;
 &lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>MDB(MessageDrivenBean)</h5>
<p>The details about Message driven will configured as a normal bean</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;invoiceListener&quot; class=&quot;jms.InvoiceMDB&quot; /&gt;</pre>
<h5>Listener Configuarion</h5>
<p>This class is used to configure the normal bean as message driven bean. While configuring, the destination details will be supplied so that the framework can have the relationship between MDB and destination</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;Invoicelistener&quot; class=&quot;org.springframework.jms
           .listener.DefaultMessageListenerContainer&quot;&gt;
    &lt;property name=&quot;concurrentConsumers&quot; value=&quot;5&quot; /&gt;
    &lt;property name=&quot;connectionFactory&quot; ref=&quot;queueConnectionFactory&quot; /&gt;
    &lt;property name=&quot;destination&quot; ref=&quot;invoiceQueue&quot; /&gt;
    &lt;property name=&quot;messageListener&quot; ref=&quot;invoiceListener&quot; /&gt;
&lt;/bean&gt;</pre>
<h5>SenderBean</h5>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;jmsInvoiceSender&quot; class=&quot;jms.InvoiceQueueSender&quot;&gt;
&lt;property name=&quot;jmsTemplate&quot;&gt;
&lt;ref bean=&quot;invoiceQueueTemplate&quot; /&gt;</pre>
<h5>The final contents will be</h5>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot;
&quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;
&lt;beans&gt;

&lt;bean id=&quot;invoiceListener&quot; class=&quot;jms.InvoiceMDB&quot; /&gt;

&lt;bean id=&quot;jndiTemplate&quot; class=&quot;org.springframework.jndi.JndiTemplate&quot;&gt;
&lt;property name=&quot;environment&quot;&gt;
 &lt;props&gt;
   &lt;prop key=&quot;java.naming.factory.initial&quot;&gt;weblogic.jndi
                   .WLInitialContextFactory&lt;/prop&gt;
   &lt;prop key=&quot;java.naming.provider.url&quot;&gt;t3://localhost:7001&lt;/prop&gt;
 &lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;queueConnectionFactory&quot; class=&quot;org.springframework.
             jndi.JndiObjectFactoryBean&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;jndiName&quot;&gt;
 &lt;value&gt;jms/connectionFactory&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;jmsDestinationResolver&quot; class=&quot;org.springframework
            .jms.support.destination.JndiDestinationResolver&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;cache&quot;&gt;
 &lt;value&gt;true&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;invoiceQueueTemplate&quot; class=&quot;org.springframework
             .jms.core.JmsTemplate&quot;&gt;
&lt;property name=&quot;connectionFactory&quot;&gt;
 &lt;ref bean=&quot;queueConnectionFactory&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;destinationResolver&quot;&gt;
 &lt;ref bean=&quot;jmsDestinationResolver&quot; /&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;jmsInvoiceSender&quot; class=&quot;jms.InvoiceQueueSender&quot;&gt;
&lt;property name=&quot;jmsTemplate&quot;&gt;
 &lt;ref bean=&quot;invoiceQueueTemplate&quot; /&gt;
&lt;/property&gt;

&lt;/bean&gt;

&lt;bean id=&quot;invoiceQueue&quot; class=&quot;org.springframework.jndi
        .JndiObjectFactoryBean&quot;&gt;
 &lt;property name=&quot;jndiTemplate&quot;&gt;
   &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
 &lt;/property&gt;
 &lt;property name=&quot;jndiName&quot;&gt;
   &lt;value&gt;jms/testQueue&lt;/value&gt;
 &lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=&quot;Invoicelistener&quot; class=&quot;org.springframework.jms
               .listener.DefaultMessageListenerContainer&quot;&gt;
    &lt;property name=&quot;concurrentConsumers&quot; value=&quot;5&quot; /&gt;
    &lt;property name=&quot;connectionFactory&quot; ref=&quot;queueConnectionFactory&quot; /&gt;
    &lt;property name=&quot;destination&quot; ref=&quot;invoiceQueue&quot; /&gt;
    &lt;property name=&quot;messageListener&quot; ref=&quot;invoiceListener&quot; /&gt;
  &lt;/bean&gt;
&lt;/beans&gt;</pre>
<h3>Step 7:</h3>
<p>Create Servlet to send message</p>
<pre class="brush: java; title: ; notranslate">package jms;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class InvoiceSenderServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
   protected void service(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
	     WebApplicationContext ctx = WebApplicationContextUtils
		.getRequiredWebApplicationContext(this.getServletContext());

		InvoiceQueueSender sender = (InvoiceQueueSender) ctx
				.getBean(&quot;jmsInvoiceSender&quot;);
		sender.sendMesage();
	}
}</pre>
<h3>Step 8:</h3>
<p>Configure the spring configuration details in the web.xml</p>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app id=&quot;WebApp_ID&quot; version=&quot;2.4&quot; 
  xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; 
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
  xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee 

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;&gt;

	&lt;display-name&gt;
	SpringJMS&lt;/display-name&gt;
	&lt;servlet&gt;
		&lt;description&gt;
		&lt;/description&gt;
		&lt;display-name&gt;
		InvoiceSenderServlet&lt;/display-name&gt;
		&lt;servlet-name&gt;InvoiceSenderServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
		jms.InvoiceSenderServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;InvoiceSenderServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/InvoiceSenderServlet&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
		&lt;/welcome-file-list&gt;

	&lt;listener&gt;
	&lt;listener-class&gt;org.springframework.web.context.
                  ContextLoaderListener&lt;/listener-class&gt;
	&lt;/listener&gt;
&lt;/web-app&gt;</pre>
<h3>Step 9:</h3>
<p>Run the servlet and check the console.</p>
<h3>Conclusion</h3>
<p>Spring JMS API is used to achieve asynchronous communication. The bean configuration file plays very important role because all the resources required for JMS is configured inside xml file.The MOM is acting as a mediator between sender and receiver. Weblogic MOM supports many features for JMS.</p>
<p>Once the programmers start using Spring in JMS applications, they will appreciate its simplicity for asynchronous messaging. The Spring JMS framework provides a variety of Java classes to implement JMS application.<br />
Hope this article will be useful for beginners to write JMS application using Spring and Web logic.</p>
<h3>Acknowledgements</h3>
<p>The Author wants to express her sincere thanks to a group of personnel from Infosys Technology who have been instrumental in bringing this article to fruition.</p>
<p>Sangeetha S was instrumental in conducting the technical review for this article.The author sincerely thanks Raghavendran N, Rajagopalan P, Satheesha BN and SV Subrahmanya for the<br />
continued encouragement and support.</p>
<h3>About the Author</h3>
<p>G. Sangeetha is a Senior Technical Evangelist in Infosys Technologies, Ltd., Mysore D.C. She is a post graduate in Computer Applications from the Bharathidasan University. She has over 8 years of teaching experience in the field of Computer Technology in varied organizations. She specializes in Java, J2EE and related technologies.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JBoss Portal Server Development</title>
		<link>http://www.javabeat.net/2009/02/jboss-portal-server-development/</link>
		<comments>http://www.javabeat.net/2009/02/jboss-portal-server-development/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 15:58:43 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=2237</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Enterprises need more than just basic services; they need value-creating entities, which are crucial for running a successful business. Portals offer tremendous value to enterprises, and JBoss Portal Server is a popular, feature-rich open-source server that provides a standards-compliant platform for hosting functionality that serves the diverse portal needs of an enterprise. Its primary strength [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Enterprises need more than just basic services; they need value-creating entities, which are crucial for running a successful business. Portals offer tremendous value to enterprises, and JBoss Portal Server is a popular, feature-rich open-source server that provides a standards-compliant platform for hosting functionality that serves the diverse portal needs of an enterprise. Its primary strength lies in its ability to provide robust support for custom implementation of functionality using the JSR-168 portlet API.</p>
<p>This book is a practical guide to installing, configuring, and using JBoss Portal Server. It explains, with examples, how to easily build feature-rich portals using JBoss. As you move further on, you will learn to personalize your portals and add new features to them.<br />
This book will equip you with everything you need to know about JBoss Portal Server to build a fully-functional portal. It will help you to quickly understand and build enterprise portals with rich features, such as personalization, AJAX, single sign-on, Google widget integration, remote portlet integration, content management, and more. Along with feature implementation, the book will also provide developers with enough detail to be able to tune and customize the portal environment to best suit the platform needs.</p>
<h2>What This Book Covers</h2>
<p><i>Chapter 1</i> reviews portals, their functions, and their values. It talks about portal servers and the specifications that govern the creation and management of portals on the J2EE platform. Portal servers go beyond serving custom content and provide a feature-rich set of robust pre-built functions that take away the need to create certain fundamental sets of features from scratch each time. This chapter shows that, by removing the development efforts behind creating such features, portal developers can now spend their time and money on developing business functions.</p>
<p><i>Chapter 2</i> talks in detail about the installation process of JBoss portal, with an emphasis on the differences and caveats for the various installation types offered, depending on the usage scenarios. A simplified installation and deployment process facilitates faster implementation and fewer problems, as demonstrated by almost immediate creation and management of pages on the platform.</p>
<p><i>Chapter 3</i> goes a bit deeper into JBoss portal server and explains portlets better by creating a simple portlet application. It goes through the complete life cycle from code creation to deployment. This overview tour gives you a good idea of the major components that are required to create a functional portlet.</p>
<p><i>Chapter 4</i> reviews the various options that are available to effectively manage the presentation of portlets using technologies such as JSP, JSF, and so on. It shows a few examples of each one of them. To understand the concepts better, a portal application is created from scratch and a custom portlet, created with JSP-based view is added to this new application.</p>
<p><i>Chapter 5</i> reviews how the power of portals can be extended by facilitating features such as customization and personalization. It further extendeds our example portal to include custom layouts, themes, and other personalization features. It also shows how we can personalize a page and offer the users options for controlling the contents on the page.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><i>Chapter 6</i> shows how JBoss portal blends the dynamism and rich functionality offered by AJAX with its strong portal architecture, to provide users with choices for developing highly-functional portal applications. It also discusses the limitations of the current specification and walks through an example that shows how easy it is to develop and deploy AJAX-based portlets.</p>
<p><i>Chapter 7</i> talks about how Hibernate, a very popular ORM tool, is used internally by JBoss applications, and how applications can integrate database support into portlet applications by using Hibernate.</p>
<p><i>Chapter 8</i> elaborates upon a simple but robust content management system provided by the JBoss portal that is sufficient for most of the needs for a portal application. Using interceptors, CMSAdmin, and CMS Portlets, the user can develop a functionality that helps to effectively manage and deliver content. This chapter extends our example further, to add some new content, and then edit it. It also shows how easy it is to add, edit, and manage content in the portal.</p>
<p><i>Chapter 9</i> discusses the various aspects of security as they relate to JBoss portal server and its functional components—the portal objects. JBoss portal allows a fine-grained level of control over portal objects such as portal instances, pages, and portlets. Security is an important function of an application. JBoss portal offers a varied set of options that allow the building of highly secure enterprise applications on the portal server.</p>
<p><i>Chapter 10</i> discusses the basics of remoting portlets before it goes into a few implementations using some real-world examples. It talks about how easily the portlets can be exposed as remotely available services, and how remote services can be consumed relatively effortlessly.</p>
<p><i>Chapter 11</i> talks about some of the features specified by the new portlet specification, such as portlet co-ordination, and filters introduction. It tells us how Portlet 2.0 provides a comprehensive set of options for performing robust portlet coordination by using events, as well as public parameters that tremendously increases the capabilities of portals and portlets by opening up possibilities for integrating not only within the application, but also with other applications within the enterprise.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/jboss-portal-server-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short and Long-Running Processes in SOA</title>
		<link>http://www.javabeat.net/2008/12/soa-process-architecture-modeling-and-simulation-in-bpel-tibcos-businessworks-and-beas-weblogic-integration/</link>
		<comments>http://www.javabeat.net/2008/12/soa-process-architecture-modeling-and-simulation-in-bpel-tibcos-businessworks-and-beas-weblogic-integration/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 16:03:57 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=2244</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>What This Book Covers SOA Cookbook covers process-oriented SOA. BPEL is the best-known language in this area, and this book presents numerous BPEL examples. It also studies proprietary vendor process languages such as TIBCO&#8217;s BusinessWorks and BEA&#8217;s Weblogic Integration. If you are building SOA processes in the field, chances are you are using one of [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><strong>What This Book Covers</strong></p>
<p><b><i>SOA Cookbook</i></b> covers process-oriented <b><i>SOA</i></b>. <b><i>BPEL</i></b> is the best-known language in this area, and this book presents numerous <strong>B</strong><b><i>PEL</i></b> examples. It also studies proprietary vendor process languages such as <b><i>TIBCO&#8217;s</i></b> BusinessWorks and <b><i>BEA&#8217;s</i></b> Weblogic Integration. If you are building <b><i>SOA</i></b> processes in the field, chances are you are using one of the languages discussed in <b><i>SOA Cookbook</i></b>. The book assumes that the reader is comfortable with <b><i>XML</i></b> and <b><i>web services</i></b>.</p>
<p>Chapter 1 is an introduction to <b><i>SOA</i></b>. This chapter looks back at a landmark book on distributed architecture from the <b><i>CORBA</i></b> era: Client/Server Survival Guide by Orfali, Harkey, and Edwards. The architecture presented in this earlier work has much in common with contemporary SOA architecture, but it differs in one key respect: the CORBA-based architecture, an object-oriented approach, lacks the sense of process that is so prevalent in <b><i>SOA</i></b>.</p>
<p>We then examine the contemporary <b><i>SOA</i></b> stack (which we call the model stack), and map its layers to the product suites of the four major <b><i>SOA</i></b> vendors: <b><i>IBM</i></b>, <b><i>Oracle</i></b>, <b><i>BEA</i></b>, and <b><i>TIBCO</i></b>. We look, briefly, at examples of orchestration processes and <b><i>ESB</i></b> mediation flows on these platforms. These examples give us a sense of the style of programming on these platforms. In subsequent chapters, we take a deeper dive.</p>
<p>Chapter 2 presents an approach to documenting and diagramming process-oriented SOA architecture using &#8217;4+1&#8242;, ARIS, SCA, <b><i>UML</i></b>, and BPMN. With this unusual concoction, we cover all of the important &#8216;views&#8217; and draw box-and-arrow process diagrams that carefully link activities to data and services. In our scheme, labeling is an exact science. We discover why the expression<br />
Account.getRecord(req.accountNum): acctRec is so much more useful than the casual Get Account Record.</p>
<p>Chapter 3 takes a closer look at the model stack and teaches, by example, how to separate a use case into <b><i>BPM</i></b> and <b><i>SOA</i></b> parts. We demonstrate two designs for credit card disputes processing: one in which a <b><i>BPM</i></b> process manages the end-to-end control flow and uses short-running <b><i>SOA </i></b>processes for integration, the other in which a long-running SOA process drives the end-to-end flow but delegates human tasks to <b><i>BPM</i></b> processes. This chapter will have you drawing circles in your sleep!</p>
<p>Chapter 4 begins by distinguishing between those oft-confused terms orchestration and choreography, and then presents an approach for modeling choreography, in BPMN and BPEL, as an invisible hub. The leading choreography standard, <b><i>WS-CDL</i></b>, is not known for its wealth of implementations; we build the choreography for electricity market enrollment in its leading tool, pi4SOA. The chapter concludes with tips on modeling orchestration; the discussion presents an algorithm for &#8216;dependable&#8217; inbound event routing.</p>
<p>Chapter 5 classifies processes by duration, dividing them into three categories: shortrunning, midrunning, and long-running. Long-running processes need state, so we examine three data models to keep process state: those used in <b><i>BEA Weblogic</i></b> Integration and Oracle&#8217;s BPEL Process Manager, and our own custom model, which borrows ideas from these two. We then discuss how to build a long-running process out of several short-running processes (implemented in <b><i>TIBCO&#8217;s </i></b>BusinessWorks) tied together with state in our custom data model. We conclude by showing how short-running BPEL processes can be compiled for faster execution.</p>
<p>Chapter 6 observes that most processes today are modeled &#8216;naïvely&#8217;. Those who design them drag all of the boxes they require onto a canvas, connect them with arrows, and create a graph so meandering and expansive that it&#8217;s as difficult to navigate as the roads of an unfamiliar city. We propose a structured approach known as fl at form, which breaks the graph into simple pieces and assembles them in a controller loop. Flat processes are, by design, flat, and thus avoid the deep nesting characteristic of naïve processes. There are three variants of flat form: event-based, statebased, and flow-based. We build examples of each in <b><i>BPEL</i></b>.</p>
<p>Chapter 7 describes the change problem—the problem of changing the definition of a process that has live cases in production—and considers examples of changes (for example, adding an activity, removing an activity, changing the sequence of activities, and introducing parallelism) which cause trouble for existing cases. We also consider dynamic process styles that take the preventative approach to the change problem by attempting to be adaptable in the first place. Dynamic forms can be process-based, rule-based, or goal-based. We study examples of each.</p>
<p>Chapter 8 presents an approach for simulating <b><i>BPEL</i></b> processes using concepts from discrete event simulation and the Poisson process. Simulating a <b><i>BPEL</i></b> process is fundamentally more difficult than simulating a single-burst service. <b><i>BPEL</i></b> processes are long-running, have multiple bursts and both initial and intermediate events, frequently go to sleep for an interval of time, and, in many<br />
implementations, queue inbound events rather than responding to them as they come. In this chapter, we build a simulator that supports this usage pattern, run a series of examples through it, and study the results. The salient conclusion is to keep bursts short!</p>
<p>Chapter 9 presents a formula for scoring <b><i>SOA</i></b> processes on complexity. We position complexity analysis as an important step in design oversight and governance. The approach we consider allows the governance team to rate each process as red, yellow, or green and to flag reds for rework. Intuitively, the &#8216;complexity&#8217; of a process is the amount of branching or nesting in its graph. Flat form, introduced in Chapter 6, scores well on complexity because it avoids excessive branching. Naïve processes score poorly. Our scoring method is a variant of McCabe cyclomatic complexity.</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">Short and Long-Running Processes</span></span></h2>
<p>As a process moves from activity to activity, it consumes time, and each activity adds to the overall duration. But different sorts of activities have different durations, and it&#8217;s not uncommon to observe a ten-step process that outpaces, say, a five-step one. It depends, of course, on what those activities are doing.</p>
<p>In <b><i>SOA</i></b>, process cycle times range from one second or less to one or more years! The latter sort need not have a large number of activities. The pyramids might have been built rock-by-rock over several decades, but protracted <b><i>SOA</i></b> processes typically span only a few dozen tasks, a handful of which consume almost the entire interval.</p>
<p>As we discuss in this chapter, most of that time is spent waiting. The disputes process introduced in Chapter 3 often requires several months to complete, because at various times it sits idle waiting for information from the customer, the merchant, or the back offi ce. Business processes crawl along at human speed, and, as we argued in Chapter 3, it often makes sense to let <b><i>SOA</i></b> manage the end-to-end fl ow.</p>
<p>It&#8217;s not easy to build an <b><i>SOA</i></b> process engine that can simultaneously blaze through a sub-second process but keep on top of a one that hasn&#8217;t moved in weeks. On the other hand, when a long-running process rouses, we expect the engine to race very quickly to the next milestone. The central argument of this chapter is that both long-running and short-running processes run in very quick bursts, but whereas a short-running process runs in a single burst, a long-running process might have several bursts, separated by long waits. To support long-running processes, the process engine needs a strategy to keep state.</p>
<p>In this chapter, we examine the fundamental differences between long-running and short-running processes. We discuss how to model state, and demonstrate how to build a long-running process as a combination of several short-running processes tied together by state. We also show how to compile short-running <b><i>BPEL</i></b> processes to improve the execution speed of a burst.</p>
<h2>Process Duration—the Long and Short of It</h2>
<p><b><i>SOA</i></b> processes have the following types of activities:</p>
<ol>
<li>Tasks to extract, manipulate, or transform process data</li>
<li>Scripts or inline code snippets</li>
<li>Calls to systems and services, both synchronous and asynchronous</li>
<li>Events, including timed events, callbacks, and unsolicited notifi cations from systems</li>
</ol>
<p>The first three sorts of activities execute quickly, the first two in the order of milliseconds, the third often sub-second but seldom more than a few seconds (in the case of a synchronous call to a slow system). These activities are active: as the process navigates through them, it actively performs work, and in doing so ties up the process engine. Event times are generally much longer and more variable. Events come from other systems, so (with the exception of timed events) the process cannot control how quickly they arrive. The process passively waits for events, in effect going to sleep until they come.</p>
<p>An event can occur at the beginning of a process—indeed, every <b><i>SOA</i></b> process starts with an event—or in the middle. An event in the middle is called an intermediate event. The segment of a process between two events is called a burst. In the following figure, events are drawn as circles, activities as boxes, and bursts as bounding boxes that contain activities. Process (a), for example, starts with an event and is followed by two activities—Set Data and Sync Call—which together form a burst. Process (b) starts with an event, continues with a burst (consisting of the activities Set Data and Call System Async), proceeds to an intermediate event (Fast Response), and concludes with a burst containing the activity Sync Call. Process (c) has two intermediate events and three bursts, and (d) has a single intermediate event and two bursts.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-1.gif"><img class="aligncenter  wp-image-6798" alt="soa-1" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-1.gif" width="496" height="274" /></a></p>
<p>Processes are classifi ed by duration as follows:</p>
<ul>
<li>Short-running: The process runs comparatively quickly, for not more than a few seconds. Most short-running processes run in single burst (as in process (a) in the fi gure), but some have intermediate events with fast arrival times—as in (b), where the intermediate event, a response to an asynchronous system call, arrives in about two seconds—and thus run in multiple bursts. <b><i>TIBCO</i></b>&#8216;s BusinessWorks and the <b><i>BPEL</i></b> compiler described later in the chapter are optimized to run both single-burst and multiple-burst short-running processes. BEA&#8217;s <b><i>Weblogic</i></b> Integration can run single-burst, short-running processes with limited overhead, but, as discussed further next, treats cases like (b) as long-running.</li>
<li>Long-running: The process has multiple bursts, and the waiting times of its intermediate events are longer than the process engine itself is expected to run before its next restart! In process (d), for example, the engine is restarted for maintenance while the process waits two days for a human action. The process survives the restart because its state is persisted. At the end of its fi rst burst (that is, after the Assign Work step), the engine writes the state to a database, recording the fact that the process is now waiting on an event for a human action. When the engine comes back up, it fetches the state from the database to remember where it left off. Most <b><i>BPEL</i></b> processes are longrunning. In <b><i>Weblogic</i></b> Integration, stateful processes can run for arbitrarily long durations.</li>
<li>Mid-running: T he process has multiple bursts, but the waiting times of its intermediate events last no more than a few minutes, and do not need to be persisted. Stakeholders accept the risk that if the process engine goes down, in-fl ight processes are lost. Chordiant&#8217;s Foundation Server uses mid-running processes to orchestrate the interaction between agent and customer when the customer dials into a call center. The call is modeled as a conversation, somewhat like a sequence of questions and answers. A burst, in this design, processes the previous answer (for example, the Process Answer activity in (c)) and prepares the next question (Prepare Question). Intermediate events<br />
(Get Answer) wait for the customer to answer. State is held in memory.</li>
</ul>
<h2>Stateful and Stateless Processes in BEA&#8217;s <b><i>Weblogic</i></b> Integration</h2>
<p>I n <b><i>Weblogic</i></b> Integration, single-burst processes are stateless, but multiple-burst processes, even short-running ones, are stateful. Even if the wait between bursts is very small (one or two seconds perhaps), <b><i>Weblogic</i></b> Integration nonetheless persists process state to a database. The distinction is subtle, but <b><i>Weblogic</i></b> Integration provides visual clues to help us detect the difference. In the next fi gure, the process on the left is stateless. The process on the right is the same as that on the left except for the addition of an event step called Control Receive; the step, in effect, puts the process in a wait state until it receives a specifi c event. When this step is added, <b><i>Weblogic</i></b> Integration changes the appearance of its start step—Start—from a circle with a thin border to one with a thick border, indicating that the process has changed from being stateless to stateful.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-2.gif"><img class="aligncenter  wp-image-6799" alt="soa-2" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-2.gif" width="449" height="346" /></a></p>
<p>Those who designed <b><i>Weblogic</i></b> Integration thought process state so important that they worked into their notation whether a process is stateful or stateless. We now study one of the most critical pieces of any process engine: how it keeps state.</p>
<h2>How to Keep Long-Running State</h2>
<p>In this section, we study the data models for long-running process state in two commercial process integration platforms: <b><i>Oracle</i></b>&#8216;s <b><i>BPEL</i></b> Process Manager and BEA&#8217;s <b><i>Weblogic</i></b> Integration. We also develop our own model, a generalization of the <b><i>Oracle</i></b> and BEA approaches, which enables us to achieve the effect of a long-running <b><i>SOA</i></b> process from a group of short-running processes. We put this model to practical use later in this chapter, in the email money transfer example.</p>
<p><b><i>SOA</i></b> process state models contain information about the following:</p>
<ul>
<li>Process metadata, including the types of processes currently deployed, their versions, and how their activities are assembled.</li>
<li>Process instances, including status, start time and end time, and the position of the instance in a call graph (that is, parent/child relationships). Some models also track the status of individual activities.</li>
<li>Pending events, and how to correlate them with process instances.</li>
</ul>
<h2>State in <b><i>Oracle</i></b>&#8216;s <b><i>BPEL</i></b> Process Manager</h2>
<p>The following figure shows the core tables in the <b><i>Oracle</i></b> <b><i>BPEL</i></b> model (version 10.1.2).</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-3.gif"><img class="aligncenter size-full wp-image-6800" alt="soa-3" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-3.gif" width="214" height="329" /></a></p>
<p>In this model process, metadata is held in two tables: Process_Default and Process_Revision. The former lists all deployed <b><i>BPEL</i></b> processes and their current revision numbers; the process_id field is not a technical key but the name of the process specified by the developer. The latter lists all of the revisions; for a given process, each revision has a distinct GUID, given by the field process_guid.</p>
<p>The seemingly-misnamed table Cube_Instance—actually, cube is synonymous with process in the internals of the product—has information about current and completed process instances. The instance has a unique key, given by cikey. From process_guid we can deduce, by joining with Process_Revision, the process type and revision of the instance. Other important information includes the instance creation date, its parent instance, and its current state. Possible states are active, aborted, stale, and completed, although the state fi eld uses numeric codes for these values.</p>
<p>The Work_Item table tracks the status of instance activities. Cikey indicates the instance to which the activity belongs. Within an instance the activity is identified by the combination of node_id, scope_id, and count_id. The fi rst two of these indicate the position of the activity in the process graph and the scope level to which it belongs; the label column is a friendlier alternative to these, assuming that the developer applied a useful label to the activity. Count_id is required in case the activity executes more than once. Work_Item has its own state fi eld (again numeric), which indicates whether the activity is completed or pending, was cancelled, or encountered an exception.</p>
<p>Dlv _Subscription records pending events and correlates them with instances. Conv_id is a conversation identifi er known to both the <b><i>BPEL</i></b> process and its partner service. To trigger the event, the partner service passes this identifi er as part of its message. The process matches it to a subscriber_id, which uniquely identifies the activity that is waiting on the event. Thus, when the event arrives, the process knows exactly from which point to continue. (Technically, subscriber_id is a delimited string, which encodes as part of its structure the values of cikey, node_id, scope_id, and count_id that point to a unique Work_Item record.) The partner also specifi es an operation name, which specifi es which type of event it is fi ring. If the process is waiting on several events in the same conversation (as part of an event pick, also known as a deferred choice), operation_name determines which path to follow. The combination of operation_name and conv_id points to a unique activity (that is, to a unique subscriber_id).</p>
<h2>State in BEA&#8217;s <b><i>Weblogic</i></b> Integration</h2>
<p>The following fi gure shows three important tables in the <b><i>Weblogic</i></b> Integration model:</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-4.gif"><img class="aligncenter size-full wp-image-6801" alt="soa-4" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-4.gif" width="368" height="251" /></a></p>
<p>WLI_Process_Def has metadata about types of deployed processes and their activities. The table has one row for each activity. Process_type is the human-readable name of a process. Activity_id is the numeric identifi er of an activity in the process, although user_node_name, the descriptive name provided by the developer is more intuitive.</p>
<p>Process instance information is held in WLI_Process_Instance_Info. Each instance has a unique numeric identifi er, given by process_instance. Process_type specifi es the process defi nition on which the instance is based. Process_status specifi es, in a numeric code, whether the instance is active, pending, or aborted. The table also tracks process start and end times, as well as time in excess of the SLA (sla_exceed_time). Through <b><i>Weblogic</i></b> Integration&#8217;s administration console, the administrator can confi gure an SLA on process cycle time.</p>
<p>In <b><i>Weblogic</i></b> Integration a process instance can receive intermediate events by several means. One of the most important of these is by listening for messages published by <b><i>Weblogic</i></b> Integration&#8217;s message broker system. The table WLI_Message_Broker_Dynamic keeps track of specifi c events waiting on broker messages. The column subscriber_instance is the process instance identifi er; it matches the process_instance value in WLI_Process_Instance_Info. Rule_name is, in effect, a pointer to the event in that instance. Filter_value is an XQuery expression that checks the content of the message to determine whether to accept the event. When a message arrives, the broker checks for any subscription events, and triggers those whose fi ltertest passes.</p>
<h2>Our Own State Model</h2>
<p>Our own model, shown in the next fi gure, follows a design approach similar to that of the <b><i>Oracle</i></b> and BEA models.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-5.gif"><img class="aligncenter size-full wp-image-6802" alt="soa-5" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-5.gif" width="378" height="504" /></a></p>
<p>To begin, the model features a single metadata table, called ProcessStarter, which enumerates the types of processes deployed (processType) and specifi es for each the type of event that can start it (triggeringEventType). The table&#8217;s main purpose is to route start events: when an external event arrives, if ProcessStarter can map it to a process, then a new instance of that process is created from the event.</p>
<p>Several tables track the state of process instances. The Process table assigns a unique identifi er to each instance (procID), indicates its type (processType), locates it in a conversation (convID), and records its start time, end time, and status (pending, completed, or aborted). The ProcessVariable table persists process variables, ensuring that instance-specifi c data survives system restarts. A variable is identified by a name (name) that is unique within its level of scope (scope) in a process instance (procID). The ProcessAudit table keeps a chronological list of important occurrences in a process instance. It is tied to a specifi c instance (procID), and has both a timestamp and a text entry. The entry can optionally be associated with a specifi c process activity (activityID). Implementations can extend the model by providing a custom state table (such as the hypothetical MyAppState in the diagram) that associates application-specifi c fi elds (myState, in this example) with an instance.</p>
<p>Final ly, the PendingEvent table assists in correlating intermediate events. An event is identifi ed by the combination of its process instance (procID), its activity node in the process (activityID), and if it is part of a deferred choice, the identity of that choice (choiceActivityID). (If the event is not part of a choice, choiceActivityID is zero or null.) There are two types of events: timed events and events triggered by a message. If the event is a timed event, timeToFire specifi es the date and time (somewhere in the future) when the event should fi re. If the event is message-based, triggeringEventType indicates the type of message that triggers it. When the event is created, the Boolean fi eld isDone is set to false. When the event fi res, isDone is switched to true. If the event is part of a choice, isDone is set to true for all events in the choice, thereby ensuring that only one event is chosen.</p>
<p>The model assumes that all messages carry the following fi elds:</p>
<ul>
<li>Event Type</li>
<li>Recipient Process Type</li>
<li>Conversation ID</li>
</ul>
<p>When a message arrives, the following logic determines how to route it:</p>
<ul>
<li>If there is an instance of the process in the conversation (that is, if there are rows in Process where processType and convID match the values from the message), check whether it has a pending event of the given event type (that is, check for rows in PendingEvent where procID matches the value from Process, isDone is false, and triggeringEventType matches the event type). If it does, fire the event. Otherwise, discard the event.</li>
<li>If there is no instance of the process in the conversation, check whether the process can be started by this type of event. (That is, check for rows in ProcessStarter where processType and triggeringEventType match those from the message.) If so, instantiate the process. Otherwise, discard the event.</li>
</ul>
<p>We put this model to use in the next section. Refer to the discussion of correlation in Chapter 4 for more details on this approach, especially the use of optimistic locking to prevent two simultaneous events from firing.</p>
<h2>Combining Short-Running Processes with State in <b><i>TIBCO</i></b>&#8216;s BusinessWorks</h2>
<p>The next discussion covers the <b><i>TIBCO</i></b> implementation of the email transfer process.</p>
<h2>Our Use Case—Sending Money by Email</h2>
<p>With this model in place, we build a process that spans several days as a set of short-running processes, none of which lasts more than a few seconds. The use case we consider is email money transfer, introduced in our discussion of choreography in Chapter 4. In a transfer there are four main parties: the sender, the sender&#8217;s bank, the recipient, and the recipient&#8217;s bank. We build the process for the sender&#8217;s bank.</p>
<p>The following figure depicts the required fl ow of events:</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-6.gif"><img class="aligncenter  wp-image-6803" alt="soa-6" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-6.gif" width="498" height="228" /></a></p>
<p>When the bank receives the request to send funds from the sender (Sender&#8217;s Request), it validates the request (Validate Request), and rejects it if discovers a problem (Send Reject to Sender). If the request is valid, the bank informs the sender of its acceptance (Send Accept to Sender), notifi es the recipient by email (Send Email To Recipient), and sets aside funds from the sender&#8217;s account (Allocate Funds). The fi rst burst is complete, but several possible paths can follow:</p>
<ol>
<li>There is a time limit on the transfer, and if it expires the transfer is aborted.</li>
<li>The sender may cancel the transfer.</li>
<li>The sender&#8217;s bank may reject the recipient&#8217;s bank&#8217;s request to move the funds into the recipient&#8217;s account. The recipient may try again later.</li>
<li>The sender&#8217;s bank may accept the recipient&#8217;s bank&#8217;s request to move the funds into the recipient&#8217;s account.</li>
</ol>
<p>The control flow to support this logic is a deferred choice inside a loop. The loop runs for as long as the variable loopExit is false. The process initializes the value to false (Set loopExit=false) immediately before entering the loop. Paths 1, 2, and 4 set it to true (Set loopExit=true) when they complete, signaling that there is no further work to do and the loop need not make another iteration. Path 3 leaves the loopExit fl ag alone, keeping it as false, thus allowing another iteration (and another chance to complete the transfer). Each iteration is a burst.</p>
<p>There are three events in the deferred choice, one for expiry (path 1), one for cancellation (path 2), and one for the recipient&#8217;s bank transfer request (paths 3 and 4). The logic for cancellation and expiry (headed by the events Sender&#8217;s Cancellation and Expired respectively) is identical: the process sends a cancellation email to the recipient (Send Email Recipient), informs the sender that the transfer is aborted (Send Abort to Sender), and restores the funds to the sender&#8217;s account (Restore Funds). In the transfer request path (starting with the event Recipient Bank&#8217;s Transfer Request), the sender bank validates the transfer (Validate Transfer) and sends the outcome to the recipient&#8217;s bank (Send Reject to Recipient Bank or Send Accept to Recipient Bank). If validation passes, the process also notifi es the sender that the transfer is complete (Send Completion to Sender) and commits the funds it had earlier allocated (Commit Funds).</p>
<p>The sender&#8217;s bank&#8217;s process is long-running, typically spanning several days from start to fi nish. To build it using a short-running process engine, such as <b><i>TIBCO</i></b>&#8216;s BusinessWorks, we need to break it into smaller processes: one to handle the sender&#8217;s request to send funds, one to handle the recipient&#8217;s bank&#8217;s request to complete the transfer, one to handle the sender&#8217;s cancellation, one to handle expiry, and one to manage the overall event routing. In dividing the process into pieces, we lose the loop and deferred choice, but we add housekeeping responsibility to each piece.</p>
<h2>The Router Process</h2>
<p>The next figure shows the BusinessWorks process to handle the overall routing.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-7.gif"><img class="aligncenter  wp-image-6804" alt="soa-7" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-7.gif" width="436" height="276" /></a></p>
<p>When it receives an inbound message on a JMS queue in GetEvent, the router process checks the event type to determine to which BusinessWorks process to route the event. There are three event types:</p>
<ul>
<li>Request: Sent by the account holder (known as the sender). Because this request starts the process, it must not contain a conversation identifi er. If it does, the route process immediately logs the event as an error and discards it (Log Illegal Input). Otherwise, it queries the ProcessStarter table, in the step Check Starter Enabled, to verify that the email transfer process may be started by this type of event. (It checks that there is a record in the table that matches the given event type and process type.) If this check passes, the route process creates a unique conversation identifi er (Set Conv ID) and calls the request process to handle the event (Call Request Process).</li>
<li>Transfer: Sent by the recipient bank. The route process checks that the message has a conversation identifi er. If it does, it calls the transfer process (Call Transfer Process) to handle the event. Otherwise, it logs the event and discards it (Log Illegal Input).</li>
<li>Cancel: S ent by the sender or internally by the timer process (discussed further next). The route process checks that the message has a conversation identifi er. If it does, it calls the cancellation process (Call Cancel Process) to handle the event. Otherwise, it logs the event and discards it (Log Illegal Input).</li>
</ul>
<h2>The Request Process</h2>
<p>The next figure shows the BusinessWorks process to handle the sender&#8217;s request to send funds:</p>
<p>The process begins by creating a unique process identifi er (Set Proc ID) and then validates the request (Validate Request). If the request is invalid, the process sends a rejection to the sender (Send Reject to Sender) and writes three records to the database:</p>
<ol>
<li>A record in the Process table (using Add Process Record Aborted) that sets the status of the instance to ABORTED. The process identifi er is the one created in Set Proc ID.</li>
<li>A log of the validation failure (using Add Audit Invalid Req) in the ProcessAudit table.</li>
<li>A copy of the inbound message in the ProcessVariable table, using Add Variable Request. The earlier step RequestAsString converts the message from XML to string form.</li>
</ol>
<p>Thus, there is a record that the instance was aborted, an explanation in the audit trail why it failed, and a copy of its message data.</p>
<p>The happy path, in which the request passes validation, contains three steps that we described earlier: Send Email Recipient, Send Accept to Sender, and Allocate Funds. It also creates the following records in the database:</p>
<ul>
<li>A record in the Process table (using Add Process Record Pending) about the instance, with a status of PENDING and the identifier created in Set Proc ID.</li>
<li>An indication that the validation passed (using Add Audit Valid Request) in the ProcessAudit table.</li>
<li>A copy of the inbound message (using Add Variable Request 2) in the ProcessVariable table.</li>
<li>Three PendingEvent records, for transfer, expiry, and cancel respectively (using the steps Add Transfer Event, Add Expiry Event, Add Cancel Event). The records share a common choiceActivityID, and for each the isDone fi eld is set to false.</li>
<li>A record in the custom table EXState (using Add EXState), which extends the Process table with information specifi c to email transfers. The next figure shows the EXState table and its relationship to Process. The table adds one fi eld to the mix, numRejects, which is initialized here to zero and is incremented each time the sender&#8217;s bank rejects the recipient&#8217;s bank&#8217;s transfer request.</li>
</ul>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-8.gif"><img class="aligncenter  wp-image-6805" alt="soa-8" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-8.gif" width="435" height="229" /></a></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>When the happy path completes, the PendingEvents table has, among its contents, three records similar to the following:</p>
<table cellspacing="20">
<tbody>
<tr>
<th>Proc ID</th>
<th>Activity ID</th>
<th>Choice Activity ID</th>
<th>Is Done</th>
<th>Time To Fire</th>
<th>Triggering Event Type</th>
</tr>
<tr>
<td>123</td>
<td>Cancel</td>
<td>1</td>
<td>False</td>
<td>-</td>
<td>EX.Cancel</td>
</tr>
<tr>
<td>123</td>
<td>Expiry</td>
<td>1</td>
<td>False</td>
<td>Dec 13, 2008</td>
<td>-</td>
</tr>
<tr>
<td>123</td>
<td>Transfer</td>
<td>1</td>
<td>False</td>
<td>-</td>
<td>EX.Transfer</td>
</tr>
</tbody>
</table>
<p>According to this information, process instance 123 has three pending events, whose activityIDs are Cancel, Expiry, and Transfer respectively. These events are set in a single deferred choice, whose choiceActivityID is 1. None of these events has occurred, indicated by isDone being false. The Cancel and Transfer events are triggered by the inbound events types EX.Cancel and EX.Transfer respectively. The Expiry event does not have a triggering event type, but has a timeToFire confi gured for December 13, 2008; Expiry is a timed event.</p>
<p>When one of these events arrives, it is processed only if the isDone fi eld is false; otherwise it is discarded. When it is processed, the isDone fl ag is set to true for all three events. Marking all three true in effect marks the whole deferred choice as complete, and prevents a second event from occurring.</p>
<h2>The Transfer Process</h2>
<p>The process that handles the recipient&#8217;s bank&#8217;s request for transfer is shown in the following figure.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-9.gif"><img class="aligncenter size-full wp-image-6806" alt="soa-9" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-9.gif" width="322" height="155" /></a></p>
<p>The process begins immediately by querying the PendingEvent table to check that its event is still pending (FindEvent). If it has already been marked as completed, the process rejects the request (Send Reject to Recipient Bank Event Not Found) and quits. Assuming the event is permitted, the process marks the choice as completed (Remove Event) and validates the request (Validate). If validation passes, the process, as already discussed, sends an acceptance to the recipient&#8217;s bank (Send Accept Recipient Bank) and a completion notifi cation to the sender (Send Completion Sender), commits the funds (Commit Funds), and then performs the following table updates:</p>
<ul>
<li>In the Process table, it sets the instance status to COMPLETED (using Close Process).</li>
<li>It adds an entry to the ProcessAudit table (using Add Audit), indicating that the transfer succeeded.</li>
<li>It saves the transfer request message to the ProcessVariable table. If a previous version of the message is already there, the process overwrites it (Update Variable); otherwise, it inserts a new message (Insert Variable).</li>
</ul>
<p>If validation fails, the process sends a rejection message to the recipient bank (Send Reject Recipient Bank) and makes four table updates:</p>
<ol>
<li>It restores the deferred choice (using Restore Event), setting isDone to false for each of the three events (Restore Event).</li>
<li>It increments the numRejects fi eld in the EXState table (Add Reject).</li>
<li>It adds an entry to the ProcessAudit table (using Add Audit), indicating that the transfer failed.</li>
<li>It saves the transfer request message to the ProcessVariable table, using the same logic as above.</li>
</ol>
<p>The successful validation path effectively terminates the larger process by removing all of its pending events. The failed validation path effectively loops back in the larger process to an earlier point, giving each of the events another chance to fire.</p>
<h2>The Cancellation Process</h2>
<p>The process to handle cancellation, shown in the next fi gure, starts out much the same way.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-10.gif"><img class="aligncenter  wp-image-6807" alt="soa-10" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-10.gif" width="436" height="257" /></a></p>
<p>The process fi rst checks that the event is still pending (Find Event), and if so, disables the deferred choice (Remove Event). The process then notifi es the sender and the recipient of the cancellation (Send Recipient Email and Send Abort to Sender), restores the funds (Restore Funds), and update the tables as follows:</p>
<ul>
<li>It marks the status of the instance as ABORTED (Close Process).</li>
<li>It adds an audit entry indicating cancellation (Add Audit).</li>
<li>It saves the cancellation event to the ProcessVariable table (Save Variable).</li>
</ul>
<h2>The Expiration Process</h2>
<p>The process to handle expired transfers, shown in the next fi gure, is somewhat different.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-11.gif"><img class="aligncenter  wp-image-6808" alt="soa-11" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-11.gif" width="431" height="206" /></a></p>
<p>The expiration process is not designed to handle the expiry of a single transfer. Rather, it scans the PendingEvents table for all expired transfers (Get Expired Transfers), and fi res a cancellation event for each of them. The outer box labeled For Each Expired is a for loop that, for each record returned by the query, constructs a cancellation message (Create Cancellation Message) and launches a cancellation process (Launch Cancellation Process) to handle the message. It launches the process by sending a message on the JMS queue to which the routing process listens. The routing process, when it receives the event, routes it to the cancellation process. Thus, it is the cancellation process that will disable the deferred choice and abort the instance, not the timer process.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-12.gif"><img class="aligncenter  wp-image-6809" alt="soa-12" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-12.gif" width="434" height="146" /></a></p>
<pre class="brush: java; title: ; notranslate">		The timer process runs on a predefi ned schedule. The Poller step
		defines how often it runs (every fi fteen minutes, for example). The timer
		process is not designed to run at the very moment a particular transfer
		expires. BusinessWorks manages the schedule internally; the schedule is
		not configured in our process state model.&lt;/code&gt;</pre>
<h2>A Note on Implementation</h2>
<p><b><i>TIBCO</i></b>&#8216;s BusinessWorks is designed for performance, and admittedly our processes make database updates rather liberally. (The request process has seven updates in the happy path!) More effi cient alternatives are to fl atten the data model (so that there are fewer tables to update) or build stored procedures to bundle updates (resulting in less IO to the database server).</p>
<p>Another option is use <b><i>TIBCO</i></b>&#8216;s proprietary checkpoint mechanism to serialize process state to the disk. The checkpoint feature is clumsy but is often an effi cient way to achieve the effect of long-running state in an engine that is designed for short-running processes. As a proprietary capability, it does not work as part of a generalized state model, which is why we did not demonstrate it here.</p>
<h2>Fast Short-Running <b><i>BPEL</i></b></h2>
<p>We conclude with a discussion of compiled <b><i>BPEL</i></b>.</p>
<h2>Uses of Short-Running Processes</h2>
<p>Having developed an approach to keep SOA processes running for an arbitrarily long time, we now turn our attention to short-running processes and ask: how can we make them run as fast as possible? The two most common uses of a short-running process are:</p>
<ol>
<li>To implement a synchronous web service operation. The process begins with an input message, runs through a quick burst of logic to process it, sends back the output message, and completes. The client application blocks for the duration, as diagram (a) in the next fi gure shows. If the process moves too slowly, the client will complain about the response time.</li>
<li>To perform complex routing for the <b><i>ESB</i></b>. As David Chapelle discusses in his book Enterprise Service Bus (O&#8217;Reilly, 2004) , a good <b><i>ESB</i></b> can natively perform basic content-based- and itinerary-based-routing, but it needs orchestration processes to handle more complex routing patterns. In diagram (b) in the figure, when the <b><i>ESB</i></b> receives a message, it passes it to an orchestration process that proceeds to perform in eight steps a series of transformation and invocation maneuvers that could never be achieved with the basic branching capabilities of the <b><i>ESB</i></b>. Again, speed is critical. The <b><i>ESB</i></b> prefers to get rid of messages as soon as it gets them. When it delegates work to an orchestration process, it expects that process to move quickly and lightly.</li>
</ol>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-13.gif"><img class="aligncenter  wp-image-6810" alt="soa-13" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-13.gif" width="387" height="319" /></a></p>
<h2>Architecture for Short-Running Processes</h2>
<p>In considering a design to optimize the performance of these two cases, we assume that our stack, like the model stack we discussed in Chapters 1 and 3, has both an <b><i>ESB</i></b> and a process integration layer. All messages in and out of the stack go through the <b><i>ESB</i></b>. The <b><i>ESB</i></b>, when it receives an inbound message, routes it to the process integration engine for processing. The process integration engine, in turn, routes all outbound messages through the <b><i>ESB</i></b>. Further, we assume that the <b><i>ESB</i></b> uses message queues to converse with the process integration layer. Client applications, on the other hand, typically use web services to converse with the <b><i>ESB</i></b>.</p>
<p>The following fi gure shows how we might enhance this architecture for faster short-running processes. (The implementation we consider is a Java-based <b><i>BPEL</i></b> process engine.)</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-14.gif"><img class="aligncenter  wp-image-6811" alt="soa-14" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-14.gif" width="432" height="297" /></a></p>
<p>When a client application or partner process calls through the <b><i>ESB</i></b>, the <b><i>ESB</i></b> routes the event, based on the event&#8217;s type, either to the general process integration engine or to an engine optimized for short-running processes. To route to the general engine, the <b><i>ESB</i></b> places the message on the Normal PI In Queue. That engine is drawn as a cloud; we are not concerned in this discussion with its inner workings. To route to the optimized engine, the <b><i>ESB</i></b> either queues the message on SR In Queue or, to reduce latency, directly calls the short-running engine&#8217;s main class, ProcessManager. (Direct calls are suitable for the orchestration routing case described in the previous figure; there, processes run as an extension of the <b><i>ESB</i></b>, so it makes sense for the <b><i>ESB</i></b> to invoke them straightaway.) A set of execution threads pulls messages from SR In Queue and invokes ProcessManager to inject these inbound events to the processes themselves. The role of ProcessManager is to keep the state of, and to execute, short-running processes. Each process is represented in compiled form as a Java class (for example, ProcessA or ProcessB) that inherits from a base class called CompiledProcess. Compiled classes are generated by a tool called <b><i>BPEL</i></b>Compiler, which creates Java code that represents the fl ow of control specifi ed in the <b><i>BPEL</i></b> XML representation of the process. ProcessManager runs processes by creating and calling the methods of instances of CompiledProcess-derived classes. It also uses TimeManager to manage timed events. Processes, whether running on the general engine or on the optimized engine, send messages to partners by placing messages on the outbound queue Out Queue, which the <b><i>ESB</i></b> picks up and routes to the relevant partner.</p>
<p>A general process engine is built to handle processes of all durations, long and short alike, and, with a mandate this extensive, does not handle the special case of time-critical short-running processes very effectively. There are three optimizations we require, and we build these into the short-running engine:</p>
<ol>
<li>Process state is held in memory. Process state is never persisted, even for processes with intermediate events. Completed process instances are cleaned out of memory immediately, so as to reduce the memory required.</li>
<li>Processes are compiled, not interpreted. That is, the process defi nition is coded in Java class form, rather than as an XML document. Compilation speeds the execution time of a burst.</li>
<li>The process may defi ne timed events of a very short duration, to the order of milliseconds. Furthermore, the engine generates a fault when the process exceeds its SLA. The process may catch the fault or let it bubble up to the calling application.</li>
</ol>
<p>The architecture we sketched in this section, as we discover presently, is designed to meet these requirements.</p>
<h2>Example of a Very Fast Process</h2>
<p>The next figure shows a short-running process with multiple bursts that benefits from these optimizations.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-15.gif"><img class="aligncenter  wp-image-6812" alt="soa-15" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-15.gif" width="436" height="151" /></a></p>
<p>When the process starts, it initializes its variables (InitVars) and asynchronously invokes a partner process called the Producer (Call Producer Asynx). It then enters into a loop (FetchLoop) that, on each iteration, waits for one of the two events from the Producer: result or noMore. If it gets the result event, it, in parallel, invokes two handler services (Call Handler A and Call Handler B), and loops back. If it gets the noMore event, the process sets the loop&#8217;s continuation fl ag to false (Set Loop Stop). The loop exits, and the process completes. While it waits for the producer events, the process also sets a timed event (too long) that fi res if neither event arrives in suffi cient time. If the timer expires, the process sends an exception message to the producer (Send Exception Msg Producer Async), and loops back.</p>
<p>The timing characteristics are shown in parentheses. The producer, on average, sends a result or noMore event in 80 milliseconds. The handlers that the process invokes to handle a result event average 50 milliseconds and 70 milliseconds, but because they run in parallel, their elapsed time is the greater of these two times, or 70 milliseconds. Thus, an iteration of the loop with a result event averages roughly 150 milliseconds. An iteration with a noMore event averages just 80 milliseconds, because the activity Set Loop Stop runs nearly instantaneously. The cycle time of an instance with one result iteration and one noMore iteration is just 220 milliseconds. The too long timed event has a duration of 200 milliseconds, which in itself is rather a small interval, but is a huge chunk of time compared to the normal cycle time. The cycle time of an instance whose three intermediate events are result, too long, and noMore is 420 milliseconds on average. Times this fast cannot be achieved on a general-purpose engine.</p>
<h2>Running the Very Fast Process on the Optimized Engine</h2>
<p>The se quence diagram in the following fi gure illustrates how this process runs on the short-running engine:</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-16.gif"><img class="aligncenter  wp-image-6813" alt="soa-16" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-16.gif" width="437" height="382" /></a></p>
<p>The process starts when client application sends a message intended to trigger the process&#8217; start event. The Pro cessManager receives this event (either as a direct call or indirectly via an execution thread that monitors the shortrunning inbound queue) in its routeMessageEvent() method. It then checks with the process class—shown as Process in the fi gure, a subclass of the CompiledProcess class we discuss presently—whether it supports the given start event type (hasStartEvent()), and if so, injects the event into the process (onStartEvent()). The process, as part of its logic, performs the activities InitVars and CallProducerAsync and enters the fi rst iteration of the while loop, in which it records in its data structures that it is now waiting for three pending events (Set Pending Events). Because one of these events is a timed event, it also registers that event with the TimeManager (addEvent()).The fi rst burst is complete.</p>
<p>In the second burst, the producer process responds with a result event (result: routeMessageEvent()). The ProcessManager checks whether the process instance is waiting for that event (hasPendingEvent()) and injects it (onIntermediateEvent()). The process invokes the two handlers (that is, it invokes CallHandler on HandlerA and HandlerB), completing the fi rst iteration of the loop. It now loops back, resets the pending events (Set Pending Events), and registers a new timed event (addEvent()). The second burst is complete.</p>
<p>Assuming the producer does not respond in suffi cient time, the timer expires, and the TimeManager which checks for expired events on its own thread notifi es the Process Manager (routeTimedEvent()). ProcessManager gives the event to the process (calling hasPendingEvent() to confi rm that the process is waiting for it and onIntermediateEvent() to inject it), and the process in turn performs the SendExceptionMsg activity, completing the second iteration of the loop. The next iteration starts, and the process resets its pending events. The third burst is complete, and we leave it there.</p>
<h2>Managing Inbound Events and Timeouts</h2>
<p>The sta te information needed to tie all of this together is held in memory.</p>
<p>ProcessManager maintains a data structure called instanceList that, much like the Process table just described, keeps a list of process instances indexed by the combination of conversation identifi er and process type. The list contains references to CompiledProcess-derived objects. The logic for routeMessageEvent(), in pseudo code, is the following:</p>
<pre class="brush: java; title: ; notranslate">
	Does instanceList have instance for specified process type and conv
									ID?
	If no
	   Instantiate this instance
	   Create a unique PID
	   Add instance of instanceList
	   Call process.hasStartEvent() to check if proc supports
	   start event of specified type
	   If no, return error
	   Else
	      Call process.onStartEvent()
	   End If
	Else
	   Call process.hasPendingEvent() to check if proc supports
							intermediate
	   Event of specified type
	   If no, return error
	   Else
	      Call process.onIntermediateEvent()
	   End Id
	End If&lt;/code&gt;</pre>
<p>TimeManager keeps a list of timed events, each tied to a particular wait node in a process instance. TimerManager&#8217;s thread periodically sweeps through the list, finding events that have expired. It calls ProcessManager&#8217;s routeTimedEvent() method to inject the event to the instance. Three types of timed events are supported:</p>
<ul>
<li>wait activity</li>
<li>onAlarm activity</li>
<li>SLA on the instance</li>
</ul>
<p>The first two event types simply wake up the process. If the process previously entered a wait activity, for example, the timed event causes it to complete. The third generates a fault. If the process has a handler for this fault, control moves immediately to the handler. Otherwise, the instance is immediately aborted.</p>
<h2>Compiled Form</h2>
<p>The Com piledProcess class (the base class for compiled <b><i>BPEL</i></b> processes) keeps track of variables, current pending events, and permitted start events, holding in memory the same sort of data that is defi ned for the tables ProcessVariable, PendingEvent, and ProcessStarter. Here is an excerpt of the code:</p>
<pre class="brush: java; title: ; notranslate">
	public abstract class CompiledProcess {
	   List pendingEvents = new ArrayList();
	   Map variables = new HashMap();
	   String pid;
	   String convID;
	   public abstract &lt;b&gt;&lt;i&gt;BPEL&lt;/i&gt;&lt;/b&gt;Graph getGraph();
	   public boolean hasStartEvent(….) {
	      check graph to see if specified event is allowed
	   }
	   public boolean hasPendingEvent(….) {
	      check pendingEvents list to see if specified event is allowed
	   }
	   public void onStartEvent(…){
	      walk();
	   }
	   public void onIntermediateEvent(…) {
	      remove event from pending events
	      walk();
	   }
	   void walk() {
		From the node containing the current event, navigate forward in
		the graph until the process completes or we hit another
		intermediate event.
		When we hit an intermediate event,add it to the pendingEvents
									list.
		For timed events, register them with TimerManager too.
		Update process variables as needed.
	   }
	}
&lt;/code&gt;</pre>
<p>Notice that the class is marked abstract, and that its method getGraph() is not implemented. In our design, each <b><i>BPEL</i></b> process is run through a special compiler utility that generates a Java class extending CompiledProcess. The utility, called <b><i>BPEL</i></b>Compiler, is a Java program that takes as input the XML source code for the <b><i>BPEL</i></b> process. It parses the XML and outputs a Java source fi le that is later compiled and loaded into the address space of the process engine. At runtime, the <b><i>BPEL</i></b> process runs at the speed of compiled Java. We thus save the performance-stultifying effect of runtime XML parsing and serialization that affl icts many process engines.</p>
<p>Here is a snippet of the Java source of the class for our sample short-running process:</p>
<pre class="brush: java; title: ; notranslate">
	public class SRProcess extends CompiledProcess {
	static &lt;b&gt;&lt;i&gt;BPEL&lt;/i&gt;&lt;/b&gt;Graph graph = null;
	   static {
		graph = new &lt;b&gt;&lt;i&gt;BPEL&lt;/i&gt;&lt;/b&gt;Graph();
		graph.initGraph();
		graph.addSequence();
		graph.addArc(1,3);
		graph.addArc(4,2);
		graph.addReceive(&amp;quot;client&amp;quot;,&amp;quot;client:SRProcess&amp;quot;,&amp;quot;initiate&amp;quot;,true,
		   &amp;quot;inputVariable&amp;quot;);
		graph.addArc(3,5);
		graph.addAssign(rules6);
		graph.addArc(5,6);
		graph.addInvoke(&amp;quot;Producer&amp;quot;,&amp;quot;ns1:SRProducer&amp;quot;,&amp;quot;initiate&amp;quot;,
		   false,&amp;quot;producer&amp;quot;,null);
		graph.addArc(6,7);
		graph.addWhile(&amp;quot;bpws:getVariableData(‘keepGoing')=true()&amp;quot;);
		graph.addArc(7,8);
		graph.addPick(false);
		graph.addArc(8,10);
		graph.addArc(11,9);
		graph.addOnMessage(&amp;quot;Producer&amp;quot;,&amp;quot;ns1:SRProducerCallback&amp;quot;,
		   &amp;quot;onResult&amp;quot;,10,&amp;quot;result&amp;quot;);
	   	...
	   }
	   @Override
	   public &lt;b&gt;&lt;i&gt;BPEL&lt;/i&gt;&lt;/b&gt;Graph getGraph() {
	      return graph;
	   }
	}
&lt;/code&gt;</pre>
<p>The class does nothing except build a graph representing its process defi nition. It begins by declaring a class-scoped member variable called graph (static <b><i>BPEL</i></b>Graph graph = null;). In the static intializer code that follows (beginning with static {), it instantiates this attribute (graph=new <b><i>BPEL</i></b>Graph();) and proceeds to construct it as a set of nodes (for example, graph.addSequence(), graph. addReceive(), graph.addAssign(), graph.addInvoke(), graph.addWhile(), graph.addPick(), and others not shown) and arcs (graph.addArc()). The class also overrides the getGraph() method that is left abstract in the base class. This method simply returns a reference to the graph variable.</p>
<p>And that&#8217;s all there is to the generated class. It inherits the most important methods from the base class. Its job is to fi ll in the one missing ingredient: the actual process defi nition. Signifi cantly, it creates this defi nition (that is, the graph) at class scope, so that there is only one copy of it in the process engine, not one copy per process instance. This saves a lot of memory.</p>
<p>The structure of the graph is similar to that of the XML-defined process in the source—which is not surprising given that this code is generated from a parse of the XML. The next fi gure depicts the graph constructed in the compiled process.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2008/12/soa-17.gif"><img class="aligncenter  wp-image-6814" alt="soa-17" src="http://www.javabeat.net/wp-content/uploads/2008/12/soa-17.gif" width="433" height="164" /></a></p>
<p>Here is a snippet of the corresponding <b><i>BPEL</i></b> source, predictably similar to the graph:</p>
<pre class="brush: java; title: ; notranslate">
	&lt;process&gt;
	   &lt;sequence&gt;
	      &lt;receive&gt;
	      &lt;assign name=&amp;quot;InitVars&amp;quot; /&gt;
	      &lt;invoke name=&amp;quot;Call Producer Async&amp;quot; /&gt;
	      &lt;while&gt;
		&lt;pick&gt;
		   &lt;onMessage name=&amp;quot;result&amp;quot;&gt;
		      &lt;flow&gt;
			&lt;invoke name=&amp;quot;Call Handler A&amp;quot; /&gt;
			&lt;invoke name=&amp;quot;Call Handler B&amp;quot; /&gt;
		      &lt;/flow&gt;
		   &lt;/onMessage&gt;
	           &lt;onMessage name=&amp;quot;noMore&amp;quot;&gt;
			&lt;assign name=&amp;quot;Set Loop Stop&amp;quot; /&gt;
		   &lt;/onMessage&gt;
		   &lt;onAlarm name=&amp;quot;Too Long&amp;quot;&gt;
			&lt;invoke name=&amp;quot;Send Exception Msg&amp;quot; /&gt;
		   &lt;/onMessage&gt;
	        &lt;/pick&gt;
	      &lt;/while&gt;
	   &lt;/sequence&gt;
	&lt;/process&gt;
&lt;/code&gt;</pre>
<p>The surest way to learn the functionality of compiled processes and the short-running engine is to play with the accompanying compiler demo. See About the Examples for a download link.</p>
<h2>Compiled Code—What Not To Do</h2>
<p>A n alternative to the graph implementation is to represent the process as a single block of code, as follows:</p>
<pre class="brush: java; title: ; notranslate">
	InitVars();
	   CallProducerAsync();
	   While (loopContinue)
	      WaitNextEvent()
	      If (event is result)
		Fork (CallHandlerA)
		Fork (CallHandlerB)
		Join the forks
	      Else if (event is noMore)
		Set loopContinue = false
	      Else if (event is too slow)
		SendExceptionMsg();
	      End If
	   End While
&lt;/code&gt;</pre>
<p>Though simple, this code hampers performance, because the intermediate event in WaitNextEvent() ties up an execution thread while it waits. That&#8217;s one less thread for the process engine to work with, which might be needed elsewhere. The graph implementation might be a little harder to code—that code is generated by a tool anyway—but it uses resources more effi ciently. Performance is the point, after all.</p>
<h2>About the Examples</h2>
<p>The source code for this chapter is available for download in the code bundle. Refer to the README fi le for information on how to set up and run the examples.</p>
<p>The example of email funds transfer, which demonstrates how to build a long-running process out of several short-running processes, uses <b><i>TIBCO</i></b>&#8216;s BusinessWorks 5.6 and Enterprise Message Service 4.4, as well as an RDBMS. <b><i>TIBCO</i></b> products can be downloaded from <a href="http://download.tibco.com" target="_blank">http://download.tibco.com</a>. You must have an account to access this site. Once in, there are several installation programs to download; refer to our README fi le for the complete list.</p>
<p>The <b><i>BPEL</i></b> compiler is a set of Java programs. To run them, you require JDK 1.4 or higher. If you wish to compile the source code or run the programs from Eclipse, you need Eclipse 3.0 or later.</p>
<h2>Summary</h2>
<p>SOA processes have both active and passive activities. Active activities include calls to systems and services, data manipulations and transformations, and scripts or inline code snippets. Passive activities are events. When performing active activities, the process is actively performing work, tying up the process engine. Events put the process into an idle wait state.</p>
<p>An event can occur at the beginning of the process or in the middle. Every SOA process starts with an event. An event in the middle is called an intermediate event, and not every SOA process has one. The segment of a process between two events is called a burst; in a burst, the process performs active activities.</p>
<p>Processes are classifi ed by duration as short-running, long-running, or mid-running.</p>
<p>Short-running processes span no more than a few seconds. Many short-running processes are a single burst, but some have intermediate events, which break the process into multiple bursts. Languages that support short-running processes include <b><i>TIBCO</i></b>&#8216;s BusinessWorks and BEA&#8217;s Weblogic Integration.</p>
<p>Long-running processes run longer—often days, weeks, months, or years— than the uptime of the process engine on which they run. Most of the time is spent waiting on intermediate events; the bursts themselves are quick. The engine persists the state of such processes to a database to survive a restart. Languages that support long-running processes include <b><i>BPEL</i></b> and Weblogic Integration.</p>
<p>Mid-running processes run for about the duration of a phone call in a call center. In call center usage, processes are structured as question-and-answer conversations between agent and customer. Bursts process the previous answer and prepare the next question; intermediate events wait for the customer&#8217;s next answer. The engine keeps process state in memory. If the engine goes down, in-fl ight instances are lost. Chordiant&#8217;s Foundation Server is an example of this sort of implementation.</p>
<p>Process data models include process metadata (information about the types of processes currently deployed), instance data (the status of live instances of processes), and pending events (and how to correlate them with instances). We studied the data models in Oracle&#8217;s <b><i>BPEL</i></b> Process Manager and BEA&#8217;s Weblogic Integration, and developed our own model that generalizes these. We used this model to build a use case that requires a long-running process (email funds transfer) from several short-running processes in <b><i>TIBCO</i></b>&#8216;s BusinessWorks.</p>
<p>We concluded by designing a process engine optimized for short-running processes. The design is able to run short-running processes faster than a typical process engine because process state is held in memory (never persisted), processes are compiled rather than interpreted, and the process may define timed events of a very short duration. Further, the engine generates a fault when the process exceeds its SLA; the process may catch the fault or let it bubble up to the caller.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/12/soa-process-architecture-modeling-and-simulation-in-bpel-tibcos-businessworks-and-beas-weblogic-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Features in WebLogic Server 10.0</title>
		<link>http://www.javabeat.net/2007/07/new-features-in-weblogic-server-10-0/</link>
		<comments>http://www.javabeat.net/2007/07/new-features-in-weblogic-server-10-0/#comments</comments>
		<pubDate>Wed, 04 Jul 2007 11:56:05 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[WebLogic]]></category>
		<category><![CDATA[WebLogic 10.0]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=140</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>There are a lot of changes and new features in Weblogic Server 10.0. This new release gets better and efficient in terms of performance, in terms of the supported APIs and in terms of the supported external libraries. Almost all of the updates in the Java EE are reflected in the WebLogic Server 10.0. In the [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><span style="font-size: 13px;">There are a lot of changes and new features in Weblogic Server 10.0. This new release gets better and efficient in terms of performance, in terms of the supported APIs and in terms of the supported external libraries. Almost all of the updates in the Java EE are reflected in </span>the WebLogic Server 10.0. In the following sections we will discuss 18 of these new features:-</p>
<h2>1) Core Server</h2>
<h3>1.1) Client Support and Modularity</h3>
<p>In order to ensure for greater flexibility some aspects of the file structure of WebLogic have reorganized. Now many of components of the WebLogic Server that used to be in weblogic.jar are now included in separate modules and <em>weblogic.jar</em> now refers to these<br />
components in the modules directory from its manifest classpath. Now this file has relative manifest classpath references to the <em>WL_HOME/modules</em> directory and because of which it can not be moved to any new location. But if required three options are available:-</p>
<ol>
<li>Include both <em>weblogic.jar</em> and <em>WL_HOME/modules/weblogic.server.modules_10.0.0.0.jar</em> directly in the classpath.</li>
<li>Modify the manifest classpath of <em>weblogic.jar</em> to refer to this JAR in the correct relative location.</li>
<li>Create a consolidated wlfullclient.jar for client applications using the Jar Builder tool.</li>
</ol>
<h3>1.2) Subcomponents Version Information</h3>
<p>There is a new <strong><em>verbose</em></strong> optional argument in the java <strong><em>weblogic.version</em></strong> command. It returns version information<br />
about many WebLogic Server components.</p>
<h3>1.3) Security Consequences</h3>
<p>The default J2SE security policy in WebLogic server has been modified to grant access to the new modules. As a result of the reorganization of the weblogic.jar, the security policy, in your scenario, may need to be modified to grant access to the newer separate<br />
modules.</p>
<h2>2) Java EE Metadata Annotations and Dependency Injection</h2>
<p>The <strong><em>Annotations</em></strong> feature in JDK 5.0 allows developers to specify how the application component behaves in the container, requests for <strong><em>Dependency Injections</em></strong> etc. in the Java class itself. This simplifies the application development process and because of these features being useful for EJBs, Web Services and Web Applications, annotations prove to be very handful for programmers in the<br />
Java EE Programming model. Now application components can declare dependencies on external resources and configuration parameters through annotations, which <span class="GramE">is</span> called <strong><em>Dependency Injection</em></strong>. It becomes the duty of the container to read those annotations and provide for the required resources.</p>
<h2>3) Web Applications</h2>
<p>Web Application technologies such as <strong><em>JSPs</em></strong> and <strong><em>Servlets</em></strong> have new and changed features. These are discussed below:-</p>
<h3>3.1) Support for Servlet 2.5</h3>
<p>Keeping up the compliance with the Java EE 5, WebLogic Server 10.0 implements the <strong><em>Servlet 2.5</em></strong> specification. As with the EJB 3.0 specification the support for annotations and Resource Injections are among the new features of this release of the <strong><em>Servlets<br />
Technology</em></strong>. The annotations are used to declare data in Java Code instead of defining it in the long and confusing deployment descriptors. Web.xml is now optional.</p>
<h3>3.2) Support for JSP 2.1</h3>
<p>Keeping up the compliance with the Java EE 5, WebLogic Server 10.0 implements the <strong><em>JSP 2.1</em></strong> specification. Among the new features of this technology is the support for <strong><em>Deferred Expressions</em></strong>. This feature allows deferring of evaluation of the expression so that it can be processed by the underlying mechanism at a suitable time within its lifecycle. Annotations for tag handlers and event listeners are other new features in <strong><em>JSP 2.1</em></strong>.</p>
<h3>3.3) Support for JSF 1.2 and JSTL 1.2</h3>
<p>These packages come with WebLogic Server 10.0 in the form of shared <strong><em>Web Application Libraries</em></strong>. Earlier versions like <strong><em>JSF 1.1</em></strong> and <strong><em>JSTL 1.1,</em></strong> are still supported in WebLogic 10.0.</p>
<h3>3.4) Annotations for Web Components in Weblogic format</h3>
<p>There are certain WebLogic specific annotations for Servlets and Filters. For Example, WLInitParam etc.</p>
<h3>3.5) Java EE Application Client Utility</h3>
<p>There is a new option available for the <strong><em>weblogic.j2eeclient.Main</em></strong> utility. This utility is used to execute Java EE application client code. The new option is used to specify the name of the client Jar to be invoked when passing in an exploded EAR file. For Example:-</p>
<pre class="brush: java; title: ; notranslate">java weblogic.j2eeclient.Main applicationclient.jar t3://localhost:7001</pre>
<h2>4) Support for the newer Enterprise JavaBeans, Version 3.0</h2>
<p>WebLogic Server 10.0 implements the <strong><em>Enterprise JavaBeans specification v3.0</em></strong>. Also it continues to support the version 2.1 of the EJB Specification. So this means the applications written in version 2.1 will continue to run on this newer Weblogic Server 10.0,<br />
without any modification. WebLogic also provides an implementation of the BEA, which means that <strong><em>JPA</em></strong> and <strong><em>JDO</em></strong> are also supported. The EJB 3.0 is oriented towards making it easier to program for the application developers. This is achieved by reducing the number of programming artifacts and introducing annotations which is related to the concept of Dependency Injections. Together these features in EJB 3.0 make programming the bean file easier and more intuitive. EJB 3.0 also looks after standardizing <strong><em>the Persistence Framework</em></strong> and <strong><em>Object-Relational Mapping Model</em></strong>.</p>
<h3>4.1) Upgrade EJB 2.x to EJB 3.0</h3>
<p>Firstly, the default transaction attribute in <strong><em>Session Beans</em></strong> and <strong><em>Message Driven Beans</em></strong> was <em>&#8220;supports&#8221;</em> in version 2.1. But now it is changed to <em>&#8220;required&#8221;</em> in EJB 3.0. So do ensure to provide proper transaction attribute while migrating to the newer version of EJBs.<br />
Other than this there is no change for any of the three bean types in their deployment in WebLogic 10.0.</p>
<h2>5) Shared Library Support gets better</h2>
<p>The Java EE supports use of optional packages and shared libraries. An EAR file may have a directory that contains libraries<br />
packaged in Jar files. The name of this directory is specified in the EAR file&#8217;s deployment descriptor <em>&#8220;library-directory&#8221;</em> element.</p>
<h2>6) JDBC and JTA</h2>
<p>A couple of features are introduced to the WebLogic <strong><em>JDBC</em></strong> and <strong><em>JTA</em></strong> in this release:-</p>
<h3>6.1) Enhanced JDBC Connection Monitoring and Testing</h3>
<p>WebLogic Server used to rely on JDBC drivers to properly handle Database connection failures. For some network failure conditions, WebLogic Server was not able to track a connection failure until the <strong><em>TCP/IP</em></strong> expires from timeout. This feature provides additional<br />
connection health monitoring and testing for connections when connectivity is suspected to be broken.</p>
<h3>6.2) Oracle Fast Connection Failover Support</h3>
<p>Now WebLogic Server supports <strong><em>Oracle Fast Connection Failover</em></strong>. This means now the JDBC applications can utilize a<br />
driver independent way to use connection failover support from Oracle 10g.</p>
<h3>6.3) Support for MySQL 5.0</h3>
<p>WebLogic Server supports <strong><em>MySQL 5.0.x</em></strong> and bundles with the required drivers as well.</p>
<h3>6.4) JTA 1.1 support</h3>
<p>WebLogic Server is compliant with <strong><em>JTA 1.1</em></strong>. It includes support for looking up the <em>TransactionSynchronizationRegistry</em> object in JNDI using <em>java/TransactionSynchronizationRegistry</em>. BEA extends this support by providing two more global JNDI names:</p>
<pre class="brush: java; title: ; notranslate">javax/transaction/TransactionSynchronizationRegistry and weblogic/
        transaction/TransactionSynchronizationRegistry.</pre>
<h3>6.5) Migrating Transaction Recovery Service Automatically</h3>
<p>Now an administrator can configure the <strong><em>JTA Transaction Recovery Service</em></strong>, using the WebLogic Server migration framework. This allows for automatic migration from the current unhealthy hosting server to a healthy active server utilizing the WebLogic Server health monitoring capabilities. So now a quick restart can be done on a redundant server should the host server fails which in turn improves the availability of the JTA TRS in a cluster.</p>
<h3>6.6) Security for JTA across multiple Domains</h3>
<p>WebLogic Server&#8217;s JTA implementation supports the new <strong><em>Cross-Domain Security</em></strong> feature.</p>
<h2>7) Messaging</h2>
<p>There are improvements in the <strong><em>WebLogic Server JMS</em></strong>, which are discussed below in detail:-</p>
<h3>7.1) Migration of JMS-Related Services</h3>
<p>Using the <strong><em>WebLogic Server Migration<br />
Framework</em></strong>, an Administrator can configure those targets that can be migrated, so that JMS related services can be migrated from an unhealthy hosting server to a healthy active server. Migrating a target, that can be migrated, from one clustered server to another in case of problems, leads to high availability. For scheduled maintenance, targets can also be migrated manually.</p>
<p>WebLogic Server also supports service level migration for JMS related services like <strong><em>Store-and-Forward (SAF) Agents</em></strong> and <strong><em>Path Services</em></strong>.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h3>7.2) Security for JMS across multiple Domains</h3>
<p>WebLogic Server&#8217;s JMS implementation also supports the new cross-domain security feature.</p>
<h2>8) Web Services</h2>
<p>In WebLogic 10.0, Web Services receive new features as well as improvements in some of the current features, as discussed below:-</p>
<h3>8.1) Implementation and Update of Java EE 5 Web Services Specifications</h3>
<p>To keep up the compliance with the Java EE 5, WebLogic Server includes two new Web Services specification implementations:-</p>
<ol>
<li><strong><em>Java API for XML-Based Web Services (JAX-WS) 2.0</em></strong></li>
<li><strong><em>Java Architecture for XML Binding (JAXB) 2.0</em></strong></li>
<li>Two specification updates are also included in WebLogic Server 10.0:-</li>
<li><strong><em>Web Services for Java EE 1.2</em></strong></li>
<li><strong><em>SOAP With Attachments API For Java (SAAJ) 1.3</em></strong></li>
</ol>
<h3>8.2) New and Updated Web Services Specification Implementations</h3>
<p>There are the following updates and additions to the Web Services specification implementations in WebLogic Server 10.0:-</p>
<ul>
<li><strong><em>SecureConversations 1.3</em></strong></li>
<li><strong><em>WS-Security 1.1</em></strong></li>
<li><strong><em>SecurityPolicy 1.2</em></strong></li>
<li><strong><em>WS-Trust 1.3</em></strong></li>
</ul>
<p>A new set of security policy files is included that comply with <strong><em>WS-SecurityPolicy 1.2</em></strong>.</p>
<h3>8.3 Standalone Client JAR File</h3>
<p>Programmers can now use the standalone client Jar file to build and run the Web Services client applications outside of the <strong><em>WebLogic Server Container</em></strong>.</p>
<h3>8.4) Web Services Ant Task Changes</h3>
<ul>
<li>Now the three Web Services Ant tasks have a new attribute called as <em>type</em>. This attribute specifies to generate either of three, a <strong><em>JAX-RPC 1.1</em></strong> or <strong><em>JAX-WS 2.0 style Web Service (jwsc/wsdlc)</em></strong> or <strong><em>Client Artifacts (clientgen)</em></strong>.</li>
<li>The documentation for the Ant Task reference, specifies which attributes apply to which type of Web Service. It actually depends on the type of Web Service and not all attributes apply to each Web Service. There are a few more updates to the WebLogic Web Services Ant Tasks as listed below:-
<ul>
<li><span style="font-size: 1.17em;">   jwsc</span></li>
</ul>
</li>
<li>This Ant task, which used to compile a JWS file into a deployable Web Service, is changed a little as follows: &#8211; The child element <em>&#8220;xsdConfig&#8221;</em> changed to <em>&#8220;binding&#8221;</em> and use of the <em>&#8220;xsdConfig&#8221;</em> element is deprecated.
<ul>
<li><span style="font-size: 1.17em;">   clientgen</span></li>
</ul>
</li>
<li>This Ant task is changed as follows: &#8211; The child element <em>&#8220;xsdConfig&#8221;</em> changed to <em>&#8220;binding&#8221;</em> and use of the <em>&#8220;xsdConfig&#8221;</em> element is deprecated.</li>
<li>The task has two new attributes: <em>&#8220;sysProperty&#8221;</em> and <em>&#8220;catalog&#8221;</em>.
<ul>
<li><span style="font-size: 1.17em;">  wsdlc</span></li>
</ul>
</li>
<li>This Ant task is changed as follows:</li>
<li>The child element <em>&#8220;xsdConfig&#8221;</em> changed to <em>&#8220;binding&#8221;</em> and use of the <em>&#8220;xsdConfig&#8221;</em> element is deprecated.</li>
<li>The task has two new attributes: <em>&#8220;typeFamily&#8221;</em> and <em>&#8220;wlw81CallbackGen&#8221;</em>.</li>
</ul>
<h2>9) JMX</h2>
<p>Starting this release of WebLogic Server, the JMX implementation supports the <em>&#8220;jmx.remote.x.request.waiting.timeout&#8221;</em> environment parameter. This parameter specifies the number of milliseconds that the JMX client will wait for the invocation of an MBean-server method to return.</p>
<h2>10) Diagnostics Features</h2>
<p>There are new feature in both the <strong><em>WebLogic Diagnostics Framework (WLDF)</em></strong> and <strong><em>The WLDF Console Extension</em></strong>:-</p>
<h3>10.1) WebLogic Diagnostic Framework</h3>
<p>Now programmers can inspect an HTTP session object with a new standard application-scoped monitor, <strong><em>HttpSessionDebug</em></strong>. Numeric operations can now be performed on a column of type String. If the data in a column of a row is non numeric, then instead of throwing an exception the row will be excluded from the result set.</p>
<h3>10.2) WebLogic Diagnostic Framework Console Extension</h3>
<ul>
<li><strong>Custom Metrics: </strong>Custom metrics can be defined on <strong><em>MBeans</em></strong>. Once defined, a custom metric attribute for that MBean instance can be graphed just like other attributes.</li>
<li><strong>Cut,Copy, and Paste: </strong>Graphs and Charts can be cut, copy and pasted, giving more flexibility in organizing graphs and charts. It also allows to move them from       one view to another.</li>
<li><strong>Updated Visual and Interaction Design: </strong>There are new icons and various improvements to the visual tools in <strong><em>WLDF Console</em></strong></li>
<li><strong><em>Extension</em></strong>. As an example,  there is some additional functionality in the context menus.</li>
</ul>
<h2>11) Deployment</h2>
<p>Two new deployment features are added in WebLogic Server 10.0:</p>
<ol>
<li>Production redeployment is now supported for both stateless and stateful Web Services.</li>
<li>A grace period can be specified for processing of <strong><em>RMI</em></strong> client requests, in cases when retiring or gracefully shutting down an  application.</li>
</ol>
<h2>12) Filtering Classloader</h2>
<p>The users can now explicitly specify the packages that are always loaded from the application rather than by the <strong><em>System Classloader</em></strong>. This has been possible because of the new <strong><em>WebLogic Server FilteringClassLoader</em></strong>.</p>
<h2>13) Migration and Clustering</h2>
<p>New features related to Migration and Clustering are discussed below:-</p>
<h3>13.1) Targets, that can be migrated, Can Host Other JMS-related Services</h3>
<p>WebLogic Server targets, that can be migrated, supports manual service-level migration for <strong><em>Store-and-Forward (SAF) agents</em></strong> and <strong><em>Path Services</em></strong>.</p>
<h3>13.2) Automatic Singleton Service Migration</h3>
<p>This feature allows for <strong><em>Automatic Health Monitoring</em></strong> and migration of the <strong><em>Singleton Services</em></strong>. This service is a user defined service which operates in a cluster and is available on only one server at a given moment. In case if a service, which can be migrated, fails it is deactivated at its current server and activated on a new server.</p>
<h3>13.3) Job Scheduler</h3>
<p>An implementation of the <em>commonj.timer</em> API, capable to be used in a clustered environment is called as a <strong><em>Job Scheduler</em></strong>. They allow for cluster wide timer to be aware of the other JVMs, which contain each server in the cluster. Therefore is able to perform load<br />
balancing and failover. <strong><em>MySQL, Informix, DB2, Microsoft SQL Server, Oracle and Sybase Databases</em></strong> are now supported by Job Scheduler.</p>
<h3>13.4) Using Unicast for Communications within a Cluster</h3>
<p>An alternative is provided for multicast communication within a cluster. Although Unicast is much easier and efficient, to communicate between members in a cluster both Unicast and Multicast are used.</p>
<h2>14) Support for Spring Framework</h2>
<p><strong><em>Spring Framework 2.0.2</em></strong> is fully supported by the WebLogic Server 10.0.</p>
<h2>15) Security</h2>
<p>There are two new features related to security in WebLogic Server 10.0. These are discussed below:-</p>
<h3>15.1) Security across Domains</h3>
<p>The WebLogic Server establishes security across multiple server domains by using a security role for cross-domain users and utilizes the <strong><em>WebLogic Credential Mapping Security Provider</em></strong> in each domain for storing the credentials to be used by the cross domain users.</p>
<h3>15.2) Windows NT Authorization Provider Deprecated</h3>
<p>The Windows NT Authentication provider is deprecated as of WebLogic Server 10.0. Some other supported authentication providers need to be used instead.</p>
<h2>16) SNMP</h2>
<p>The changes related to the WebLogic Server SNMP Services are listed below:-</p>
<ul>
<li>After <strong><em>SNMPv1</em></strong> and <strong><em>SNMPv2</em></strong>, <strong><em>SNMPv3</em></strong> enters the list of supported protocols for the servers.</li>
<li>Multiple SNMP agents can now be created to be targeted to WebLogic Server instances.</li>
<li>These agents now can communicate through <strong><em>TCP</em></strong> port as well, in addition to the <strong><em>UDP</em></strong> port.</li>
<li>SNMP can now be used to monitor custom MBeans.</li>
<li>There are some changes to the SNMP command line utility as well.</li>
<li>Most changes in the configuration of SNMP changes including port numbers takes</li>
<li>Effect without restarting the server. Earlier versions required a restart of the server.</li>
</ul>
<h2>17) Administration Console</h2>
<p>WebLogic Server release 10.0 introduces the following changes to the Administration Console:</p>
<ul>
<li>The <strong><em>WebLogic Scripting Tool (WLST)</em></strong> commands can now be stored as a series of commands, which can later be executed as a script.</li>
<li>The number of seconds that the Administration console waits for the management operation to complete can now be set as a</li>
<li>preference. This timeout actually specifies how long the Administration console waits for the method invocation to complete.</li>
<li>Administration console extensions must be packaged as a WAR file instead of JAR file, otherwise many features of console-extension are unsupported.</li>
</ul>
<h2>18) Some Deprecated Classes</h2>
<p>Some deprecated classes, such as <em>weblogic.apache.xerces.*</em> are now removed from the WebLogic Server 10.0.</p>
<h2>Summary</h2>
<p>In this article we discussed most of the new features added in WebLogic 10.0 and enhancements of the existing features. This new release is prepared well to handle the applications built on Java EE 5.0. It supports latest API Specifications for EJBs, Servlets, JSPs, JDBC, JTA and so on. The concept of annotations is also integrated well in this release. This release is improved in terms of security features and features in the Administration console etc. The server performs well in a clustered environment with the help of added<br />
functionality for cross domain operations. Over all this server is heavily loaded with extensive new features for Programmers as well as Administrators.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2007/07/new-features-in-weblogic-server-10-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
