<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>0 and 1&#8217;s</title>
	<atom:link href="https://ramakrsna.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://ramakrsna.wordpress.com</link>
	<description>My technical weblog.</description>
	<lastBuildDate>Thu, 17 Feb 2011 16:29:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<site xmlns="com-wordpress:feed-additions:1">186610</site><cloud domain='ramakrsna.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s2.wp.com/i/webclip.png</url>
		<title>0 and 1&#8217;s</title>
		<link>https://ramakrsna.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://ramakrsna.wordpress.com/osd.xml" title="0 and 1&#039;s" />
	<atom:link rel='hub' href='https://ramakrsna.wordpress.com/?pushpress=hub'/>
	<item>
		<title>Call javap for rescue</title>
		<link>https://ramakrsna.wordpress.com/2011/02/17/call-javap-for-rescue/</link>
					<comments>https://ramakrsna.wordpress.com/2011/02/17/call-javap-for-rescue/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Thu, 17 Feb 2011 16:29:45 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=294</guid>

					<description><![CDATA[Are you struck on a system with no java doc, Java IDE and internet and have to develop java applications. I encountered the same situation today. I wanted to check out the API methods offered by standard java libraries, but was struck. Finally, javap came to my rescue. The command javap is class disassembler that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Are you struck on a system with no java doc, Java IDE and internet and have to develop java applications. I encountered the same situation today. I wanted to check out the API methods offered by standard java libraries, but was struck. Finally, <a title="http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javap.html" href="http://download.oracle.com/javase/1.5.0/docs/tooldocs/windows/javap.html" target="_blank">javap </a>came to my rescue.</p>
<p>The command javap is class disassembler that lists all methods offered by a Java Class.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png"><img data-attachment-id="295" data-permalink="https://ramakrsna.wordpress.com/2011/02/17/call-javap-for-rescue/capture/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png" data-orig-size="1181,695" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Capture" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=625" class="alignleft size-full wp-image-295" title="Capture" src="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=720&amp;h=424 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=150&amp;h=88 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=300&amp;h=177 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=768&amp;h=452 768w, https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png?w=1024&amp;h=603 1024w, https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png 1181w" sizes="(max-width: 720px) 100vw, 720px" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2011/02/17/call-javap-for-rescue/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">294</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2011/02/capture.png" medium="image">
			<media:title type="html">Capture</media:title>
		</media:content>
	</item>
		<item>
		<title>Webservice Client using Spring-WS &#8211; A UML perspective</title>
		<link>https://ramakrsna.wordpress.com/2010/06/01/webservice-client-using-spring-ws-a-uml-perspective/</link>
					<comments>https://ramakrsna.wordpress.com/2010/06/01/webservice-client-using-spring-ws-a-uml-perspective/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Tue, 01 Jun 2010 06:53:50 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Webservice]]></category>
		<category><![CDATA[Spring-WS]]></category>
		<category><![CDATA[web service]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=288</guid>

					<description><![CDATA[A picture is worth thousand words. The following is the UML diagram that shows the classes involved for developing webservice client code using Spring-WS. References: Spring Web Services &#8211; Reference Documentation Spring IN ACTION UML Diagram created using Visual Paradigm for UML Community Edition]]></description>
										<content:encoded><![CDATA[<p>A picture is worth thousand words. The following is the UML diagram that shows the classes involved for developing webservice client code using Spring-WS.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg"><img data-attachment-id="289" data-permalink="https://ramakrsna.wordpress.com/2010/06/01/webservice-client-using-spring-ws-a-uml-perspective/springws-client/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg" data-orig-size="1046,576" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="SpringWS-Client" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=625" class="alignleft size-full wp-image-289" title="SpringWS-Client" src="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=720&amp;h=396 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=150&amp;h=83 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=300&amp;h=165 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=768&amp;h=423 768w, https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg?w=1024&amp;h=564 1024w, https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg 1046w" sizes="(max-width: 720px) 100vw, 720px" /></a></p>
<p>References:</p>
<p>Spring Web Services &#8211; Reference Documentation</p>
<p>Spring IN ACTION</p>
<p>UML Diagram created using Visual Paradigm for UML Community Edition</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2010/06/01/webservice-client-using-spring-ws-a-uml-perspective/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">288</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2010/06/springws-client.jpg" medium="image">
			<media:title type="html">SpringWS-Client</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting idl2java Ant Task up and running</title>
		<link>https://ramakrsna.wordpress.com/2009/11/25/getting-idl2java-ant-task-up-and-running/</link>
					<comments>https://ramakrsna.wordpress.com/2009/11/25/getting-idl2java-ant-task-up-and-running/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Wed, 25 Nov 2009 19:19:26 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CORBA]]></category>
		<category><![CDATA[IDL]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=275</guid>

					<description><![CDATA[This blog is about using idl2java Ant task to generate Java artifacts from CORBA IDL file. The idl2java Ant task is provided by OpenORB, an open source CORBA implementation. Any CORBA project starts with a idl file that describes the interface or service. Then, we use a tool to generate language specific client and server [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This blog is about using idl2java Ant task to generate Java artifacts from <a class="zem_slink" title="Common Object Request Broker Architecture" rel="wikipedia" href="http://en.wikipedia.org/wiki/Common_Object_Request_Broker_Architecture">CORBA</a> <a class="zem_slink" title="Interface description language" rel="wikipedia" href="http://en.wikipedia.org/wiki/Interface_description_language">IDL</a> file. The idl2java Ant task is provided by<a title="http://openorb.sourceforge.net/" href="http://openorb.sourceforge.net/" target="_blank"> OpenORB</a>, an open source CORBA implementation.</p>
<p>Any CORBA project starts with a idl file that describes the interface or service. Then, we use a tool to generate language specific client and server artifacts. The tool can be a command line executable or a Ant task.</p>
<p>The following idl file represents a simple attendance service.</p>
<pre class="brush: java; title: ; notranslate">

module tracker {

	interface attendance {
		long addEmployee(in string empName);

		string removeEmployee(in long empId);

		void enterEmp(in long empId, in string empName);

		string empReport(in long empId);

	};

};

</pre>
<p>The Ant Task idl2java is contained in openorb_orb_tools-&lt;version&gt;.jar. So, i add the jar to the Apache Ant Classpath. The task defination class is org.openorb.compiler.taskdefs.Idl2Java. I add the task defination.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png"><img data-attachment-id="277" data-permalink="https://ramakrsna.wordpress.com/2009/11/25/getting-idl2java-ant-task-up-and-running/taskdef/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png" data-orig-size="596,442" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="taskdef" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png?w=596" class="aligncenter size-full wp-image-277" title="taskdef" src="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png 596w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png?w=150&amp;h=111 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png?w=300&amp;h=222 300w" sizes="(max-width: 596px) 100vw, 596px" /></a></p>
<p>The Ant build file is a very simple one. It invokes the idl2java task with two attributes, one points to the directory which contains the idl file and another points to the directory where the generated source files are dumped.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;project&gt;
	&lt;property name=&quot;idlDir&quot; value=&quot;idl&quot;&gt;
	&lt;/property&gt;
	&lt;property name=&quot;srcDir&quot; value=&quot;src&quot;&gt;
	&lt;/property&gt;
	&lt;target name=&quot;idl2java_task&quot;&gt;
		&lt;idl2java srcdir=&quot;${idlDir}&quot; destdir=&quot;${srcDir}&quot; verbose=&quot;false&quot;&gt;
		&lt;/idl2java&gt;
	&lt;/target&gt;
&lt;/project&gt;

</pre>
<p>The Ant task idl2java has extensive set of options available. Check the documentation for more details.</p>
<p>Execute the Ant task and the build fails with the following error.</p>
<pre><span style="color:#ff0000;">Buildfile: C:\java\myProjWorkSpace001\CORBAProj\build.xml
</span>
idl2java_task:</pre>
<pre><span style="color:#ff0000;">BUILD FAILED
</span>
java.lang.NoClassDefFoundError: org/openorb/util/launcher/CompoundClassLoader</pre>
<pre><span style="color:#ff0000;">Total time: 188 milliseconds

</span></pre>
<p>As per error message, a class is missing. The documentation does not mention of any additional jar that needs to be added. I decided to check more on this missing class in additional jars that accompany the OpenORB distribution. But, none of them have it. Then, i checked out in website <a title="http://www.findjar.com" href="http://www.findjar.com">http://www.findjar.com</a> and found that the jar <a href="http://www.findjar.com/jar/tmporb/jars/tmporb-tools-1.0-DEAD.jar.html">tmporb-tools-1.0-DEAD.jar</a> had the class. The website <a title="http://www.findjar.com" href="http://www.findjar.com/">http://www.findjar.com</a> provided a maven link for the jar, but i got 404 error. Searched in Google and found a maven repository which had it.</p>
<p>I added this jar to the Ant Classpath and executed the build script again. The ant task executed successfully and the Java artifacts coresponding to the idl are generated.</p>
<pre>C:\java\myProjWorkSpace001\CORBAProj\src&gt;cd tracker
C:\java\myProjWorkSpace001\CORBAProj\src\tracker&gt;ls -ltr
total 22
a-----      3444 26-Nov-109 00:33 attendanceHelper.java
a-----       531 26-Nov-109 00:33 attendanceOperations.java
a-----      1809 26-Nov-109 00:33 attendancePOATie.java
a-----      7360 26-Nov-109 00:33 _attendanceStub.java
a-----      3359 26-Nov-109 00:33 attendancePOA.java
a-----      1244 26-Nov-109 00:33 attendanceHolder.java
a-----       222 26-Nov-109 00:33 attendance.java
</pre>
<p>Next, to move ahead with implementation. <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/448f7c6f-20ee-4302-a5d0-d23cf2d6e726/" rel="nofollow"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2009/11/25/getting-idl2java-ant-task-up-and-running/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">275</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2009/11/taskdef.png" medium="image">
			<media:title type="html">taskdef</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=448f7c6f-20ee-4302-a5d0-d23cf2d6e726" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
		<item>
		<title>Process Explorer &#8211; Tool which provides Unix/Linux lsof command functionality for Windows</title>
		<link>https://ramakrsna.wordpress.com/2009/09/15/process-explorer-tool-which-provides-unixlinux-lsof-command-functionality-for-windows/</link>
					<comments>https://ramakrsna.wordpress.com/2009/09/15/process-explorer-tool-which-provides-unixlinux-lsof-command-functionality-for-windows/#respond</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Tue, 15 Sep 2009 18:43:36 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Process Explorer]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=268</guid>

					<description><![CDATA[lsof command available in Unix and Linux operating system provides insight to running program. As explained in previous blog, the command is helpful to find the list of jars loaded by a Java application. To do the same on Windows operating system, use the Process Explorer program available at http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx. Start the Process Explorer, select [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="zem_slink" title="Lsof" rel="wikipedia" href="http://en.wikipedia.org/wiki/Lsof">lsof</a> command available in Unix and Linux operating system provides insight to running program. As explained in previous blog, the command is helpful to find the list of jars loaded by a Java application.</p>
<p>To do the same on <a class="zem_slink" title="Microsoft Windows" rel="wikipedia" href="http://en.wikipedia.org/wiki/Microsoft_Windows">Windows operating system</a>, use the <a class="zem_slink" title="Process Explorer" rel="homepage" href="http://www.microsoft.com/technet/sysinternals/SystemInformation/ProcessExplorer.mspx" rel="nofollow">Process Explorer</a> program available at <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" target="_blank">http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx</a>.</p>
<p>Start the Process Explorer, select the process which you want to analyze and enter CTRL + L. This brings up a lower pane that displays all system resources accessed by the process including files, threads, directories, port, etc. Filter the type column and you will be able to find all currently open files used by the application.</p>
<p>The following image displays the list of jar files accessed by Eclipse IDE.</p>
<p><img loading="lazy" data-attachment-id="272" data-permalink="https://ramakrsna.wordpress.com/2009/09/15/process-explorer-tool-which-provides-unixlinux-lsof-command-functionality-for-windows/processexplorer-2/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png" data-orig-size="935,593" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="processExplorer" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=625" class="aligncenter size-full wp-image-272" title="processExplorer" src="https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=625" alt="processExplorer"   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=720&amp;h=457 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=150&amp;h=95 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=300&amp;h=190 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png?w=768&amp;h=487 768w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png 935w" sizes="(max-width: 720px) 100vw, 720px" /></p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/72dd77e7-6c5f-4aa6-b684-a68d5b1d4f12/" rel="nofollow"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2009/09/15/process-explorer-tool-which-provides-unixlinux-lsof-command-functionality-for-windows/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">268</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2009/09/processexplorer1.png" medium="image">
			<media:title type="html">processExplorer</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=72dd77e7-6c5f-4aa6-b684-a68d5b1d4f12" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
		<item>
		<title>lsof and Unclosed file handlers</title>
		<link>https://ramakrsna.wordpress.com/2009/08/26/lsof-and-unclosed-file-handlers/</link>
					<comments>https://ramakrsna.wordpress.com/2009/08/26/lsof-and-unclosed-file-handlers/#respond</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Wed, 26 Aug 2009 03:28:05 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[Classpath]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[lsof]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=255</guid>

					<description><![CDATA[After checking out a blog entry about analyzing Classpath of a running Java program by Thilina Mahesh Buddhika, i decided to try the command on the Java Web server used at my organization. To my surprise, i was able to find unclosed file handlers in the application hosted on the Web server. The command lsof [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>After checking out a blog entry about <a title="Analyse the classpath of a running Java program" href="http://thilinamb.wordpress.com/2009/07/01/analyse-the-classpath-of-a-running-java-program/" target="_blank">analyzing Classpath of a running Java program</a> by Thilina Mahesh Buddhika, i decided to try the command on the Java <a class="zem_slink" title="Web server" rel="wikipedia" href="http://en.wikipedia.org/wiki/Web_server">Web server</a> used at my organization. To my surprise, i was able to find unclosed file handlers in the application hosted on the Web server.</p>
<p><img loading="lazy" data-attachment-id="264" data-permalink="https://ramakrsna.wordpress.com/2009/08/26/lsof-and-unclosed-file-handlers/drawer_metal_drawers_281984_l/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg" data-orig-size="500,375" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="drawer_metal_drawers_281984_l" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg?w=500" class="aligncenter size-medium wp-image-264" title="drawer_metal_drawers_281984_l" src="https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg?w=300&#038;h=225" alt="drawer_metal_drawers_281984_l" width="300" height="225" srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg?w=300 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg?w=150 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg 500w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>The command <a class="zem_slink" title="Lsof" rel="wikipedia" href="http://en.wikipedia.org/wiki/Lsof">lsof</a> -p  lists all open sockets, files and pipes. By analyzing the output of the command, i was able to check all the files opened by the application and able to reason why it was open by going through the application code. This also helped me in fixing unclosed file handlers.</p>
<p>Try out the command and try figuring out why the files are referred to. This gives an insight to functioning of the application.</p>
<p>Check out the usage of the command @ following link <a href="http://sial.org/howto/debug/unix/lsof/" target="_blank">http://sial.org/howto/debug/unix/lsof/</a></p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/a3c97381-e882-4723-9acb-56dc5cbcc1d3/" rel="nofollow"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2009/08/26/lsof-and-unclosed-file-handlers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">255</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2009/08/drawer_metal_drawers_281984_l.jpg?w=300" medium="image">
			<media:title type="html">drawer_metal_drawers_281984_l</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=a3c97381-e882-4723-9acb-56dc5cbcc1d3" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating the DDL(Create and DROP) Statements of JPA Entities in EclipseLink</title>
		<link>https://ramakrsna.wordpress.com/2009/02/14/generating-the-ddlcreate-and-drop-statements-of-jpa-entities-in-eclipselink/</link>
					<comments>https://ramakrsna.wordpress.com/2009/02/14/generating-the-ddlcreate-and-drop-statements-of-jpa-entities-in-eclipselink/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sat, 14 Feb 2009 03:40:35 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Data Definition Language]]></category>
		<category><![CDATA[Databases and Persistence]]></category>
		<category><![CDATA[DDL]]></category>
		<category><![CDATA[EclipseLink]]></category>
		<category><![CDATA[Java Persistence API]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=134</guid>

					<description><![CDATA[This blog is about generating the DDL Statements (CREATE and DROP DDL)  for the entities managed by the JPA. The JPA implementation used here is EclipseLink. I have used the following Person class to be managed as Entity. The persistence.xml file is as follows. The persistence.xml contains information about the database. The DDL generation information [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This blog is about generating the DDL Statements (CREATE and DROP DDL)  for the entities managed by the JPA. The JPA implementation used here is <a title="EclipseLink" href="http://wiki.eclipse.org/EclipseLink" target="_blank">EclipseLink</a>.</p>
<p>I have used the following Person class to be managed as Entity.</p>
<pre class="brush: java; title: ; notranslate">

package com.entities;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Person {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    int id;
    String fName;
    String lName;
    int age;

   //the setter, getter, methods for each of the attributes, toString,   

   //hashCode,  equals and default constructor are not shown here.
}

</pre>
<p>The persistence.xml file is as follows.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;persistence:persistence version=&quot;1.0&quot;
	xmlns:persistence=&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 ../../persistence_1_0.xsd &quot;&gt;
&lt;persistence:persistence-unit name=&quot;simplePersistenceUnit&quot;&gt;
&lt;persistence:provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/persistence:provider&gt;
&lt;persistence:class&gt;com.entities.Person&lt;/persistence:class&gt;
&lt;persistence:properties&gt;
&lt;persistence:property name=&quot;eclipselink.jdbc.driver&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;
&lt;persistence:property name=&quot;eclipselink.jdbc.url&quot; value=&quot;jdbc:mysql://localhost:3306/default&quot;/&gt;
&lt;persistence:property name=&quot;eclipselink.jdbc.user&quot; value=&quot;root&quot;/&gt;
&lt;persistence:property name=&quot;eclipselink.jdbc.password&quot; value=&quot;developer&quot;/&gt;
	&lt;/persistence:properties&gt;
	&lt;/persistence:persistence-unit&gt;
&lt;/persistence:persistence&gt;

</pre>
<p>The persistence.xml contains information about the database.</p>
<p>The DDL generation information is provided to the persistence manager via a java.util.Map object.</p>
<pre class="brush: java; title: ; notranslate">
package com.test;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.eclipse.persistence.config.PersistenceUnitProperties;

import org.junit.Before;
import org.junit.Test;

public class TestExampleJPA {

	EntityManager em;

	@Test
	public void testDDLGeneration() {
		Map&lt;String, String&gt; persistProperties = new HashMap&lt;String, String&gt;();
		persistProperties.put(PersistenceUnitProperties.DDL_GENERATION, &quot;create-tables&quot;);
		persistProperties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, &quot;sql-script&quot;);
		persistProperties.put(PersistenceUnitProperties.APP_LOCATION, &quot;C:\MyFolder\temp&quot;);
		EntityManagerFactory emf = Persistence.createEntityManagerFactory( &quot;simplePersistenceUnit&quot;, persistProperties);
		em = emf.createEntityManager();
	}
}

</pre>
<p>I have specified the database information in the persistence.xml file and DDL generation information into a Map object and providing it at runtime when creating the EntityManagerFactory object. Both the information can be provided fully either as part of  persistence.xml or Map object. I have combined both approaches for providing configuration information to JPA.</p>
<p>On executing the above test case the following sql files which contains the DDL for CREATE and DROP are created in C:\MyFolder\temp folder.</p>
<p><img loading="lazy" data-attachment-id="191" data-permalink="https://ramakrsna.wordpress.com/2009/02/14/generating-the-ddlcreate-and-drop-statements-of-jpa-entities-in-eclipselink/jpa_ddl/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png" data-orig-size="867,277" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="jpa_ddl" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=625" class="alignnone size-full wp-image-191" title="jpa_ddl" src="https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=625" alt="jpa_ddl"   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=720&amp;h=230 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=150&amp;h=48 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=300&amp;h=96 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png?w=768&amp;h=245 768w, https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png 867w" sizes="(max-width: 720px) 100vw, 720px" /></p>
<p>References:</p>
<p><a title="http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer" href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer" target="_blank">http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer</a></p>
<p><a title="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)" href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)" target="_blank">http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)</a></p>
<p><a class="st-taf" href="http://tellafriend.socialtwist.com:80"><img style="border:0;margin:0;padding:0;" src="https://i0.wp.com/images.socialtwist.com/2009040314359/button.png" alt="SocialTwist Tell-a-Friend" /></a></p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/b4430830-8678-489f-953e-fa3abc4c44eb/"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2009/02/14/generating-the-ddlcreate-and-drop-statements-of-jpa-entities-in-eclipselink/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">134</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2009/02/jpa_ddl.png" medium="image">
			<media:title type="html">jpa_ddl</media:title>
		</media:content>

		<media:content url="http://images.socialtwist.com/2009040314359/button.png" medium="image">
			<media:title type="html">SocialTwist Tell-a-Friend</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=b4430830-8678-489f-953e-fa3abc4c44eb" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
		<item>
		<title>WebService Client Target NameSpace clash</title>
		<link>https://ramakrsna.wordpress.com/2008/09/28/webservice-client-target-namespace-clash/</link>
					<comments>https://ramakrsna.wordpress.com/2008/09/28/webservice-client-target-namespace-clash/#respond</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sun, 28 Sep 2008 15:54:22 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Namespace]]></category>
		<category><![CDATA[web service]]></category>
		<category><![CDATA[Weblogic]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=110</guid>

					<description><![CDATA[When handling multiple web services, you may have encountered scenarios where two web services declare schema definition under same namespace. Having multiple elements defined under same name space is not a problem. But, defining a same element with different structure under same namespace but in different web service can create problem. This situation can happen [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>When handling multiple web services, you may have encountered scenarios where two web services declare schema definition under same namespace. Having multiple elements defined under same name space is not a problem. But, defining a same element with different structure under same namespace but in different web service can create problem.</p>
<p>This situation can happen when there is no global repository for the schema definitions in a company. I will explain the situation in more detail.</p>
<p>Consider a company XYZ with web address <a href="http://www.xyz.com" rel="nofollow">http://www.xyz.com</a>. The company has two enterprise applications A and B. The application A decides to expose business function as web services. Two different teams 1 and 2 in application A are working on building the web service.</p>
<p>Both the team use the same target namespace <a href="http://www.xyz.org/appA/" rel="nofollow">http://www.xyz.org/appA/</a>.</p>
<p>Team 1 builds an web service WS-1. They create a element NewOperation.</p>
<p>The schema of the element NewOperation and part of the wsdl definition is listed below</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;wsdl:definitions xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://www.xyz.org/appA/&quot; xmlns:wsdl=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; name=&quot;NewWSDLFile&quot; targetNamespace=&quot;http://www.xyz.org/appA/&quot;&gt;
  &lt;wsdl:types&gt;
    &lt;xsd:schema targetNamespace=&quot;http://www.xyz.org/appA/&quot;&gt;
      &lt;xsd:element name=&quot;NewOperation&quot;&gt;
        &lt;xsd:complexType&gt;
          &lt;xsd:sequence&gt;
            &lt;xsd:element name=&quot;in&quot; type=&quot;xsd:string&quot;/&gt;
          &lt;/xsd:sequence&gt;
        &lt;/xsd:complexType&gt;
      &lt;/xsd:element&gt;
   &lt;/wsdl:types&gt;

</pre>
<p>Team 2 also builds an web service WS-2. They also create a element NewOperation.</p>
<p>The schema of the element NewOperation and part of the wsdl definition is listed below</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;wsdl:definitions xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://www.xyz.org/appA/&quot; xmlns:wsdl=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; name=&quot;NewWSDLFile&quot; targetNamespace=&quot;http://www.xyz.org/appA/&quot;&gt;
  &lt;wsdl:types&gt;
    &lt;xsd:schema targetNamespace=&quot;http://www.xyz.org/appA/&quot;&gt;
      &lt;xsd:element name=&quot;NewOperation&quot;&gt;
        &lt;xsd:complexType&gt;
          &lt;xsd:sequence&gt;
              &lt;xsd:element name=&quot;in&quot; type=&quot;xsd:string&quot; /&gt;
              &lt;xsd:element name=&quot;in_1&quot; type=&quot;xsd:string&quot;&gt;&lt;/xsd:element&gt;
          &lt;/xsd:sequence&gt;
        &lt;/xsd:complexType&gt;
      &lt;/xsd:element&gt;
   &lt;/wsdl:types&gt;

</pre>
<p>As you can see both the elements have the same name, but have different structure which is an not a good design. Since, both the team do not interact with other, they have failed to identify the flaw. Both, the team build server implementation of their web service and deploy each as EAR independent of the other. Both the teams do not face any issue, since both the server implementations are deployed independently.</p>
<p>Now, team in application B decides to use the web services provided by application A. They build client implementations for both the web services provided by A using standard build tools (<a title="http://edocs.bea.com/wls/docs81/webserv/anttasks.html#1080160" href="http://edocs.bea.com/wls/docs81/webserv/anttasks.html#1080160" target="_blank">clientgen </a>from Weblogic). The build tools usually generate the java files (in a jar) binding the schema elements to classes created in the reverse namespace package (i.e., org.xyz.www.appA). They put the client jars of both the web service in the same classpath of the application B.</p>
<p>When they try to use the operations provided by the web service, they face exception related to serialization or deserialization whenever an operation involving the element NewOperation is involved. The exception can happen in either the WS-1 or WS-2 web service. This is because, a wrong class is used in the web service. As per java classpath rule, whenever NewOperation class needs to be loaded it finds only one version of the class depending on which client jar appears first. The other NewOperation class is never found by the application.</p>
<p>In order to resolve the issue, the team A needs to move the definition of the element NewOperation in one of the web service to a different target namespace. But this is a costly option, since WS-1 and WS-2 are already implemented and will require changes in the server implementation and also for all the clients using the web service.</p>
<p>The other option is for the client to use options provided in the build tools to generate class binding the schema definition in different package other than that generated by default for one of the web service.</p>
<p>This can done in Weblogic tool <a title="http://edocs.bea.com/wls/docs81/webserv/anttasks.html#1080160" href="http://edocs.bea.com/wls/docs81/webserv/anttasks.html#1080160" target="_blank">clientgen</a> by adding the option <strong>typePackageName</strong>. Note the additional attribute <strong>typePackageName</strong> in the ant build script.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;clientgen wsdl=&quot;http://example.com/myapp/myservice.wsdl&quot;
           packageName=&quot;myapp.myservice.client&quot;
           clientJar=&quot;myapps/myService_client.jar&quot;
       typePackageName=&quot;com.appB&quot;
/&gt;

</pre>
<p>Also the same can be done in Eclipse by checking the <strong>&#8220;Define custom mapping for namespace to package&#8221; </strong>option and defining the custom mapping when generating the client implementation of the web service.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png"><img loading="lazy" data-attachment-id="120" data-permalink="https://ramakrsna.wordpress.com/2008/09/28/webservice-client-target-namespace-clash/ws-client1/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png" data-orig-size="496,523" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="ws-client1" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png?w=496" class="alignnone size-full wp-image-120" title="ws-client1" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png 496w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png?w=142&amp;h=150 142w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png?w=285&amp;h=300 285w" sizes="(max-width: 496px) 100vw, 496px" /></a></p>
<p>This avoids the clash as the client implementations are generated under different package.</p>
<p>This problem needs to be avoided in first place when creating the web service. Each company needs to have a central repository where all the schema definitions are available to avoid duplication of element name under same target namespace.</p>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/567a04c6-e9c5-4145-9c97-ede5f8d425e3/"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/09/28/webservice-client-target-namespace-clash/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">110</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/09/ws-client1.png" medium="image">
			<media:title type="html">ws-client1</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=567a04c6-e9c5-4145-9c97-ede5f8d425e3" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
		<item>
		<title>Take care when using SELECT SQL Statement with IN Clause</title>
		<link>https://ramakrsna.wordpress.com/2008/09/28/take-care-when-using-select-sql-statement-with-in-clause/</link>
					<comments>https://ramakrsna.wordpress.com/2008/09/28/take-care-when-using-select-sql-statement-with-in-clause/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sun, 28 Sep 2008 06:22:05 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Oracle]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=112</guid>

					<description><![CDATA[Consider the following code snippet The method builds an Select query using the elements in the arraylist dataValues in the IN clause. The SQL returned by the method executes normally when the size of dataValues is less then or equal to 1000. But, when the size of dataValues is greater than 1000, the SQL throws [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Consider the following code snippet</p>
<pre class="brush: java; title: ; notranslate">

	public static String getMySqlStatement(ArrayList&lt;String&gt; dataValues) {
		if ((dataValues == null) || (dataValues.size() == 0)) {
			throw new IllegalArgumentException();
		}
		StringBuilder sql = new StringBuilder (&quot;SELECT * FROM MY_TABLE WHERE MY_COLUMN IN (&quot;);
		StringBuilder colValues = new StringBuilder();
		for (String data: dataValues) {
			colValues.append(&quot;&#039;&quot;).append(data).append(&quot;&#039;,&quot;);
		}
		//Remove the trailing comma(,) and add the final braces
		sql.append(colValues.substring(0, (colValues.length()-1))).append(&quot;)&quot;);
		return sql.toString();
	}
</pre>
<p>The method builds an Select query using the elements in the arraylist dataValues in the IN clause.<br />
The SQL returned by the method executes normally when the size of dataValues is less then or equal to 1000. But, when the size of dataValues is greater than 1000, the SQL throws an exception.</p>
<p>This is because there is a limit on the number of parameters in the IN Clause. For Oracle 9i, the limit is 1000. The limit can vary based on database.</p>
<p>Hence, the above method does not work in all cases. It is required to build SQL queries based on the size of the parameters in the IN clause like breaking up into multiple SQL statements and then combining the results. The above method is modified to return multiple SQL statements if the number of parameters is greater than the limit(in this case 1000).</p>
<p>    public static ArrayList<String> getMySqlStatements(ArrayList<String> dataValues) {<br />
        if ((dataValues == null) || (dataValues.size() == 0)) {<br />
            throw new IllegalArgumentException();<br />
        }<br />
        final int IN_PARAMETER_LIMIT = 1000;<br />
        ArrayList<String> sqlStatements = new ArrayList<String>();<br />
        StringBuilder sql = new StringBuilder (&#8220;SELECT * FROM MY_TABLE WHERE MY_COLUMN IN (&#8220;);<br />
        StringBuilder colValues = null;<br />
        for (int i=0, j=0, length= dataValues.size(); i < length; i++) {
            if (colValues == null) {
                colValues = new StringBuilder();
            }
            j++;
            String data = dataValues.get(i);
            colValues.append("'").append(data).append("',");
            if (j == IN_PARAMETER_LIMIT) {
                sqlStatements.add((sql.append(colValues.substring(0, (colValues.length()-1))).append(")")).toString());
                j=0;
                colValues = null;
            }
        }
        return sqlStatements;
    }

[/sourcecode]

This error may not show up in normal circumstances unless the number of parameters is greater than 1000. <strong>To find bugs due to software limits, it is always required to unit test under maximum load conditions.</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/09/28/take-care-when-using-select-sql-statement-with-in-clause/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">112</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring an Java Object</title>
		<link>https://ramakrsna.wordpress.com/2008/09/03/exploring-an-java-object/</link>
					<comments>https://ramakrsna.wordpress.com/2008/09/03/exploring-an-java-object/#respond</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Wed, 03 Sep 2008 16:06:55 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[reflection]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=90</guid>

					<description><![CDATA[Java Reflection API&#8217;s provides functionality to explore an object(i.e., retrieving the class information of the object). This API is used in Java IDE&#8217;s, application server and libraries to operate on unknown objects. The objects loaded at runtime are dynamically analyzed using the  Java Reflection API&#8217;s. The following code shows how the Java Reflection API&#8217;s can [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Java Reflection API&#8217;s provides functionality to explore an object(i.e., retrieving the class information of the object). This API is used in Java IDE&#8217;s, application server and libraries to operate on unknown objects. The objects loaded at runtime are dynamically analyzed using the  Java Reflection API&#8217;s.</p>
<p>The following code shows how the Java Reflection API&#8217;s can be used to retrieving information. The</p>
<pre class="brush: java; title: ; notranslate">

public static void exploreObject(Object obj, PrintStream ps)

</pre>
<p>method takes an Object argument and analyzes it. It displays the class name, the interfaces the class extends, the superclass, the attributes and it&#8217;s datatype and the list of all methods complete with their signature.</p>
<p>Also, a sample usage is shown passing an instance of String object.</p>
<pre class="brush: java; title: ; notranslate">

package com.explore;

import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ClassExplorer {

    public static void main(String[] args) {
        exploreObject(new String(), System.out);
    }

    public static void exploreObject(Object obj, PrintStream ps) {
        StringBuilder sb = new StringBuilder();
        sb.append(&quot;CLASS NAME&quot;).append(&#039;\n&#039;);
        sb.append(obj.getClass().getName()).append(&#039;\n&#039;);
        sb.append(&quot;#####################################################################&quot;).append(&#039;\n&#039;);
        Class&lt;?&gt;[] interfaces = obj.getClass().getInterfaces();
        if (interfaces.length != 0) {
            sb.append(&quot;INTERFACES&quot;).append(&#039;\n&#039;);
            for (Class&lt;?&gt; i: interfaces)
                sb.append(i.getName()).append(&#039;\n&#039;);
            sb.append(&quot;#####################################################################&quot;).append(&#039;\n&#039;);
        }
        Class&lt;?&gt; superClass = obj.getClass().getSuperclass();
        if (superClass != null) {
            sb.append(&quot;SUPERCLASS&quot;).append(&#039;\n&#039;);
            sb.append(superClass.getName()).append(&#039;\n&#039;);
            sb.append(&quot;#####################################################################&quot;).append(&#039;\n&#039;);
        }
        sb.append(&quot;ATTRIBUTES&quot;).append(&#039;\n&#039;);
        //Get the attributes
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field f: fields) {
            if (f.getType().getComponentType() != null) {
                sb.append(f.getType().getComponentType().getName()).append(&quot;[]&quot;).append(&#039;\t&#039;).append(f.getName()).append(&#039;\n&#039;);
            }
            else {
                sb.append(f.getType().getName()).append(&#039;\t&#039;).append(f.getName()).append(&#039;\n&#039;);
            }
        }
        sb.append(&quot;#####################################################################&quot;).append(&#039;\n&#039;);
        sb.append(&quot;METHODS&quot;).append(&#039;\n&#039;);
        //Get all methods
        Method[] methods = obj.getClass().getDeclaredMethods();
        for (Method m: methods) {
            //Get the modifier
            sb.append(Modifier.toString(m.getModifiers())).append(&quot; &quot;);
            //Get the return type of the method
            if (m.getReturnType().getComponentType() != null) {
                sb.append(m.getReturnType().getComponentType().getName()).append(&quot;[] &quot;);
            } else {
                sb.append(m.getReturnType().getName()).append(&quot; &quot;);
            }
            //Get the method name
            sb.append(m.getName()).append(&quot;(&quot;);
            //Get the parameter list
            Class&lt;?&gt;[] parameters = m.getParameterTypes();
            if (parameters.length != 0) {
                StringBuilder parameterList = new StringBuilder();
                for (Class&lt;?&gt; p: parameters) {
                    if (p.getComponentType() != null) {
                        parameterList.append(p.getComponentType().getName()).append(&quot;[], &quot;);
                    } else {
                        parameterList.append(p.getName()).append(&quot;, &quot;);
                    }
                }
                sb.append(parameterList.substring(0, parameterList.length()-2));
            }
            sb.append(&quot;)&quot;);
            //Get the exceptions
            Class&lt;?&gt;[] exceptions = m.getExceptionTypes();
            if (exceptions.length != 0) {
                StringBuilder exceptionList = new StringBuilder();
                sb.append(&quot; throws &quot;);
                for (Class&lt;?&gt; e: exceptions)
                    exceptionList.append(e.getName()).append(&quot;, &quot;);
                sb.append(exceptionList.substring(0, (exceptionList.length() - 2)));
            }
            sb.append(&quot;;&quot;).append(&#039;\n&#039;);
        }    

        //Print to the stream
        ps.print(sb.toString());
    }

}

</pre>
<p>On executing the above class, the output is</p>
<div style="background-color:#000000;padding:2em;">
<span style="color:#FFFFFF;"></p>
<pre>

CLASS NAME
java.lang.String
#####################################################################
INTERFACES
java.io.Serializable
java.lang.Comparable
java.lang.CharSequence
#####################################################################
SUPERCLASS
java.lang.Object
#####################################################################
ATTRIBUTES
char[]    value
int    offset
int    count
int    hash
long    serialVersionUID
java.io.ObjectStreamField[]    serialPersistentFields
java.util.Comparator    CASE_INSENSITIVE_ORDER
#####################################################################
METHODS
public int hashCode();
public volatile int compareTo(java.lang.Object);
public int compareTo(java.lang.String);
public int indexOf(java.lang.String, int);
static int indexOf(char[], int, int, char[], int, int, int);
public int indexOf(java.lang.String);
public int indexOf(int);
public int indexOf(int, int);
public boolean equals(java.lang.Object);
public java.lang.String toString();
public char charAt(int);
private static void checkBounds(byte[], int, int);
public int codePointAt(int);
public int codePointBefore(int);
public int codePointCount(int, int);
public int compareToIgnoreCase(java.lang.String);
public java.lang.String concat(java.lang.String);
public boolean contains(java.lang.CharSequence);
public boolean contentEquals(java.lang.StringBuffer);
public boolean contentEquals(java.lang.CharSequence);
public static java.lang.String copyValueOf(char[], int, int);
public static java.lang.String copyValueOf(char[]);
public boolean endsWith(java.lang.String);
public boolean equalsIgnoreCase(java.lang.String);
public static transient java.lang.String format(java.lang.String, java.lang.Object[]);
public static transient java.lang.String format(java.util.Locale, java.lang.String, java.lang.Object[]);
public byte[] getBytes(java.nio.charset.Charset);
public byte[] getBytes();
public byte[] getBytes(java.lang.String) throws java.io.UnsupportedEncodingException;
public void getBytes(int, int, byte[], int);
public void getChars(int, int, char[], int);
void getChars(char[], int);
public native java.lang.String intern();
public boolean isEmpty();
public int lastIndexOf(java.lang.String);
public int lastIndexOf(int);
public int lastIndexOf(int, int);
static int lastIndexOf(char[], int, int, char[], int, int, int);
public int lastIndexOf(java.lang.String, int);
public int length();
public boolean matches(java.lang.String);
public int offsetByCodePoints(int, int);
public boolean regionMatches(int, java.lang.String, int, int);
public boolean regionMatches(boolean, int, java.lang.String, int, int);
public java.lang.String replace(char, char);
public java.lang.String replace(java.lang.CharSequence, java.lang.CharSequence);
public java.lang.String replaceAll(java.lang.String, java.lang.String);
public java.lang.String replaceFirst(java.lang.String, java.lang.String);
public java.lang.String[] split(java.lang.String, int);
public java.lang.String[] split(java.lang.String);
public boolean startsWith(java.lang.String, int);
public boolean startsWith(java.lang.String);
public java.lang.CharSequence subSequence(int, int);
public java.lang.String substring(int);
public java.lang.String substring(int, int);
public char[] toCharArray();
public java.lang.String toLowerCase();
public java.lang.String toLowerCase(java.util.Locale);
public java.lang.String toUpperCase();
public java.lang.String toUpperCase(java.util.Locale);
public java.lang.String trim();
public static java.lang.String valueOf(char[]);
public static java.lang.String valueOf(int);
public static java.lang.String valueOf(long);
public static java.lang.String valueOf(float);
public static java.lang.String valueOf(double);
public static java.lang.String valueOf(java.lang.Object);
public static java.lang.String valueOf(char);
public static java.lang.String valueOf(char[], int, int);
public static java.lang.String valueOf(boolean);
</pre>
<p></span>
</div>
<p>There are lot of API&#8217;s in the Java Reflection package to support more operations. These API&#8217;s can be used to analyse objects dynamically.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/09/03/exploring-an-java-object/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">90</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>
	</item>
		<item>
		<title>Using TCP/IP Monitor with Weblogic Webservice Clients</title>
		<link>https://ramakrsna.wordpress.com/2008/08/27/using-tcpip-monitor-with-weblogic-webservice-clients/</link>
					<comments>https://ramakrsna.wordpress.com/2008/08/27/using-tcpip-monitor-with-weblogic-webservice-clients/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Wed, 27 Aug 2008 05:42:25 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[TCP/IP Monitor]]></category>
		<category><![CDATA[web service]]></category>
		<category><![CDATA[Weblogic]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=82</guid>

					<description><![CDATA[TCP/IP Monitor is an excellent eclipse plugin to monitor TCP/IP or HTTP traffic. In this scenario, i have used this plugin to analyze the SOAP messages that are exchanged between the webservice client and server developed using Weblogic tools. TCP/IP Monitor is a proxy server that monitors for all traffic flowing through. In case, you [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>TCP/IP Monitor is an excellent eclipse plugin to monitor TCP/IP or HTTP traffic. In this scenario, i have used this plugin to analyze the SOAP messages that are exchanged between the webservice client and server developed using Weblogic tools.</p>
<p>TCP/IP Monitor is a proxy server that monitors for all traffic flowing through. In case, you want to monitor the traffic between two network nodes, you will have to use TCP/IP Monitor as proxy server so that it can monitor the traffic flowing between the endpoints.</p>
<p>Initially setup the TCP/IP Monitor using Preferences window in Eclipse. Create a new monitor by specifying the local monitoring port(which will the port number of the TCP/IP Monitor proxy server), host name(host name of the webservice server), port(port number of the webservice server port) and type(select HTTP or TCP/IP). After the new monitor is defined start the monitor.</p>
<p style="text-align:center;"><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png"><img loading="lazy" data-attachment-id="83" data-permalink="https://ramakrsna.wordpress.com/2008/08/27/using-tcpip-monitor-with-weblogic-webservice-clients/tcp_mon_1/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png" data-orig-size="342,291" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="tcp_mon_1" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png?w=342" class="size-full wp-image-83 aligncenter" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png 342w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png?w=150&amp;h=128 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png?w=300&amp;h=255 300w" sizes="(max-width: 342px) 100vw, 342px" /></a></p>
<p>Modify the Weblogic webservice client code to use the TCP/IP Monitor proxy server. This is done by the following piece of code. This code needs to be executed before client webservice port creation.</p>
<pre class="brush: java; title: ; notranslate">

        System.setProperty(&quot;http.proxyHost&quot;, &quot;localhost&quot;);
        System.setProperty(&quot;http.proxyPort&quot;, &quot;80&quot;);
        System.setProperty(&quot;weblogic.webservice.transport.http.proxy.host&quot;, &quot;localhost&quot;);
        System.setProperty(&quot;weblogic.webservice.transport.http.proxy.port&quot;, &quot;80&quot;);

</pre>
<p>The port specified will have to be same as the one of the TCP/IP Monitor created to monitor the webservice.</p>
<p>On invocation of the webservice client, you will be able to see the data exchanged between the client and the server in the TCP/IP Monitor view. It shows the SOAP messages exchanged.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png"><img loading="lazy" data-attachment-id="84" data-permalink="https://ramakrsna.wordpress.com/2008/08/27/using-tcpip-monitor-with-weblogic-webservice-clients/tcp_mon_2/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png" data-orig-size="814,396" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="tcp_mon_2" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=625" class="alignnone size-full wp-image-84" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=625" alt=""   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=720&amp;h=350 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=150&amp;h=73 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=300&amp;h=146 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png?w=768&amp;h=374 768w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png 814w" sizes="(max-width: 720px) 100vw, 720px" /></a></p>
<p>TCP/IP Monitor is an excellent tool to analyze the SOAP messages exchanged in webservice invocations.</p>
<p>The TCP/IP Monitor plugin is part of standard Eclipse distribution for J2EE developers.</p>
<p><strong><em>Useful Links</em></strong></p>
<p>To search documentation on TCP/IP Monitor</p>
<p><a title="http://help.eclipse.org/ganymede/index.jsp" href="http://help.eclipse.org/ganymede/index.jsp" target="_blank">http://help.eclipse.org/ganymede/index.jsp</a></p>
<p>Using proxy for Weblogic webservice client</p>
<p><a title="http://edocs.bea.com/wls/docs81/webserv/client.html#1077879" href="http://edocs.bea.com/wls/docs81/webserv/client.html#1077879" target="_blank">http://edocs.bea.com/wls/docs81/webserv/client.html#1077879</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/08/27/using-tcpip-monitor-with-weblogic-webservice-clients/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">82</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_1.png" medium="image" />

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/08/tcp_mon_2.png" medium="image" />
	</item>
		<item>
		<title>Comparing Version Numbers</title>
		<link>https://ramakrsna.wordpress.com/2008/07/05/comparing-version-numbers/</link>
					<comments>https://ramakrsna.wordpress.com/2008/07/05/comparing-version-numbers/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sat, 05 Jul 2008 07:12:04 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[version]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=49</guid>

					<description><![CDATA[I have written a small code snippet in Java for comparing the version numbers. Sample version numbers are 1.0, 2.2, 1.3.4, etc&#8230; Just decided to share it. import java.util.Scanner; public class CompareVersion {     final static int LESSER = -1;        //versionA is lesser than versionB     final static int EQUALS = 0;        //versionA [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I have written a small code snippet in Java for comparing the version numbers. Sample version numbers are 1.0, 2.2, 1.3.4, etc&#8230;</p>
<p>Just decided to share it.</p>
<p>import java.util.Scanner;</p>
<p>public class CompareVersion {</p>
<p>    final static int LESSER = -1;        //versionA is lesser than versionB<br />
    final static int EQUALS = 0;        //versionA equal to versionB<br />
    final static int GREATER = 1;        //versionA is greater then versionB</p>
<p>    public static int compareVersions(String versionA, String versionB) {<br />
        Scanner a = (new Scanner(versionA)).useDelimiter(&#8220;\\.&#8221;);<br />
        Scanner b = (new Scanner(versionB)).useDelimiter(&#8220;\\.&#8221;);<br />
        int i, j;<br />
        while (a.hasNext() &#038;&#038; b.hasNext()) {<br />
            i = Integer.parseInt(a.next());<br />
            j = Integer.parseInt(b.next());<br />
            if (i > j) {<br />
                return CompareVersion.GREATER;<br />
            } else if ( i < j) {
                return CompareVersion.LESSER;
            }
        }
        if (a.hasNext() &#038;&#038; !b.hasNext()) {
		return CompareVersion.GREATER;
	}
	else if (!a.hasNext() &#038;&#038; b.hasNext()) {
	        return CompareVersion.LESSER;
	}
	else {
		return CompareVersion.EQUALS;
	}
    }
}

[/sourcecode]


<h4>Sample Usage Scenarios..</h4>
<address>CompareVersion.compareVersions(&#8220;1.1&#8221;, &#8220;1.1&#8221;);</address>
<address>CompareVersion.compareVersions(&#8220;1.1&#8221;, &#8220;2.1&#8221;);</address>
<address>CompareVersion.compareVersions(&#8220;1.4.3&#8221;, &#8220;1.1&#8221;);</address>
<address> </address>
<p>The code snippet can be included as part of a larger toolset to compare versions in different environments.</p>
<address> </address>
<p><span style="text-decoration:line-through;">The code confirms to Java 1.4</span><br />
<em><span style="color:#800000;">The code uses the class java.util.Scanner and this this class is available in Java Version 5 and above. Hence, the code works only with Java 5 and above. Also, the code has been updated. The previous code missed an scenario. </span></em></p>
<p><span style="color:#000000;">I have rewritten the code for Java 1.4. I have used String manipulation method instead of using java.util.Scanner.</span><em><span style="color:#800000;"> </span></em><span style="color:#000000;">The code is as follows.</span><em><span style="color:#800000;"><br />
</span></em></p>
<p>public class CompareVersion {</p>
<p>	final static int LESSER = -1; // versionA is lesser than versionB<br />
	final static int EQUALS = 0; // versionA equal to versionB<br />
	final static int GREATER = 1; // versionA is greater then versionB</p>
<p>	public static int compareVersions(String versionA, String versionB) {<br />
		String[] a = versionA.split(&#8220;\\.&#8221;);<br />
		String[] b = versionB.split(&#8220;\\.&#8221;);<br />
		int i, j;<br />
		int index = 0;<br />
		while ((index < a.length) &#038;&#038; (index < b.length)) {
			i = Integer.parseInt(a[index]);
			j = Integer.parseInt(b[index]);
			if (i > j) {<br />
				return CompareVersion.GREATER;<br />
			} else if (i < j) {
				return CompareVersion.LESSER;
			}
			index++;
		}
		if ((index < a.length) &#038;&#038; (index == b.length)) {
			return CompareVersion.GREATER;
		} else if ((index == a.length) &#038;&#038; (index < b.length)) {
			return CompareVersion.LESSER;
		} else {
			return CompareVersion.EQUALS;
		}
	}
}
[/sourcecode]
<em><br />
</em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/07/05/comparing-version-numbers/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">49</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>
	</item>
		<item>
		<title>Analysing application flow using Throwable object</title>
		<link>https://ramakrsna.wordpress.com/2008/05/05/analyse-application-flow-using-throwable-object/</link>
					<comments>https://ramakrsna.wordpress.com/2008/05/05/analyse-application-flow-using-throwable-object/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Mon, 05 May 2008 14:07:33 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[stackTrace]]></category>
		<category><![CDATA[Throwable]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=38</guid>

					<description><![CDATA[Often it will be required to find out how a particular method is invoked in order to investigate a bug or to understand the application flow. This can be done easily in small application using debugging tool or reading through the code. Even though, it is possible to debug large applications to find out the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Often it will be required to find out how a particular method is invoked in order to investigate a bug or to understand the application flow. This can be done easily in small application using debugging tool or reading through the code. Even though, it is possible to debug large applications to find out the flow, it will obviously difficult to try the wide variety of usage scenarios. In case of large web applications, the developer may not even know every usage scenarios. Even missing a single usage scenario, also misses  method usage scenario.</p>
<p>This blog is about how to track various usage scenario in Java from code perspective.</p>
<p>The stack trace provides an excellent way to track the code flow. You would have seen in stack trace logs when exceptions are thrown, the stack trace has detail information on the classes, methods and the line numbers. We will use the same approach to trace the code flow without waiting for exceptions to happen.</p>
<p>In this scenario, we create a Throwable object, which the parent class of Exception. The Throwable object contains the entire stackTrace at the point where the object is created. We can use the getStackTrace() method on the Throwable object to obtain the stackTrace. The method returns an array of StackTraceElement. Each StackTraceElement represent a single stack frame and has information regarding the method which was invoked in the execution sequence. Also, the java class file name, complete java class name and the line number of invocation is also present.</p>
<p>Consider the following simple code scenario.</p>
<pre class="brush: java; title: ; notranslate">

public String getName() {
          return &quot;SOL_APP_MANG&quot;;
}

</pre>
<p>Inorder to trace, how the method getName is used in a application, the method is modified as follows.</p>
<pre class="brush: java; title: ; notranslate">

public String getName() {
          Throwable throwable = new Throwable();
          StackTraceElement[] stElements = throwable.getStackTrace();
          for (StackTraceElement ste: stElement)
                   system.out.println(&quot;File Name:&quot; + ste.getFileName());
                   system.out.println(&quot;Class Name:&quot; + ste.getClassName());
                   system.out.println(&quot;Method Name:&quot; + ste.getMethodName());
                   system.out.println(&quot;Line number:&quot; + ste.getLineNumber());
          return &quot;SOL_APP_MANG&quot;;
}

</pre>
<p>The code is very straightforword and simple.</p>
<p>I have implemented a small library for analyzing the stackTrace of the Throwable object. The library is a very small jar file with size of just 6.5 kb. The UML diagram is shown below.</p>
<p style="text-align:center;"><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif"><img loading="lazy" data-attachment-id="41" data-permalink="https://ramakrsna.wordpress.com/2008/05/05/analyse-application-flow-using-throwable-object/ast_classdia1/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif" data-orig-size="502,276" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="ast_classdia1" data-image-description="" data-image-caption="&lt;p&gt;Class diagram of ast.jar&lt;/p&gt;
" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif?w=502" class="aligncenter size-full wp-image-41" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif?w=625" alt="Class diagram of ast.jar"   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif 502w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif?w=150&amp;h=82 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif?w=300&amp;h=165 300w" sizes="(max-width: 502px) 100vw, 502px" /></a></p>
<p>It consists of 2 classes and a interface. The interface IDisplayableStackTrace has the method</p>
<pre class="brush: java; title: ; notranslate">

public String getDisplayedStackTrace(StackTraceElement st)

</pre>
<p>Every implementation of the IDisplayableStackTrace should implement the method and implement the functionality of how a StackTraceElement should be represented as a String.</p>
<p>This allows any implmentation to be plugged based on requirement.</p>
<p>The following SimpleDisplayableStackTrace is an implementation.</p>
<pre class="brush: java; title: ; notranslate">

package com.ast.sampleExample;

import com.ast.analyse.IDisplayableStackTrace;

public class SimpleDisplayableStackTrace implements IDisplayableStackTrace {

    @Override
    public String getDisplayedStackTrace(StackTraceElement st) {
        StringBuilder sb = new StringBuilder();
        sb.append(&quot;:$FILE$:&quot;).append(st.getFileName())
          .append(&quot;:$CLASS$:&quot;).append(st.getClassName())
          .append(&quot;:$METHOD$:&quot;).append(st.getMethodName())
          .append(&quot;:$LINE$:&quot;).append(st.getLineNumber());
        return sb.toString();
    }
}

</pre>
<p>You can write your own implementation of IDisplayableStackTrace depending on requirement.</p>
<p>The AnalyseThrowable class is the single most important class of the library. The AnalyseThrowable class has a static method.</p>
<pre class="brush: java; title: ; notranslate">

public static void dumpStackTrace(IDisplayableStackTrace dst, PrintStream pw, Throwable throwable)
            throws AnalyseThrowableException

</pre>
<p>This method has the following arguments.</p>
<ul>
<li>IDisplayableStackTrace dst &#8211; An implementation of the class IDisplayableStackTrace</li>
<li>PrintStream pw &#8211; A PrintStream object to where the customized stack trace needs to be written</li>
<li>Throwable throwable &#8211; A Throwable whose stack trace needs to be analysed</li>
</ul>
<p>Also, the class provides the method</p>
<pre class="brush: java; title: ; notranslate">

public void dumpStackTrace(Throwable throwable) throws AnalyseThrowableException

</pre>
<p>which can be invoked using an instanceof AnalyseThrowable. The AnalyseThrowable has a parameterized constructor which accepts an implementation of IDisplayableStackTrace and PrintStream.</p>
<p>One of the variations of the dumpStackTrace method can be used depending on the scenario.</p>
<p>The class AnalyseThrowableException extends Exception class and some of the methods of class<br />
AnalyseThrowable throws the AnalyseThrowableException exception object which needs to be<br />
handled by the client using the library.</p>
<p>A typical usage scenario of the library is given below.</p>
<pre class="brush: java; title: ; notranslate">

public String getName() {
          try {
                AnalyseThrowable.dumpStackTrace(new SimpleDisplayableStackTrace(), System.out, new Throwable());
          }
          catch(AnalyseThrowableException ex) {
                ex.printStackTrace(System.out);
          }
          return &quot;SOL_APP_MANG&quot;;
}

</pre>
<p>An sample stack trace, when executed through a junit test case is shown below.</p>
<h6>:$FILE$:AnalyseThrowableTest.java:$CLASS$:com.ast.analyse.AnalyseThrowableTest:$METHOD$:testDumpStackTraceIDisplayableStackTracePrintStreamThrowable:$LINE$:13<br />
:$FILE$:NativeMethodAccessorImpl.java:$CLASS$:sun.reflect.NativeMethodAccessorImpl:$METHOD$:invoke0:$LINE$:-2<br />
:$FILE$:NativeMethodAccessorImpl.java:$CLASS$:sun.reflect.NativeMethodAccessorImpl:$METHOD$:invoke:$LINE$:39<br />
:$FILE$:DelegatingMethodAccessorImpl.java:$CLASS$:sun.reflect.DelegatingMethodAccessorImpl:$METHOD$:invoke:$LINE$:25<br />
:$FILE$:Method.java:$CLASS$:java.lang.reflect.Method:$METHOD$:invoke:$LINE$:597<br />
:$FILE$:TestMethodRunner.java:$CLASS$:org.junit.internal.runners.TestMethodRunner:$METHOD$:executeMethodBody:$LINE$:99<br />
:$FILE$:TestMethodRunner.java:$CLASS$:org.junit.internal.runners.TestMethodRunner:$METHOD$:runUnprotected:$LINE$:81<br />
:$FILE$:BeforeAndAfterRunner.java:$CLASS$:org.junit.internal.runners.BeforeAndAfterRunner:$METHOD$:runProtected:$LINE$:34<br />
:$FILE$:TestMethodRunner.java:$CLASS$:org.junit.internal.runners.TestMethodRunner:$METHOD$:runMethod:$LINE$:75<br />
:$FILE$:TestMethodRunner.java:$CLASS$:org.junit.internal.runners.TestMethodRunner:$METHOD$:run:$LINE$:45<br />
:$FILE$:TestClassMethodsRunner.java:$CLASS$:org.junit.internal.runners.TestClassMethodsRunner:$METHOD$:invokeTestMethod:$LINE$:66<br />
:$FILE$:TestClassMethodsRunner.java:$CLASS$:org.junit.internal.runners.TestClassMethodsRunner:$METHOD$:run:$LINE$:35<br />
:$FILE$:TestClassRunner.java:$CLASS$:org.junit.internal.runners.TestClassRunner$1:$METHOD$:runUnprotected:$LINE$:42<br />
:$FILE$:BeforeAndAfterRunner.java:$CLASS$:org.junit.internal.runners.BeforeAndAfterRunner:$METHOD$:runProtected:$LINE$:34<br />
:$FILE$:TestClassRunner.java:$CLASS$:org.junit.internal.runners.TestClassRunner:$METHOD$:run:$LINE$:52<br />
:$FILE$:JUnit4TestReference.java:$CLASS$:org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference:$METHOD$:run:$LINE$:38<br />
:$FILE$:TestExecution.java:$CLASS$:org.eclipse.jdt.internal.junit.runner.TestExecution:$METHOD$:run:$LINE$:38<br />
:$FILE$:RemoteTestRunner.java:$CLASS$:org.eclipse.jdt.internal.junit.runner.RemoteTestRunner:$METHOD$:runTests:$LINE$:460<br />
:$FILE$:RemoteTestRunner.java:$CLASS$:org.eclipse.jdt.internal.junit.runner.RemoteTestRunner:$METHOD$:runTests:$LINE$:673<br />
:$FILE$:RemoteTestRunner.java:$CLASS$:org.eclipse.jdt.internal.junit.runner.RemoteTestRunner:$METHOD$:run:$LINE$:386<br />
:$FILE$:RemoteTestRunner.java:$CLASS$:org.eclipse.jdt.internal.junit.runner.RemoteTestRunner:$METHOD$:main:$LINE$:196</h6>
<p><a class="alignleft" title="ast.jar" href="http://www.divshare.com/download/4417819-6f2" target="_self"><span class="alignleft">Download jar file</span></a></p>
<p>OR</p>
<p><a class="alignleft" title="ast.jar" href="http://www.mediafire.com/?9jxu0lv4j12" target="_blank">Download jar file</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/05/05/analyse-application-flow-using-throwable-object/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">38</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/05/ast_classdia1.gif" medium="image">
			<media:title type="html">Class diagram of ast.jar</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating Java beans Src files from Xml</title>
		<link>https://ramakrsna.wordpress.com/2008/03/31/generating-java-beans-src-files-from-xml/</link>
					<comments>https://ramakrsna.wordpress.com/2008/03/31/generating-java-beans-src-files-from-xml/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Mon, 31 Mar 2008 19:08:00 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java bean]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=33</guid>

					<description><![CDATA[This article is about a tool, that generates java bean source files from xml, which confirms to specified xsd. For example, consider the following xml file. Note the tags in the xml, which specifies the structure of the class( import, package, name, interface, extension and attributes, comments). Now, we use the tool xml2javabean.jar to generate [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This article is about a tool, that generates java bean source files from xml, which confirms to specified xsd. For example, consider the following xml file. Note the tags in the xml, which specifies the structure of the class( import, package, name, interface, extension and attributes, comments).</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;tns:classList xmlns:tns=&quot;http://www.example.org/NewXMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.example.org/NewXMLSchema ../xsds/NewXMLSchema.xsd &quot;&gt;
  &lt;tns:comment&gt;Java Bean Class of the MyProject project&lt;/tns:comment&gt;
  &lt;tns:class&gt;
    &lt;tns:import&gt;&lt;/tns:import&gt;
    &lt;tns:package&gt;com.myProject&lt;/tns:package&gt;
    &lt;tns:name&gt;Person&lt;/tns:name&gt;
    &lt;tns:interface&gt;java.io.Serializable&lt;/tns:interface&gt;
    &lt;tns:inherits&gt;&lt;/tns:inherits&gt;
    &lt;tns:variables&gt;
      &lt;tns:type&gt;String&lt;/tns:type&gt;
      &lt;tns:name&gt;fname&lt;/tns:name&gt;
    &lt;/tns:variables&gt;
    &lt;tns:variables&gt;
        &lt;tns:type&gt;String&lt;/tns:type&gt;
        &lt;tns:name&gt;lname&lt;/tns:name&gt;
    &lt;/tns:variables&gt;
    &lt;tns:variables&gt;
        &lt;tns:type&gt;int&lt;/tns:type&gt;
        &lt;tns:name&gt;age&lt;/tns:name&gt;
    &lt;/tns:variables&gt;
    &lt;tns:variables&gt;
        &lt;tns:type&gt;String&lt;/tns:type&gt;
        &lt;tns:name&gt;nationality&lt;/tns:name&gt;
    &lt;/tns:variables&gt;
    &lt;tns:variables&gt;
        &lt;tns:type&gt;String&lt;/tns:type&gt;
        &lt;tns:name&gt;sex&lt;/tns:name&gt;
    &lt;/tns:variables&gt;
  &lt;/tns:class&gt;
&lt;/tns:classList&gt;</pre>
<p>Now, we use the tool <strong>xml2javabean.jar</strong> to generate the java bean source files.<br />
<strong></strong><strong><span style="color:#800000;">java -jar xml2javabean.jar test.xml</span></strong></p>
<p><strong></strong>The following is the java bean source file generated.<br />
<strong></strong></p>
<pre class="brush: java; title: ; notranslate">

/**
 * Java Bean Class of the MyProject project
 * Java Bean File created @ 30-03-2008 10:50:03.656
 */

package com.myProject;

public class Person implements java.io.Serializable {
     private String fname;
     private String lname;
     private int age;
     private String nationality;
     private String sex;

     // Default Constructor
     public Person() {
         super();
         fname = new String();
         lname = new String();
         age = 0;
         nationality = new String();
         sex = new String();
     }

     //parameterized Constructor
     public Person(
         String fname ,
         String lname ,
         int age ,
         String nationality ,
         String sex) {
         super();
         this.fname = fname;
         this.lname = lname;
         this.age = age;
         this.nationality = nationality;
         this.sex = sex;
     } 

     public void setFname(String fname) {
         this.fname = fname;
     }

     public String getFname() {
         return fname;
     }

     public void setLname(String lname) {
         this.lname = lname;
     }

     public String getLname() {
         return lname;
     }

     public void setAge(int age) {
         this.age = age;
     }

     public int getAge() {
         return age;
     }

     public void setNationality(String nationality) {
         this.nationality = nationality;
     }

     public String getNationality() {
         return nationality;
     }

     public void setSex(String sex) {
         this.sex = sex;
     }

     public String getSex() {
         return sex;
     }

     public boolean equals(Object obj) {
         if (this == obj)
             return true;
         if (obj == null)
             return false;
         if (getClass() != obj.getClass())
             return false;
         final Person other = (Person)obj;
         if (fname == null) {
             if (other.fname != null)
                 return false;
         } else if (!fname.equals(other.fname))
             return false;
         if (lname == null) {
             if (other.lname != null)
                 return false;
         } else if (!lname.equals(other.lname))
             return false;
         if (age != other.age)
             return false;
         if (nationality == null) {
             if (other.nationality != null)
                 return false;
         } else if (!nationality.equals(other.nationality))
             return false;
         if (sex == null) {
             if (other.sex != null)
                 return false;
         } else if (!sex.equals(other.sex))
             return false;
         return true;
     } 

     public int hashCode() {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((fname == null)?0:fname.hashCode());
         result = prime * result + ((lname == null)?0:lname.hashCode());
         result = prime * result + age;
         result = prime * result + ((nationality == null)?0:nationality.hashCode());
         result = prime * result + ((sex == null)?0:sex.hashCode());
         return result;
     }

     public String toString() {
         StringBuilder s = new StringBuilder();
         s.append(&quot;&lt;class name=\&quot;Person\&quot;&gt;&quot;);
         s.append(&quot;&lt;fname&gt;&quot;).append(fname.toString()).append(&quot;&lt;/fname&gt;&quot;);
         s.append(&quot;&lt;lname&gt;&quot;).append(lname.toString()).append(&quot;&lt;/lname&gt;&quot;);
         s.append(&quot;&lt;age&gt;&quot;).append(age).append(&quot;&lt;/age&gt;&quot;);
         s.append(&quot;&lt;nationality&gt;&quot;).append(nationality.toString()).append(&quot;&lt;/nationality&gt;&quot;);
         s.append(&quot;&lt;sex&gt;&quot;).append(sex.toString()).append(&quot;&lt;/sex&gt;&quot;);
         s.append(&quot;&lt;/class&gt;&quot;);
         return s.toString();
     }
}</pre>
<p>The above approach of java bean source file generation can be extended to other languages as well.<br />
Well, this blog is about use of a tool to generate java beans from language independent xml language.I have chosen java beans for the code generation. This is because java beans have a standard behavior that is well explained in Java Documentation. Also, in any web applications and enterprise applications, the most important objects, the domain objects are defined as java beans. The behavior and the implementation of domain objects will be well defined and will be same for the hundreds of domain objects in any application. Hence, instead of developing the domain objects by developers, it is advisable to generate the domain objects using some code generation tool. The tool, which i have mentioned helps in this task.The following diagram gives an complete generalized overview of the entire process.</p>
<p><a title="Overview_xml2javabean" href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/untitled.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/untitled.png?w=619&#038;h=206" alt="Overview_xml2javabean" width="619" height="206" /></a></p>
<p>The tool, which i have developed is for Java platform. Also, several assumptions were made before the development of the tool.</p>
<p>The  initial step in this process is about developing a xsd that specifies the structure of the xml. As, you can see from the xsd diagram, the main element is classList, which encompasses any number of class element and comment element. The comment element is of String type and specified the comments that should be included in the Source file of the generated java beans. The class element has import,package, name, interface, inherits and variables elements, which represents the structure of the class in java. Except variables, all other sub-elements of the class element are of type String. The sub-element variables is of element Variable which represents the attributes of a java class.</p>
<p><a title="xsd" href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/x2j.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/x2j.png?w=781&#038;h=172" alt="xsd" width="781" height="172" /></a></p>
<p>The xsd document corresponding the above diagram.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;schema xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;
    targetNamespace=&quot;http://www.example.org/NewXMLSchema&quot;
    xmlns:tns=&quot;http://www.example.org/NewXMLSchema&quot;
    elementFormDefault=&quot;qualified&quot;&gt;

    &lt;complexType name=&quot;variable&quot;&gt;
        &lt;sequence&gt;
            &lt;element name=&quot;type&quot; type=&quot;string&quot; maxOccurs=&quot;1&quot;
                minOccurs=&quot;1&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;name&quot; type=&quot;string&quot; maxOccurs=&quot;1&quot;
                minOccurs=&quot;1&quot;&gt;
            &lt;/element&gt;
        &lt;/sequence&gt;
    &lt;/complexType&gt;

    &lt;complexType name=&quot;class&quot;&gt;
        &lt;sequence&gt;
            &lt;element name=&quot;import&quot; type=&quot;string&quot; maxOccurs=&quot;unbounded&quot;
                minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;package&quot; type=&quot;string&quot; maxOccurs=&quot;1&quot;
                minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;name&quot; type=&quot;string&quot; maxOccurs=&quot;1&quot;
                minOccurs=&quot;1&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;interface&quot; type=&quot;string&quot;
                maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;inherits&quot; type=&quot;string&quot; maxOccurs=&quot;1&quot;
                minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;variables&quot; type=&quot;tns:variable&quot;
                maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
        &lt;/sequence&gt;
    &lt;/complexType&gt;

    &lt;complexType name=&quot;classList&quot;&gt;
        &lt;sequence&gt;
            &lt;element name=&quot;comment&quot; type=&quot;string&quot; maxOccurs=&quot;unbounded&quot;
                minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
            &lt;element name=&quot;class&quot; type=&quot;tns:class&quot; maxOccurs=&quot;unbounded&quot;
                minOccurs=&quot;0&quot;&gt;
            &lt;/element&gt;
        &lt;/sequence&gt;
    &lt;/complexType&gt;

    &lt;element name=&quot;classList&quot; type=&quot;tns:classList&quot;&gt;&lt;/element&gt;
&lt;/schema&gt;</pre>
<p>Some of the assumptions made are</p>
<ul>
<li>The comment element is common for all the generated java bean source files</li>
<li>There is no verification of imports, interfaces, extension and data type of variable</li>
<li>Interfaces are assumed to be of marker interface</li>
<li>No abstract classes to extend</li>
<li>The datatype mentioned in the xml is checked with the list of primitive datatype list in the tool. If it is not found, then the data type is assumed to be user defined datatype</li>
</ul>
<p>The tool has been developed to generate the java bean source code as per the following assumptions.</p>
<ul>
<li>Setter and getter methods for all attributes of the class</li>
<li>equals and hashcode implementation</li>
<li>toString implementation</li>
</ul>
<p>Now, i will provide a slight overview of the design and development of the tool.</p>
<p>The input for the tool is xml and it verifies the xml against the xsd, i have JAXB for dealing with xml data. JAXB provides easy way to represent the xml document as java objects, easing dealing with xml data. I have used XJC eclipse plugin to generate the java classes corresponding the elements in the xsd. The following class diagrams represents the java classes generated by the XJC plugin.</p>
<pre> <a title="xsd jaxb diagram" href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/xsdclassdiagram1.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/xsdclassdiagram1.png?w=808&#038;h=431" alt="xsd jaxb diagram" width="808" height="431" /></a></pre>
<p>The object representation of the xml document can be obtained using an instance of javax.xml.bind.Unmarshaller class. This object parses the xml document and creates instances of the xsd binding objects. The next step involves generating the java bean source files using the objects, which represent the xml.</p>
<p>The following class diagram represents the classes, which does the actual work of generating the java bean source files from the xml. The CreateJavaBeans class has methods, which builds the java bean source file part by part. The Xml2JavaBean acts as the master. Xml2Obj class transforms the xml document to objects.</p>
<p><a title="class diagram" href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/classdiagram.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/classdiagram.png?w=564&#038;h=402" alt="class diagram" width="564" height="402" /></a></p>
<p>This tool may not meet the requirements for all cases. But, the tool can be enhanced to generate the java bean source files as per requirement. All, the classes are packed together in the xml2javabean.jar. The source code is available for download without any license or terms.The implementation of the methods of the class CreateJavaBeans can be changed to generate different implementation of the generated java beans.</p>
<p><strong>Usage</strong></p>
<p>Create a xml document, which confirms to the xsd document in the downloads section.</p>
<p>Generate the java bean source files using the following command</p>
<p><strong>java -jar xml2javabean.jar &lt;xml-file&gt;</strong></p>
<p><em> OR</em></p>
<p><strong>java -jar xml2javabean.jar &lt;xml-file&gt; &lt;directory-path&gt;</strong></p>
<p>&lt;directory-path&gt; is optional. The &lt;directory-path&gt; specifies the directory where the java   files are to be generated.</p>
<p><strong>Advantages of using this approach </strong></p>
<ul>
<li>A single xml file that represents the entire domain objects</li>
<li>Better version control management</li>
<li>Domain object&#8217;s language representation(ex: javabeans) confirm to standard specification(you decide)</li>
<li>Better control over domain objects</li>
<li>Easier and faster domain object generation</li>
<li>Can be integrated with build tool (as an task in Ant build script) for generation of java bean source files during code build</li>
<li>Language independent domain object representation (xml) provides easier option, when migrating to different language and platform</li>
<li>xml2javabean.jar which is the xml to java bean conversion engine can be replaced with engines(for generation of domain objects in other language), thereby providing plugin model for the whole approach</li>
</ul>
<p><strong>Final Picture</strong><br />
The tool can be integrated as part of a much larger tool, which provides graphical domain objects modeling, with verification of the datatypes of attributes, interfaces, inheritance, imports etc, using xml as persistent layer and plugins to generate the domain objects in any languages. And this imaginary tools seems to be like UML tool with reverse engineering option for many languages.</p>
<p>The tool is just the demonstration of the concept outlined above.</p>
<p>I have learnt a lot in the development of this tool. I will continue to enhance the tool further.</p>
<p><strong>Downloads </strong></p>
<p><a href="http://www.divshare.com/download/4143100-197" target="_blank"><em>XSD document </em></a></p>
<p><a href="http://www.divshare.com/download/4128317-a14" target="_blank"><em>Source Code</em></a></p>
<p><a href="http://www.divshare.com/download/4128333-c4c" target="_blank"><em>Jar file enclosed in zip </em></a></p>
<p>Class diagram of the tool</p>
<p><a href="http://www.divshare.com/download/4129609-175"><img loading="lazy" style="border:0 none;" src="https://i0.wp.com/www.divshare.com/img/thumb/4129609-175.png" border="0" alt="" width="94" height="130" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/03/31/generating-java-beans-src-files-from-xml/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">33</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/untitled.png" medium="image">
			<media:title type="html">Overview_xml2javabean</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/x2j.png" medium="image">
			<media:title type="html">xsd</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/xsdclassdiagram1.png" medium="image">
			<media:title type="html">xsd jaxb diagram</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/classdiagram.png" medium="image">
			<media:title type="html">class diagram</media:title>
		</media:content>

		<media:content url="http://www.divshare.com/img/thumb/4129609-175.png" medium="image" />
	</item>
		<item>
		<title>Ajax address suggestion using Lucene and J2EE</title>
		<link>https://ramakrsna.wordpress.com/2008/03/16/ajax-address-suggestion-using-lucene-and-j2ee/</link>
					<comments>https://ramakrsna.wordpress.com/2008/03/16/ajax-address-suggestion-using-lucene-and-j2ee/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sun, 16 Mar 2008 18:54:22 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lucene]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=30</guid>

					<description><![CDATA[This blog is about implementing an Ajax address suggestion. It is implemented as a J2EE web application. It displays the address suggestions as you type in. I have used the &#8220;National Register of Historic Places&#8221; data which was available at site http://www.itasoftware.com/careers/SolveThisWorkHerePuzzles.html?catid=114 The data file is an xml file and has around 84000 addresses. Each [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This blog is about implementing an Ajax address suggestion. It is implemented as a J2EE web application. It displays the address suggestions as you type in.</p>
<p>I have used the &#8220;National Register of Historic Places&#8221; data which was available at site <a href="http://www.itasoftware.com/careers/SolveThisWorkHerePuzzles.html?catid=114" target="_blank">http://www.itasoftware.com/careers/SolveThisWorkHerePuzzles.html?catid=114</a><br />
The data file is an xml file and has around 84000 addresses. Each address is represented as a Property object.</p>
<p>The address data is indexed using the Open Source search engine Apache Lucene. The xml file is loaded into memory using the JAXB API&#8217;s.</p>
<p>In order to use JAXB, we will need schema to generate classes corresponding to the each Property xml data. I have generated schema for the xml file using trang jar.</p>
<p>Command for generating the schema for the xml document.</p>
<p><strong>java -jar trang.jar </strong><strong> -I xml -O xsd nrhp.xml nrhp.xsd</strong></p>
<p>The xsd document is as follows.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; elementFormDefault=&quot;qualified&quot;&gt;
  &lt;xs:element name=&quot;properties&quot;&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element maxOccurs=&quot;unbounded&quot; ref=&quot;property&quot;/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name=&quot;property&quot;&gt;
    &lt;xs:complexType&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element maxOccurs=&quot;unbounded&quot; ref=&quot;name&quot;/&gt;
        &lt;xs:element minOccurs=&quot;0&quot; ref=&quot;address&quot;/&gt;
        &lt;xs:element minOccurs=&quot;0&quot; ref=&quot;city&quot;/&gt;
        &lt;xs:element ref=&quot;state&quot;/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute name=&quot;id&quot; use=&quot;required&quot; type=&quot;xs:integer&quot;/&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name=&quot;name&quot; type=&quot;xs:string&quot;/&gt;
  &lt;xs:element name=&quot;address&quot; type=&quot;xs:string&quot;/&gt;
  &lt;xs:element name=&quot;city&quot; type=&quot;xs:string&quot;/&gt;
  &lt;xs:element name=&quot;state&quot; type=&quot;xs:NCName&quot;/&gt;
&lt;/xs:schema&gt;</pre>
<p>Next, the schema needs to be binded., generating a set of java classes that represent the schema.This can be done using the xjc command from commandline or using the xjc eclipse plugin. The following classes are generated.</p>
<pre class="brush: java; title: ; notranslate">

com.objects.ObjectFactory.java
    com.objects.Properties.java
    com.objects.Property.java</pre>
<p>In most of the cases, the schema binding classes will be READ ONLY. But, we can modify the classes under careful consideration. I have modifed the class com.objects.Properties.java to include the following method.</p>
<pre class="brush: java; title: ; notranslate">

public void setProperty(List&lt;Property&gt; prop) {
        property = prop;
    }</pre>
<p>which, is used when returing the results from server to web browser.I have created two classes, com.dataConversion.Xml2Obj to convert xml document to java objects and com.dataConversion.Obj2Xml to<br />
convert java objects back to XML document. With JAXB, both the tasks can be easily implemented.Class com.dataConversion.Xml2Obj</p>
<pre class="brush: java; title: ; notranslate">

package com.dataConversion;

import java.io.File;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class Xml2Obj {
    public List&lt;com.objects.Property&gt; getAddressList(String xmlFilePath) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance(&quot;com.objects&quot;);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        com.objects.Properties properties =
            (com.objects.Properties)unmarshaller.unmarshal(new File(xmlFilePath));
        return properties.getProperty();
    }
}</pre>
<p>Class com.dataConversion.Obj2Xml</p>
<pre class="brush: java; title: ; notranslate">

package com.dataConversion;

import java.io.Writer;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Obj2Xml {
    public void persistAddressList(com.objects.Properties prop, Writer writer) throws JAXBException {
        JAXBContext jaxbContext = JAXBContext.newInstance(&quot;com.objects&quot;);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(prop, writer);
    }
}</pre>
<p>The most important process is indexing the data. The address data is indexed on address and city field together. Since, i am storing the index in memory for performance, i have used org.apache.lucene.store.RAMDirectory to store the index. The indexing process involves org.apache.lucene.index.IndexWriter object, adding org.apache.lucene.document.Document objects to IndexWriter<br />
object. Each Document object corresponds to an Property object. The property Id is the key. The class com.dataServices.AddressSearch implements the creating the index and providing method for search.The implementation is as follows.</p>
<pre class="brush: java; title: ; notranslate">

package com.dataServices;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.RAMDirectory;

import com.objects.*;
import com.dataConversion.*;

public class AddressSearch {
    private RAMDirectory inMemoryIndex;
    private IndexWriter indexWriter;
    private Searcher searcher;
    private StandardAnalyzer standardAnalyzer;
    private QueryParser queryParser;
    private Hashtable&lt;String, Property&gt; addressLookup= null;
    private static AddressSearch addressSearch;
    //Default file path
    private String xmlFilePath = &quot;C:/java/nrhp.xml&quot;;

    private AddressSearch() throws CorruptIndexException, LockObtainFailedException, IOException, JAXBException {
        inMemoryIndex = new RAMDirectory();
        indexWriter = new IndexWriter(inMemoryIndex, new StandardAnalyzer());
        addressLookup = new Hashtable&lt;String, Property&gt;();
        buildIndex();
        searcher = new IndexSearcher(inMemoryIndex);
        standardAnalyzer = new StandardAnalyzer();
        queryParser = new QueryParser(&quot;data&quot;, standardAnalyzer);
        queryParser.setAllowLeadingWildcard(true);
    }

    private void buildIndex() throws JAXBException, CorruptIndexException, IOException {
        List&lt;Property&gt; propList = getAddressList();
        Document doc = null;
        StringBuffer sb = null;
        for (Property p: propList) {
            doc = new Document();
            sb= new StringBuffer();
            if ((p.getId()==null)||(p.getAddress()==null)) continue;
            doc.add(new Field(&quot;propId&quot;, p.getId().toString(),Field.Store.YES, Field.Index.NO));
            if ((p.getAddress()==null) || (p.getCity()==null) || (p.getState()==null))
                continue;
            sb.append(p.getAddress().replaceAll(&quot; &quot;, &quot;&quot;)).append(p.getCity().replaceAll(&quot; &quot;, &quot;&quot;));
            doc.add(new Field(&quot;data&quot;, sb.toString(), Field.Store.COMPRESS, Field.Index.TOKENIZED));
            indexWriter.addDocument(doc);
            //also add to HashTable
            addressLookup.put(p.getId().toString(), p);
        }
        indexWriter.optimize();
        indexWriter.close();
    }

    public List&lt;Property&gt; search(String searchString) throws ParseException, IOException {
        List&lt;Property&gt; results = new ArrayList&lt;Property&gt;();
        Query query = queryParser.parse(searchString);
        Hits hits = searcher.search(query);
        if (hits.length() != 0)
            for (int i=0; i&lt; hits.length(); i++) {
                results.add(addressLookup.get(hits.doc(i).get(&quot;propId&quot;)));
            }
        return results;
    }

    public static synchronized AddressSearch getAddressSearch() throws Exception{
        if (addressSearch == null)
            addressSearch = new AddressSearch();
        return addressSearch;
    }

    private List&lt;Property&gt; getAddressList() throws JAXBException {
        Xml2Obj x2o = new Xml2Obj();
        return x2o.getAddressList(xmlFilePath);
    }

    public static void initialize(String xmlFile) throws Exception {
        getAddressSearch();
    }
}</pre>
<p>The class com.dataServices.GetAddress is a HttpServlet that provides the address search functionality by accessing the  AddressSearch object. The result of the search is a list of Property objects, which match the search term. The Property objects are converted to xml using the class Obj2Xml and sent back as response.The addressSuggestion.jsp is the client side page, through which the users can type in address. The important javascript methods which does the ajax resquest and handing the response is shown below.</p>
<pre class="brush: jscript; title: ; notranslate">

//For Ajax
var req;

function init() {
    if (window.XMLHttpRequest)
        req = new XMLHttpRequest;
    else if (window.ActiveXObject)
        req = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
    var url = &#039;http://&#039; + location.host + &#039;/AjaxAddressSugg/GetAddress&#039;;
    req.open(&quot;POST&quot;, url, true);
    req.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
}

function initiateSearch() {
    var searchString = document.getElementById(&#039;address&#039;).value;
    if ((searchString == null) || (searchString.length &lt; 3)) {
        return;
    }
    init();
    req.onreadystatechange = displayResults;
    var request=&quot;searchString=&quot;+searchString;
    req.send(request);
}

function displayResults() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            var propertyTags = req.responseXML.getElementsByTagName(&#039;property&#039;);
            for (var i=0; i&lt; propertyTags.length; i++) {
                var full_address = &quot;
&lt;table width=&#039;100%&#039; cellspacing=&#039;0&#039; cellpadding=&#039;1&#039;&gt;
&lt;tr style=&#039;background-color: #CCDEF7;&#039;&gt;
&lt;td&gt;&lt;b&gt;&quot;;
                for (var j=0; j&lt; propertyTags&amp;#91;i&amp;#93;.getElementsByTagName(&#039;name&#039;).length; j++)
                full_address = full_address +
                                propertyTags&amp;#91;i&amp;#93;.getElementsByTagName(&#039;name&#039;)&amp;#91;j&amp;#93;.firstChild.nodeValue;
                full_address =  full_address + &quot;&lt;/b&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style=&#039;background-color: #DDE9FB;&#039;&gt;
&lt;td&gt;&quot; +
                        propertyTags[i].getElementsByTagName(&#039;address&#039;)[0].firstChild.nodeValue
                        + &#039; &#039; + propertyTags[i].getElementsByTagName(&#039;city&#039;)[0].firstChild.nodeValue
                        + &#039; &#039; + propertyTags[i].getElementsByTagName(&#039;state&#039;)[0].firstChild.nodeValue
                        + &#039;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&#039;;
                var row = document.getElementById(&#039;table001&#039;).insertRow(-1);
                var cell = row.insertCell(-1);
                cell.innerHTML = full_address;
            }
        }
    }
}

function removeResults() {
    var resultsTable = document.getElementById(&#039;table001&#039;);
    var records = resultsTable.rows.length;
    for (var i=(records-1); i&gt; 0; i--)
        resultsTable.deleteRow(i);
}</pre>
<p>I have attached the screen shot of one of the searches below.<a title="Ajax Address Suggestion" href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/ajaxsearch.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/ajaxsearch.png?w=552&#038;h=560" alt="Ajax Address Suggestion" width="552" height="560" /></a>On my laptop with 1.66 Ghz Intel Core Duo and 2 GB RAM, and java version 1.6.0_02 the response was around 170-250 ms.<br />
The code can be improved a lot through optimization, which the current implementation lacks.I have enclosed the war file, which includes the source code. The war file is successfully tested on Tomcat and Glassfish.</p>
<p>The search fails in some cases with the following exception.</p>
<p><em>org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024 </em></p>
<p>This happens when the search string you entered results in more than 1024 tokens. This can be fixed by increasing maxClauseCount in the BooleanQuery class to 2048.</p>
<p>Also, the ajax search begins when user enters minimum of 3 characters.</p>
<p>The servlet above is not thread-safe.</p>
<p><em><strong>Update</strong></em></p>
<p>The  servlet has been changed to fetch the location of the xml data file from web.xml instead of using workaround.</p>
<p><strong>Quick Preview</strong></p>
<div class="embed-vimeo" style="text-align: center;"><iframe src="https://player.vimeo.com/video/1501123" width="625" height="352" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
<p><strong>Resources </strong></p>
<p><a href="http://www.thaiopensource.com/relaxng/trang.html" target="_blank">trang.jar </a></p>
<p><strong>SourceCode and WAR file</strong></p>
<p><a href="http://www.divshare.com/download/4069123-aa2" target="_blank">AjaxAddressSugg.war </a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/03/16/ajax-address-suggestion-using-lucene-and-j2ee/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">30</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/03/ajaxsearch.png" medium="image">
			<media:title type="html">Ajax Address Suggestion</media:title>
		</media:content>
	</item>
		<item>
		<title>Unix Command uniq in Java</title>
		<link>https://ramakrsna.wordpress.com/2008/03/16/unix-command-uniq-in-java/</link>
					<comments>https://ramakrsna.wordpress.com/2008/03/16/unix-command-uniq-in-java/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sun, 16 Mar 2008 18:43:14 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[uniq]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/2008/03/16/unix-command-uniq-in-java/</guid>

					<description><![CDATA[Today, i encountered a situation where i needed to get unique lines from a file. On Unix/Linux, this can be done easily using the system built in command ‘uniq’. But, i was on Windows. I am very poor with DOS commands, and didn&#8217;t even bother to check DOS documentation to check if such a utility [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today, i encountered a situation where i needed to get unique lines from a file. On Unix/Linux, this can be done easily using the system built in command ‘uniq’. But, i was on Windows. I am very poor with DOS commands, and didn&#8217;t even bother to check DOS documentation to check if such a utility existed. I used to use Unix commands in Windows using the “Unix commands in windows” utility. It didn&#8217;t have the uniq tool. I developed a similar utility using Java. The actual code is about 10 lines.<br />
The tool reads every line from a file and loads it to a LinkedHashSet and then writes the contents to a file.</p>
<pre class="brush: java; title: ; notranslate">

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

public class GetUniqueLines {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(args[0]));
        Set&lt;String&gt; s = new LinkedHashSet&lt;String&gt;();
        String line = null;
        while ((line = br.readLine())!= null)
            s.add(line);
        Iterator&lt;String&gt; it = s.iterator();
        BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
        while (it.hasNext()) {
            bw.write(it.next());
            bw.newLine();
        }
        bw.close();
        br.close();
    }
}

</pre>
<p>8 lines of imports for 12 lines of code. <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/03/16/unix-command-uniq-in-java/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">29</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>
	</item>
		<item>
		<title>Scripting Graphs in Browser</title>
		<link>https://ramakrsna.wordpress.com/2008/02/24/scripting-graphs-in-browser/</link>
					<comments>https://ramakrsna.wordpress.com/2008/02/24/scripting-graphs-in-browser/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Sun, 24 Feb 2008 16:46:08 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[javascript]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=21</guid>

					<description><![CDATA[Few would have encountered situations where a graph based on dynamic data needs to be part of a web page. In these cases, we either opt for some open source or commercial graph generating tools. We can also use Canvas HTML element to create graphs, if we can put some effort in learning. In this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Few would have encountered situations where a graph based on dynamic data needs to be part of a web page. In these cases, we either opt for some open source or commercial graph generating tools. We can also use Canvas HTML element to create graphs, if we can put some effort in learning. In this blog, i will describe how i used Canvas HTML element to generate graphs.</p>
<p>Canvas HTML element is used to create graph. Canvas HTML element is part of HTML 5 Specification. Hence, any browser that confirms to HTML 5 specification should be able to properly render the Canvas element. As of now Firefox(above 1.5v) and Opera supports this. IE doesn&#8217;t support this tag, but there is a workaround.</p>
<p>A snapshot of the line graph. Since, i have used random number generator for generating the values, the graph is more random.</p>
<p><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/canvas.png?w=800&#038;h=400" alt="Canvas Graph" width="800" height="400" align="absmiddle" /></p>
<p>This is the JavaScript source code, which generated the graph.</p>
<p>var graphArray;<br />
function populateGraphArray() {<br />
        //value can be anything from 0 to 100<br />
 graphArray = new Array();<br />
 var randomnumber;<br />
 for (var i=0; i< 200 ; i++){
 	graphArray[i] = Math.floor(Math.random()*101);
 }
}

function drawGraph() {
      var canvas = document.getElementById("graphCanvas");
      var graphWidth = canvas.width;
      var graphHeight = canvas.height;
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");
 ctx.beginPath();
 //Draw the x and y axis
 ctx.lineWidth = 5;
 ctx.lineTo(0, 0);
 ctx.lineTo(0, graphHeight);
 ctx.lineTo(graphWidth, graphHeight);
 ctx.stroke();
 //Draw the Graph
 ctx.lineWidth = 1;
 ctx.strokeStyle='rgb(114, 172, 216)';
 var unitX;
 var unitY;
 if (graphHeight > 100)<br />
 	unitY = Math.floor(graphHeight/100);<br />
 else<br />
 	unitY = Math.floor(100/graphHeight);<br />
 if ( graphWidth > graphArray.length)<br />
 	unitX = Math.floor(graphWidth/graphArray.length);<br />
 else<br />
 	unitX = Math.floor(graphArray.length/graphWidth);<br />
 for (var i=0; i < graphArray.length; i++){
 	if (i==0)
 		ctx.moveTo(unitX*i, (graphHeight - (graphArray[i]*unitY)));
 	ctx.lineTo(unitX*i, (graphHeight - (graphArray[i]*unitY)));
 }
 ctx.stroke();
      }
}[/sourcecode]

<strong><br />
&#8220;graphCanvas&#8221;</strong> is the Canvas element in the HTML page. The code is pretty simple if you go through the documentation on Canvas at <a href="http://developer.mozilla.org/en/docs/HTML:Canvas" target="_blank">Mozilla Developer Center</a>.</p>
<p>Our logic just boils down to generate the x and y coordinate values, which usually will be a small algorithm.</p>
<p>You can also create a bar graph with just 2 lines of code change. The bar graph generated is..<img loading="lazy" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/canvas00.png?w=800&#038;h=400" alt="Bar Graph" width="800" height="400" align="absmiddle" /></p>
<p>The javascript code is</p>
<p>    function drawGraph() {<br />
      var canvas = document.getElementById(&#8220;graphCanvas&#8221;);<br />
   var graphWidth = canvas.width;<br />
   var graphHeight = canvas.height;<br />
      if (canvas.getContext) {<br />
        var ctx = canvas.getContext(&#8220;2d&#8221;);<br />
 	ctx.beginPath();<br />
 	//Draw the x and y axis<br />
 	ctx.lineWidth = 5;<br />
 	ctx.lineTo(0, 0);<br />
 	ctx.lineTo(0, graphHeight);<br />
 	ctx.lineTo(graphWidth, graphHeight);<br />
 	ctx.stroke();<br />
 	//Draw the Graph<br />
 	ctx.lineWidth = 1;<br />
 	ctx.strokeStyle=&#8217;rgb(80, 45, 46)&#8217;;<br />
 	var unitX;<br />
 	var unitY;<br />
 	if (graphHeight > 100)<br />
 		unitY = Math.floor(graphHeight/100);<br />
 	else<br />
 		unitY = Math.floor(100/graphHeight);<br />
 	if ( graphWidth > graphArray.length)<br />
 		unitX = Math.floor(graphWidth/graphArray.length);<br />
 	else<br />
 		unitX = Math.floor(graphArray.length/graphWidth);<br />
 	ctx.lineWidth = unitY;<br />
 	for (var i=0; i < graphArray.length; i++){
 		ctx.moveTo(unitX*i, graphHeight);
 		ctx.lineTo(unitX*i, (graphHeight - (graphArray[i]*unitY)));
 	}
 	ctx.stroke();
      }
    }[/sourcecode]

<strong>References</strong></p>
<ul>
<li> <a href="http://developer.mozilla.org/en/docs/HTML:Canvas" target="_blank">Mozilla Developer Center</a></li>
</ul>
<p><strong>Source Code Download</strong></p>
<ul>
<li><a href="http://www.divshare.com/download/3868321-b98" target="_blank">Link</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/02/24/scripting-graphs-in-browser/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">21</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/canvas.png" medium="image">
			<media:title type="html">Canvas Graph</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/canvas00.png" medium="image">
			<media:title type="html">Bar Graph</media:title>
		</media:content>
	</item>
		<item>
		<title>A J2EE application using JMS.</title>
		<link>https://ramakrsna.wordpress.com/2008/02/13/a-j2ee-application-using-jms/</link>
					<comments>https://ramakrsna.wordpress.com/2008/02/13/a-j2ee-application-using-jms/#comments</comments>
		
		<dc:creator><![CDATA[Rama Krishna]]></dc:creator>
		<pubDate>Wed, 13 Feb 2008 10:57:37 +0000</pubDate>
				<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Application server]]></category>
		<category><![CDATA[derby]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Enterprise JavaBean]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Message Service]]></category>
		<category><![CDATA[jms]]></category>
		<guid isPermaLink="false">http://ramakrsna.wordpress.com/?p=19</guid>

					<description><![CDATA[About JMS. The Java Message Service (JMS) API is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. JMS is a part of the Java Platform, Enterprise Edition, and is defined by a specification developed under the Java Community Process as JSR 914. &#8211; Source www.wikipedia.com There are already [&#8230;]]]></description>
										<content:encoded><![CDATA[<h4>About JMS.</h4>
<p>The <strong>Java Message Service</strong> (<strong>JMS</strong>) <a href="http://en.wikipedia.org/wiki/Application_Programming_Interface">API</a> is a <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29">Java</a> <a href="http://en.wikipedia.org/wiki/Message_Oriented_Middleware">Message Oriented Middleware</a> (MOM) API for sending messages between two or more <a href="http://en.wikipedia.org/wiki/Client_%28computing%29">clients</a>. JMS is a part of the <a href="http://en.wikipedia.org/wiki/Java_Platform%2C_Enterprise_Edition">Java Platform, Enterprise Edition</a>, and is defined by a specification developed under the <a href="http://en.wikipedia.org/wiki/Java_Community_Process">Java Community Process</a> as JSR 914.</p>
<p>&#8211; Source <a href="http://www.wikipedia.com">www.wikipedia.com</a></p>
<p>There are already a lot of resources about JMS on net. Hence, I will not elaborate more on this.</p>
<p>I have provided some links in the references section, which i found to be of great help in understanding JMS.</p>
<p>This post is about my experience of developing a simple JMS application using Glassfish Application Server. The IDE used is Eclipse. The messaging model is Point to Point.</p>
<p><strong>The functionality of the application to be implemented.</strong></p>
<p>This application provides a JMS consumer, which accepts ObjectMessage from the JMS producers. The ObjectMessage object encapsulates a User object. The User object is similar to objects in a typical business application. The JMS Consumer persists the User object. The JMS producer is a part of a typical online application, which sends the User object, whenever a new user registers for the service. And, the Consumer can be thought as a module, which performs certain operations with the User data with interfacing systems, which together provide a business work flow.</p>
<p>This the UML diagram of the User object.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/classdiagram.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/classdiagram-thumb.png?w=198&#038;h=375" border="0" alt="classdiagram" width="198" height="375" /></a></p>
<p>The JMS Consumer just persists the User object in database.  The User class is part of a projBeans.jar jar file. Since, this class is common for both the server and client module, i have created a separate jar for the User Class.</p>
<p><strong></strong></p>
<p><strong>Developing the server part of the application.</strong></p>
<p>The server part of the application includes the JMS Consumer module, setting up connection factory and destination resource in the Glassfish application Server together with the database setup.</p>
<p>The web based admin console of the Glassfish application server can be accessed at port number 4848. Create a new JMS Connection factory <strong>persistUserConnectionFactory</strong> of type QueueConnectionFactory and a new JMS Destination Resource <strong>persistUserQueue</strong> of type Queue.</p>
<p><img loading="lazy" data-attachment-id="199" data-permalink="https://ramakrsna.wordpress.com/2008/02/13/a-j2ee-application-using-jms/jms1/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png" data-orig-size="735,545" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="jms1" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png?w=625" class="alignnone size-full wp-image-199" title="jms1" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png?w=625" alt="jms1"   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png?w=720&amp;h=534 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png?w=150&amp;h=111 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png?w=300&amp;h=222 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png 735w" sizes="(max-width: 720px) 100vw, 720px" /></p>
<p><img loading="lazy" data-attachment-id="200" data-permalink="https://ramakrsna.wordpress.com/2008/02/13/a-j2ee-application-using-jms/jms2/" data-orig-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png" data-orig-size="735,545" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="jms2" data-image-description="" data-image-caption="" data-large-file="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png?w=625" class="alignnone size-full wp-image-200" title="jms2" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png?w=625" alt="jms2"   srcset="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png?w=720&amp;h=534 720w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png?w=150&amp;h=111 150w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png?w=300&amp;h=222 300w, https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png 735w" sizes="(max-width: 720px) 100vw, 720px" /></p>
<p>I have used EJB 3 Annotations to develop the Message Beans.</p>
<p>Create a New java project in Eclipse and implemented the following classes.</p>
<p>The JMS Consumer is the UserMessageListener Class, which is implemented as follows.</p>
<pre class="brush: java; title: ; notranslate">

package com.ebeans.message;

import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import org.apache.log4j.Logger;
import com.beans.User;
import com.persist.db.PersistUser;

@MessageDriven(mappedName = &quot;persistUserQueue&quot;)
public class UserMessageListener implements MessageListener{

	static Logger log = null;

	static {
 	log = Logger.getLogger(UserMessageListener.class);
 }

	public UserMessageListener() {
 }

	@Override
 public void onMessage(Message arg0) {
 	Object obj = null;
 	if (arg0 instanceof ObjectMessage) {
 		try {
 			obj = ((ObjectMessage)arg0).getObject();
 		} catch (JMSException e) {
 			e.printStackTrace();
 			log.error(&quot;Message could not be casted to ObjectMessage&quot;, e);
 		}
 		if (obj instanceof User) {
 			log.info(&quot;User object will be persisted.&quot; + ((User)obj).toString());
 			PersistUser persist = new PersistUser();
 			persist.persistToDb((User)obj);
 		}
 	}
 	else {
 		log.warn(&quot;ObjectMessage is not of type User.&quot; + obj.getClass());
 	}
 }

}</pre>
<p>A class needs to implement the MessageListener interface to be a Message Bean, and hence the class UserMessageListener.The interface MessageListener has the following method, that needs to be overridden. This is the method, which is called by the JMS container when a message is received by the application server.</p>
<pre class="brush: java; title: ; notranslate">
public void onMessage(Message arg0) {
}</pre>
<p>This method includes the message processing logic. In this method, i create an instance of PersistUser and invoke the method persistToDb to persist the User object to database. The database used here is Derby.The implementation of the class PersistUser  is as follows.</p>
<pre class="brush: java; title: ; notranslate">
package com.persist.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.sql.DriverManager;
import org.apache.log4j.Logger;
import com.beans.User;

public class PersistUser {

	static String dbDeryUrl = &quot;jdbc:derby://localhost:1527/sample&quot;;

	static Logger log = null;

	static {
 	log = Logger.getLogger(PersistUser.class);
 }

	public PersistUser() {

	}
 public void persistToDb(User obj) {
 	Connection conn = null;
 	try {
 		Class.forName(&quot;org.apache.derby.jdbc.ClientDriver&quot;);
 		Properties prop = new Properties();
 		prop.put(&quot;user&quot;, &quot;system&quot;);
 		prop.put(&quot;password&quot;, &quot;manager&quot;);
 		StringBuilder sb = getSqlQuery(obj);
 		log.info(&quot;SQL = &quot; + sb.toString());
 		conn = DriverManager.getConnection(dbDeryUrl, prop);
 		Statement st = conn.createStatement();
 		st.execute(sb.toString());
 		conn.close();
 	} catch (ClassNotFoundException e) {
 		log.error(&quot;JDBC Driver could not be found.&quot;, e);
 		e.printStackTrace();
 	} catch (SQLException e) {
 		log.error(&quot;SQL Exception.&quot; + e);
 		e.printStackTrace();
 	}
 	finally {
 		if (conn != null) {
 			try {
 				conn.close();
 			} catch (SQLException e) {
 				log.error(&quot;SQL Exception in finally block.&quot; + e);
 				e.printStackTrace();
 			}
 		}
 	}
 }

	private StringBuilder getSqlQuery(User obj) {
 	StringBuilder sb = new StringBuilder();
 	sb.append(&quot;INSERT INTO USERSINFO (first_name, last_name, middle_name, age, country) VALUES (&#039;&quot;)
 	  .append(obj.getFname())
 	  .append(&quot;&#039;,&#039;&quot;)
 	  .append(obj.getLname())
 	  .append(&quot;&#039;,&#039;&quot;)
 	  .append(obj.getMname())
 	  .append(&quot;&#039;,&quot;)
 	  .append(obj.getAge())
 	  .append(&quot;,&#039;&quot;)
 	  .append(obj.getCountry())
 	  .append(&quot;&#039;)&quot;);
 	return sb;
 }
}</pre>
<p>I have used Log4j for logging. Also, included javaee.jar (part of Glassfish library), projBeans.jar (for User Class) , derbyClient.jar and apache-log4j-1.2.15 libraries.The structure of the project in Eclipse project explorer is as follows.<a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project1.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project1-thumb.png?w=381&#038;h=234" alt="project1" width="381" height="234" /></a>Next, create the table with defination as follows in Derby database.</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE USERSINFO (
           FIRST_NAME VARCHAR(20),
           LAST_NAME VARCHAR(20),
           MIDDLE_NAME VARCHAR(20),
           AGE INTEGER,
          COUNTRY VARCHAR(20) )</pre>
<p>The database is also ready. Next, we need to pack up the java project developed above as a Enterprise Archive (EAR) file.To create the ear file, create a new Enterprise Application Project under J2EE section of New Project Wizard and include the java project previously developed as part of this project.Next, create a directory lib under EarContent directory of the Enterprise Application Project and add the following libraries.</p>
<ul>
<li>projBeans.jar</li>
<li>derbyClient.jar</li>
<li>apache-log4j-1.2.15</li>
</ul>
<p>The structure of the Enterprise Application Project is as shown.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project2.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project2-thumb.png?w=181&#038;h=103" alt="project2" width="181" height="103" /></a></p>
<p>Now, export this project as EAR file using the export option available in eclipse. Since,  J2EE 5 Annotation feature, there is no requirement of deployment descriptor file required in the EAR file.</p>
<p>The EAR file is ready for deployment in the Glassfish Application Server.</p>
<p>Use the Glassfish application server Web based admin console to deploy the EAR. When deploying the EAR, enable the &#8220;Run Verifier&#8221; option. With this option turned on, the application server verifies the EAR file and deploys, if successfully verified. If the verification fails, a message is displayed on the web console. To check the complete log, the logs is located in the following location.</p>
<p>%glassfish_home%/domains/%your_domain%/logs/server.log</p>
<p>The JMS Consumer is now successfully deployed.</p>
<h5>Developing the client part (JMS Producer)</h5>
<p>The jms producer which we will be creating runs as a separate standalone java process outside the application server. Hence, we cannot make use of Annotations provided by EJB3 for developing the jms producer module.</p>
<p>The implementation of the jms producer class UserJMSClient is as follows.</p>
<pre class="brush: java; title: ; notranslate">
package com.client;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.beans.User;

public class UserJMSClient {
 InitialContext jndi = null;
 QueueConnectionFactory qFactory = null;
 Queue queue = null;
 boolean initialized = false;

	private void initialize() throws NamingException {
 	jndi = new InitialContext();
 	qFactory = (QueueConnectionFactory)jndi.lookup(&quot;persistUserConnectionFactory&quot;);
 	queue = (Queue)jndi.lookup(&quot;persistUserQueue&quot;);
 }

	public void sendObject(User user) throws Exception {
 	if (!initialized) {
 		try {
 			initialize();
 		} catch(NamingException e) {
 			e.printStackTrace();
 			throw new Exception(&quot;Jndi lookup failed&quot;);
 		}
 		initialized = true;
 	}
 	try {
 		QueueConnection qConn = (QueueConnection)qFactory.createQueueConnection();
 		Session session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 		ObjectMessage oMsg = session.createObjectMessage(user);
 		session.createProducer(queue).send(oMsg);
 	} catch (JMSException e) {
 		e.printStackTrace();
 		throw new Exception(&quot;sendObject Method Failure&quot;);
 	}
 }
}</pre>
<p>The class uses the JNDI to obtain references to QueueConnectionFactory and Queue. Included the following jar files.</p>
<ul>
<li>javaee.jar (%glassfish%\lib)</li>
<li>projBeans.jar</li>
<li>junit-4.4.jar</li>
<li>imqjmsra.jar (%glassfish%/lib\install\applications\jmsra)</li>
<li>appserv-rt.jar (%glassfish%\lib)</li>
<li>sun-appserv-ant.jar (%glassfish%\lib)</li>
</ul>
<p>The following is the project structure in Eclipse.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project4.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project4-thumb.png?w=356&#038;h=210" alt="project4" width="356" height="210" /></a></p>
<p>To test the UserJMSClient class,  i have used JUnit test case.</p>
<p>On executing the JUnit test case, the UserJMSClient object sent an User object to JMS consumer running in the application server. The JMS Consumer persisted the user object to the derby database, which i verified by querying the database.</p>
<p><a href="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project5.png"><img loading="lazy" style="border:0 none;" src="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project5-thumb.png?w=349&#038;h=121" border="0" alt="project5" width="349" height="121" /></a></p>
<p>A simple JMS based application has been developed and verified successfully. This blog is more of practical implementation of JMS.</p>
<h5>References</h5>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Java_Message_Service" target="_blank">Java Message Service</a> &#8211; <em>Wikipedia article</em></li>
<li><a href="http://java.sun.com/products/jms/" target="_blank">Java Message Service</a> &#8211; <em>Sun&#8217;s Documentation</em></li>
<li><a href="http://today.java.net/pub/a/today/2008/01/22/jms-messaging-using-glassfish.html" target="_blank">JMS Messaging Using GlassFish</a></li>
</ul>
<h5>Resources</h5>
<ul>
<li><a href="http://www.eclipse.org/webtools/" target="_blank">Eclipse (WTP)</a></li>
<li><a href="https://glassfish.dev.java.net/" target="_blank">Glassfish Application Server</a></li>
<li><a href="http://db.apache.org/derby/" target="_blank">Apache Derby</a></li>
<li><a href="http://logging.apache.org/log4j/1.2/index.html" target="_blank">Apache Log4j</a></li>
<li><a href="http://www.junit.org/" target="_blank">JUnit</a></li>
</ul>
<h5>Source Code</h5>
<ul>
<li><a href="http://www.divshare.com/download/3770704-21b" target="_blank"> Client Code (JMS Producer)</a></li>
<li> <a href="http://www.box.net/shared/nh2ikdgg0s" target="_blank">Server Code (JMS Consumer)</a></li>
<li><a href="http://www.box.net/shared/n01ixe8bos" target="_blank">Common Jar File</a></li>
</ul>
<div class="zemanta-pixie" style="margin-top:10px;height:15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/b3edd475-8187-477b-8133-c9ba415bcacc/"><img class="zemanta-pixie-img" style="border:medium none;float:right;" src="https://i0.wp.com/img.zemanta.com/reblog_e.png" alt="Reblog this post [with Zemanta]" /></a></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ramakrsna.wordpress.com/2008/02/13/a-j2ee-application-using-jms/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">19</post-id>
		<media:content url="https://0.gravatar.com/avatar/065749744d13f97efd0e8f1ced63c723d317e0ed8f324bf4840a4d1949f416e8?s=96&#38;d=https%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Rama Krishna</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/classdiagram-thumb.png" medium="image">
			<media:title type="html">classdiagram</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms1.png" medium="image">
			<media:title type="html">jms1</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/jms2.png" medium="image">
			<media:title type="html">jms2</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project1-thumb.png" medium="image">
			<media:title type="html">project1</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project2-thumb.png" medium="image">
			<media:title type="html">project2</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project4-thumb.png" medium="image">
			<media:title type="html">project4</media:title>
		</media:content>

		<media:content url="https://ramakrsna.wordpress.com/wp-content/uploads/2008/02/project5-thumb.png" medium="image">
			<media:title type="html">project5</media:title>
		</media:content>

		<media:content url="http://img.zemanta.com/reblog_e.png?x-id=b3edd475-8187-477b-8133-c9ba415bcacc" medium="image">
			<media:title type="html">Reblog this post [with Zemanta]</media:title>
		</media:content>
	</item>
	</channel>
</rss>
