<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-36956413</id><updated>2012-01-24T01:03:46.690-08:00</updated><category term='CXF'/><category term='Java Properties Problem'/><category term='autoboxing'/><category term='aligment'/><category term='Using compc with large number of resources'/><category term='removing user prompt while connecting in j2ssh'/><category term='failover protocol on client side'/><category term='Hibernate'/><category term='ConsoleKnownHostskeyVerification'/><category term='Jexcel'/><category term='Performace Test'/><category term='Java Properties escaping special charecters'/><category term='log4j tutorial'/><category term='AccesscontrolException'/><category term='Open MBean'/><category term='Environment'/><category term='log4j layout'/><category term='Streaming'/><category term='CXF Tutorial'/><category term='Ruby and Gmail'/><category term='Flex 3'/><category term='Log information of CVS in java'/><category term='Gem'/><category term='Flex'/><category term='Java Abstract Method'/><category term='Integrating Tomcat and activeMQ'/><category term='JMS'/><category term='Formatting cells'/><category term='ActiveMQ jndi.properties'/><category term='JXL tutorial'/><category term='Send SMS'/><category term='Lightstreamer Tutorial'/><category term='RMI Tutorial'/><category term='Atmosphere'/><category term='Nature'/><category term='Network of  brokers'/><category term='Send SMS Online'/><category term='toXMLString'/><category term='scala'/><category term='FileInfoEvent'/><category term='Action Script Generator'/><category term='Lightstreamer Java Adapter Sample'/><category term='JXL Wrap text'/><category term='j2ssh'/><category term='CVS'/><category term='ActiveMQ'/><category term='BlazeBS Turnkey Problem'/><category term='RMI'/><category term='filter'/><category term='webservice'/><category term='Listener and Builders in javacvs'/><category term='Merging cells'/><category term='javaFx'/><category term='Criteria query'/><category term='Add resource using compc'/><category term='Tomcat'/><category term='AspectJ'/><category term='Keeping flex and java model in sync'/><category term='JMX'/><category term='Filtering in Java'/><category term='Eclipse'/><category term='xdoc plugin to generate actionscript'/><category term='JMS Producer'/><category term='JS Caching'/><category term='velocity'/><category term='Convert XML file to String in Java'/><category term='Objectoutputstream'/><category term='Java AutoBoxing Problem'/><category term='VTL'/><category term='Sample JMS program'/><category term='filtering result'/><category term='Embed Problem'/><category term='javascript'/><category term='Send Email using Ruby'/><category term='MBean'/><category term='Result Transformer'/><category term='Tutorial'/><category term='velocity basic tutorial'/><category term='javacvs lib'/><category term='RMI and Tomcat'/><category term='generate actionscript from java classes'/><category term='jetty'/><category term='scalatra'/><category term='Webservice Tutorial using CXF'/><category term='JAX-WS'/><category term='Send SMS Using Ruby'/><category term='Outputstream writes the same object'/><category term='Spring'/><category term='Tabular Data'/><category term='Ruby on Rails'/><category term='dataTables'/><category term='JMS Message Listener'/><category term='Temporary and permanent queue'/><category term='using compc with with -include-file'/><category term='xdoclet2'/><category term='Return Types'/><category term='borders'/><category term='Generate Java code'/><category term='filtering collection'/><category term='actionscript generator'/><category term='AS generator'/><category term='Flex dragging components'/><category term='Gem proxy'/><category term='Using JMS with ActiveMQ'/><category term='Java Properties using &apos;:&apos; as key'/><category term='Underline cells'/><category term='mysql2'/><category term='Topic subscriber client'/><category term='Flex 3 issues with datagrid header'/><category term='Java'/><category term='actionscript code generator using xdoclet'/><category term='Lightstreamer Flex sample'/><category term='log4j'/><category term='pagination'/><category term='jquery'/><category term='Reflection'/><category term='Filtering Collections'/><category term='xdoclet2 plugin tutorial'/><category term='Ruby'/><category term='Properties'/><category term='log4j appender'/><category term='Pointcut'/><category term='Problem writing Object to outputstream'/><category term='Eager fetching in hibernate'/><category term='XSocket'/><category term='ajax javascript pagination'/><category term='JMS Consumer'/><category term='New ways to contribute towards saving nature'/><category term='msql2 error'/><title type='text'>Anonymity Re-Discovered!</title><subtitle type='html'>Java, JSP, Web Services using axis2, tcpmon with axis2, Hibernate, Excel vb scripting, Registry tweaks, Java decompilers, buddy spy, tor, privoxy, Flex, Active MQ, JMS, JExcel, j2ssh, xdoclet2, velocity, CXF webservice, AS3 Generator,JAX-WS, RMI, log4j, Lightstreamer, XSocket, AspectJ, JavaFX, JQuery, Ruby</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>57</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-36956413.post-4189086356774066923</id><published>2012-01-04T18:54:00.001-08:00</published><updated>2012-01-04T18:54:42.796-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jetty'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='scalatra'/><category scheme='http://www.blogger.com/atom/ns#' term='scala'/><title type='text'>Run Jetty in eclipse with scalatra</title><content type='html'>&lt;p&gt;Though this is very simple and straight forward, there is no direct answer to this question on internet. You can run any webapp in eclipse using this approach, not necessarily with scalatra. The code is available for Lift web framework and works well with scalatra too.&lt;/p&gt;  &lt;pre class="brush: scala; ruler: true; collapse: true;"&gt;import org.eclipse.jetty.server.Server&lt;br /&gt;import org.eclipse.jetty.webapp.WebAppContext&lt;br /&gt;&lt;br /&gt;object RunWebApp {&lt;br /&gt;  def main(args: Array[String]) {&lt;br /&gt;    val server = new Server(9080)&lt;br /&gt;    val context: WebAppContext = new WebAppContext();&lt;br /&gt;    context.setServer(server)&lt;br /&gt;    context.setContextPath(&amp;quot;/&amp;quot;);&lt;br /&gt;    context.setWar(&amp;quot;src/main/webapp&amp;quot;)&lt;br /&gt;    server.setHandler(context);&lt;br /&gt;&lt;br /&gt;    try {&lt;br /&gt;      println(&amp;quot;&amp;gt;&amp;gt;&amp;gt; STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP&amp;quot;)&lt;br /&gt;      server.start()&lt;br /&gt;      server.join()&lt;br /&gt;    } catch {&lt;br /&gt;      case ex: Exception =&amp;gt; {&lt;br /&gt;        ex.printStackTrace()&lt;br /&gt;        System.exit(1)&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-4189086356774066923?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/4189086356774066923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2012/01/run-jetty-in-eclipse-with-scalatra.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4189086356774066923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4189086356774066923'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2012/01/run-jetty-in-eclipse-with-scalatra.html' title='Run Jetty in eclipse with scalatra'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-3724737705490940</id><published>2011-11-02T16:43:00.001-07:00</published><updated>2011-11-02T16:47:31.425-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='Atmosphere'/><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='jquery'/><category scheme='http://www.blogger.com/atom/ns#' term='Streaming'/><title type='text'>Atmosphere with jquery tutorial to stream data to web browser</title><content type='html'>&lt;blockquote&gt;   &lt;p&gt;When I started to learn Atmosphere to do async server push to client I was overwhelmed with the available tutorials on the net! The blog at &lt;a href="http://jfarcand.wordpress.com/2010/06/15/using-atmospheres-jquery-plug-in-to-build-applicationsupporting-both-websocket-and-comet/" target="_blank"&gt;6312&lt;/a&gt; is the best but it had too much details. Not much patience to read, I just needed a really quick start and not a really long page with lot of details. So, Here is a short tutorial to the people of my kinds who just want to learn and implement server push fast and dirty. For more details and explanation see the blog I mentioned before.&lt;/p&gt;    &lt;p&gt;I am using atmosphere 0.7.2, tomcat 6, and JDK 6.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Download the sample jquery-pubsub-0.7.2.war from &lt;a href="https://oss.sonatype.org/content/repositories/releases/org/atmosphere/samples/atmosphere-pubsub/0.7.2/" target="_blank"&gt;here&lt;/a&gt; . Extract the war to a known directory. Copy the jars from the WEB-INF/lib to your webapp lib which needs the atmosphere support. Make sure that your application lib contains only one version of the jar. You do not want to find yourself troubleshooting problems due to multiple version of same jar in the classpath of your webcontainer.&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create a folder META-INF in the same level as WEB-INF in your application war. Create context.xml from the content shown below and put the same file in both META-INF and WEB-INF. &lt;/p&gt;   &lt;pre class="brush: xml; ruler: true; collapse: false;"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;Context&amp;gt;&lt;br /&gt;    &amp;lt;Loader delegate=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/Context&amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Put the below snippet in web.xml between web-app xml tag. Make sure to note the “/account/number” and “/atm/*” path provided. We will use this path “/atm/account/number” to subscribe from the server as shown later.&lt;/p&gt;&lt;br /&gt;  &lt;pre class="brush: xml; ruler: true; collapse: false;"&gt;&amp;lt;servlet&amp;gt;&lt;br /&gt;    &amp;lt;servlet-name&amp;gt;AtmosphereServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;    &amp;lt;description&amp;gt;AtmosphereServlet&amp;lt;/description&amp;gt;&lt;br /&gt;    &amp;lt;servlet-class&amp;gt;org.atmosphere.cpr.AtmosphereServlet&amp;lt;/servlet-class&amp;gt;&lt;br /&gt;    &amp;lt;init-param&amp;gt;&lt;br /&gt;        &amp;lt;param-name&amp;gt;grizzly.application.path&amp;lt;/param-name&amp;gt;&lt;br /&gt;        &amp;lt;param-value&amp;gt;/account/number&amp;lt;/param-value&amp;gt;&lt;br /&gt;    &amp;lt;/init-param&amp;gt;&lt;br /&gt;    &amp;lt;init-param&amp;gt;&lt;br /&gt;        &amp;lt;param-name&amp;gt;org.atmosphere.useWebSocket&amp;lt;/param-name&amp;gt;&lt;br /&gt;        &amp;lt;param-value&amp;gt;true&amp;lt;/param-value&amp;gt;&lt;br /&gt;    &amp;lt;/init-param&amp;gt;&lt;br /&gt;    &amp;lt;init-param&amp;gt;&lt;br /&gt;        &amp;lt;param-name&amp;gt;org.atmosphere.useNative&amp;lt;/param-name&amp;gt;&lt;br /&gt;        &amp;lt;param-value&amp;gt;true&amp;lt;/param-value&amp;gt;&lt;br /&gt;    &amp;lt;/init-param&amp;gt;&lt;br /&gt;    &amp;lt;init-param&amp;gt;&lt;br /&gt;        &amp;lt;param-name&amp;gt;org.atmosphere.cpr.broadcastFilterClasses&amp;lt;/param-name&amp;gt;&lt;br /&gt;        &amp;lt;param-value&amp;gt;org.atmosphere.client.FormParamFilter,org.atmosphere.client.JavascriptClientFilter&lt;br /&gt;        &amp;lt;/param-value&amp;gt;&lt;br /&gt;    &amp;lt;/init-param&amp;gt;&lt;br /&gt;    &amp;lt;load-on-startup&amp;gt;0&amp;lt;/load-on-startup&amp;gt;&lt;br /&gt;&amp;lt;/servlet&amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;pre class="brush: xml; ruler: true; collapse: false;"&gt;&amp;lt;servlet-mapping&amp;gt;&lt;br /&gt;    &amp;lt;servlet-name&amp;gt;AtmosphereServlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;    &amp;lt;url-pattern&amp;gt;/atm/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;lt;/servlet-mapping&amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; I would assume you know jquery. Create atm.js with the below code and add it to your collection of javascripts in war.&lt;/p&gt;&lt;br /&gt;  &lt;pre class="brush: js; ruler: true; collapse: true;"&gt;var topicSubs = 'all'&lt;br /&gt;var urlLocation = 'http://localhost:8080/mywebapp/atm/account/';&lt;br /&gt;&lt;br /&gt;var onData = function(data){&lt;br /&gt;    $('body').append(&amp;quot;Message Received: &amp;quot; + data);&lt;br /&gt;}&lt;br /&gt;var appSubscriber = function() {&lt;br /&gt;    var callbackAdded = false;&lt;br /&gt;&lt;br /&gt;    function subscribe() {&lt;br /&gt;        function callback(response) {                    &lt;br /&gt;            if (response.transport != 'polling' &amp;amp;&amp;amp; response.state != 'connected' &amp;amp;&amp;amp; response.state != 'closed') {                        &lt;br /&gt;                if (response.status == 200) {&lt;br /&gt;                    var data = response.responseBody;&lt;br /&gt;                    if (data.length &amp;gt; 0 &amp;amp;&amp;amp; data.search('--&amp;gt;')==-1) {&lt;br /&gt;                        onData(data);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;        $.atmosphere.subscribe(urlLocation + topicSubs, !callbackAdded ? callback : null,$.atmosphere.request = { transport: 'websocket' });&lt;br /&gt;        callbackAdded = true;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    subscribe();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;  &lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; In your html page subscribe using the below shown code. Make sure to include the above script atm.js in the page. Here, I am overriding the variables declared in the atm.js above with required values. See the path in urlLocation, http”//localhost:8080/mywebapp” is your application URL, “/atm” is for atmosphere servlet URL pattern, “/account” is for jersey as you will see in server side code in sext step, and “/8832221” which is added to the URL by atm.js code is used by the server code to push data for that account number.&lt;/p&lt;br /&gt;  &lt;pre class="brush: js; ruler: true; collapse: true;"&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;        $(document).ready(function(){&lt;br /&gt;           topicSubs = '8832221';&lt;br /&gt;           urlLocation = 'http://localhost:8080/mywebapp/atm/account/';&lt;br /&gt;           onData = function(data){&lt;br /&gt;                $('#content').append(&amp;quot;Message Received: &amp;quot; + data + &amp;quot;&amp;lt;/br&amp;gt;&amp;quot;);&lt;br /&gt;           };&lt;br /&gt;           appSubscriber();&lt;br /&gt;        });&lt;br /&gt;&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Now that we have the html UI ready, we can write the server side code. Note that the html page will get updates only those that are pushed using the below push method after the html page has loaded and subscribed using the JS above. If you need old updates, then you have to cache when the subscriber is not available for a account and if you need to make sure not some random person can access the data from others account number, then an auth token can be embedded in the subscription string with account number that can be validated. You can code these requirements in the EventsLogger class that has the callback hooks from the atmosphere when different events occur. Some of you may not get updates if you are using different applications talking to each other due to cross domain issue which is solved by adding a http header in the below shown code. If you look at the path annotation it maps the “/account/{topic}”, where the topic is the account number from the html page that is sent to subscribe. Push method also prints all the broadcasters available which are equal to the subscribers from the html and have the id as the name.&lt;/p&gt;&lt;br /&gt;  &lt;pre class="brush: java; ruler: true; collapse: true;"&gt;import org.atmosphere.cpr.*;&lt;br /&gt;import javax.servlet.http.HttpServletRequest;&lt;br /&gt;import javax.servlet.http.HttpServletResponse;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.*;&lt;br /&gt;import com.sun.jersey.spi.resource.Singleton;&lt;br /&gt;import javax.ws.rs.*;&lt;br /&gt;import javax.ws.rs.core.Context;&lt;br /&gt;&lt;br /&gt;import org.atmosphere.annotation.Broadcast;&lt;br /&gt;import org.atmosphere.annotation.Resume;&lt;br /&gt;import org.atmosphere.annotation.Suspend;&lt;br /&gt;import org.atmosphere.cpr.AtmosphereHandler;&lt;br /&gt;import org.atmosphere.jersey.Broadcastable;&lt;br /&gt;import org.atmosphere.jersey.JerseyBroadcaster;&lt;br /&gt;import org.atmosphere.jersey.SuspendResponse;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;@Path(&amp;quot;/account/{topic}&amp;quot;)&lt;br /&gt;@Produces(&amp;quot;text/html;charset=ISO-8859-1&amp;quot;)&lt;br /&gt;public class OurAtmosphereHandler{&lt;br /&gt;    private @PathParam(&amp;quot;topic&amp;quot;)&lt;br /&gt;    Broadcaster topic;&lt;br /&gt;&lt;br /&gt;    @GET&lt;br /&gt;    public SuspendResponse&amp;lt;String&amp;gt; subscribe(@Context HttpServletResponse httpResponse) {&lt;br /&gt;        httpResponse.addHeader(&amp;quot;Access-Control-Allow-Origin&amp;quot;,&amp;quot;*&amp;quot;);&lt;br /&gt;        return new SuspendResponse.SuspendResponseBuilder&amp;lt;String&amp;gt;()&lt;br /&gt;                .broadcaster(topic)&lt;br /&gt;                .outputComments(true)&lt;br /&gt;                .addListener(new EventsLogger())&lt;br /&gt;                .build();&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void push(String message, String topic){&lt;br /&gt;&lt;br /&gt;        Collection&amp;lt;Broadcaster&amp;gt; broadcasters = BroadcasterFactory.getDefault().lookupAll();&lt;br /&gt;&lt;br /&gt;        for(Broadcaster b : broadcasters){&lt;br /&gt;            System.out.println(b.toString());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        System.out.println(&amp;quot;Request to push- Message: &amp;quot; + message + &amp;quot;, Topic: &amp;quot; + topic);&lt;br /&gt;        Broadcaster b = null;&lt;br /&gt;        if(null != (b = BroadcasterFactory.getDefault().lookup(JerseyBroadcaster.class,topic))){&lt;br /&gt;            System.out.println(&amp;quot;Request to push- Message: &amp;quot; + message + &amp;quot;, Topic: &amp;quot; + topic);&lt;br /&gt;            b.broadcast(message + &amp;quot;\n&amp;quot;);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private class EventsLogger implements AtmosphereResourceEventListener {&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void onSuspend(AtmosphereResourceEvent&amp;lt;HttpServletRequest, HttpServletResponse&amp;gt; event) {&lt;br /&gt;            event.getResource().getResponse().addHeader(&amp;quot;Access-Control-Allow-Origin&amp;quot;,&amp;quot;*&amp;quot;);&lt;br /&gt;            System.out.println(&amp;quot;onSuspend(): &amp;quot; + event.getResource().getRequest().getRemoteAddr() + &amp;quot; : &amp;quot; +  event.getResource().getRequest().getRemoteHost());            &lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void onResume(AtmosphereResourceEvent&amp;lt;HttpServletRequest, HttpServletResponse&amp;gt; event) {&lt;br /&gt;            event.getResource().getResponse().addHeader(&amp;quot;Access-Control-Allow-Origin&amp;quot;,&amp;quot;*&amp;quot;);&lt;br /&gt;            System.out.println(&amp;quot;onResume(): &amp;quot; + event.getResource().getRequest().getRemoteAddr() + &amp;quot; : &amp;quot; +  event.getResource().getRequest().getRemoteHost());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void onDisconnect(AtmosphereResourceEvent&amp;lt;HttpServletRequest, HttpServletResponse&amp;gt; event) {            &lt;br /&gt;            System.out.println(&amp;quot;onDisconnect(): &amp;quot; + event.getResource().getRequest().getRemoteAddr() + &amp;quot; : &amp;quot; +  event.getResource().getRequest().getRemoteHost());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void onBroadcast(AtmosphereResourceEvent&amp;lt;HttpServletRequest, HttpServletResponse&amp;gt; event) {&lt;br /&gt;            event.getResource().getResponse().addHeader(&amp;quot;Access-Control-Allow-Origin&amp;quot;,&amp;quot;*&amp;quot;);&lt;br /&gt;            System.out.println(&amp;quot;onBroadcast(): &amp;quot; + event.getMessage());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void onThrowable(AtmosphereResourceEvent&amp;lt;HttpServletRequest, HttpServletResponse&amp;gt; event) {            &lt;br /&gt;            System.out.println(&amp;quot;onThrowable(): &amp;quot; + event);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;So, have fun using streaming technology using atmosphere. I would suggest using chrome as it supports websockets and is most reliable. You can use polling if working with other browsers. Just change the transport in the atm.js with “polling”. Atmosphere is an awesome technology and I would suggest to visit the blog 6312 that I mentioned in the beginning for more details and many different options and customization.&lt;/blockquote&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-3724737705490940?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/3724737705490940/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/11/atmosphere-with-jquery-tutorial-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/3724737705490940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/3724737705490940'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/11/atmosphere-with-jquery-tutorial-to.html' title='Atmosphere with jquery tutorial to stream data to web browser'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2397786284579254521</id><published>2011-09-21T18:28:00.001-07:00</published><updated>2011-11-02T16:56:04.189-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='Spring'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Solution for: Spring JMS + ActiveMQ + Tomcat = Tomcat does not shutdown</title><content type='html'>&lt;p&gt;This is one of the most frustrating problems. When you decide to use Tomcat with Spring JMS to connect and message with ActiveMQ, everything works fine till you try to shutdown Tomcat.&amp;#160; It keeps throwing exception and looks like the DefaultMessageListnerContainer thread lives on. As seen from the logs on tomcat console, the problem occurs because the tomcat shutsdown before the JMS Spring container “DefaultMessageListenerContainer” and you will see Nullpointer, Classnotfound exceptions, as tomcat container is down and the classloader doesn’t exist to give the necessary classes from the previously loaded jars. And I could not find a single solution on google. After, much googling I found a solution for a similar problem when using Quartz, tomcat and spring. So, this solution was derived from that one [Sorry, I don’t have that link anymore].&lt;/p&gt;  &lt;p&gt;Create a ServletContextListener, and in contextDestroyed method get the jms container bean to manually call shutdown. The listener contextInitialized and contextDestroyed are called at start and end of Servlet lifecycle. The below code assumes that you have a class called SpringApplicationContextInstance that gives you the spring context using which you can access your beans defined in spring context.&lt;/p&gt;  &lt;pre class="brush: java; ruler: true; collapse: true;"&gt;...&lt;br /&gt;import javax.servlet.ServletContextEvent;&lt;br /&gt;import javax.servlet.ServletContextListener;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * Created by Shreyas Purohit&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class JMSContainerShutDownHook implements ServletContextListener {&lt;br /&gt;    @Override&lt;br /&gt;    public void contextInitialized(ServletContextEvent servletContextEvent) {&lt;br /&gt;        LogManager.log(Level.INFO, &amp;quot;JMSContainerShutDownHook: Initialized called&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @Override&lt;br /&gt;    public void contextDestroyed(ServletContextEvent servletContextEvent) {&lt;br /&gt;        LogManager.log(Level.INFO, &amp;quot;JMSContainerShutDownHook: Destroyed called&amp;quot;);&lt;br /&gt;        try {&lt;br /&gt;            LogManager.log(Level.INFO, &amp;quot;JMSContainerShutDownHook: Fetching JMS Container Bean from Application Context&amp;quot;);&lt;br /&gt;            DefaultMessageListenerContainer container = SpringApplicationContextInstance.getInstance().getBean(&amp;quot;jmsContainer&amp;quot;);&lt;br /&gt;            LogManager.log(Level.INFO, &amp;quot;JMSContainerShutDownHook: Calling shutdown on DefaultMessageListenerContainer&amp;quot;);&lt;br /&gt;            container.shutdown();&lt;br /&gt;            Thread.sleep(3000); //Wait for the container to shutdown&lt;br /&gt;        } catch (Exception e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            LogManager.log(Level.ERROR, e);&lt;br /&gt;        }&lt;br /&gt;        LogManager.log(Level.INFO, &amp;quot;JMSContainerShutDownHook: Exiting&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2397786284579254521?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2397786284579254521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/solution-for-spring-jms-activemq-tomcat.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2397786284579254521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2397786284579254521'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/solution-for-spring-jms-activemq-tomcat.html' title='Solution for: Spring JMS + ActiveMQ + Tomcat = Tomcat does not shutdown'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-7507039608399413260</id><published>2011-09-14T12:50:00.001-07:00</published><updated>2011-09-14T12:52:17.661-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Performace Test'/><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMQ'/><title type='text'>ActiveMQ 5.5.0 performance test plugin</title><content type='html'>&lt;p&gt;It not very simple to apply the perf test instructions given at &lt;a href="http://activemq.apache.org/activemq-performance-module-users-manual.html"&gt;http://activemq.apache.org/activemq-performance-module-users-manual.html&lt;/a&gt; I encountered many problems, and here is a way to make it run.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Required: &lt;/strong&gt;Maven 2, SVN client like tortoise SVN&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Steps&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. &lt;/strong&gt;Checkout the source code for Active MQ 5.5.0 from SVN &lt;a title="http://svn.apache.org/repos/asf/activemq/tags/activemq-5.5.0" href="http://svn.apache.org/repos/asf/activemq/tags/activemq-5.5.0"&gt;http://svn.apache.org/repos/asf/activemq/tags/activemq-5.5.0&lt;/a&gt; to directory AMQ&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Checkout perf test code from SVN &lt;a title="http://svn.apache.org/repos/asf/activemq/sandbox/activemq-perftest/" href="http://svn.apache.org/repos/asf/activemq/sandbox/activemq-perftest/"&gt;http://svn.apache.org/repos/asf/activemq/sandbox/activemq-perftest/&lt;/a&gt; to directory AMQPerf&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; cd AMQ/activemq-tooling/maven-activemq-perf-plugin and edit pom.xml. Remove line &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt; from org.slf4j dependency.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;4. &lt;/strong&gt;cd AMQPerf and edit pom.xml. Change &amp;lt;version&amp;gt; in &amp;lt;parent&amp;gt; to 5.5.0&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;5. &lt;/strong&gt;cd AMQ/activemq-tooling and run “mvn clean install”&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;6. &lt;/strong&gt;cd AMQPerf and run “mvn clean install”&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;7. &lt;/strong&gt;Run Commands as provided in &lt;a title="http://activemq.apache.org/activemq-performance-module-users-manual.html" href="http://activemq.apache.org/activemq-performance-module-users-manual.html"&gt;http://activemq.apache.org/activemq-performance-module-users-manual.html&lt;/a&gt; from the AMQPerf directory in separate command prompts/Consoles, that is- &lt;/p&gt; &lt;pre&gt;Console1&amp;gt; mvn activemq-perf:consumer&lt;br /&gt;Console2&amp;gt; mvn activemq-perf:producer&lt;/pre&gt;&lt;br /&gt;This works for me perfectly.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-7507039608399413260?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/7507039608399413260/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/activemq-550-performance-test-plugin.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7507039608399413260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7507039608399413260'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/activemq-550-performance-test-plugin.html' title='ActiveMQ 5.5.0 performance test plugin'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-4946756061937379697</id><published>2011-09-12T20:26:00.000-07:00</published><updated>2011-09-12T20:29:40.484-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='msql2 error'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql2'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><title type='text'>Ruby On Rails mysql2 error</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I was having trouble installing mysql2 gem on my Win7 64 bit. I have copied these instructions from stackoverflow. And these really work.&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;b&gt;For Win 7:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 12px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class="post-text" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 5px; margin-left: 0px; margin-right: 5px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; width: 660px;"&gt;&lt;ol style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; line-height: 18px; list-style-image: initial; list-style-position: initial; list-style-type: decimal; margin-bottom: 1em; margin-left: 30px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;&lt;li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (&lt;a href="http://dev.mysql.com/downloads/mysql/5.1.html" rel="nofollow" style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; cursor: pointer; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none; vertical-align: baseline;"&gt;From here&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.&lt;/span&gt;&lt;/li&gt;&lt;li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;Extract all the files from the zip file into the folder you just created.&lt;/span&gt;&lt;/li&gt;&lt;li style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;now run this command&lt;/span&gt;&lt;/div&gt;&lt;div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;I just installed mysql2 gem v. 0.3.7&lt;/span&gt;&lt;/div&gt;&lt;div style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline; word-wrap: break-word;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;"&gt;EDIT:&lt;/span&gt;&amp;nbsp;One more thing: make sure you run the command in Command Prompt directly. As in not PowerShell or Consol2 - for some reason if you try that it will give you and error " invalid option" - has to do with the way -- is parsed.&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;i&gt;--Answered by&amp;nbsp;&lt;span class="Apple-style-span" style="background-color: white; line-height: 17px; white-space: nowrap;"&gt;Nick Gorbikoff&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;b&gt;For Linux:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="line-height: 18px;"&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="background-color: white; line-height: 17px; white-space: nowrap;"&gt;sudo apt-get install libmysql-ruby libmysqlclient-de&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: white; line-height: 17px; white-space: nowrap;"&gt;v&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;i&gt;--Answered by spacemonkey&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="background-color: white; font-family: Arial, Helvetica, sans-serif; line-height: 17px; white-space: nowrap;"&gt;I successfully installed mysql 5.5, and gem&amp;nbsp;mysql2-0.3.7&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-4946756061937379697?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/4946756061937379697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/ruby-on-rails-mysql2-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4946756061937379697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4946756061937379697'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/09/ruby-on-rails-mysql2-error.html' title='Ruby On Rails mysql2 error'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total><georss:featurename>Grapevine, TX, USA</georss:featurename><georss:point>32.9342919 -97.0780654</georss:point><georss:box>32.880984399999996 -97.1570294 32.9875994 -96.9991014</georss:box></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-482751048091448451</id><published>2011-08-31T14:39:00.000-07:00</published><updated>2011-08-31T14:41:30.290-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Gem proxy'/><category scheme='http://www.blogger.com/atom/ns#' term='Gem'/><title type='text'>Install Ruby gems when behind a proxy</title><content type='html'>There are many posts out there on the net instructing you to do certain thing when behind a proxy. Different things work for different people, but none of that worked for me. So, try this one if you are facing trouble with proxy too, and keep your fingers crossed! I am using Ruby 1.9.2, with gems version 1.7.2 on Windows 7. The below command allowed me to use proxy and download and install any gem.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;blockquote style="color: #38761d;"&gt;&lt;b&gt;gem install gemname -p http://username:password@proxyaddress:port --platform=ruby&lt;/b&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-482751048091448451?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/482751048091448451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/08/install-ruby-gems-when-behind-proxy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/482751048091448451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/482751048091448451'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/08/install-ruby-gems-when-behind-proxy.html' title='Install Ruby gems when behind a proxy'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total><georss:featurename>3701 Grapevine Mills Pkwy, Grapevine, TX 76051, USA</georss:featurename><georss:point>32.978716146003336 -97.03880310058594</georss:point><georss:box>32.925430146003336 -97.11776710058594 33.032002146003336 -96.95983910058594</georss:box></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-7437169132260699268</id><published>2011-08-25T05:11:00.001-07:00</published><updated>2011-08-25T18:18:04.332-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Send SMS'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby and Gmail'/><category scheme='http://www.blogger.com/atom/ns#' term='Send Email using Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Send SMS Online'/><category scheme='http://www.blogger.com/atom/ns#' term='Send SMS Using Ruby'/><title type='text'>Send SMS Using Ruby and Send Email using Ruby with Gmail SMTP Server</title><content type='html'>&lt;p&gt;There was a HP Touchpad sale event where HP tablets where being sold out for $99 yesterday. Instead of manually monitoring the HP website, I decided to write a small Ruby script that will monitor and send SMS and Email to notify. I wanted to use Gmail SMTP server for mail, but that does work by default with Ruby SMTP support as it uses TLS. Finally, I found a ruby script on the internet which provides that support. I have copy pasted it from that website. There are many scripts out there on web, but none really work with gmail. Hence, it is important to spread this script. To send SMS I use the free &lt;a title="http://www.textsurprise.com" href="http://www.textsurprise.com"&gt;http://www.textsurprise.com&lt;/a&gt; service by making GET request using open-uri. The best thing about Ruby syntax is, its readable and need no explanation. &lt;/p&gt; &lt;pre class="brush: ruby; ruler: true; collapse: true;"&gt;# Requests the HP page for 16GB Tablet URL:http://www.shopping.hp.com/product/rts_tablet/rts_tablet/1/storefronts/FB355UA%2523ABA?aoid=35252&lt;br /&gt;# If status &amp;quot;Coming soon&amp;quot; is not displayed then alert using SMS and email&lt;br /&gt;# SMS: http://www.textsurprise.com&lt;br /&gt;# Email: Uses gmail as sender smtp&lt;br /&gt;&lt;br /&gt;require 'open-uri'&lt;br /&gt;require 'net/smtp'&lt;br /&gt;require_relative 'smtp_tls'&lt;br /&gt;&lt;br /&gt;URL_16GB = 'http://www.shopping.hp.com/product/rts_tablet/rts_tablet/1/storefronts/FB355UA%2523ABA?aoid=35252'&lt;br /&gt;URL_32GB = 'http://www.shopping.hp.com/webapp/product/rts_tablet/rts_tablet/1/storefronts/FB359UA%2523ABA?aoid=35252'&lt;br /&gt;$carriers = {:auto =&amp;gt; 0, :att =&amp;gt; 3, :tmobile =&amp;gt; 11, :metropcs =&amp;gt; 12, :verizon =&amp;gt; 16, :virgin =&amp;gt; 21, :sprint =&amp;gt; 9}&lt;br /&gt;$numbers = {&amp;quot;XXXXXXXXXX&amp;quot; =&amp;gt; :att}&lt;br /&gt;$emails = [&amp;quot;xxxxxx@gmail.com&amp;quot;]&lt;br /&gt;$notInterestedStatuses = [&amp;quot;Coming soon&amp;quot;, &amp;quot;not found&amp;quot;, &amp;quot;outofstock&amp;quot;]&lt;br /&gt;$urls = {[URL_16GB,&amp;quot;HP_Website_16GB&amp;quot;,$notInterestedStatuses] =&amp;gt; false, [URL_32GB,&amp;quot;HP_Website_32GB&amp;quot;,$notInterestedStatuses] =&amp;gt; false}&lt;br /&gt;$running = true;&lt;br /&gt;$sleepTimeInSec = 240&lt;br /&gt;&lt;br /&gt;def send_email(to,subject,message)&lt;br /&gt;     username = 'xxxxxxxxx'&lt;br /&gt;     password = 'yyyyyyyyyy'&lt;br /&gt;     emailMessage = &amp;lt;&amp;lt;MESSAGE_END&lt;br /&gt;From: Shreyas Purohit &amp;lt;xxxxxxxxxx@gmail.com&amp;gt;&lt;br /&gt;To: #{to} &amp;lt;#{to}&amp;gt;&lt;br /&gt;Subject: #{subject}&lt;br /&gt;&lt;br /&gt;#{message}&lt;br /&gt;MESSAGE_END&lt;br /&gt;     &lt;br /&gt;     Net::SMTP.start(   'smtp.gmail.com' , &lt;br /&gt;                                  587, &lt;br /&gt;                                  'gmail.com', &lt;br /&gt;                                  username, &lt;br /&gt;                                  password, &lt;br /&gt;                                  'plain' ){ |smtp|&lt;br /&gt;        smtp.send_message(  emailMessage, &lt;br /&gt;                              &amp;quot;xxxxxxxxxx@gmail.com&amp;quot;, &lt;br /&gt;                                to)&lt;br /&gt;    }&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def readWebsite(url)  &lt;br /&gt;  uriContent = &amp;quot;&amp;quot;&lt;br /&gt;    open(url){|f| uriContent = f.read }&lt;br /&gt;  return uriContent  &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def notifyObservers(customMessage, url)&lt;br /&gt;        # Send SMS using URL        &lt;br /&gt;        $numbers.each do |key, value|          &lt;br /&gt;        open(&amp;quot;http://www.textsurprise.com/a.php?api=true&amp;amp;from=purohit@hotmail.com&amp;amp;phone=#{key.to_s}&amp;amp;amount=1&amp;amp;message=Check_HP_website_,_status_changed_#{customMessage}&amp;amp;carrier=#{$carriers[value].to_s}&amp;amp;data=0&amp;quot;){|f| &lt;br /&gt;            p f.read}        &lt;br /&gt;        end&lt;br /&gt;        &lt;br /&gt;        send_email($emails,&amp;quot;Alert- Website Update&amp;quot;,&amp;quot;Alert! Website Status Changed. Please Check Online (#{customMessage}) (#{url})&amp;quot;)&lt;br /&gt;         &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def checkStatusOnWebsiteString(uriContent, statusNotOfInterestOnSite)&lt;br /&gt;  statusNotOfInterestOnSite.each do |status|&lt;br /&gt;    if (uriContent.include? status)&lt;br /&gt;      return false&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  return true&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def logToFile(fileName, mode, content)&lt;br /&gt;  File.open(fileName, mode) {|f| f.write(content) }&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;def process(urls)  &lt;br /&gt;  checkedStatusOnce = false&lt;br /&gt;  statusChangedKeys = []&lt;br /&gt;  &lt;br /&gt;  urls.each do |key, status|&lt;br /&gt;    url = key[0];&lt;br /&gt;    customMessage = key[1];&lt;br /&gt;    if !status&lt;br /&gt;      checkedStatusOnce = true&lt;br /&gt;      p &amp;quot;#{Time.now} : Trying HP Site #{customMessage} Now...&amp;quot;&lt;br /&gt;      uriContent = readWebsite(url);&lt;br /&gt;      statusChanged = checkStatusOnWebsiteString(uriContent,key[2])&lt;br /&gt;      logToFile(&amp;quot;alter_#{customMessage}.log&amp;quot;, &amp;quot;w+&amp;quot;, &amp;quot;URI DATA AT &amp;quot; + Time.now.to_s + &amp;quot; for url #{url} \n&amp;quot; + uriContent)&lt;br /&gt;      if statusChanged&lt;br /&gt;        p &amp;quot;Status changed..(#{customMessage}) Notifying Observers..&amp;quot;&lt;br /&gt;        notifyObservers(customMessage, url)&lt;br /&gt;        statusChangedKeys &amp;lt;&amp;lt; key           &lt;br /&gt;      else&lt;br /&gt;        p &amp;quot;Status Not Changed... (#{customMessage})&amp;quot;&lt;br /&gt;      end      &lt;br /&gt;    end       &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  statusChangedKeys.each do |key|&lt;br /&gt;    urls[key] = true&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  if !checkedStatusOnce&lt;br /&gt;    $running = false&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;while $running do&lt;br /&gt;    p &amp;quot;#{Time.now} : Sleeping #{$sleepTimeInSec} sec(#{$sleepTimeInSec/60.0} min)...&amp;quot;&lt;br /&gt;    sleep($sleepTimeInSec)       &lt;br /&gt;    process($urls)&lt;br /&gt;end&lt;/pre&gt;&lt;br /&gt;Also, The script smtp_tls.rb is below that is required for the above script to run.&lt;br /&gt;&lt;pre class="brush: ruby; ruler: true; collapse: true;"&gt;require &amp;quot;openssl&amp;quot;&lt;br /&gt;require &amp;quot;net/smtp&amp;quot;&lt;br /&gt;&lt;br /&gt;Net::SMTP.class_eval do&lt;br /&gt;  private&lt;br /&gt;  def do_start(helodomain, user, secret, authtype)&lt;br /&gt;    raise IOError, 'SMTP session already started' if @started&lt;br /&gt;    check_auth_args user, secret, authtype if user or secret&lt;br /&gt;&lt;br /&gt;    sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }&lt;br /&gt;    @socket = Net::InternetMessageIO.new(sock)&lt;br /&gt;    @socket.read_timeout = 60 #@read_timeout&lt;br /&gt;    @socket.debug_output = STDERR #@debug_output&lt;br /&gt;&lt;br /&gt;    check_response(critical { recv_response() })&lt;br /&gt;    do_helo(helodomain)&lt;br /&gt;&lt;br /&gt;    raise 'openssl library not installed' unless defined?(OpenSSL)&lt;br /&gt;    starttls&lt;br /&gt;    ssl = OpenSSL::SSL::SSLSocket.new(sock)&lt;br /&gt;    ssl.sync_close = true&lt;br /&gt;    ssl.connect&lt;br /&gt;    @socket = Net::InternetMessageIO.new(ssl)&lt;br /&gt;    @socket.read_timeout = 60 #@read_timeout&lt;br /&gt;    @socket.debug_output = STDERR #@debug_output&lt;br /&gt;    do_helo(helodomain)&lt;br /&gt;&lt;br /&gt;    authenticate user, secret, authtype if user&lt;br /&gt;    @started = true&lt;br /&gt;  ensure&lt;br /&gt;    unless @started&lt;br /&gt;      # authentication failed, cancel connection.&lt;br /&gt;        @socket.close if not @started and @socket and not @socket.closed?&lt;br /&gt;      @socket = nil&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def do_helo(helodomain)&lt;br /&gt;     begin&lt;br /&gt;      if @esmtp&lt;br /&gt;        ehlo helodomain&lt;br /&gt;      else&lt;br /&gt;        helo helodomain&lt;br /&gt;      end&lt;br /&gt;    rescue Net::ProtocolError&lt;br /&gt;      if @esmtp&lt;br /&gt;        @esmtp = false&lt;br /&gt;        @error_occured = false&lt;br /&gt;        retry&lt;br /&gt;      end&lt;br /&gt;      raise&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def starttls&lt;br /&gt;    getok('STARTTLS')&lt;br /&gt;  end&lt;br /&gt;end&lt;/pre&gt;&lt;br /&gt;So, that’s it! Have fun reusing code!! &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-7437169132260699268?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/7437169132260699268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/08/send-sms-using-ruby-and-send-email.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7437169132260699268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7437169132260699268'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/08/send-sms-using-ruby-and-send-email.html' title='Send SMS Using Ruby and Send Email using Ruby with Gmail SMTP Server'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5856417472742360352</id><published>2011-07-26T14:33:00.000-07:00</published><updated>2011-08-10T14:43:57.033-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='JS Caching'/><category scheme='http://www.blogger.com/atom/ns#' term='ajax javascript pagination'/><category scheme='http://www.blogger.com/atom/ns#' term='pagination'/><category scheme='http://www.blogger.com/atom/ns#' term='dataTables'/><title type='text'>Using JS caching on serverside data with jquery datatables plugin</title><content type='html'>&lt;p&gt;First of all, I would like to say that I have been working on lots of stuff but have had no time to update this blog. Recently I was speaking with my friend who checks my blogs regularly, and was inspired to make some time and post stuff that is useful for many. So, here is one of the things that I worked on and pretty useful.&lt;/p&gt;  &lt;p&gt;Pagination is one of the most important concepts that must be implemented correctly for better performance of the database and that of your application. It is common sense to say that caching all the data on the server session is bad, or contacting database for every page is also bad; esp when working on tables with millions of records. The better alternative is to load and cache a good set of data on UI, and as and when needed update cache with more data. This removes caching done on server side, say in session, and negative performance impact that you get when you query database often while pagination. &lt;/p&gt;  &lt;p&gt;Many use jquery framework on javascript side. One of the plugins that I have worked with is datatables. Located at &lt;a href="http://www.datatables.net/"&gt;http://www.datatables.net/&lt;/a&gt; . There exist other frameworks like YUI for pagination and definitely other plugins for jquery framework for pagination. The datatables plugin works with server side data but does not provide good caching mechanism. Every new page is a request for getting data from the server to display that page. I wrote the below given javascript function that can be used with “fnServerData” option while initializing the datatables to provide caching.&lt;/p&gt;  &lt;pre class="brush: js; ruler: true; collapse: true;"&gt;var cache = new Object();&lt;br /&gt;var rowsToCache = 2000; //Minimum Cache size &amp;gt;(must) 2 * Maximum Display Length * Number of Navigation Button (Avoids false hits while traversing distant pages), Default Assumption: 2000 &amp;gt; 2 * 100 * 5&lt;br /&gt;//Intelligient to fetch only unfetched data. Maintains cache window to left(rowsToCache/2) and right(rowsToCache/2) of current position.&lt;br /&gt;&lt;br /&gt;var fnJSManagedCacheServer = &lt;br /&gt;function ( sSource, aoData, fnCallback ) {&lt;br /&gt;        //Get the required variable values&lt;br /&gt;        var _tableDispLength;&lt;br /&gt;        var _indexDisplayStart;&lt;br /&gt;        var _searchData;&lt;br /&gt;        var sEcho;&lt;br /&gt;        var _useCache = true;&lt;br /&gt;        var _bIsSearch = false;&lt;br /&gt;&lt;br /&gt;        for(var i in aoData){&lt;br /&gt;            var d = aoData[i];&lt;br /&gt;            if(d.name == 'iDisplayLength') {&lt;br /&gt;            _tableDispLength = d.value;&lt;br /&gt;            }&lt;br /&gt;            if(d.name == 'iDisplayStart') {&lt;br /&gt;            _indexDisplayStart = d.value;&lt;br /&gt;            }&lt;br /&gt;            if(d.name == 'sSearch'){&lt;br /&gt;            _searchData = d.value;&lt;br /&gt;            }&lt;br /&gt;            if(d.name == 'sEcho'){&lt;br /&gt;            sEcho = d.value;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        //Process all conditions that may result in a true call and not access cache&lt;br /&gt;        //Find if the call is result of only pagination and not because of search&lt;br /&gt;        if(_searchData != undefined &amp;amp;&amp;amp; _searchData != &amp;quot;&amp;quot;){&lt;br /&gt;            _useCache = false;&lt;br /&gt;            _bIsSearch = true;&lt;br /&gt;        }&lt;br /&gt;        //If cache doesnot exist&lt;br /&gt;        if(cache['aaDataServer'] == undefined){&lt;br /&gt;            _useCache = false;&lt;br /&gt;        }&lt;br /&gt;        //If _useCache is still true, try to get data from the cache, else allow call to server&lt;br /&gt;        //by setting _useCache to false&lt;br /&gt;        if(_useCache == true){&lt;br /&gt;            //Predict False hit&lt;br /&gt;            _useCache = false;&lt;br /&gt;&lt;br /&gt;            //Get data from cache and paint&lt;br /&gt;            //Does requested page end is lesser than or equal to cache endpage&lt;br /&gt;            if(_indexDisplayStart + _tableDispLength &amp;lt;= (cache.cached_indexDisplayStart + cache.realLength)&lt;br /&gt;                || cache.realLength &amp;lt; cache.requestedLength){//Last page and no more data present at server&lt;br /&gt;            //Does requested _indexDisplayStart is greater than or equal to cache _indexDisplayStart&lt;br /&gt;            if(_indexDisplayStart &amp;gt;= (cache.cached_indexDisplayStart)){&lt;br /&gt;                //Data must exist in cache&lt;br /&gt;                var json = cache['jsonResult'];&lt;br /&gt;                var aaData = cache['aaDataServer'].slice(Math.abs(cache.cached_indexDisplayStart - _indexDisplayStart), Math.abs(cache.cached_indexDisplayStart - _indexDisplayStart) + _tableDispLength &amp;lt; cache['aaDataServer'].length ? Math.abs(cache.cached_indexDisplayStart - _indexDisplayStart) + _tableDispLength : cache['aaDataServer'].length);&lt;br /&gt;                json.aaData = aaData;&lt;br /&gt;                json.sEcho = sEcho;&lt;br /&gt;                fnCallback(json);&lt;br /&gt;                //Cache hit&lt;br /&gt;                _useCache = true;&lt;br /&gt;            }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        if(_useCache == false){&lt;br /&gt;&lt;br /&gt;            //Get rowsToCache/2 from existing cache and save&lt;br /&gt;            var _prevCacheData = [];&lt;br /&gt;            var _movingRight = true;&lt;br /&gt;            if(cache.cached_indexDisplayStart != undefined){&lt;br /&gt;            if(_indexDisplayStart &amp;gt; cache.cached_indexDisplayStart){&lt;br /&gt;                _movingRight = true;&lt;br /&gt;            }else{&lt;br /&gt;                _movingRight = false;&lt;br /&gt;            }&lt;br /&gt;            if(_indexDisplayStart &amp;gt; cache.cached_indexDisplayStart&lt;br /&gt;                &amp;amp;&amp;amp; _indexDisplayStart == (cache.cached_indexDisplayStart + cache['aaDataServer'].length)){&lt;br /&gt;                _prevCacheData = cache['aaDataServer'].slice(cache['aaDataServer'].length - rowsToCache/2);&lt;br /&gt;            }else if(_indexDisplayStart &amp;lt;= cache.cached_indexDisplayStart&lt;br /&gt;                &amp;amp;&amp;amp; _indexDisplayStart == (cache.cached_indexDisplayStart - _tableDispLength)){&lt;br /&gt;                _prevCacheData = cache['aaDataServer'].slice(0, cache['aaDataServer'].length == rowsToCache ? rowsToCache/2 : 0);&lt;br /&gt;            }&lt;br /&gt;            }&lt;br /&gt;            //Invalidate and re-init cache&lt;br /&gt;            cache = new Object();&lt;br /&gt;            cache._tableDispLength = _tableDispLength;&lt;br /&gt;            cache._indexDisplayStart = _indexDisplayStart;&lt;br /&gt;            cache['aaDataServer'] = _prevCacheData;&lt;br /&gt;            cache._movingRight = _movingRight;&lt;br /&gt;&lt;br /&gt;            if(_bIsSearch != true){&lt;br /&gt;            //Modify settings of datatables to fetch rowsToCache records&lt;br /&gt;            cache.requestedLength = 0;&lt;br /&gt;            var _indexDisplayStartIsZero = false;&lt;br /&gt;            for(var i in aoData){&lt;br /&gt;                var d = aoData[i];&lt;br /&gt;                if(d.name == 'iDisplayStart') {&lt;br /&gt;                cache.requestedLength += d.value - (rowsToCache/2) &amp;gt;= 0 ? rowsToCache/2 : 0; //Order of these stmts important&lt;br /&gt;                if(cache._movingRight == false){&lt;br /&gt;                    d.value = (d.value+_tableDispLength) - (rowsToCache/2) &amp;gt;= 0 ? (d.value+_tableDispLength) - (rowsToCache/2) : 0; //Shift _indexDisplayStart to left by half cache page size (adding _tableDispLength to get the _indexDisplayStart to original location before taking it forward, else we will miss a page)&lt;br /&gt;                    cache.cached_indexDisplayStart = d.value;&lt;br /&gt;                }else{&lt;br /&gt;                    cache.cached_indexDisplayStart = d.value - _prevCacheData.length;&lt;br /&gt;                }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            for(var i in aoData){&lt;br /&gt;                var d = aoData[i];&lt;br /&gt;                if(d.name == 'iDisplayLength') {&lt;br /&gt;                d.value = cache.cached_indexDisplayStart != 0 ? rowsToCache/2 : rowsToCache/2;&lt;br /&gt;                cache.requestedLength = d.value; //Adjust cache fetch requested&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            }&lt;br /&gt;            cache._bIsSearch = _bIsSearch;&lt;br /&gt;            //Use ajax to Call&lt;br /&gt;            $.ajax( {&lt;br /&gt;            &amp;quot;dataType&amp;quot;: 'json',&lt;br /&gt;            &amp;quot;type&amp;quot;: &amp;quot;POST&amp;quot;,&lt;br /&gt;            &amp;quot;url&amp;quot;: sSource,&lt;br /&gt;            &amp;quot;data&amp;quot;: aoData,&lt;br /&gt;            &amp;quot;success&amp;quot;: function(json) {&lt;br /&gt;                //Cache&lt;br /&gt;                cache['jsonResult'] = json;&lt;br /&gt;                if(cache._movingRight == true){&lt;br /&gt;                cache['aaDataServer'] = cache['aaDataServer'].concat(json.aaData.slice(0));//append entire aaData to right of existing cached data&lt;br /&gt;                }else{&lt;br /&gt;                cache['aaDataServer'] = (json.aaData.slice(0)).concat(cache['aaDataServer']);//append entire aaData to left of existing cached data&lt;br /&gt;                }&lt;br /&gt;                cache.realLength = cache['aaDataServer'].length;&lt;br /&gt;                if(cache._bIsSearch != true){&lt;br /&gt;                //redraw a part of json, as requested between 0 and current pagesize(cache._tableDispLength)&lt;br /&gt;                    json.aaData = cache['aaDataServer'].slice(Math.abs(cache.cached_indexDisplayStart - cache._indexDisplayStart), cache.realLength &amp;lt; Math.abs(cache.cached_indexDisplayStart - cache._indexDisplayStart) + cache._tableDispLength ? cache.realLength : Math.abs(cache.cached_indexDisplayStart - cache._indexDisplayStart) + cache._tableDispLength);&lt;br /&gt;                }&lt;br /&gt;                fnCallback(json);&lt;br /&gt;            }&lt;br /&gt;            } );&lt;br /&gt;        }&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;To use this, just include the javascript, override “rowsToCache” if default is not appropriate for you, and set “fnServerData” : fnJSManagedCacheServer.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Do let me know if you find any bugs! &lt;/br&gt;&lt;br /&gt;PS: No caching when searching. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5856417472742360352?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5856417472742360352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/07/using-js-caching-on-serverside-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5856417472742360352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5856417472742360352'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2011/07/using-js-caching-on-serverside-data.html' title='Using JS caching on serverside data with jquery datatables plugin'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6095378058463947598</id><published>2010-10-22T15:22:00.001-07:00</published><updated>2010-10-22T15:51:13.642-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='javaFx'/><title type='text'>javaFx custom component– Line segment with arrowhead</title><content type='html'>&lt;p&gt;I have been working with javaFx for some time now for projects in School during my M.S tenure. I love the ease with which I can create new components. The only complain I have had till now is that it is not fast enough to handle really fast animations. It was very patchy when I worked with it in a project with multiple images/lines/rectangles on stage changing at rate of 200ms. It simply could not handle it. The Timeline class itself takes a moment in time hindering animations. Just a claim about Timeline with no proofs. Coming back to the problem, a line segment with arrowhead. A very trivial feature missing in javaFx and many people searching for a solution. Here is a custom component which does that exactly the same using CustomNode, Line and a Polygon.&lt;/p&gt;  &lt;pre class="brush: javafx;"&gt;import javafx.scene.shape.Line;&lt;br /&gt;import javafx.scene.CustomNode;&lt;br /&gt;import javafx.scene.Node;&lt;br /&gt;import javafx.scene.Group;&lt;br /&gt;import javafx.scene.shape.Polygon;&lt;br /&gt;import javafx.scene.paint.Paint;&lt;br /&gt;import javafx.scene.transform.Transform;&lt;br /&gt;import java.lang.Math;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author Shreyas Purohit&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;public class ArrowHeadLine extends CustomNode{&lt;br /&gt;    var group:Group;&lt;br /&gt;    public var x:Number;&lt;br /&gt;    public var y:Number;&lt;br /&gt;&lt;br /&gt;    public var startX:Number on replace{&lt;br /&gt;        handleChange();&lt;br /&gt;    };&lt;br /&gt;    public var startY:Number on replace{&lt;br /&gt;        handleChange();&lt;br /&gt;    };&lt;br /&gt;    public var endX:Number on replace{&lt;br /&gt;        handleChange();&lt;br /&gt;    };&lt;br /&gt;    public var endY:Number on replace{&lt;br /&gt;        handleChange();&lt;br /&gt;    };&lt;br /&gt;    public var fill:Paint;&lt;br /&gt;    public var stroke:Paint;&lt;br /&gt;&lt;br /&gt;    var arrowhead:Polygon;&lt;br /&gt;    var segment:Line;&lt;br /&gt;&lt;br /&gt;    override protected function create () : Node {&lt;br /&gt;        group = Group{&lt;br /&gt;            translateX: bind x;&lt;br /&gt;            translateY: bind y;&lt;br /&gt;            content:[&lt;br /&gt;                segment = Line{&lt;br /&gt;                    startX: bind startX&lt;br /&gt;                    startY: bind startY&lt;br /&gt;                    endX: bind endX&lt;br /&gt;                    endY: bind endY&lt;br /&gt;                    stroke: bind stroke;&lt;br /&gt;                },&lt;br /&gt;                arrowhead = Polygon{&lt;br /&gt;                    points :[-6,-6,&lt;br /&gt;                              0,0,&lt;br /&gt;                            -6,6];&lt;br /&gt;                    fill: bind fill;&lt;br /&gt;                }&lt;br /&gt;                ]&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    function handleChange():Void{&lt;br /&gt;        var angle:Number = Math.toDegrees(Math.atan2(endY-startY, endX-startX));&lt;br /&gt;        arrowhead.translateX = endX;&lt;br /&gt;        arrowhead.translateY = endY;&lt;br /&gt;        arrowhead.transforms = [Transform.rotate(angle,0,0)]&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6095378058463947598?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6095378058463947598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/10/javafx-custom-componentline-segment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6095378058463947598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6095378058463947598'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/10/javafx-custom-componentline-segment.html' title='javaFx custom component– Line segment with arrowhead'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6097148047992502995</id><published>2010-10-18T21:34:00.001-07:00</published><updated>2010-10-18T21:36:21.649-07:00</updated><title type='text'>Betwixt and List/ArrayList</title><content type='html'>&lt;p&gt;I just can not imagine wasting 3-4 hours to just make Betwixt from Apache (&lt;a title="http://commons.apache.org/betwixt/index.html" href="http://commons.apache.org/betwixt/index.html"&gt;http://commons.apache.org/betwixt/index.html&lt;/a&gt;) work with List and ArrayList in my java beans. Betwixt simply does not work with List/ArrayList when converting from XML to java bean unless I stop using List/ArrayList completely and replace them with arrays or the solution that I used – create a .betwixt file to configure its use. If you adopt the first option then I found out that if I have 2 array types defined in my class then a weird ClassCastException to java.util.List was being encountered. I finally successfully used List/ArrayList in my class.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Steps&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;1. Define the class say, Info – java bean – to be serialized to XML and back using List/ArrayList as shown. Note the last two methods – addRouteInfo and addEntityInfo. These are the key methods to be added to your java bean.&lt;/p&gt;&lt;pre class="brush: java;"&gt;package com.ssb.repo;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.Map;&lt;br /&gt;/**&lt;br /&gt; * @author Shreyas P&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class Info {&lt;br /&gt;    private String siteId;&lt;br /&gt;    private String applicationId;&lt;br /&gt;    private List&amp;lt;RouteInfo&amp;gt; routeInfos = new ArrayList&amp;lt;RouteInfo&amp;gt;();&lt;br /&gt;    private List&amp;lt;EntityInfo&amp;gt; entityInfos = new ArrayList&amp;lt;EntityInfo&amp;gt;();&lt;br /&gt;    &lt;br /&gt;    public Info(){&lt;br /&gt;        &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    /**&lt;br /&gt;     * @return the siteId&lt;br /&gt;     */&lt;br /&gt;    public String getSiteId() {&lt;br /&gt;        return siteId;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @param siteId the siteId to set&lt;br /&gt;     */&lt;br /&gt;    public void setSiteId(String siteId) {&lt;br /&gt;        this.siteId = siteId;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @return the applicationId&lt;br /&gt;     */&lt;br /&gt;    public String getApplicationId() {&lt;br /&gt;        return applicationId;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @param applicationId the applicationId to set&lt;br /&gt;     */&lt;br /&gt;    public void setApplicationId(String applicationId) {&lt;br /&gt;        this.applicationId = applicationId;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @return the entityInfos&lt;br /&gt;     */&lt;br /&gt;    public List&amp;lt;EntityInfo&amp;gt; getEntityInfos() {&lt;br /&gt;        return entityInfos;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @param entityInfos the entityInfos to set&lt;br /&gt;     */&lt;br /&gt;    public void setEntityInfos(List&amp;lt;EntityInfo&amp;gt; entityInfos) {&lt;br /&gt;        this.entityInfos = entityInfos;&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * @return the routeInfos&lt;br /&gt;     */&lt;br /&gt;    public List&amp;lt;RouteInfo&amp;gt; getRouteInfos() {&lt;br /&gt;        return routeInfos;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * @param routeInfos the routeInfos to set&lt;br /&gt;     */&lt;br /&gt;    public void setRouteInfos(List&amp;lt;RouteInfo&amp;gt; routes) {&lt;br /&gt;        this.routeInfos = routes;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void addRouteInfo(RouteInfo routeInfo) {&lt;br /&gt;        routeInfos.add(routeInfo);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public void addEntityInfo(EntityInfo entityInfo) {&lt;br /&gt;        entityInfos.add(entityInfo);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;2. Create .betwixt file naming &amp;lt;classname&amp;gt;.betwixt. In our case, Info.betwixt. Betwixt automatically uses this file and need not be supplied as an argument to any function. Just place the file along with your class file. Note the ‘updates’ attribute, they link to the method to be used to add to the list/arraylist. Do not forget to put ‘addDefaults’ element which is responsible for generating all the remaining attributes.&lt;/p&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;?xml version='1.0'?&amp;gt;&lt;br /&gt;&amp;lt;info&amp;gt;&lt;br /&gt;    &amp;lt;element name='Info'&amp;gt;&lt;br /&gt;        &amp;lt;element name='routeInfos'&amp;gt;&lt;br /&gt;            &amp;lt;element name='routeInfo' property='routeInfos' updater='addRouteInfo'/&amp;gt;&lt;br /&gt;        &amp;lt;/element&amp;gt;&lt;br /&gt;        &amp;lt;element name='entityInfos'&amp;gt;&lt;br /&gt;            &amp;lt;element name='entityInfo' property='entityInfos' updater='addEntityInfo'/&amp;gt;&lt;br /&gt;        &amp;lt;/element&amp;gt;&lt;br /&gt;        &amp;lt;addDefaults/&amp;gt;&lt;br /&gt;    &amp;lt;/element&amp;gt;&lt;br /&gt;&amp;lt;/info&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;3. Create .betwixt files for any class using list/arraylist as there attributes.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;That’s all folks. Hopefully, this will save some time and effort to many. I had to dig through Betwixt testcases to come up with this along with the documents on there website.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6097148047992502995?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6097148047992502995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/10/betwixt-and-listarraylist.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6097148047992502995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6097148047992502995'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/10/betwixt-and-listarraylist.html' title='Betwixt and List/ArrayList'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2856076087771338980</id><published>2010-08-14T03:04:00.001-07:00</published><updated>2010-08-14T03:05:30.837-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AspectJ'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Pointcut'/><title type='text'>AspectJ - Pointcut and Advices for methods with more than one arguments</title><content type='html'>I am still doing my Masters in computer science and have worked on many new technologies like javaFX, Jasper Reports etc. But, I have not had time to update my blog on any of these. I was working on AspectJ for another project for my course, only to realize that Google is not able to find a blog that provides me the syntax to use Poitcut with parameters when there are more than one arguments to a method for which the join point is being defined. After lot of frustration, I found the solution in trial and error method. The AspectJ documentation only provides the trivial examples with functions having one arguments, for example - a setter. I went through a AOP textbook and even that failed to provide me this solution. Hopefully, this piece of information will come in Google search if anyone is searching solution of exact or similar problem.  Since, its my school project I cant put the real code and project on the blog. I will consider a dummy situation here. Lets say that there exists a Class named Transaction, and there exist a method doInsert as shown below.  &lt;pre class="brush: java; collapse: false;"&gt;&lt;br /&gt;public class Transaction{&lt;br /&gt;    public Boolean doInsert(Integer accountNumber, Double amount){&lt;br /&gt;        //.&lt;br /&gt;        //.&lt;br /&gt;        //.&lt;br /&gt;        return boolVal;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To define a point cut for the same, the below aspect can be used.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: java; collapse: false;"&gt;&lt;br /&gt;&lt;br /&gt;public aspect TransactionAspect {&lt;br /&gt;	pointcut t1(Transaction t, Integer accountNumber) : &lt;br /&gt;		target(t) &amp;&amp; args(accountNumber,..) &amp;&amp;  &lt;br /&gt;			execution(* *(Integer,..));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;	before(Transaction t, Integer accountNumber) : t1(t, accountNumber){&lt;br /&gt;		if(!isDoAbleForAccount(t,accountNumber)){&lt;br /&gt;			throw new RuntimeException("Error : Detected error before transacting");&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	private boolean isDoAbleForAccount(Transaction t,Integer accountNumber){&lt;br /&gt;	//&lt;br /&gt;	//&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above aspect defines a pointcut named t1 with 2 parameters. The first parameter is the Transaction object itself which is the target object in execution, the second parameter is an Integer account number that is passed as an argument to the doInsert method. Note the syntax of the "args" in the pointcut. It has one to one mapping to the execution pattern "* *(Integer,..)" which defines any method, with any return value, but 1st argument as Integer and any number of remaining argument. The before advice uses this pointcut, and the remaing code is just not that important.&lt;br /&gt;&lt;br /&gt;There is a one to one mapping for arguments between the "args" and the pattern used to select method's from a target object. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2856076087771338980?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2856076087771338980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/08/aspectj-pointcut-and-advices-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2856076087771338980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2856076087771338980'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2010/08/aspectj-pointcut-and-advices-for.html' title='AspectJ - Pointcut and Advices for methods with more than one arguments'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6499870440274901437</id><published>2009-08-28T22:48:00.001-07:00</published><updated>2009-08-28T22:51:54.508-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Listener and Builders in javacvs'/><category scheme='http://www.blogger.com/atom/ns#' term='CVS'/><category scheme='http://www.blogger.com/atom/ns#' term='javacvs lib'/><category scheme='http://www.blogger.com/atom/ns#' term='FileInfoEvent'/><category scheme='http://www.blogger.com/atom/ns#' term='Log information of CVS in java'/><title type='text'>javacvs – Netbeans lib to access CVS in java, Tutorial</title><content type='html'>&lt;p&gt;Well, I din expect i will have a topic to write so soon after join for MS course. But, thanks to Dr. Li I had a chance to work with java again!!! I love java! So, here goes a tutorial which explains how to use javacvs lib. &lt;/p&gt;  &lt;p&gt;I will explain important snippets here, will provide the complete source at the end of the tutorial.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: &lt;/strong&gt;Create the CVS Root object defining the meta data such as username, host etc To do this, we have to read the CVS/Root file. &lt;pre class="brush: java;"&gt;File root = new File(cvsPath + PATH_DELIM + cvsRoot);        &lt;br /&gt;    if(true == root.exists()){&lt;br /&gt;            BufferedReader bufferedReader = new BufferedReader(new FileReader(root));&lt;br /&gt;            if(null != bufferedReader){&lt;br /&gt;                System.out.println(MSG_CAPTURE_CVS_DETAIL);&lt;br /&gt;                String cvsRootData = bufferedReader.readLine();&lt;br /&gt;                CVSRoot rootData = CVSRoot.parse(cvsRootData);//Create the CVS Root object defining the meta data such as username, host etc&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2: &lt;/strong&gt;Set the global options, needed for executing commands.&lt;br /&gt;&lt;pre class="brush: java;"&gt;GlobalOptions globalOptions = new GlobalOptions();&lt;br /&gt;globalOptions.setCVSRoot(cvsRootData);&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 3: &lt;/strong&gt;Obtain the connection with the credentials and the details provided and then open the connection.&lt;br /&gt;&lt;pre class="brush: java;"&gt;PServerConnection connection = new PServerConnection(rootData);&lt;br /&gt;connection.open();&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Create a client that can execute the cvs log command, and register the listener to be invoked for CVS outputs. The loglistener is explained at the end.&lt;br /&gt;&lt;pre class="brush: java;"&gt;Client client = new Client(connection, new StandardAdminHandler());     &lt;br /&gt;client.setLocalPath(cvsPath);&lt;br /&gt;client.getEventManager().addCVSListener(new LogListener());&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 5: &lt;/strong&gt;The log command that does the job of getting the log for every file in the directory. The log builder is responsible to invoke fileinfo events on the loglistener.&lt;br /&gt;&lt;pre class="brush: java;"&gt;LogCommand command = new LogCommand();&lt;br /&gt;command.setRecursive(true);&lt;br /&gt;Builder builder = new LogBuilder(client.getEventManager(), command);&lt;br /&gt;command.setBuilder(builder);&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 6: &lt;/strong&gt;Initialize the writers, and execute the command, close the writers..&lt;br /&gt;&lt;pre class="brush: java;"&gt;xl = new File(F_OUTPUT_CSV);&lt;br /&gt;xlWriter = new BufferedWriter(new FileWriter(xl));&lt;br /&gt;xlWriter.write(HEADER);&lt;br /&gt;client.executeCommand(command, globalOptions);&lt;br /&gt;xlWriter.close();&lt;br /&gt;bufferedReader.close();&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;LogListener&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;It extends BasicListener, and overrides the messageSent with an empty definition. It also overrides the fileInfoGenerated method, where the actual processing of each file is done. That is log each of&amp;#160; file. The snippet is below.&lt;br /&gt;&lt;pre class="brush: java;"&gt;//Handle control to Super class.&lt;br /&gt; super.fileInfoGenerated(fileinfoevent);&lt;br /&gt;            &lt;br /&gt;//Get the log information for the current file event.&lt;br /&gt;LogInformation infoContainer = (LogInformation) fileinfoevent.getInfoContainer();&lt;br /&gt;try {&lt;br /&gt;    //Log to Excel in csv format.&lt;br /&gt;    logToExcel(infoContainer);&lt;br /&gt;} catch (IOException e) {&lt;br /&gt;    //Just print trace, and try logging the next file event.&lt;br /&gt;    e.printStackTrace();&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;logToExcel is a simple method that writes the log to the file. The datastructure LogInformation has data related to the file being processed, all the revisions of the file, head revision, the message associated with each revision and lot of more details. I use only the ones I mentioned.&lt;br /&gt;The complete code including the LogListener is below. Ignore the logic that is being done at logToExcel method, that some thing related to my work. But, the goal is to know that fileInfoEvent has LogInformation, that can be used to see data. You can write different listeners, builders in the similar way.&lt;br /&gt;&lt;pre class="brush: java; collapse: true;"&gt;/**&lt;br /&gt; * &lt;br /&gt; */&lt;br /&gt;package com.ssb.nb.cvs;&lt;br /&gt;/*&lt;br /&gt; * Java SE Packages&lt;br /&gt; */&lt;br /&gt;import java.io.BufferedReader;&lt;br /&gt;import java.io.BufferedWriter;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt;import java.io.FileReader;&lt;br /&gt;import java.io.FileWriter;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.Properties;&lt;br /&gt;import java.util.StringTokenizer;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; * Java CVS Packages&lt;br /&gt; */&lt;br /&gt;import org.netbeans.lib.cvsclient.CVSRoot;&lt;br /&gt;import org.netbeans.lib.cvsclient.Client;&lt;br /&gt;import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.Builder;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.CommandException;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.GlobalOptions;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.log.LogBuilder;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.log.LogCommand;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.log.LogInformation;&lt;br /&gt;import org.netbeans.lib.cvsclient.command.log.LogInformation.Revision;&lt;br /&gt;import org.netbeans.lib.cvsclient.commandLine.BasicListener;&lt;br /&gt;import org.netbeans.lib.cvsclient.connection.AuthenticationException;&lt;br /&gt;import org.netbeans.lib.cvsclient.connection.PServerConnection;&lt;br /&gt;import org.netbeans.lib.cvsclient.event.FileInfoEvent;&lt;br /&gt;import org.netbeans.lib.cvsclient.event.MessageEvent;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author Shreyas Purohit&lt;br /&gt; *&lt;br /&gt; */&lt;br /&gt;public class NBCvs {&lt;br /&gt;    /*&lt;br /&gt;     * Private Static variables&lt;br /&gt;     */&lt;br /&gt;    private static File xl;&lt;br /&gt;    private static BufferedWriter xlWriter;&lt;br /&gt;    private static String cvsPath = &amp;quot;F:/EWorkspace/org.eclipse.core.commands&amp;quot;;&lt;br /&gt;    private static String F_OUTPUT_CSV = &amp;quot;F:/output.csv&amp;quot;;&lt;br /&gt;    &lt;br /&gt;    /*&lt;br /&gt;     * Private Constants &lt;br /&gt;     */&lt;br /&gt;    private static final String APP_NAME = &amp;quot;CVS2l : &amp;quot;;&lt;br /&gt;    private static final String MSG_METHOD = &amp;quot; method: &amp;quot;;&lt;br /&gt;    private static final String MSG_USERNAME = &amp;quot; username: &amp;quot;;&lt;br /&gt;    private static final String MSG_REPOSITORY = &amp;quot; repository: &amp;quot;;&lt;br /&gt;    private static final String MSG_PORT = &amp;quot; port: &amp;quot;;&lt;br /&gt;    private static final String MSG_HOST = &amp;quot;Using host: &amp;quot;;&lt;br /&gt;    private static final String cvsRoot = &amp;quot;CVS/Root&amp;quot;;&lt;br /&gt;    private static final String PATH_DELIM = &amp;quot;/&amp;quot;;&lt;br /&gt;    private static final String MSG_EXIT_SUCCESS = APP_NAME + &amp;quot;Completed sucessfully, terminating process.&amp;quot;;&lt;br /&gt;    private static final String MSG_EXEC_LOG = APP_NAME + &amp;quot;Executing log command&amp;quot;;&lt;br /&gt;    private static final String MSG_INIT_OUTPUT = APP_NAME + &amp;quot;Initializing output file&amp;quot;;&lt;br /&gt;    private static final String MSG_CONNECTING_CVS = APP_NAME + &amp;quot;Connecting to CVS&amp;quot;;&lt;br /&gt;    private static final String MSG_CAPTURE_CVS_DETAIL = APP_NAME + &amp;quot;Capturing CVS metadata&amp;quot;;&lt;br /&gt;    private static final String MSG_LOADED_PROP = APP_NAME + &amp;quot;Loaded required properties&amp;quot;;&lt;br /&gt;    private static final String MSG_PROP_NOT_READABLE = APP_NAME + &amp;quot;Could not read tool.properties, make sure it is not being used by some other application&amp;quot;;&lt;br /&gt;    private static final String MSG_EXITING = APP_NAME + &amp;quot;Exiting..&amp;quot;;&lt;br /&gt;    private static final String MSG_PROP_NOT_FOUND = APP_NAME + &amp;quot;Could not find tool.properties, make sure it exists in same directory as the cvs2l.jar&amp;quot;;&lt;br /&gt;    private static final String TOOL_PROPERTIES = &amp;quot;tool.properties&amp;quot;;&lt;br /&gt;    private static final String MSG_INIT = APP_NAME + &amp;quot;Initializing&amp;quot;;&lt;br /&gt;    private static final String HEADER = &amp;quot;File Name,Package,Revision,Bug no.,Description\n&amp;quot;;&lt;br /&gt;    &lt;br /&gt;    /*&lt;br /&gt;     * Static block to load properties.&lt;br /&gt;     */&lt;br /&gt;    static{&lt;br /&gt;        System.out.println(MSG_INIT);&lt;br /&gt;        Properties prop = new Properties();&lt;br /&gt;        try {&lt;br /&gt;            prop.load(new FileInputStream(TOOL_PROPERTIES));&lt;br /&gt;        } catch (FileNotFoundException e) {&lt;br /&gt;            System.out.println(MSG_PROP_NOT_FOUND);&lt;br /&gt;            splashExitMsg();&lt;br /&gt;            systemExit();&lt;br /&gt;        } catch (IOException e) {&lt;br /&gt;            System.out.println(MSG_PROP_NOT_READABLE);&lt;br /&gt;            splashExitMsg();&lt;br /&gt;            systemExit();&lt;br /&gt;        }&lt;br /&gt;        cvsPath = prop.getProperty(&amp;quot;CVS_PATH&amp;quot;);&lt;br /&gt;        F_OUTPUT_CSV = prop.getProperty(&amp;quot;OUTPUT&amp;quot;);&lt;br /&gt;        System.out.println(MSG_LOADED_PROP);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    /**&lt;br /&gt;     * Displays exit message&lt;br /&gt;     */&lt;br /&gt;    private static void splashExitMsg() {&lt;br /&gt;        System.out.println(MSG_EXITING);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * Exits system&lt;br /&gt;     */&lt;br /&gt;    private static void systemExit() {&lt;br /&gt;        System.exit(1);&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    /**&lt;br /&gt;     * @param args&lt;br /&gt;     * @throws IOException &lt;br /&gt;     * @throws FileNotFoundException &lt;br /&gt;     * @throws AuthenticationException &lt;br /&gt;     * @throws CommandException &lt;br /&gt;     */&lt;br /&gt;    public static void main(String[] args) throws FileNotFoundException, IOException, AuthenticationException, CommandException {&lt;br /&gt;        /*&lt;br /&gt;         * Get the path to the CVS Root folder, connect to CVS and execute the log command to retrieve the &lt;br /&gt;         * file revision, package, bug number and description. &lt;br /&gt;         */&lt;br /&gt;        File root = new File(cvsPath + PATH_DELIM + cvsRoot);        &lt;br /&gt;        if(true == root.exists()){&lt;br /&gt;            BufferedReader bufferedReader = new BufferedReader(new FileReader(root));&lt;br /&gt;            if(null != bufferedReader){&lt;br /&gt;                System.out.println(MSG_CAPTURE_CVS_DETAIL);&lt;br /&gt;                String cvsRootData = bufferedReader.readLine();&lt;br /&gt;                CVSRoot rootData = CVSRoot.parse(cvsRootData);//Create the CVS Root object defining the meta data such as username, host etc&lt;br /&gt;                &lt;br /&gt;                GlobalOptions globalOptions = new GlobalOptions();&lt;br /&gt;                globalOptions.setCVSRoot(cvsRootData); //Set the global options, needed for executing commands.&lt;br /&gt;&lt;br /&gt;                System.out.println(APP_NAME + MSG_HOST + rootData.getHostName() + MSG_PORT + rootData.getPort() + MSG_REPOSITORY + rootData.getRepository() + MSG_USERNAME + rootData.getUserName() + MSG_METHOD + rootData.getMethod());&lt;br /&gt;                System.out.println(MSG_CONNECTING_CVS);&lt;br /&gt;                PServerConnection connection = new PServerConnection(rootData);// Obtain the connection with the credentials and the details provided.&lt;br /&gt;                connection.open(); //Open the connection.&lt;br /&gt;                &lt;br /&gt;                /*&lt;br /&gt;                 * Create a client that can execute the cvs log command, and register the listener to be invoked for CVS outputs.&lt;br /&gt;                 */&lt;br /&gt;                Client client = new Client(connection, new StandardAdminHandler());     &lt;br /&gt;                client.setLocalPath(cvsPath);&lt;br /&gt;                client.getEventManager().addCVSListener(new LogListener());&lt;br /&gt;                &lt;br /&gt;                /*&lt;br /&gt;                 * The log command that does the job of getting the log for every file in the&lt;br /&gt;                 * directory.&lt;br /&gt;                 * The log builder is responsible to invoke fileinfo events on the loglistner.&lt;br /&gt;                 */&lt;br /&gt;                LogCommand command = new LogCommand();&lt;br /&gt;                command.setRecursive(true);&lt;br /&gt;                Builder builder = new LogBuilder(client.getEventManager(), command);&lt;br /&gt;                command.setBuilder(builder);&lt;br /&gt;                &lt;br /&gt;                /*&lt;br /&gt;                 * Initialize the writers, and execute the command, close the writers..&lt;br /&gt;                 */&lt;br /&gt;                System.out.println(MSG_INIT_OUTPUT);&lt;br /&gt;                xl = new File(F_OUTPUT_CSV);&lt;br /&gt;                xlWriter = new BufferedWriter(new FileWriter(xl));&lt;br /&gt;                xlWriter.write(HEADER);&lt;br /&gt;                System.out.println(MSG_EXEC_LOG);&lt;br /&gt;                client.executeCommand(command, globalOptions);&lt;br /&gt;                xlWriter.close();&lt;br /&gt;                bufferedReader.close();&lt;br /&gt;                System.out.println(MSG_EXIT_SUCCESS);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    /**&lt;br /&gt;     * The Listener class for the log command to be executed.&lt;br /&gt;     * &lt;br /&gt;     * @author Shreyas Purohit&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    public static class LogListener extends BasicListener{&lt;br /&gt;        private static final String DOT_STR = &amp;quot;.&amp;quot;;&lt;br /&gt;        /*&lt;br /&gt;         * Private static constants.&lt;br /&gt;         */&lt;br /&gt;        private static final String BUG_FOLLOWED_SPACE_STR = &amp;quot;Bug &amp;quot;;&lt;br /&gt;        private static final String BUG_STR = &amp;quot;Bug&amp;quot;;&lt;br /&gt;        private static final String SPACE = &amp;quot; &amp;quot;;&lt;br /&gt;        private static final String NEW_LINE = &amp;quot;\n&amp;quot;;&lt;br /&gt;        private static final String DOUBLE_COMMA = &amp;quot;,,&amp;quot;;&lt;br /&gt;        private static final String COMMA_STR = &amp;quot;,&amp;quot;;&lt;br /&gt;        private static final String EMPTY_STR = &amp;quot;&amp;quot;;&lt;br /&gt;        private static final String JAVA_STR = &amp;quot;java&amp;quot;;&lt;br /&gt;        private static final String SRC_STR = &amp;quot;src&amp;quot;;&lt;br /&gt;        private static final String BACKSLASH = &amp;quot;\\&amp;quot;;&lt;br /&gt;        private static final String SRC = &amp;quot;\\src\\&amp;quot;;&lt;br /&gt;&lt;br /&gt;        @Override&lt;br /&gt;        public void messageSent(MessageEvent e) {&lt;br /&gt;            /*&lt;br /&gt;             * Override the super class, so as to prevent from logging to console.&lt;br /&gt;             */&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        @Override&lt;br /&gt;        public void fileInfoGenerated(FileInfoEvent fileinfoevent) {&lt;br /&gt;            //Handle control to Super class.&lt;br /&gt;            super.fileInfoGenerated(fileinfoevent);&lt;br /&gt;            &lt;br /&gt;            //Get the log information for the current file event.&lt;br /&gt;            LogInformation infoContainer = (LogInformation) fileinfoevent.getInfoContainer();&lt;br /&gt;            try {&lt;br /&gt;                //Log to Excel in csv format.&lt;br /&gt;                logToExcel(infoContainer);&lt;br /&gt;            } catch (IOException e) {&lt;br /&gt;                //Just print trace, and try logging the next file event.&lt;br /&gt;                e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        public void logToExcel(LogInformation info) throws IOException{&lt;br /&gt;            System.out.print(NEW_LINE);&lt;br /&gt;            System.out.println(&amp;quot;------------------Processing---------------------------&amp;quot;);&lt;br /&gt;            System.out.println(&amp;quot;File : &amp;quot; + info.getRepositoryFilename());&lt;br /&gt;            System.out.println(&amp;quot;Available Revisions...&amp;quot;);&lt;br /&gt;            &lt;br /&gt;            String path = info.getFile().getPath();&lt;br /&gt;            String strPackage = EMPTY_STR;&lt;br /&gt;            /*&lt;br /&gt;             * Extract package information from the path information. &lt;br /&gt;             */&lt;br /&gt;            if(path.indexOf(SRC) &amp;gt;= 0 ){&lt;br /&gt;                String packagePath = path.substring(path.indexOf(SRC));&lt;br /&gt;                StringTokenizer tokenizer = new StringTokenizer(packagePath,BACKSLASH);&lt;br /&gt;                while(tokenizer.hasMoreTokens()){&lt;br /&gt;                    String nextToken = tokenizer.nextToken();&lt;br /&gt;                    if(!nextToken.equalsIgnoreCase(SRC_STR) &amp;amp;&amp;amp; !(nextToken.indexOf(JAVA_STR)&amp;gt;=0)){&lt;br /&gt;                        strPackage += nextToken + DOT_STR;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;                if(strPackage != EMPTY_STR){&lt;br /&gt;                    strPackage = strPackage.substring(0, strPackage.length()-1);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            boolean fileNameWritten = false; &lt;br /&gt;            &lt;br /&gt;            /*&lt;br /&gt;             * Process all the revisions for the current file. &lt;br /&gt;             */&lt;br /&gt;            List&amp;lt;Revision&amp;gt; revisionList = info.getRevisionList();&lt;br /&gt;            for(Revision revision :  revisionList){&lt;br /&gt;                System.out.print(revision.getNumber() + SPACE);&lt;br /&gt;                //Remove new line character from the message else it hinders rendering in the Excel sheet.&lt;br /&gt;                String message = (revision.getMessage() != null &amp;amp;&amp;amp; revision.getMessage().indexOf(NEW_LINE) &amp;gt;= 0 ? revision.getMessage().replaceAll(NEW_LINE, SPACE) : revision.getMessage());&lt;br /&gt;                String bugNumber = null;&lt;br /&gt;                &lt;br /&gt;                /*&lt;br /&gt;                 * Extract the bug number from the message string if any. &lt;br /&gt;                 */&lt;br /&gt;                if(message.indexOf(BUG_FOLLOWED_SPACE_STR) &amp;gt;= 0){&lt;br /&gt;                    StringTokenizer tokenizer = new StringTokenizer(message,SPACE);&lt;br /&gt;                    while(tokenizer.hasMoreTokens()){&lt;br /&gt;                        if(BUG_STR.equalsIgnoreCase(tokenizer.nextToken())){&lt;br /&gt;                            if(bugNumber != null){&lt;br /&gt;                                bugNumber += SPACE + tokenizer.nextToken(); &lt;br /&gt;                            }else{&lt;br /&gt;                                bugNumber = tokenizer.nextToken();&lt;br /&gt;                            }&lt;br /&gt;                            if(null != bugNumber){&lt;br /&gt;                                bugNumber = bugNumber.replaceAll(COMMA_STR, SPACE);&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    &lt;br /&gt;                }&lt;br /&gt;                /*&lt;br /&gt;                 * Write to CSV, if there exist a bug in the message for this revision.&lt;br /&gt;                 */&lt;br /&gt;                if(null != bugNumber){&lt;br /&gt;                    /*&lt;br /&gt;                     * Write the filename only once, and repeat the revisions for the same file.&lt;br /&gt;                     */&lt;br /&gt;                    if(false == fileNameWritten){&lt;br /&gt;                        xlWriter.write(info.getFile().getName() + COMMA_STR + strPackage + DOUBLE_COMMA+ NEW_LINE);&lt;br /&gt;                        fileNameWritten = true;&lt;br /&gt;                    }&lt;br /&gt;                    xlWriter.write(EMPTY_STR+ DOUBLE_COMMA + revision.getNumber() + COMMA_STR + (bugNumber != null ? bugNumber : SPACE) + COMMA_STR + message + NEW_LINE);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6499870440274901437?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6499870440274901437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/08/javacvs-netbeans-lib-to-access-cvs-in.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6499870440274901437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6499870440274901437'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/08/javacvs-netbeans-lib-to-access-cvs-in.html' title='javacvs – Netbeans lib to access CVS in java, Tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-329478225347307212</id><published>2009-07-27T12:57:00.000-07:00</published><updated>2009-07-27T13:02:13.605-07:00</updated><title type='text'>A student again!</title><content type='html'>I quit my company Tavant, and have decided to pursue my higher education, MS in Compuer Science at University of Alabama, Huntsville. So, this blog may not be updated at a great frequency. When I work on some thing cool, will definitely update the Tech details here.&lt;br /&gt;&lt;br /&gt;You can follow my other blog if you are interested at http://sprouting-beans.blogspot.com/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-329478225347307212?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/329478225347307212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/07/student-again.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/329478225347307212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/329478225347307212'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/07/student-again.html' title='A student again!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2841922953611757003</id><published>2009-06-18T13:10:00.001-07:00</published><updated>2009-06-23T07:38:26.802-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Streaming'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='XSocket'/><title type='text'>Streaming Data using Flex and XSocket</title><content type='html'>&lt;p&gt;I have worked on couple of push technologies namely blazeDS and Lightstreamer and always wondered how does it work. I am just concerned about streaming in Flex and not anything else. You can think I am little inclined towards flex, but the truth is Flex rocks, and after I entered the world of Flex, other UI technologies - I don't care anymore! Anyways, this logic of streaming data to Flex from a backend came to me just by chance! It took 2 days effort to get the below crappy thing going! I read a blog on the Internet that used URLStream to load image data in Flex progressively. Now, if you can load image progressively, then I should be able to do the same with any data. So, here I present Flex - XSocket combination to subscribe/load data from backend for a watchlist. There are a few things, that I did not resolve, as I did not have time to dedicate for it. I will explain those at the end. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;JAVA &lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Lets start from the java backend. I use XScoket Xlightweb library to create a NIO server that can take any symbol as subscription and pushes randomly generated quotes to the client. &lt;/p&gt; &lt;p&gt;I will not be explaining XSockets here. Please visit &lt;a href="http://xsocket.sourceforge.net/"&gt;http://xsocket.sourceforge.net/&lt;/a&gt; for tutorials and downloads. &lt;/p&gt; &lt;p&gt;Lets write a request handler. In XLightweb, the request handler implements the IHttpRequestHandler. &lt;/p&gt; &lt;pre class="brush: java;"&gt;public class ERequestHandler implements IHttpRequestHandler{ &lt;br /&gt;    //Timer that generates the quotes at the specified interval &lt;br /&gt;    private final Timer timer = new Timer(&amp;quot;timer&amp;quot;, true); &lt;br /&gt;    public static Map&amp;lt;String, SymbolSender&amp;gt; state = new HashMap&amp;lt;String, SymbolSender&amp;gt;(); &lt;/pre&gt;&lt;br /&gt;Lets implement the onRequest method. The same handler will be used to receive commands, like add symbol, remove symbol and also to receive data request, we use the URI to differentiate between the two request. &lt;br /&gt;&lt;pre class="brush: java;"&gt;    public void onRequest(IHttpExchange exchange) throws IOException, &lt;br /&gt;            BadMessageException { &lt;br /&gt;        IHttpRequest req = exchange.getRequest(); &lt;br /&gt;        String ipAddress = exchange.getConnection().getRemoteAddress().getHostAddress(); &lt;br /&gt;        if (req.getRequestURI().endsWith(&amp;quot;/link1&amp;quot;)) {//The Action link &lt;br /&gt;            String symbol = req.getParameter(&amp;quot;symbol&amp;quot;); &lt;br /&gt;            String command = req.getParameter(&amp;quot;action&amp;quot;);&lt;/pre&gt;&lt;br /&gt;Every ipAddress is given its own handler. So, obtain the handler ie SymbolSender and delegate the action to it. The SymbolSender is a private class that is given little below. Before any client sends an action, it has to connect to this server. &lt;br /&gt;&lt;pre class="brush: java;"&gt;            SymbolSender symbolSender = state.get(ipAddress); &lt;br /&gt;            if(command.equalsIgnoreCase(&amp;quot;add&amp;quot;)){ &lt;br /&gt;                symbolSender.addSymbol(symbol); &lt;br /&gt;            }else if(command.equalsIgnoreCase(&amp;quot;delete&amp;quot;)){ &lt;br /&gt;                symbolSender.removeSymbol(symbol); &lt;br /&gt;            }else if(command.equalsIgnoreCase(&amp;quot;stop&amp;quot;)){ &lt;br /&gt;                symbolSender.stop(); &lt;br /&gt;            }&lt;/pre&gt;&lt;br /&gt;The action has been delegated, so close the channel with a 200 Response header as in the below snippet. &lt;br /&gt;&lt;pre class="brush: java;"&gt;            IHttpResponseHeader respHdr = new HttpResponseHeader(200, &amp;quot;text/plain&amp;quot;); &lt;br /&gt;            BodyDataSink outChannel = exchange.send(respHdr); &lt;br /&gt;            outChannel.close(); &lt;br /&gt;        }else if(req.getRequestURI().endsWith(&amp;quot;/link2&amp;quot;)){//The initial Data link, that is used to send data back.    &lt;br /&gt;            String command = req.getParameter(&amp;quot;action&amp;quot;); &lt;br /&gt;Initialize a new SymbolSender if none exist for the given ipAddress and start the handler using the timer. Here, it is scheduled at a fixed rate of every 500ms. &lt;br /&gt;&lt;br /&gt;            if(!state.keySet().contains(ipAddress) || state.get(ipAddress) == null){ &lt;br /&gt;                state.put(ipAddress, new SymbolSender(exchange)); &lt;br /&gt;            } &lt;br /&gt;            SymbolSender symbolSender = state.get(ipAddress); &lt;br /&gt;            if(command.equalsIgnoreCase(&amp;quot;start&amp;quot;)){ &lt;br /&gt;                timer.scheduleAtFixedRate(symbolSender,new Date(), 500); &lt;br /&gt;            } &lt;br /&gt;        } &lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;Lets define the SymbolSender timer task, which is a handler for each ip address separately. &lt;br /&gt;&lt;pre class="brush: java;"&gt;     private class SymbolSender extends TimerTask { &lt;br /&gt;        private IHttpExchange exchange; //The exchange handler &lt;br /&gt;        private List&amp;lt;String&amp;gt; symbolList = new ArrayList&amp;lt;String&amp;gt;(); &lt;br /&gt;        private BodyDataSink outChannel; &lt;br /&gt;        private String ipAddress; &lt;br /&gt;        public SymbolSender(IHttpExchange exchange) { &lt;br /&gt;                    this.exchange = exchange; &lt;br /&gt;            IHttpResponseHeader respHdr = new HttpResponseHeader(200, &amp;quot;text/plain&amp;quot;); &lt;br /&gt;                try { &lt;br /&gt;                outChannel = this.exchange.send(respHdr); &lt;br /&gt;                outChannel.setEncoding(&amp;quot;utf-8&amp;quot;); &lt;br /&gt;            } catch (IllegalStateException e) { &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;            } catch (IOException e) { &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;            } &lt;br /&gt;            ipAddress = exchange.getConnection().getRemoteAddress().getHostAddress(); &lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;API for adding and removing the subscription symbol from this ipAddress. &lt;br /&gt;&lt;pre class="brush: java;"&gt;        public void addSymbol(String symbol){ &lt;br /&gt;            symbolList.add(symbol); &lt;br /&gt;        } &lt;br /&gt;&lt;br /&gt;        public void removeSymbol(String symbol){ &lt;br /&gt;            symbolList.remove(symbol); &lt;br /&gt;        } &lt;/pre&gt;&lt;br /&gt;The run method where the random data is generated for the symbols subscribed from this ipAddress, and written to the client. &lt;br /&gt;&lt;pre class="brush: java;"&gt; @Override &lt;br /&gt;        public void run() { &lt;br /&gt;            try { &lt;br /&gt;                if(symbolList.size() &amp;gt; 0){ &lt;br /&gt;                    for(String symbol : symbolList){ &lt;br /&gt;                        String data = &amp;quot;|symbol=&amp;quot; + symbol + &amp;quot;#lastPrice=&amp;quot; + randomToTwoDecimal() + &amp;quot;#lastAsk=&amp;quot; + randomToTwoDecimal() + &amp;quot;#lastBid=&amp;quot; + randomToTwoDecimal() + &amp;quot;|\r\n&amp;quot;;                    &lt;br /&gt;                        outChannel.write(data); &lt;br /&gt;                    } &lt;br /&gt;                }else{ &lt;br /&gt;                    outChannel.write(&amp;quot;STAY ALIVE\r\n&amp;quot;); &lt;br /&gt;                } &lt;br /&gt;            } catch (BufferOverflowException e) { &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;                stop(); &lt;br /&gt;            } catch (IOException e) { &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;                stop(); &lt;br /&gt;            } catch(Exception e){ &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;                stop(); &lt;br /&gt;            } &lt;br /&gt;&lt;br /&gt;        } &lt;/pre&gt;&lt;br /&gt;A simple random way of generating xx.yy number. &lt;br /&gt;&lt;pre class="brush: java;"&gt;        private String randomToTwoDecimal(){ &lt;br /&gt;            Double p1 = Math.random() * 100; &lt;br /&gt;            String value1 = String.valueOf(p1); &lt;br /&gt;            Double p2 = Math.random() * 100; &lt;br /&gt;            String value2 = String.valueOf(p2); &lt;br /&gt;            String randNumber = value1.substring(0, value1.indexOf(&amp;quot;.&amp;quot;)) + &amp;quot;.&amp;quot; + value2.substring(0, value2.indexOf(&amp;quot;.&amp;quot;)); &lt;br /&gt;            return randNumber; &lt;br /&gt;        } &lt;/pre&gt;&lt;br /&gt;Stopping this handler is achieved by stopping the task, and removing the handler form the state for the ipAddress. &lt;br /&gt;&lt;pre class="brush: java;"&gt;        public void stop(){ &lt;br /&gt;            this.cancel(); &lt;br /&gt;            try { &lt;br /&gt;                outChannel.close(); &lt;br /&gt;            } catch (IOException e) { &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;            } &lt;br /&gt;            ERequestHandler.state.remove(ipAddress); &lt;br /&gt;        } &lt;br /&gt;    } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;The main class that starts the server is given below. &lt;br /&gt;&lt;pre class="brush: java;"&gt;public class Streamer { &lt;br /&gt;        public static void runServer() throws IOException{ &lt;br /&gt;            System.setProperty(&amp;quot;org.xlightweb.showDetailedError&amp;quot;, &amp;quot;true&amp;quot;); &lt;br /&gt;            Context rootCtx = new Context(&amp;quot;&amp;quot;); &lt;br /&gt;            IHttpRequestHandler handler = new ERequestHandler(); &lt;br /&gt;Add the two contexts that this server listens to. &lt;br /&gt;&lt;br /&gt;            rootCtx.addHandler(&amp;quot;/link1&amp;quot;,handler ); &lt;br /&gt;            rootCtx.addHandler(&amp;quot;/link2&amp;quot;, handler); &lt;br /&gt;            // creates the server by passing over the port number &amp;amp; the server handler &lt;br /&gt;            HttpServer server = new HttpServer(9980, rootCtx); &lt;br /&gt;            ConnectionUtils.start(server); &lt;br /&gt;        } &lt;br /&gt;        public static void main(String[] args) throws Exception { &lt;br /&gt;            runServer(); &lt;br /&gt;        } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;The java part for the streaming server is over. Now lets go ahead with the flex part. &lt;br /&gt;&lt;p&gt;&lt;strong&gt;FLEX &lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;For the flex part lets create an application. &lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot; creationComplete=&amp;quot;init()&amp;quot;&amp;gt; &lt;br /&gt;&amp;lt;mx:Script&amp;gt; &lt;br /&gt;        &amp;lt;![CDATA[ &lt;br /&gt;            import mx.collections.ArrayCollection; &lt;br /&gt;            import mx.controls.Alert; &lt;/pre&gt;&lt;br /&gt;Lets declare two variables, one for streaming data, and another for writing actions to the xsocket server we just wrote above. &lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;            private var dataStream:URLStream = new URLStream();&lt;br /&gt;private var actionStream:URLLoader = new URLLoader(); &lt;/pre&gt;&lt;br /&gt;The string that we will be getting from the backend is appended here. &lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;private var dataStr:String = &amp;quot;&amp;quot;; &lt;/pre&gt;&lt;br /&gt;Lets declare the remaining things i.e a dataprovider, dictionary to keep map of symbol to object and a timer that will be used to parse data and create objects for data provider.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;[Bindable] &lt;br /&gt;private var watchListData:ArrayCollection = new ArrayCollection(); &lt;br /&gt;private var symbolObjectMap:Dictionary = new Dictionary(); &lt;br /&gt;private static var timer:Timer = new Timer(60); &lt;/pre&gt;&lt;br /&gt;Lets write the init method thats called on creation complete. We will add a progress listener, that will be really useful to us and the remaining listeners that is just for time pass.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;private function init():void{                &lt;br /&gt;    dataStream.addEventListener(ProgressEvent.PROGRESS, streamListener); &lt;br /&gt;    dataStream.addEventListener(Event.COMPLETE, listener); &lt;br /&gt;    dataStream.addEventListener(Event.ACTIVATE, listener); &lt;br /&gt;    dataStream.addEventListener(Event.DEACTIVATE, listener); &lt;br /&gt;    dataStream.addEventListener(Event.OPEN, listener); &lt;br /&gt;    dataStream.addEventListener(HTTPStatusEvent.HTTP_STATUS, listener); &lt;br /&gt;    dataStream.addEventListener(IOErrorEvent.IO_ERROR, listener); &lt;br /&gt;    dataStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, listener); &lt;br /&gt;    timer.addEventListener(TimerEvent.TIMER, parse, false, 0, true); &lt;br /&gt;            timer.start(); &lt;br /&gt;}            &lt;/pre&gt;&lt;br /&gt;The stream listener for the data is given below. Very simple logic, just read the multi byte which is already written in form of utf-8 by the server and append it to the data string. Now, this stream listener is called by Flex when there is some specific amount of data is present. And, it does not make sense for me to parse the data here to create objects at that rate. Instead as you will see next code, the timer will invoke the parse method every 60ms and then parse the data in the data string to an appropriate VO.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;private function streamListener(event:ProgressEvent):void{ &lt;br /&gt;    if(dataStream.bytesAvailable == 0)return; &lt;br /&gt;    if(dataStream.connected){ &lt;br /&gt;        while(dataStream.bytesAvailable &amp;gt;= 1){ &lt;br /&gt;            dataStr = dataStr + dataStream.readMultiByte(dataStream.bytesAvailable, &amp;quot;utf-8&amp;quot;); &lt;br /&gt;        }                &lt;br /&gt;        trace(dataStr); &lt;br /&gt;    } &lt;br /&gt;}            &lt;/pre&gt;&lt;br /&gt;Now, the timepass listener is here. Comment the alerts if you do not want, or use trace instead.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;private function listener(event:Event):void{ &lt;br /&gt;    Alert.show(&amp;quot;Here at other side of the world :(&amp;quot;); &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;Now, here is the parse method for the data I stream from the server. Actually, I do not like to call it streaming, as it is just a normal read and write to streams. Heck! that's why we call it streaming. He he..&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;private function parse(event:TimerEvent):void{ &lt;br /&gt;                if(this.dataStr != null &lt;br /&gt;                    &amp;amp;&amp;amp; this.dataStr.indexOf(&amp;quot;|&amp;quot;) &amp;gt;=0){ &lt;br /&gt;                    var skipLast:Boolean = false; &lt;br /&gt;                    var streamData:Array = this.dataStr.split(&amp;quot;\r\n&amp;quot;);&lt;/pre&gt;&lt;br /&gt;Find out if the data is written partially. That means if its not ending with &amp;quot;|&amp;quot;. If that is the case then keep the last piece of string in the data string for appending with the next data arrived from the backend. This will be parsed after the data has arrived and 60ms time lag.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;if(String(streamData[streamData.length-1]).charAt(streamData.length-1) != &amp;quot;|&amp;quot;){ &lt;br /&gt;                        dataStr = String(streamData[streamData.length-1]); &lt;br /&gt;                        skipLast = true; &lt;br /&gt;                        streamData[streamData.length-1] = &amp;quot;STAY ALIVE&amp;quot;; &lt;br /&gt;                    } &lt;/pre&gt;&lt;br /&gt;Parse all the data other than &amp;quot;STAY ALIVE&amp;quot; pings. I am not sure if you can stop sending STAY ALIVE or delay its frequency. And, I am not doing that R &amp;amp; D either. My purpose remains just of stream data to Flex. Only the positive use case :) The rest of the for loop is just parsing data, creating or updating the StreamerVO object. &lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;for each(var string:String in streamData){ &lt;br /&gt;                        if(string != &amp;quot;STAY ALIVE&amp;quot;){ &lt;br /&gt;                            string = string.substring(1,string.length-1); &lt;br /&gt;                            var nodes:Array = string.split(&amp;quot;#&amp;quot;); &lt;br /&gt;                            var symbolAttribute:String = String(nodes[0]); &lt;br /&gt;                            var symbolData:Array = symbolAttribute.split(&amp;quot;=&amp;quot;); &lt;br /&gt;                            if(String(symbolData[0]) == &amp;quot;symbol&amp;quot;){ &lt;br /&gt;                                var symbol:String = String(symbolData[1]); &lt;br /&gt;                                if(!symbolObjectMap.hasOwnProperty(symbol)){ &lt;br /&gt;                                    symbolObjectMap[symbol] = new StreamerVO(); &lt;br /&gt;                                    watchListData.addItem(symbolObjectMap[symbol]); &lt;br /&gt;                                } &lt;br /&gt;                                var vo:StreamerVO = StreamerVO(symbolObjectMap[symbol]); &lt;br /&gt;                                for each(var node:String in nodes){ &lt;br /&gt;                                    var nodeData : Array = node.split(&amp;quot;=&amp;quot;); &lt;br /&gt;                                    vo[nodeData[0]] = nodeData[1]; &lt;br /&gt;                                } &lt;br /&gt;                            } &lt;br /&gt;                        } &lt;br /&gt;                    } &lt;br /&gt;                } &lt;br /&gt;            }&lt;/pre&gt;&lt;br /&gt;Next lets write the 4 actions supported namely add, delete, start and stop. The url's are in sync with the actions supported by respective links given in the backend code. The get parameters are constructed manually as shown below.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt;            private function subscribe():void{ &lt;br /&gt;                var urlReq:URLRequest = new URLRequest(&amp;quot;http://localhost:9980/link1&amp;quot;); &lt;br /&gt;                urlReq.url += &amp;quot;?action=add&amp;amp;symbol=&amp;quot; + txtSymbol.text; &lt;br /&gt;                actionStream = new URLLoader(); &lt;br /&gt;                actionStream.load(urlReq); &lt;br /&gt;            } &lt;br /&gt;&lt;br /&gt;            private function unSubscribe():void{ &lt;br /&gt;                var urlReq:URLRequest = new URLRequest(&amp;quot;http://localhost:9980/link1&amp;quot;); &lt;br /&gt;                urlReq.url += &amp;quot;?action=delete&amp;amp;symbol=&amp;quot; + txtSymbol.text; &lt;br /&gt;                actionStream = new URLLoader(); &lt;br /&gt;                actionStream.load(urlReq); &lt;br /&gt;            } &lt;br /&gt;            private function connect():void{ &lt;br /&gt;                var urlReq:URLRequest = new URLRequest(&amp;quot;http://localhost:9980/link2&amp;quot;); &lt;br /&gt;                urlReq.url += &amp;quot;?action=start&amp;quot;; &lt;br /&gt;                dataStream.load(urlReq); &lt;br /&gt;            } &lt;br /&gt;            private function disconnect():void{ &lt;br /&gt;                var urlReq:URLRequest = new URLRequest(&amp;quot;http://localhost:9980/link1&amp;quot;); &lt;br /&gt;                urlReq.url += &amp;quot;?action=stop&amp;quot;; &lt;br /&gt;                actionStream = new URLLoader(); &lt;br /&gt;                actionStream.load(urlReq); &lt;br /&gt;            } &lt;/pre&gt;&lt;br /&gt;Now, lets create the view or UI to do the job. I don't think any explanation is needed for this part, as it cant get simpler than this.&lt;br /&gt;&lt;pre class="brush: actionscript3;"&gt; ]]&amp;gt; &lt;br /&gt;    &amp;lt;/mx:Script&amp;gt; &lt;br /&gt;    &amp;lt;mx:VBox&amp;gt; &lt;br /&gt;        &amp;lt;mx:TextInput id=&amp;quot;txtSymbol&amp;quot;/&amp;gt; &lt;br /&gt;        &amp;lt;mx:HBox&amp;gt; &lt;br /&gt;            &amp;lt;mx:Button label=&amp;quot;Connect&amp;quot; click=&amp;quot;connect()&amp;quot;/&amp;gt; &lt;br /&gt;            &amp;lt;mx:Button label=&amp;quot;DisConnect&amp;quot; click=&amp;quot;disconnect()&amp;quot;/&amp;gt; &lt;br /&gt;            &amp;lt;mx:Button label=&amp;quot;Subscribe&amp;quot; click=&amp;quot;subscribe()&amp;quot;/&amp;gt; &lt;br /&gt;            &amp;lt;mx:Button label=&amp;quot;UnSubscribe&amp;quot; click=&amp;quot;unSubscribe()&amp;quot;/&amp;gt; &lt;br /&gt;        &amp;lt;/mx:HBox&amp;gt; &lt;br /&gt;        &amp;lt;mx:DataGrid id=&amp;quot;watchList&amp;quot; dataProvider=&amp;quot;{watchListData}&amp;quot;&amp;gt; &lt;br /&gt;            &amp;lt;mx:columns&amp;gt; &lt;br /&gt;                &amp;lt;mx:DataGridColumn headerText=&amp;quot;Symbol&amp;quot; dataField=&amp;quot;symbol&amp;quot;/&amp;gt; &lt;br /&gt;                &amp;lt;mx:DataGridColumn headerText=&amp;quot;LastPrice&amp;quot; dataField=&amp;quot;lastPrice&amp;quot;/&amp;gt; &lt;br /&gt;                &amp;lt;mx:DataGridColumn headerText=&amp;quot;LastAsk&amp;quot; dataField=&amp;quot;lastAsk&amp;quot;/&amp;gt; &lt;br /&gt;                &amp;lt;mx:DataGridColumn headerText=&amp;quot;LastBid&amp;quot; dataField=&amp;quot;lastBid&amp;quot;/&amp;gt; &lt;br /&gt;            &amp;lt;/mx:columns&amp;gt; &lt;br /&gt;        &amp;lt;/mx:DataGrid&amp;gt;        &lt;br /&gt;    &amp;lt;/mx:VBox&amp;gt; &lt;br /&gt;&amp;lt;/mx:Application&amp;gt; &lt;/pre&gt;&lt;br /&gt;And, that's all folks. The backed is writing the data to the channel, and front end flex is reading it and displaying. Well, there are few bugs in this code I presented. &lt;br /&gt;&lt;br /&gt; The data does not start to flow to the front end for initial 20 sec or so. Try to connect and subscribe say 3-4 symbols IBM, GOOG, MSFT, CSCO soon. I guess the problem is with the Operating system buffer because even when I said flush manually in the XSocket code (Application buffer) no effect could be seen or the problem could exist in Flex also, I am not sure. As I said earlier, my goal is not to solve these problems but to rather get streaming up, which gets up after a initial delay which is fine with me right now. &lt;br /&gt;&lt;br /&gt; I had to use two links so that I could add symbols to be subscribed with out re-connecting to get the data that is being pushed. I could not figure out a way to do it using a single link. You guys can give a shot and let me know. I leave this here for now, as I am in no mood of writing a complete infrastructure for push when several exists. &lt;br /&gt;&lt;br /&gt;Below is a small video of the Flex UI using the code above showing streaming data.&lt;br /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;embed width="340" height="320" type="application/x-shockwave-flash" src="http://v5.tinypic.com/player.swf?file=jg5kw1&amp;amp;s=5"&gt;&lt;br&gt;&lt;font size="1"&gt;&lt;a href="http://tinypic.com/player.php?v=jg5kw1&amp;amp;s=5"&gt;Streaming Data using XSocket and FLex&lt;/a&gt;&lt;/font&gt; &lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;/embed&gt;&lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2841922953611757003?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2841922953611757003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/06/streaming-data-using-flex-and-xsocket.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2841922953611757003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2841922953611757003'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/06/streaming-data-using-flex-and-xsocket.html' title='Streaming Data using Flex and XSocket'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-9105384553246132094</id><published>2009-06-17T23:18:00.001-07:00</published><updated>2009-06-23T07:54:09.473-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Open MBean'/><category scheme='http://www.blogger.com/atom/ns#' term='Tabular Data'/><category scheme='http://www.blogger.com/atom/ns#' term='JMX'/><category scheme='http://www.blogger.com/atom/ns#' term='MBean'/><title type='text'>Open Mbeans Tutorial</title><content type='html'>&lt;p&gt;Writing an MBean in java is very simple. But, when you want the return type to a table of data(say, some metrics) then simple Mbeans are not of much use. One way to get table of data as a return type is using a Open Mbeans. This tutorial gives a simple example of how to write an Open Mbean that returns Table of data. &lt;/p&gt; &lt;strong&gt;Step 1: &lt;/strong&gt; Define a dynamic MXBean by implementing interface &amp;quot;DynamicMBean&amp;quot;. &lt;pre class="brush: java;"&gt;public class QuoteMXBean implements DynamicMBean { &lt;br /&gt;    public Object getAttribute(String attribute) throws AttributeNotFoundException, &lt;br /&gt;        MBeanException, ReflectionException{ &lt;br /&gt;        //TODO &lt;br /&gt;    } &lt;br /&gt;    public void setAttribute(Attribute attribute) throws AttributeNotFoundException, &lt;br /&gt;        InvalidAttributeValueException, MBeanException, ReflectionException{ &lt;br /&gt;        //TODO &lt;br /&gt;    } &lt;br /&gt;    public AttributeList getAttributes(String[] attributes){ &lt;br /&gt;        //TODO    &lt;br /&gt;    } &lt;br /&gt;    public AttributeList setAttributes(AttributeList attributes){ &lt;br /&gt;        //TODO    &lt;br /&gt;    } &lt;br /&gt;    public Object invoke(String actionName, Object params[], String signature[]) &lt;br /&gt;        throws MBeanException, ReflectionException{ &lt;br /&gt;        //TODO &lt;br /&gt;    } &lt;br /&gt;    public MBeanInfo getMBeanInfo(){ &lt;br /&gt;        //TODO &lt;br /&gt;    } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 2: &lt;/strong&gt;&lt;br /&gt;A table is made up of rows. And each row is made up of columns. We will have to give exactly this description defining a table.&lt;pre class="brush: java;"&gt;String[] itemNames = { &amp;quot;symbol&amp;quot;, &amp;quot;localTimeStamp&amp;quot;, &amp;quot;latestResponse&amp;quot;}; &lt;br /&gt;String[] itemDescriptions = { &amp;quot;Symbol&amp;quot;, &lt;br /&gt;            &amp;quot;The Timestamp for the response as on server&amp;quot;, &amp;quot;The response String from Quoteserver&amp;quot;}; &lt;br /&gt;OpenType[] itemTypes = { SimpleType.STRING, &lt;br /&gt;            SimpleType.STRING, SimpleType.STRING};            &lt;br /&gt;CompositeType snapshotType = new CompositeType(&amp;quot;snapshot&amp;quot;, &amp;quot;Quote Data&amp;quot;, &lt;br /&gt;                itemNames, itemDescriptions, itemTypes);&lt;/pre&gt;All the variables can be made private and initialized either in a static block or in the constructor. The CompositeType just defined that each row will contain the columns &amp;quot;symbol&amp;quot;, &amp;quot;localTimeStamp&amp;quot;, &amp;quot;latestResponse&amp;quot;. Now lets define the table type it self.&lt;pre class="brush: java;"&gt;String[] index = { &amp;quot;symbol&amp;quot; }; &lt;br /&gt;TabularType quoteTableType = new TabularType(&amp;quot;quoteSnapshots&amp;quot;, &lt;br /&gt;                    &amp;quot;List of Quotes&amp;quot;, snapshotType, &lt;br /&gt;                    index);&lt;/pre&gt;That is, a table type &amp;quot;quoteTableType&amp;quot; is a collection of rows given by Composite type &amp;quot;snapshotType&amp;quot;. The &amp;quot;index&amp;quot; gives, the unique identification for the table.&lt;br /&gt;&lt;br/&gt; &lt;br /&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;br /&gt;Lets declare the table with type &amp;quot;quoteTableType&amp;quot;.&lt;br /&gt;&lt;pre class="brush: java;"&gt;private TabularDataSupport quoteSnapshot = new TabularDataSupport(quoteTableType); &lt;/pre&gt;&lt;br /&gt;Please add the getter and setters for the same. &lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;br /&gt;Lets implement getMBeanInfo().&lt;br /&gt;&lt;pre class="brush: java;"&gt;OpenMBeanInfoSupport info; &lt;br /&gt;    OpenMBeanAttributeInfoSupport[] attributes = new OpenMBeanAttributeInfoSupport[1]; &lt;br /&gt;    OpenMBeanConstructorInfoSupport[] constructors = new OpenMBeanConstructorInfoSupport[1]; &lt;br /&gt;        OpenMBeanOperationInfoSupport[] operations = new OpenMBeanOperationInfoSupport[4]; &lt;br /&gt;        MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[0]; &lt;br /&gt;&lt;br /&gt;//Just one attribute &lt;br /&gt;     attributes[0] = new OpenMBeanAttributeInfoSupport(&amp;quot;QuoteSnapshot&amp;quot;, &lt;br /&gt;                &amp;quot;Table of quotes data&amp;quot;, quoteSnapshotType, true, false, &lt;br /&gt;                false); &lt;br /&gt;//No arg constructor                &lt;br /&gt;         constructors[0] = new OpenMBeanConstructorInfoSupport( &lt;br /&gt;                        &amp;quot;QuoteMXBean&amp;quot;, &lt;br /&gt;                        &amp;quot;Constructs a QuoteMXBean instance.&amp;quot;, &lt;br /&gt;                new OpenMBeanParameterInfoSupport[0]); &lt;br /&gt;&lt;br /&gt;//Just one operation &lt;br /&gt;&lt;br /&gt;    OpenMBeanParameterInfo[] params = new OpenMBeanParameterInfoSupport[0]; &lt;br /&gt;        operations[0] = new OpenMBeanOperationInfoSupport( &lt;br /&gt;                &amp;quot;resetAndGetQuoteSnapshot&amp;quot;, &lt;br /&gt;                &amp;quot;Reset and get the latest available data for the Quotes&amp;quot;, &lt;br /&gt;                params, quoteSnapshotType, &lt;br /&gt;                MBeanOperationInfo.INFO); &lt;br /&gt;//Build the info &lt;br /&gt;&lt;br /&gt;    info = new OpenMBeanInfoSupport(this .getClass().getName(), &lt;br /&gt;                &amp;quot;Quote - Open - MBean&amp;quot;, attributes, constructors, &lt;br /&gt;                operations, notifications);    &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 5:&lt;/strong&gt;&lt;br /&gt;Implement getAttribute() and getAttributes().&lt;br /&gt;&lt;pre class="brush: java;"&gt; public Object getAttribute(String attributeName) throws AttributeNotFoundException, &lt;br /&gt;            MBeanException, ReflectionException { &lt;br /&gt;        if (attributeName.equals(&amp;quot;QuoteSnapshot&amp;quot;)) { &lt;br /&gt;                return (TabularData)getQuoteSnapshot(); &lt;br /&gt;            } &lt;br /&gt;        throw new AttributeNotFoundException(&amp;quot;Cannot find &amp;quot; &lt;br /&gt;                + attributeName + &amp;quot; attribute &amp;quot;); &lt;br /&gt;    } &lt;br /&gt;    public AttributeList getAttributes(String[] attributeNames) { &lt;br /&gt;            AttributeList resultList = new AttributeList(); &lt;br /&gt;            if (attributeNames.length == 0) &lt;br /&gt;                return resultList; &lt;br /&gt;            for (int i = 0; i &amp;lt; attributeNames.length; i++) { &lt;br /&gt;                try { &lt;br /&gt;                    Object value = getAttribute(attributeNames[i]); &lt;br /&gt;                    resultList.add(new Attribute(attributeNames[i], value)); &lt;br /&gt;                } catch (Exception e) { &lt;br /&gt;                    e.printStackTrace(); &lt;br /&gt;                } &lt;br /&gt;            } &lt;br /&gt;            return (resultList); &lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 6:&lt;/strong&gt;&lt;br /&gt;Implement setAttribute().&lt;br /&gt;There is nothing to set in this example. &lt;br /&gt;&lt;pre class="brush: java;"&gt;    public void setAttribute(Attribute arg0) throws AttributeNotFoundException, &lt;br /&gt;            InvalidAttributeValueException, MBeanException, ReflectionException { &lt;br /&gt;        throw new AttributeNotFoundException( &lt;br /&gt;        &amp;quot;No attribute can be set in this MBean&amp;quot;); &lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;    @Override &lt;br /&gt;    public AttributeList setAttributes(AttributeList arg0) { &lt;br /&gt;        return new AttributeList(); &lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 7:&lt;/strong&gt;&lt;br /&gt;Implement invoke().&lt;br /&gt;&lt;pre class="brush: java;"&gt;public Object invoke(String operationName, Object[] params, String[] signature) &lt;br /&gt;            throws MBeanException, ReflectionException { &lt;br /&gt;        if (operationName.equals(&amp;quot;resetAndGetQuoteSnapshot&amp;quot;)) { &lt;br /&gt;            try { &lt;br /&gt;                return buildSnapshot(); //This is where you delegate the invokation to your original method. &lt;br /&gt;            } catch (OpenDataException e) { &lt;br /&gt;                throw new MBeanException(e, &amp;quot;invoking resetAndGetQuoteSnapshot: &amp;quot; &lt;br /&gt;                        + e.getClass().getName() + &amp;quot;caught [&amp;quot; &lt;br /&gt;                        + e.getMessage() + &amp;quot;]&amp;quot;); &lt;br /&gt;            } &lt;br /&gt;        } &lt;br /&gt;        else{ &lt;br /&gt;            throw new ReflectionException(new NoSuchMethodException( &lt;br /&gt;                    operationName), &amp;quot;Cannot find the operation &amp;quot; &lt;br /&gt;                    + operationName); &lt;br /&gt;        } &lt;br /&gt;    } &lt;br /&gt;    public Object buildSnapshot() throws OpenDataException { &lt;br /&gt;            quoteSnapshot = new TabularDataSupport(quoteTableType); &lt;br /&gt;            SomeVo vo = //get the data &lt;br /&gt;            Object[] itemValues = { vo.symbol, vo.localDate, vo.response}; &lt;br /&gt;            CompositeData result = new CompositeDataSupport(snapshotType, &lt;br /&gt;                    itemNames, itemValues); &lt;br /&gt;                    quoteSnapshot.put(result); &lt;br /&gt;            return quoteSnapshot; &lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;This is all is needed to build an Open MBean that supports a Tabular data as output. You can use jconsole and view the output. Obviously, you have to deploy the MBean in mbean server. I use spring to do that job. The spring XML is given below.&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;bean id=&amp;quot;exporter&amp;quot; class=&amp;quot;org.springframework.jmx.export.MBeanExporter&amp;quot; lazy-init=&amp;quot;false&amp;quot;&amp;gt; &lt;br /&gt;        &amp;lt;property name=&amp;quot;beans&amp;quot;&amp;gt; &lt;br /&gt;          &amp;lt;map&amp;gt; &lt;br /&gt;            &amp;lt;entry key=&amp;quot;com.ssb.mbean:type=QuoteMXBean&amp;quot; value-ref=&amp;quot;quoteMXBean&amp;quot;/&amp;gt; &lt;br /&gt;          &amp;lt;/map&amp;gt; &lt;br /&gt;        &amp;lt;/property&amp;gt; &lt;br /&gt;     &amp;lt;/bean&amp;gt; &lt;br /&gt;    &amp;lt;bean id=&amp;quot;quoteMXBean&amp;quot; class=&amp;quot;com.ssb.mbean.QuoteMXBean&amp;quot;/&amp;gt; &lt;br /&gt;    &amp;lt;bean id=&amp;quot;registry&amp;quot; class=&amp;quot;org.springframework.remoting.rmi.RmiRegistryFactoryBean&amp;quot; &lt;br /&gt;         p:port=&amp;quot;9999&amp;quot; /&amp;gt; &lt;br /&gt;    &amp;lt;bean id=&amp;quot;serverConnector&amp;quot; class=&amp;quot;org.springframework.jmx.support.ConnectorServerFactoryBean&amp;quot; &lt;br /&gt;         p:objectName=&amp;quot;connector:name=rmi&amp;quot; &lt;br /&gt;         p:serviceUrl=&amp;quot;service:jmx:rmi://localhost/jndi/rmi://localhost:9999/quotesconnector&amp;quot; &lt;br /&gt;         p:threaded=&amp;quot;true&amp;quot; &lt;br /&gt;         p:daemon=&amp;quot;true&amp;quot;/&amp;gt;&lt;/pre&gt;&lt;br /&gt;The above example is trying to display the latest quote data that is available to the system.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-9105384553246132094?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/9105384553246132094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/06/open-mbeans-tutorial.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9105384553246132094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9105384553246132094'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/06/open-mbeans-tutorial.html' title='Open Mbeans Tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-7712728067336993276</id><published>2009-04-04T10:19:00.001-07:00</published><updated>2009-06-25T04:07:27.489-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Lightstreamer Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Lightstreamer Flex sample'/><title type='text'>Lightstreamer : A tutorial for java Adapters and Flex clients : Part 2</title><content type='html'>&lt;p&gt;I know i am posting this second part pretty late, but can't help, have loads of work at hand. So, here goes the next part of the Lightstreamer tutorial which explains the Flex part. Remember, the flex client swc is available only if you download the evaluation version of the Lightstreamer. This is not packaged with the Moderato version. &lt;/p&gt;  &lt;p&gt;This tutorial will explain how to use the native AS3 Flex client lib to subscribe data from the Adapter that I present in the previous post. Strictly speaking, this post will just provide a beginning to LS, we have developed a complete framework on the Flex side which is being used by around 9 modules transparently with out the knowledge of existence of LS. Well, I will not and I am not supposed to provide any more details about it. &lt;/p&gt;  &lt;p&gt;Change the port at which the LS server runs. Edit the $LS_HOME/conf/lightstreamer_conf.xml. Change &amp;lt;port&amp;gt;8080&amp;lt;/port&amp;gt; to &amp;lt;port&amp;gt;8787&amp;lt;/port&amp;gt; in the HTTP server configuration present. Restart the server. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;/p&gt; Use the LSClient to connect to the LS server which has the adapter deployed.   &lt;pre class="brush: as3;"&gt;var lsClient:LSClient = new LSClient(); &lt;br /&gt;lsClient.addEventListener(StatusChangeEvent.STATUS_CHANGE,onLSStatusChange); // The LS sends status changes. The method onLSStatusChange handles it. &lt;br /&gt;&lt;br /&gt;var connectionInfo:ConnectionInfo = new ConnectionInfo(); &lt;br /&gt;connectionInfo.setServer(&amp;quot;localhost&amp;quot;);// Place where the server is running &lt;br /&gt;connectionInfo.setAdapter(&amp;quot;MyJavaAdapter&amp;quot;); // This is the name of the adapter we configured in the adapters.xml &lt;br /&gt;connectionInfo.setControlPort(&amp;quot;8787&amp;quot;);// The port we configured above. &lt;br /&gt;connectionInfo.setPort(&amp;quot;8787&amp;quot;);// The port we configured above. &lt;br /&gt;connectionInfo.setControlProtocol(&amp;quot;http&amp;quot;);// The protocol to use http or https. For quotes data, http is preferred. &lt;br /&gt;connectionInfo.setProtocol(&amp;quot;http&amp;quot;); &lt;br /&gt;&lt;br /&gt;var connectionPolicy:ConnectionPolicy = new ConnectionPolicy(); //These are more configurations, as needed by the application. &lt;br /&gt;connectionPolicy.setTimeoutForStalled(2); &lt;br /&gt;connectionPolicy.setTimeoutForReconnect(15); &lt;br /&gt;connectionPolicy.setRetryTimeout(5); &lt;br /&gt;&lt;br /&gt;//Connect to Lightstreamer Server &lt;br /&gt;try { &lt;br /&gt;    lsClient.openConnection(connectionInfo,connectionPolicy); &lt;br /&gt;} catch(e:Error) { &lt;br /&gt;    Alert.show(e.message); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;public function onLSStatusChange(event:StatusChangeEvent):void{ &lt;br /&gt;    trace(event.previousStatus + &amp;quot; =&amp;gt; &amp;quot; + event.status); &lt;br /&gt;    //The status can change as below. You can display a popup or some indicators to the user showing what is happening. &lt;br /&gt;  /*    &amp;quot;DISCONNECTED&amp;quot; =&amp;gt; &amp;quot;CONNECTING&amp;quot; &lt;br /&gt;    &amp;quot;CONNECTING&amp;quot; =&amp;gt; &amp;quot;STREAMING&amp;quot; &lt;br /&gt;    &amp;quot;STREAMING&amp;quot; =&amp;gt; &amp;quot;CONNECTING&amp;quot; &lt;br /&gt;    &amp;quot;STALLED&amp;quot; =&amp;gt; &amp;quot;CONNECTING&amp;quot; &lt;br /&gt;    &amp;quot;CONNECTING&amp;quot; =&amp;gt; &amp;quot;POLLING&amp;quot; &lt;br /&gt;  /* &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; &lt;br /&gt;Subscribe to the data. You can use Visual or NonVisual table. We use only the NonVisual table. ok, I am sure you did not understand what is a table. In a simple term, a table contains rows and columns. In LS term, the columns are the items you subscribe for. For e.g. LastPrice. The rows are the items you subscribe. For E.g. Quote data for IBM. So, each row is a unique subscription for the items present as columns. Non-Visual table is not a component that will be displayed on the UI. You handle the display yourself. I feel this is more flexible and powerful than Visual Table.&lt;br /&gt;&lt;pre class="brush: java;"&gt;var nonVisualTable:NonVisualTable = new NonVisualTable(new Array(&amp;quot;IBM&amp;quot;),new Array(&amp;quot;LastAsk&amp;quot;,&amp;quot;LastBid&amp;quot;,&amp;quot;LastPrice&amp;quot;,&amp;quot;Symbol&amp;quot;),&amp;quot;MERGE&amp;quot;); &lt;br /&gt;nonVisualTable.setDataAdapter(&amp;quot;MYJAVAADAPTER&amp;quot;); &lt;br /&gt;nonVisualTable.setSnapshotRequired(false); &lt;br /&gt;nonVisualTable.addEventListener(NonVisualItemUpdateEvent.NON_VISUAL_ITEM_UPDATE,handleUpdate); &lt;br /&gt;nonVisualTable.setRequestedMaxFrequency(1); &lt;br /&gt;lsClient.subscribeTable(nonVisualTable); &lt;/pre&gt;&lt;br /&gt;Ok, here I will explain some terms. &lt;br /&gt;The last param in the constructor arg of NonVisualTable is the management mode. There are 4 types, namely, RAW, DISTINCT, MERGE and COMMAND. You can look at documentation for detailed explanation of all these.&lt;br /&gt;In simple terms, if your data is constantly changing like quotes, and LS sends only those data that have changed. The data that is not changed is not sent and its state is maintained as previous. i.e the last unchanged value. This type of management of data is called MERGE mode. &lt;br /&gt;  If you need the data as being generated, i.e each of the data should be pushed to the front end, like news data, then you use the DISTINCT mode. &lt;br /&gt;  RAW mode is similar to Distinct. Each and every data is sent to the client. I am not so sure, but the only difference the document says is, in case of DISTINCT not all the events be sent to the client. &lt;br /&gt;  COMMAND is more complicated and has better performance, please read the documentation for it. I have used MERGE and DISTINCT mode till now successfully.&lt;br /&gt;&lt;br /&gt;The DataAdapter is the one you configured in adapters.xml, in our case &amp;quot;MYJAVAADAPTER&amp;quot;. &lt;br /&gt;You can request a snapshot if the data-adapter supports one.&lt;br /&gt;&lt;br /&gt;The requested max frequency limits the updates I get from the LS server. I do not need more than 1 update per item per second. So, its 1 in my case. Make sure you use this with MERGE mode only.&lt;br /&gt;&lt;br /&gt;handleUpdate gets the updates from the LS. It is given below. The code is self explanatory.&lt;br /&gt;&lt;pre class="brush: as3;"&gt;public function handleUpdate(event:NonVisualItemUpdateEvent):void{ &lt;br /&gt;    var eventType:String = event.item; //This provides the update event name, in our case IBM. &lt;br /&gt;    trace(extractFieldData(event,&amp;quot;LastAsk&amp;quot;)); &lt;br /&gt;    trace(extractFieldData(event,&amp;quot;LastBid&amp;quot;)); &lt;br /&gt;    trace(extractFieldData(event,&amp;quot;LastPrice&amp;quot;));    &lt;br /&gt;} &lt;br /&gt;private function extractFieldData(event:NonVisualItemUpdateEvent,field:*):String { &lt;br /&gt;var value:String; &lt;br /&gt;    if (event.isFieldChanged(field)) { &lt;br /&gt;        value = event.getFieldValue(field); &lt;br /&gt;    } else { &lt;br /&gt;        value = event.getOldFieldValue(field); &lt;br /&gt;    } &lt;br /&gt;return value; &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; When all done, please un-subscribe the table.&lt;br /&gt;&lt;pre class="brush: as3;"&gt;lsClient.unsubscribeTable(nonVisualTable); &lt;/pre&gt;&lt;br /&gt;This is all you need to get going on the Flex side with LS. We started from here and you wont believe where we have reached. The LS forums is really really helpful. Please post any queries there, I have always got sensible and useful replies. Try going through the lightstreamer_conf.xml, there are a lot of things you can configure there. Any developer with some experience will understand it. If you need more help, just go to the forums.&lt;br /&gt;&lt;br /&gt;This will end the Lightstreamer tutorials from my side. Try this technology, am sure you will love it...  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-7712728067336993276?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/7712728067336993276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/04/lightstreamer-tutorial-for-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7712728067336993276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7712728067336993276'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/04/lightstreamer-tutorial-for-java.html' title='Lightstreamer : A tutorial for java Adapters and Flex clients : Part 2'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-1018564627385275152</id><published>2009-02-09T09:06:00.001-08:00</published><updated>2009-06-25T04:12:13.813-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Lightstreamer Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Lightstreamer Java Adapter Sample'/><title type='text'>Lightstreamer : A tutorial for java Adapters and Flex clients : Part 1</title><content type='html'>&lt;p&gt;I think there is shortage of tutorials on web related to Lightstreamer, which is one awesome technology. Initially you may become over whelmed at the terminologies and trying to understand each and every part of it. I use lightstreamer as a part of architecture of a trading platform. I have used it pretty extensively within limits for the application. Hence, I would like to give this tutorial for people who wants to use this push software in there app's. I will cover the concepts with some amount of examples that will make ME understand Lightstreamer. :)&lt;/p&gt;  &lt;p&gt;The basic requirement to understand this tutorial is, you need to know the concept of push technology first. I have used BlazeDS Messaging initially, so, may be if you are a Flex developer, first check out BlazeDS messaging. Then understand the concept of Push technology. Then, come to this tutorial to make more sense out of it. &lt;/p&gt;  &lt;p&gt;In Lightstreamer, there are two parts for the push (I will call it 'streaming') to work. A backend and a front end. The backend is explained in java and front end is explained in Flex. &lt;/p&gt;  &lt;p&gt;This 1st part of Tutorial is about Java Backend. I will explain the Flex Client side UI in the next part of the Tutorial. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Installation:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Download the zip from &lt;a href="http://www.lightstreamer.com/"&gt;http://www.lightstreamer.com/&lt;/a&gt;. Extract it in a directory which I will call $LS_HOME, and read the GETTING_STARTED.txt in $LS_HOME. Its neatly and clearly written. There should not be a problem in understanding it. I would suggest you download a trial version than using the Moderato, the free one. And, Also buy it if you find it very useful :) Anyway's, its valid for 60 days, which is more than enough for you to evaluate it and understand its capability. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;The Backend:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Structure: The first thing is, where do you put the code that has been written and how do you put it. There are two approaches.    &lt;br /&gt;First one is, compile your java code, get the .class files, and put it under $LS_HOME/adapters/myadapter/classes.     &lt;br /&gt;Second one is, create a jar out of your class files, and put it in $LS_HOME/adapters/myadapter/lib. &lt;/p&gt;  &lt;p&gt;Create the two folders myadapter and classes/lib as needed by your approach. &lt;/p&gt;  &lt;p&gt;Once the structure is ready, copy the adapters.xml from the samples given in $LS_HOME/adapters/Demo. &lt;/p&gt;  &lt;p&gt;So, &lt;em&gt;&lt;strong&gt;what is Adapter&lt;/strong&gt;&lt;/em&gt;? Simplest term, this is what is responsible for pushing your data to your UI. &lt;/p&gt;  &lt;p&gt;Lets write an adapter. Also, there are three more terminologies which we need to know.&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; 2. &lt;strong&gt;itemName&lt;/strong&gt;: This is any String that can be used to uniquely identify the type of data that has been requested by the client to the server. The server, i.e this adapter should understand the data that client from UI is requesting to be pushed. In the example below, it is as simple as Symbol IBM, that the server pushes data to UI.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; 3. &lt;strong&gt;ItemEventListener&lt;/strong&gt;: This is the interface defined by Lightstreamer(LS) that is instantiated by LS, when the LS server is started. This has a method 'update', that is used to push data to the UI.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; 4. &lt;strong&gt;Snapshot&lt;/strong&gt;: If the data is not available to be pushed, but a snapshot of it is available then the isSnapShotAvailable method can return true, and the itemEvenListener can send true in the last arguments for snapshots. The UI can request for a snapshot if it needs it. In trading sample app that I give below, a snapshot is not of much use, so, is defined as false.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;And, this is it, we are good to go for an example. &lt;/p&gt;  &lt;p&gt;Its very simple, create a Class MyJavaAdapter and implement com.lightstreamer.interfaces.data.DataProvider. That is it.. :) &lt;/p&gt;  &lt;p&gt;Below is a simple adapter, that can be used generically with any Class that extends DataGenerator abstract class and is capable of generating data from any source, either database or from another server that pumps data over a network. You can define your own implementation. &lt;/p&gt;  &lt;p&gt;In the code sample below, the MyJavaAdapter delegates its work to any class that extends DataGenerator. DataGenerator, does the job of setting and working with Listener given by the LS. Any class, that extends the DataGenerator is hidden from the intricacies of the LS. The push method in the DataGenerator does the actual job of pushing data to the UI. The data is sent in form of a key=value pair. The extended class, has to worry just about its business logic, i.e, where to get data from and push it to the server by converting it to a map. The sample below is a very very simple design, and can be highly modified/replaced to make it more generic and better, I hope you get the point. &lt;/p&gt;  &lt;pre class="brush: java;"&gt;public abstract class DataGenerator{ &lt;br /&gt;    private ItemEventListener listener &lt;br /&gt;&lt;br /&gt;    public void init(); &lt;br /&gt;    public boolean isSnapshotAvailable(String arg0) &lt;br /&gt;            throws SubscriptionException { &lt;br /&gt;            return false; &lt;br /&gt;            } &lt;br /&gt;&lt;br /&gt;    public final void setListener(ItemEventListener listener) { &lt;br /&gt;        this.listener = listener; &lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;    public void subscribe(String itemName, boolean arg1); &lt;br /&gt;&lt;br /&gt;    public void unsubscribe(String itemName); &lt;br /&gt;    public void push(String itemName,Map&amp;lt;String, String&amp;gt; values, boolean isSnapShot){ &lt;br /&gt;        listener.update(itemName , values, isSnapShot);    &lt;br /&gt;    } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;The sample QuotesStubber that extends DataGenerator is given below. It uses timer to generate data at regular interval and push it to the front end. The push is happening in the run method if you observe.&lt;br /&gt;&lt;pre class="brush: java;"&gt;public class QuotesStubber extends DataGenerator { &lt;br /&gt;    private static final Timer dispatcher = new Timer(); &lt;br /&gt;    private List&amp;lt;String&amp;gt; subscribedSymbols; &lt;br /&gt;    public void init(){ &lt;br /&gt;        subscribedSymbols = new ArrayList&amp;lt;String&amp;gt;(); &lt;br /&gt;        run(); &lt;br /&gt;    } &lt;br /&gt;    public void subscribe(String symbol, boolean arg1){ &lt;br /&gt;        subscribedSymbols.add(symbol); &lt;br /&gt;    } &lt;br /&gt;    public void unsubscribe(String symbol){ &lt;br /&gt;        subscribedSymbols.remove(removalIndex); &lt;br /&gt;    } &lt;br /&gt;    private void run(){ &lt;br /&gt;        dispatcher.scheduleAtFixedRate(new TimerTask(){ &lt;br /&gt;                    public void run(){                &lt;br /&gt;                            for(int i=0; i &amp;lt; subscribedSymbols.size(); i++){ &lt;br /&gt;                                String req = subscribedSymbols.get(i); &lt;br /&gt;                                Map&amp;lt;String,String&amp;gt; response = generateQuotesResponse(req); &lt;br /&gt;                                push(req,response,false) &lt;br /&gt;                                if(i &amp;gt;= subscribedSymbols.size()){ &lt;br /&gt;                                    i = 0; &lt;br /&gt;                                } &lt;br /&gt;                            } &lt;br /&gt;                    } &lt;br /&gt;                    private Map&amp;lt;String,String&amp;gt; generateQuotesResponse(String symbol) { &lt;br /&gt;                        Map&amp;lt;String,String&amp;gt; response = new HashMap&amp;lt;String,String&amp;gt;(); &lt;br /&gt;                            response.put(&amp;quot;LastAsk&amp;quot;,getRandom(2,2)); &lt;br /&gt;                            response.put(&amp;quot;LastBid&amp;quot;,getRandom(2,2)); &lt;br /&gt;                            response.put(&amp;quot;LastPrice&amp;quot;,getRandom(2,2)); &lt;br /&gt;                            response.put(&amp;quot;Symbol&amp;quot;,symbol); &lt;br /&gt;                        return response; &lt;br /&gt;                    }                    &lt;br /&gt;                    private String getRandom(int digitB4Decimal, int digitAfterDecimal) { &lt;br /&gt;                            String sRand = null; &lt;br /&gt;                                Random random = new Random(); &lt;br /&gt;                                String sB4Decimal = String.valueOf(Math.abs(random.nextLong())).substring(0, digitB4Decimal); &lt;br /&gt;                                String sAfter4Decimal = String.valueOf(Math.abs(random.nextLong())).substring(0, digitB4Decimal); &lt;br /&gt;                                sRand = sB4Decimal + &amp;quot;.&amp;quot; + sAfter4Decimal; &lt;br /&gt;                            return sRand; &lt;br /&gt;                    } &lt;br /&gt;            }, 0, 500);        &lt;br /&gt;    } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;The Adapter is below, this is responsible for interactions with the DataGenerator given above. The methods defined here is called by LS server at appropriate times. The reference for the datagenerator in the adapter below can be either injected or instantiated as given in comment.&lt;br /&gt;&lt;pre class="brush: java;"&gt;public class MyJavaAdapter implements DataProvider{ &lt;br /&gt;&lt;br /&gt;    private ItemEventListener listener; &lt;br /&gt;    private DataGenerator generator;//injected using spring or can be instantiated in the init method below &lt;br /&gt;    public void init(Map arg0, File arg1) throws DataProviderException { &lt;br /&gt;        generator.init(); &lt;br /&gt;    } &lt;br /&gt;    public boolean isSnapshotAvailable(String arg0) &lt;br /&gt;            throws SubscriptionException { &lt;br /&gt;        generator.isSnapshotAvailable(arg0);    &lt;br /&gt;            } &lt;br /&gt;    public void setListener(ItemEventListener listener) { &lt;br /&gt;        generator.setListener(listener); &lt;br /&gt;    } &lt;br /&gt;    public void subscribe(String itemName, boolean arg1) &lt;br /&gt;            throws SubscriptionException, FailureException { &lt;br /&gt;        generator.subscribe(itemName,arg1); &lt;br /&gt;            } &lt;br /&gt;    public void unsubscribe(String itemName) throws SubscriptionException, &lt;br /&gt;            FailureException { &lt;br /&gt;        generator.unsubscribe(itemName,arg1);    &lt;br /&gt;            } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;Finally, open adapter.xml that you copied before, and define a dataprovider as:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;data_provider name=&amp;quot;MYJAVAADAPTER&amp;quot;&amp;gt; &lt;br /&gt;        &amp;lt;adapter_class&amp;gt;MyJavaAdapter&amp;lt;/adapter_class&amp;gt; &lt;br /&gt;&amp;lt;/data_provider&amp;gt; &lt;/pre&gt;&lt;br /&gt;You will use the 'name' attribute defined here from the Flex UI when you start requesting data to be pushed to it.&lt;br /&gt;The Flex part of it will be provided in my next post/tutorial as a continuation to this one.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-1018564627385275152?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/1018564627385275152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/02/lightstreamer-tutorial-for-java.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1018564627385275152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1018564627385275152'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2009/02/lightstreamer-tutorial-for-java.html' title='Lightstreamer : A tutorial for java Adapters and Flex clients : Part 1'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5172933162870110280</id><published>2008-12-24T03:39:00.001-08:00</published><updated>2009-06-25T04:21:40.109-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='using compc with with -include-file'/><category scheme='http://www.blogger.com/atom/ns#' term='Embed Problem'/><category scheme='http://www.blogger.com/atom/ns#' term='Add resource using compc'/><category scheme='http://www.blogger.com/atom/ns#' term='Using compc with large number of resources'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><title type='text'>Flex : Solution to Error: unable to resolve '/assets/icons/icon.png' for transcoding using Embed tag</title><content type='html'>&lt;p&gt;It so happens that when we work on IDE like flex builder, every thing seems to be working fine but the same would not work other wise. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Problem: &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We use maven as build tool, and my mxml and css has tags like: &lt;/p&gt;  &lt;p&gt;[Embed(source='/assets/icons/icon.png')] &lt;/p&gt;  &lt;p&gt;We get the error &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Error: unable to resolve '/assets/icons/icon.png' for transcoding &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You have tried to put assets folder in line with the main application file, in common and any other place you can think of, and still this problem is not resolved.    &lt;br /&gt;You have also tried with or with out '/' in front of 'assets' in your Embed tag as given by many people around the Internet. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Solution: &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;With all the assets that will be used in the Embed tag, create a 'swc' library and put it in the mxmlc class path. And use with out a forward slash in the beginning,as in, assets/icons/icon.png. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Next Problem:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;How do you create a swc file? &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;The method I adopted in the beginning to just to get my app up as I had a release next day was, if you own Flexbuilder, then create a Flex Library project, and include all these resources in the library. Use this generated library in the mxmlc build path to build the project. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Next Problem:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;I can not always keep adding a resource as and when included into my Flex builder library project to generate the swc. So, I will have to automate this. Before, I build the mxmlc, I have to create the swc, and add it in the build path of mxmlc so that the compilation is successful. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;This is done using the compc compiler. So, I will have to use this compiler to generate the swc of the resources being embedded in the Flex project, then run the mxmlc. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Next Problem:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Running compc directly from command line, to include files, takes the form: &lt;/p&gt;  &lt;p&gt;compc -output assets.swc -include-file &amp;lt;file_alias_1&amp;gt; &amp;lt;real file path 1&amp;gt; .. -include-file &amp;lt;file_alias_n&amp;gt; &amp;lt;real file path&amp;#160; n&amp;gt; &lt;/p&gt;  &lt;p&gt;or &lt;/p&gt;  &lt;p&gt;We can use the compc task in the maven ant run plugin. But, this compc task, can include only classes, and could not include all the resources. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;I assume that the folder structure is like below: &lt;/p&gt;  &lt;p&gt;flex    &lt;br /&gt;|- libs     &lt;br /&gt;|- mainapp     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |--src     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |-- index.mxml     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |-- assets     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |&amp;#160;&amp;#160;&amp;#160;&amp;#160; |-- icons     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |&amp;#160;&amp;#160;&amp;#160; |-- images     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |-- css     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |-- pom.xml &lt;/p&gt;  &lt;p&gt;The packages that Flex app uses can be any where, either in mainapp/src or out side it, but its configured in the class path of the mxmlc task in pom.xml. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/strong&gt; Add the following dependencies with in the maven-antrun-plugin. &lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;dependencies&amp;gt; &lt;br /&gt; &amp;lt;dependency&amp;gt; &lt;br /&gt;     &amp;lt;groupId&amp;gt;ant-contrib&amp;lt;/groupId&amp;gt; &lt;br /&gt;     &amp;lt;artifactId&amp;gt;ant-contrib&amp;lt;/artifactId&amp;gt; &lt;br /&gt;     &amp;lt;version&amp;gt;1.0b2&amp;lt;/version&amp;gt; &lt;br /&gt; &amp;lt;/dependency&amp;gt; &lt;br /&gt; &amp;lt;dependency&amp;gt; &lt;br /&gt;     &amp;lt;groupId&amp;gt;ant&amp;lt;/groupId&amp;gt; &lt;br /&gt;     &amp;lt;artifactId&amp;gt;ant-jakarta-regexp&amp;lt;/artifactId&amp;gt; &lt;br /&gt;     &amp;lt;version&amp;gt;1.6.1&amp;lt;/version&amp;gt; &lt;br /&gt; &amp;lt;/dependency&amp;gt; &lt;br /&gt; &amp;lt;dependency&amp;gt; &lt;br /&gt;     &amp;lt;groupId&amp;gt;ant&amp;lt;/groupId&amp;gt; &lt;br /&gt;     &amp;lt;artifactId&amp;gt;ant-nodeps&amp;lt;/artifactId&amp;gt; &lt;br /&gt;     &amp;lt;version&amp;gt;1.6.5&amp;lt;/version&amp;gt; &lt;br /&gt;&amp;lt;/dependency&amp;gt; &lt;br /&gt;&amp;lt;/dependencies&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/strong&gt; Define ant-contrib task as below:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;taskdef &lt;br /&gt;    resource=&amp;quot;net/sf/antcontrib/antlib.xml&amp;quot; classpathref=&amp;quot;maven.plugin.classpath&amp;quot;&amp;gt; &lt;br /&gt;&amp;lt;/taskdef&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 3:&lt;/u&gt;&lt;/strong&gt; Before invoking the mxmlc task, add the below ant script. If you are not using maven, then directly use the below ant script in the ant build.xml, making sure the dependent jars are present in the ant/lib directory.&lt;br /&gt;&lt;pre class="brush: xml;"&gt;    &amp;lt;fileset id=&amp;quot;assets.flex&amp;quot; dir=&amp;quot;src&amp;quot; includes=&amp;quot;**/*.jpg,**/*.png,**/*.css,**/*.swf,**/*.TTF,**/*.jpeg,**/*.xml&amp;quot; /&amp;gt; &lt;br /&gt;     &amp;lt;pathconvert pathsep=&amp;quot; &amp;quot; property=&amp;quot;assets.flex.output&amp;quot; refid=&amp;quot;assets.flex&amp;quot; dirsep=&amp;quot;/&amp;quot;&amp;gt; &lt;br /&gt;           &amp;lt;map from=&amp;quot;${basedir}/src/&amp;quot; to=&amp;quot;&amp;quot;/&amp;gt;                                    &lt;br /&gt;     &amp;lt;/pathconvert&amp;gt;                                  &lt;br /&gt;     &amp;lt;echo message=&amp;quot;...Resources being considered...&amp;quot;/&amp;gt; &lt;br /&gt;       &amp;lt;var name=&amp;quot;filelist&amp;quot; value=&amp;quot;&amp;quot;/&amp;gt; &lt;br /&gt;       &amp;lt;var name=&amp;quot;prefixfilelist&amp;quot; value=&amp;quot;-include-file&amp;quot;/&amp;gt; &lt;br /&gt;       &amp;lt;for list=&amp;quot;${assets.flex.output}&amp;quot; delimiter=&amp;quot; &amp;quot; param=&amp;quot;asset&amp;quot;&amp;gt; &lt;br /&gt;           &amp;lt;sequential&amp;gt;                                            &lt;br /&gt;             &amp;lt;echo&amp;gt;Asset:  @{asset}&amp;lt;/echo&amp;gt; &lt;br /&gt;             &amp;lt;propertyregex property=&amp;quot;prop&amp;quot; &lt;br /&gt;                      input=&amp;quot;@{asset}&amp;quot; &lt;br /&gt;                      regexp=&amp;quot;(.*)mainapp/src/(.*)&amp;quot; &lt;br /&gt;                      select=&amp;quot;\2&amp;quot; &lt;br /&gt;                      casesensitive=&amp;quot;false&amp;quot; /&amp;gt; &lt;br /&gt;             &amp;lt;var name=&amp;quot;filelist_tmp&amp;quot; value=&amp;quot;${filelist}&amp;quot;/&amp;gt; &lt;br /&gt;             &amp;lt;var name=&amp;quot;filelist&amp;quot; unset=&amp;quot;true&amp;quot;/&amp;gt; &lt;br /&gt;             &amp;lt;var name=&amp;quot;filelist&amp;quot; value=&amp;quot;${filelist_tmp} ${prefixfilelist} ${prop} @{asset}&amp;quot;/&amp;gt; &lt;br /&gt;             &amp;lt;var name=&amp;quot;prop&amp;quot; unset=&amp;quot;true&amp;quot;/&amp;gt;                                                &lt;br /&gt;           &amp;lt;/sequential&amp;gt; &lt;br /&gt;       &amp;lt;/for&amp;gt; &lt;br /&gt;      &amp;lt;echo message=&amp;quot;-output assets.swc ${filelist}&amp;quot;/&amp;gt; &lt;br /&gt;      &amp;lt;exec executable=&amp;quot;${FLEX_HOME}/bin/compc.exe&amp;quot; failonerror=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;      &amp;lt;arg line=&amp;quot;-output ../libs/assets.swc ${filelist}&amp;quot;/&amp;gt;                                    &lt;br /&gt;      &amp;lt;/exec&amp;gt; &lt;/pre&gt;&lt;br /&gt;Its just a simple program that generates the required argument for compc compiler and invokes it, any developer should be able to read and understand this script. Hence, I will leave out the explanations part of it.&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 4:&lt;/u&gt;&lt;/strong&gt; Proceed with the mxmlc task with libs in the class path, sample is given below:&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;mxmlc  file=&amp;quot;src/index.mxml&amp;quot; &lt;br /&gt;                    output=&amp;quot;../target/App.swf&amp;quot; &lt;br /&gt;                    link-report=&amp;quot;../target/report.xml&amp;quot; &lt;br /&gt;                warnings=&amp;quot;false&amp;quot; &lt;br /&gt;                services=&amp;quot;${CONFIG}/services-config.xml&amp;quot; &lt;br /&gt;                context-root = &amp;quot;/App&amp;quot; &lt;br /&gt;                                &amp;gt; &lt;br /&gt;                &amp;lt;load-config filename=&amp;quot;${FLEX_HOME}/frameworks/flex-config.xml&amp;quot;/&amp;gt; &lt;br /&gt;                &amp;lt;source-path path-element=&amp;quot;${FLEX_HOME}/frameworks&amp;quot;/&amp;gt; &lt;br /&gt;                &amp;lt;compiler.library-path dir=&amp;quot;${FLEX_HOME}/frameworks&amp;quot; append=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;                    &amp;lt;include name=&amp;quot;libs&amp;quot; /&amp;gt; &lt;br /&gt;                &amp;lt;/compiler.library-path&amp;gt; &lt;br /&gt;                &amp;lt;compiler.library-path dir=&amp;quot;../.&amp;quot; append=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;                    &amp;lt;include name=&amp;quot;libs&amp;quot; /&amp;gt; &lt;br /&gt;                &amp;lt;/compiler.library-path&amp;gt; &lt;br /&gt;                &amp;lt;compiler.source-path path-element=&amp;quot;../mainapp/src&amp;quot;/&amp;gt; &lt;br /&gt;            &amp;lt;/mxmlc&amp;gt; &lt;/pre&gt;&lt;br /&gt;This will make sure all your assets is present in the mxmlc build path, and the Embed transcode error does not occur.&lt;br /&gt;&lt;em&gt;I will put the entire ant run plugin in the pom file here for reference: &lt;/em&gt;&amp;#160;&amp;#160;&amp;#160;&lt;br /&gt;&lt;pre class="brush: xml; collapse: true;"&gt;&amp;lt;build&amp;gt; &lt;br /&gt;         &amp;lt;plugins&amp;gt; &lt;br /&gt;       &amp;lt;plugin&amp;gt; &lt;br /&gt;         &amp;lt;artifactId&amp;gt;maven-antrun-plugin&amp;lt;/artifactId&amp;gt; &lt;br /&gt;                  &amp;lt;dependencies&amp;gt; &lt;br /&gt;                    &amp;lt;dependency&amp;gt; &lt;br /&gt;                        &amp;lt;groupId&amp;gt;ant-contrib&amp;lt;/groupId&amp;gt; &lt;br /&gt;                        &amp;lt;artifactId&amp;gt;ant-contrib&amp;lt;/artifactId&amp;gt; &lt;br /&gt;                        &amp;lt;version&amp;gt;1.0b2&amp;lt;/version&amp;gt; &lt;br /&gt;                    &amp;lt;/dependency&amp;gt; &lt;br /&gt;                    &amp;lt;dependency&amp;gt; &lt;br /&gt;                        &amp;lt;groupId&amp;gt;ant&amp;lt;/groupId&amp;gt; &lt;br /&gt;                        &amp;lt;artifactId&amp;gt;ant-jakarta-regexp&amp;lt;/artifactId&amp;gt; &lt;br /&gt;                        &amp;lt;version&amp;gt;1.6.1&amp;lt;/version&amp;gt; &lt;br /&gt;                    &amp;lt;/dependency&amp;gt; &lt;br /&gt;                    &amp;lt;dependency&amp;gt; &lt;br /&gt;                        &amp;lt;groupId&amp;gt;ant&amp;lt;/groupId&amp;gt; &lt;br /&gt;                        &amp;lt;artifactId&amp;gt;ant-nodeps&amp;lt;/artifactId&amp;gt; &lt;br /&gt;                        &amp;lt;version&amp;gt;1.6.5&amp;lt;/version&amp;gt; &lt;br /&gt;                   &amp;lt;/dependency&amp;gt; &lt;br /&gt;                   &amp;lt;/dependencies&amp;gt; &lt;br /&gt;                   &amp;lt;executions&amp;gt; &lt;br /&gt;                  &amp;lt;execution&amp;gt; &lt;br /&gt;                    &amp;lt;phase&amp;gt;compile&amp;lt;/phase&amp;gt; &lt;br /&gt;                   &amp;lt;configuration&amp;gt; &lt;br /&gt;                   &amp;lt;tasks&amp;gt; &lt;br /&gt;                    &amp;lt;taskdef &lt;br /&gt;                        resource=&amp;quot;net/sf/antcontrib/antlib.xml&amp;quot; classpathref=&amp;quot;maven.plugin.classpath&amp;quot;&amp;gt; &lt;br /&gt;                    &amp;lt;/taskdef&amp;gt; &lt;br /&gt;                    &amp;lt;taskdef resource=&amp;quot;flexTasks.tasks&amp;quot; /&amp;gt; &lt;br /&gt;                    &amp;lt;fileset id=&amp;quot;assets.flex&amp;quot; dir=&amp;quot;src&amp;quot; includes=&amp;quot;**/*.jpg,**/*.png,**/*.css,**/*.swf,**/*.TTF,**/*.jpeg,**/*.xml&amp;quot; /&amp;gt; &lt;br /&gt;                        &amp;lt;pathconvert pathsep=&amp;quot; &amp;quot; property=&amp;quot;assets.flex.output&amp;quot; refid=&amp;quot;assets.flex&amp;quot; dirsep=&amp;quot;/&amp;quot;&amp;gt; &lt;br /&gt;                        &amp;lt;map from=&amp;quot;${basedir}/src/&amp;quot; to=&amp;quot;&amp;quot;/&amp;gt;                                    &lt;br /&gt;                      &amp;lt;/pathconvert&amp;gt;                                  &lt;br /&gt;                    &amp;lt;echo message=&amp;quot;...Resources being considered...&amp;quot;/&amp;gt; &lt;br /&gt;                      &amp;lt;var name=&amp;quot;filelist&amp;quot; value=&amp;quot;&amp;quot;/&amp;gt; &lt;br /&gt;                     &amp;lt;var name=&amp;quot;prefixfilelist&amp;quot; value=&amp;quot;-include-file&amp;quot;/&amp;gt; &lt;br /&gt;                    &amp;lt;for list=&amp;quot;${assets.flex.output}&amp;quot; delimiter=&amp;quot; &amp;quot; param=&amp;quot;asset&amp;quot;&amp;gt; &lt;br /&gt;                        &amp;lt;sequential&amp;gt;                                            &lt;br /&gt;                            &amp;lt;echo&amp;gt;Asset:  @{asset}&amp;lt;/echo&amp;gt; &lt;br /&gt;                            &amp;lt;propertyregex property=&amp;quot;prop&amp;quot; &lt;br /&gt;                                      input=&amp;quot;@{asset}&amp;quot; &lt;br /&gt;                                      regexp=&amp;quot;(.*)mainapp/src/(.*)&amp;quot; &lt;br /&gt;                                      select=&amp;quot;\2&amp;quot; &lt;br /&gt;                                      casesensitive=&amp;quot;false&amp;quot; /&amp;gt; &lt;br /&gt;                            &amp;lt;var name=&amp;quot;filelist_tmp&amp;quot; value=&amp;quot;${filelist}&amp;quot;/&amp;gt; &lt;br /&gt;                                &amp;lt;var name=&amp;quot;filelist&amp;quot; unset=&amp;quot;true&amp;quot;/&amp;gt; &lt;br /&gt;                            &amp;lt;var name=&amp;quot;filelist&amp;quot; value=&amp;quot;${filelist_tmp} ${prefixfilelist}     ${prop} @{asset}&amp;quot;/&amp;gt; &lt;br /&gt;                            &amp;lt;var name=&amp;quot;prop&amp;quot; unset=&amp;quot;true&amp;quot;/&amp;gt;                                                &lt;br /&gt;                        &amp;lt;/sequential&amp;gt; &lt;br /&gt;                    &amp;lt;/for&amp;gt; &lt;br /&gt;                    &amp;lt;echo message=&amp;quot;-output assets.swc ${filelist}&amp;quot;/&amp;gt; &lt;br /&gt;                    &amp;lt;exec executable=&amp;quot;${FLEX_HOME}/bin/compc.exe&amp;quot; failonerror=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;                        &amp;lt;arg line=&amp;quot;-output ../libs/assets.swc ${filelist}&amp;quot;/&amp;gt;                                    &lt;br /&gt;                    &amp;lt;/exec&amp;gt; &lt;br /&gt;                    &amp;lt;mxmlc  file=&amp;quot;src/index.mxml&amp;quot; &lt;br /&gt;                            output=&amp;quot;../target/App.swf&amp;quot; &lt;br /&gt;                            link-report=&amp;quot;../target/report.xml&amp;quot; &lt;br /&gt;                        warnings=&amp;quot;false&amp;quot; &lt;br /&gt;                        services=&amp;quot;${CONFIG}/services-config.xml&amp;quot; &lt;br /&gt;                        context-root = &amp;quot;/App&amp;quot; &lt;br /&gt;                                        &amp;gt; &lt;br /&gt;                        &amp;lt;load-config filename=&amp;quot;${FLEX_HOME}/frameworks/flex-config.xml&amp;quot;/&amp;gt; &lt;br /&gt;                        &amp;lt;source-path path-element=&amp;quot;${FLEX_HOME}/frameworks&amp;quot;/&amp;gt; &lt;br /&gt;                        &amp;lt;compiler.library-path dir=&amp;quot;${FLEX_HOME}/frameworks&amp;quot; append=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;                            &amp;lt;include name=&amp;quot;libs&amp;quot; /&amp;gt; &lt;br /&gt;                        &amp;lt;/compiler.library-path&amp;gt; &lt;br /&gt;                        &amp;lt;compiler.library-path dir=&amp;quot;../.&amp;quot; append=&amp;quot;true&amp;quot;&amp;gt; &lt;br /&gt;                            &amp;lt;include name=&amp;quot;libs&amp;quot; /&amp;gt; &lt;br /&gt;                        &amp;lt;/compiler.library-path&amp;gt; &lt;br /&gt;                        &amp;lt;compiler.source-path path-element=&amp;quot;../mainapp/src&amp;quot;/&amp;gt; &lt;br /&gt;                    &amp;lt;/mxmlc&amp;gt; &lt;br /&gt;                        &amp;lt;goals&amp;gt; &lt;br /&gt;                            &amp;lt;goal&amp;gt;run&amp;lt;/goal&amp;gt; &lt;br /&gt;                        &amp;lt;/goals&amp;gt; &lt;br /&gt;                    &amp;lt;/execution&amp;gt; &lt;br /&gt;                &amp;lt;/executions&amp;gt; &lt;br /&gt;            &amp;lt;/plugin&amp;gt; &lt;br /&gt;        &amp;lt;/plugins&amp;gt; &lt;br /&gt;    &amp;lt;/build&amp;gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5172933162870110280?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5172933162870110280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/flex-solution-to-error-unable-to.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5172933162870110280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5172933162870110280'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/flex-solution-to-error-unable-to.html' title='Flex : Solution to Error: unable to resolve &amp;#39;/assets/icons/icon.png&amp;#39; for transcoding using Embed tag'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-9216942113565027736</id><published>2008-12-07T00:00:00.001-08:00</published><updated>2008-12-07T00:01:43.736-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='webservice'/><category scheme='http://www.blogger.com/atom/ns#' term='JAX-WS'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='Generate Java code'/><title type='text'>Tutorial to use Eclipse with JAX-WS for contract-first Webservice</title><content type='html'>&lt;p&gt;I assume that the wsdl is already present and this tutorial is to show, how to use eclipse to generate the java code. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Configuration:         &lt;br /&gt;&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;Eclipse 3.3    &lt;br /&gt;JAX-WS RI 2.1.5    &lt;br /&gt;JDK 6 &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Download the JAX-WS RI jar(JAXWS2.1.5-20081030.jar) from &lt;a href="https://jax-ws.dev.java.net/2.1.5/"&gt;https://jax-ws.dev.java.net/2.1.5/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Run the command java -jar JAXWS2.1.5-20081030.jar, Accept the license and allow it to be installed. I will call this $JAXWS_HOME &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Open eclipse, and Run-&amp;gt;External Tools-&amp;gt;Open External Tools Dialogue.. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Give name as GenerateJavaFromWSDL, Location as $JAXWS_HOME\bin\wsimport.bat, Working Directory(path to directory containing wsdl) as ${project_loc}/WEB-INF/wsdl where ${project_loc} [Eclipse variable already defined in eclipse, no need to create this ]is the project location in eclipse, arguments as &amp;quot;myWSDL.wsdl -keep -d ${project_loc}/WEB-INF/src&amp;quot; [without quotes] where myWSDL.wsdl is the wsdl to generate java code, keep is to keep the generated java files and d is the output directory. You can also provide p as argument to specify the package for the java files being generated. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Click the Run button. The java files are generated.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-9216942113565027736?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/9216942113565027736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/tutorial-to-use-eclipse-with-jax-ws-for.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9216942113565027736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9216942113565027736'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/tutorial-to-use-eclipse-with-jax-ws-for.html' title='Tutorial to use Eclipse with JAX-WS for contract-first Webservice'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5312452448350809749</id><published>2008-12-03T23:27:00.001-08:00</published><updated>2009-06-25T04:24:05.131-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Filtering Collections'/><category scheme='http://www.blogger.com/atom/ns#' term='Filtering in Java'/><title type='text'>Filtering in Java</title><content type='html'>&lt;p&gt;I find the below piece of code pretty useful for filtering purposes in java. I use the apache Commons collection library for this purpose. In the below code snippet, I am filtering on id in the model Data present in the List. After running this code snippet, the 'list' will contain only those Data Objects that satisfy the filter criteria, in this case that will be 'userId = Id'. Predicate defines the filter criteria in the snippet below. &lt;/p&gt;  &lt;pre class="brush: java;"&gt;public void filterOnId(String Id,List&amp;lt;Data&amp;gt; list){ &lt;br /&gt;    final StringBuilder string = new StringBuilder(Id); &lt;br /&gt;    Predicate predicate = new Predicate(){ &lt;br /&gt;        public boolean evaluate(Object object) { &lt;br /&gt;            boolean returnValue = false; &lt;br /&gt;                if(object instanceof Data){ &lt;br /&gt;                Data vo = (Data)object; &lt;br /&gt;                returnValue = vo.getUserId().compareTo(string.toString())==0?true:false; &lt;br /&gt;            } &lt;br /&gt;            return returnValue; &lt;br /&gt;        } &lt;br /&gt;    }; &lt;br /&gt;CollectionUtils.filter(list, predicate); &lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5312452448350809749?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5312452448350809749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/filtering-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5312452448350809749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5312452448350809749'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/12/filtering-in-java.html' title='Filtering in Java'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-3829444725685804019</id><published>2008-11-30T23:05:00.001-08:00</published><updated>2009-06-26T02:30:51.991-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='Integrating Tomcat and activeMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Integrating ActiveMQ 5.1 with Tomcat 6</title><content type='html'>&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Add resource entry to CATALINA_HOME/conf/server.xml under GlobalNamingResources..&lt;/p&gt; &lt;pre class="brush: xml;"&gt;    &amp;lt;Resource &lt;br /&gt;name=&amp;quot;jms/ConnectionFactory&amp;quot; &lt;br /&gt;auth=&amp;quot;Container&amp;quot; &lt;br /&gt;type=&amp;quot;org.apache.activemq.ActiveMQConnectionFactory&amp;quot; &lt;br /&gt;description=&amp;quot;JMS Connection Factory&amp;quot; &lt;br /&gt;factory=&amp;quot;org.apache.activemq.jndi.JNDIReferenceFactory&amp;quot; &lt;br /&gt;brokerURL=&amp;quot;tcp://localhost:61616&amp;quot; &lt;br /&gt;brokerName=&amp;quot;LocalActiveMQBroker&amp;quot; &lt;br /&gt;useEmbeddedBroker=&amp;quot;false&amp;quot; &lt;br /&gt;    /&amp;gt; &lt;br /&gt;    &amp;lt;Resource &lt;br /&gt;name=&amp;quot;jms/Data&amp;quot; &lt;br /&gt;auth=&amp;quot;Container&amp;quot; &lt;br /&gt;type=&amp;quot;org.apache.activemq.command.ActiveMQTopic&amp;quot; &lt;br /&gt;description=&amp;quot;Data Topic&amp;quot; &lt;br /&gt;factory=&amp;quot;org.apache.activemq.jndi.JNDIReferenceFactory&amp;quot; &lt;br /&gt;physicalName=&amp;quot;queue.data&amp;quot;&lt;br /&gt;    /&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add resource link entry to CATALINA_HOME/conf/context.xml (For God knows What reason, An entry the context.xml in META-INF of my webapp did not work)&lt;br /&gt;&lt;pre class="brush: xml;"&gt;&amp;lt;ResourceLink global=&amp;quot;jms/ConnectionFactory&amp;quot; name=&amp;quot;jms/ConnectionFactory&amp;quot; type=&amp;quot;javax.jms.ConnectionFactory&amp;quot;/&amp;gt; &lt;br /&gt;&amp;lt;ResourceLink global=&amp;quot;jms/Data&amp;quot; name=&amp;quot;jms/Data&amp;quot; type=&amp;quot;javax.jms.Topic&amp;quot;/&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Add resource ref entry in web.xml&lt;br /&gt;&lt;pre class="brush: xml;"&gt;    &amp;lt;resource-ref&amp;gt; &lt;br /&gt;        &amp;lt;res-ref-name&amp;gt;jms/ConnectionFactory&amp;lt;/res-ref-name&amp;gt; &lt;br /&gt;        &amp;lt;res-type&amp;gt;javax.jms.ConnectionFactory&amp;lt;/res-type&amp;gt; &lt;br /&gt;        &amp;lt;res-auth&amp;gt;Container&amp;lt;/res-auth&amp;gt; &lt;br /&gt;        &amp;lt;res-sharing-scope&amp;gt;Shareable&amp;lt;/res-sharing-scope&amp;gt; &lt;br /&gt;    &amp;lt;/resource-ref&amp;gt; &lt;br /&gt;    &amp;lt;resource-ref&amp;gt; &lt;br /&gt;        &amp;lt;res-ref-name&amp;gt;jms/Data&amp;lt;/res-ref-name&amp;gt; &lt;br /&gt;        &amp;lt;res-type&amp;gt;javax.jms.Topic&amp;lt;/res-type&amp;gt; &lt;br /&gt;        &amp;lt;res-auth&amp;gt;Container&amp;lt;/res-auth&amp;gt; &lt;br /&gt;        &amp;lt;res-sharing-scope&amp;gt;Shareable&amp;lt;/res-sharing-scope&amp;gt; &lt;br /&gt;    &amp;lt;/resource-ref&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Put the following jars in CATALINA_HOME/lib from ActiveMQ_HOME/lib &lt;br /&gt;activemq-core-5.1.0.jar &lt;br /&gt;commons-logging-1.1.jar &lt;br /&gt;geronimo-j2ee-management_1.0_spec-1.0.jar &lt;br /&gt;geronimo-jms_1.1_spec-1.1.1.jar &lt;br /&gt;geronimo-jta_1.0.1B_spec-1.0.1.jar&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Start the server, you should be able to use JNDI to connect to ActiveMQ. &lt;/p&gt;&lt;br /&gt;&lt;strong&gt;Step 6&lt;/strong&gt;: When you use IntialContext in your code, first get the context of &amp;quot;java:comp/env&amp;quot;.&lt;br /&gt;&lt;pre class="brush: java;"&gt;    Context initCtx = new InitialContext(); &lt;br /&gt;    jndiContext = (Context) initCtx.lookup(&amp;quot;java:comp/env&amp;quot;); &lt;br /&gt;    Then you can use: &lt;br /&gt;    connectionFactory = (ConnectionFactory)jndiContext.lookup(&amp;quot;jms/ConnectionFactory&amp;quot;); &lt;br /&gt;    destination = (Destination)jndiContext.lookup(&amp;quot;jms/Data&amp;quot;); &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then, carry on with normal JMS flow.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-3829444725685804019?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/3829444725685804019/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/integrating-activemq-51-with-tomcat-6.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/3829444725685804019'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/3829444725685804019'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/integrating-activemq-51-with-tomcat-6.html' title='Integrating ActiveMQ 5.1 with Tomcat 6'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-9156611789239613276</id><published>2008-11-30T23:02:00.001-08:00</published><updated>2009-06-26T02:39:34.790-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JMS'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS Consumer'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS Message Listener'/><category scheme='http://www.blogger.com/atom/ns#' term='Topic subscriber client'/><title type='text'>JMS Tutorial : Topic Subscriber Client</title><content type='html'>&lt;p&gt;This is in continuation of my tutorial on JMS. The below client uses topic to communicate with the ActiveMQ. &lt;/p&gt; &lt;p&gt;The &lt;strong&gt;jndi.properties&lt;/strong&gt; &lt;/p&gt; &lt;pre class="brush: bash;"&gt;# START SNIPPET: jndi &lt;br /&gt;&lt;br /&gt;java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory &lt;br /&gt;&lt;br /&gt;# use the following property to configure the default connector &lt;br /&gt;java.naming.provider.url = tcp://localhost:61616 &lt;br /&gt;&lt;br /&gt;# use the following property to specify the JNDI name the connection factory &lt;br /&gt;# should appear as. &lt;br /&gt;#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry &lt;br /&gt;connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry &lt;br /&gt;&lt;br /&gt;# register some queues in JNDI using the form &lt;br /&gt;# queue.[jndiName] = [physicalName] &lt;br /&gt;&lt;br /&gt;# register some topics in JNDI using the form &lt;br /&gt;# topic.[jndiName] = [physicalName] &lt;br /&gt;#topic.MyTopic = example.MyTopic &lt;br /&gt;topic.sample.data = sample.data &lt;br /&gt;&lt;br /&gt;# END SNIPPET: jndi &lt;/pre&gt;&lt;br /&gt;&lt;pre class="brush: java;"&gt;/** &lt;br /&gt;* @author shreyas.purohit &lt;br /&gt;* &lt;br /&gt;*/ &lt;br /&gt;public class SampleJMSConsumer implements Runnable { &lt;br /&gt;&lt;br /&gt;    public void run() { &lt;br /&gt;        Context jndiContext = null; &lt;br /&gt;        TopicConnectionFactory connectionFactory = null; &lt;br /&gt;        TopicConnection connection = null; &lt;br /&gt;        TopicSession session = null; &lt;br /&gt;        TopicSubscriber consumer = null; &lt;br /&gt;        Topic destination = null; &lt;br /&gt;        String sourceName = null; &lt;br /&gt;        final int numMsgs; &lt;br /&gt;        sourceName = &amp;quot;sample.data&amp;quot;; &lt;br /&gt;&lt;br /&gt;        /* &lt;br /&gt;         * Create a JNDI API InitialContext object &lt;br /&gt;         */ &lt;br /&gt;        try { &lt;br /&gt;            jndiContext = new InitialContext(); &lt;br /&gt;        } catch (NamingException e) { &lt;br /&gt;            e.printStackTrace(); &lt;br /&gt;            System.exit(1); &lt;br /&gt;        } &lt;br /&gt;&lt;br /&gt;        /* &lt;br /&gt;         * Look up connection factory and destination. &lt;br /&gt;         */ &lt;br /&gt;        try { &lt;br /&gt;            connectionFactory = (TopicConnectionFactory) jndiContext &lt;br /&gt;                    .lookup(&amp;quot;topicConnectionFactry&amp;quot;); &lt;br /&gt;            destination = (Topic)jndiContext.lookup(sourceName); &lt;br /&gt;        } catch (NamingException e) { &lt;br /&gt;            e.printStackTrace(); &lt;br /&gt;            System.exit(1); &lt;br /&gt;        } &lt;br /&gt;&lt;br /&gt;        try { &lt;br /&gt;            connection = connectionFactory.createTopicConnection(); &lt;br /&gt;            session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); &lt;br /&gt;            consumer = session.createSubscriber(destination); &lt;br /&gt;            connection.start(); &lt;br /&gt;            try { &lt;br /&gt;                Thread.sleep(2000); &lt;br /&gt;            } catch (InterruptedException e) { &lt;br /&gt;                // TODO Auto-generated catch block &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;            } &lt;br /&gt;            MessageListener listener = new MyTopicMessageListener(); &lt;br /&gt;            consumer.setMessageListener(listener); &lt;br /&gt;            // Let the thread run for some time so that the Consumer has &lt;br /&gt;            // suffcient time to consume the message &lt;br /&gt;            try { &lt;br /&gt;                Thread.sleep(50000); &lt;br /&gt;            } catch (InterruptedException e) { &lt;br /&gt;                // TODO Auto-generated catch block &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;            } &lt;br /&gt;        } catch (JMSException e) { &lt;br /&gt;            e.printStackTrace(); &lt;br /&gt;        } finally { &lt;br /&gt;            if (connection != null) { &lt;br /&gt;                try { &lt;br /&gt;                    connection.close(); &lt;br /&gt;                } catch (JMSException e) { &lt;br /&gt;                } &lt;br /&gt;            } &lt;br /&gt;        } &lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;The message listener&lt;/strong&gt;:&lt;br /&gt;&lt;pre class="brush: java;"&gt;/** &lt;br /&gt;* @author shreyas.purohit &lt;br /&gt;* &lt;br /&gt;*/ &lt;br /&gt;public class MyTopicMessageListener implements MessageListener { &lt;br /&gt;&lt;br /&gt;    /* (non-Javadoc) &lt;br /&gt;     * @see javax.jms.MessageListener#onMessage(javax.jms.Message) &lt;br /&gt;     */ &lt;br /&gt;    public void onMessage(Message arg0) { &lt;br /&gt;        if(arg0 instanceof ObjectMessage){ &lt;br /&gt;            try { &lt;br /&gt;            //Print it out &lt;br /&gt;            System.out.println(&amp;quot;Recieved message in listener: &amp;quot; + ((ObjectMessage)arg0).getObject()); &lt;br /&gt;            System.out.println(&amp;quot;Co-Rel Id: &amp;quot; + ((ObjectMessage)arg0).getJMSCorrelationID()); &lt;br /&gt;            }catch(Exception e){ &lt;br /&gt;                e.printStackTrace(); &lt;br /&gt;                System.exit(1); &lt;br /&gt;            } &lt;br /&gt;        }else{ &lt;br /&gt;            System.out.println(&amp;quot;~~~~Error in format~~~&amp;quot;); &lt;br /&gt;        } &lt;br /&gt;    } &lt;br /&gt;&lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;The JMS Application&lt;/strong&gt;:&lt;br /&gt;&lt;pre class="brush: java;"&gt;/** &lt;br /&gt;* @author shreyas.purohit &lt;br /&gt;* &lt;br /&gt;*/ &lt;br /&gt;public class JMSApp { &lt;br /&gt;&lt;br /&gt;    /** &lt;br /&gt;     * @param args &lt;br /&gt;     */ &lt;br /&gt;    public static void main(String[] args) { &lt;br /&gt;        runInNewthread(new SampleJMSConsumer()); &lt;br /&gt;    } &lt;br /&gt;    public static void runInNewthread(Runnable runnable) { &lt;br /&gt;        Thread brokerThread = new Thread(runnable); &lt;br /&gt;        brokerThread.setDaemon(false); &lt;br /&gt;        brokerThread.start(); &lt;br /&gt;    } &lt;br /&gt;}&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-9156611789239613276?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/9156611789239613276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/jms-tutorial-topic-subscriber-client.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9156611789239613276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/9156611789239613276'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/jms-tutorial-topic-subscriber-client.html' title='JMS Tutorial : Topic Subscriber Client'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-7888745237269490129</id><published>2008-11-11T06:32:00.001-08:00</published><updated>2009-06-26T02:48:55.914-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RMI and Tomcat'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='RMI'/><category scheme='http://www.blogger.com/atom/ns#' term='RMI Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='AccesscontrolException'/><title type='text'>RMI Tutorial : RMI and tomcat</title><content type='html'>&lt;p&gt;Using RMI in java is very very easy, but, people like me will still get stuck using it, when trying to integrate with Tomcat. And, the help is very less outside in the internet. &lt;/p&gt; &lt;p&gt;There are &lt;strong&gt;two things&lt;/strong&gt; to remember:&lt;br/&gt;  &lt;strong&gt;1.&lt;/strong&gt; Provide sufficient access priviledges to the classes and jars using the RMI. This is done using catalina.policy present in $CATALINA_HOME/conf. Below is the addition to the policy files: &lt;/p&gt; &lt;pre class="brush: plain;"&gt;grant codeBase &amp;quot;file:${catalina.home}/webapps/MyAPP/WEB-INF/classes/-&amp;quot; { &lt;br /&gt;    permission java.security.AllPermission &amp;quot;&amp;quot;, &amp;quot;&amp;quot;; &lt;br /&gt;}; &lt;br /&gt;&lt;br /&gt;grant codeBase &amp;quot;file:${catalina.home}/webapps/MyAPP/WEB-INF/lib/-&amp;quot; { &lt;br /&gt;    permission java.security.AllPermission &amp;quot;&amp;quot;, &amp;quot;&amp;quot;; &lt;br /&gt;}; &lt;br /&gt;grant codeBase &amp;quot;file:${catalina.home}/webapps/MyAPP/WEB-INF/lib/some-common-3.0.jar&amp;quot; { &lt;br /&gt;    permission java.io.FilePermission &amp;quot;*&amp;quot;, &amp;quot;read, write&amp;quot;; &lt;br /&gt;}; &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;2.&lt;/strong&gt; Do not copy the entire code that is avalable on the internet for the server and client. The main() method given at lot of places in the web should not be copied as it is. Specifically, comment out the below snippet on both client and server:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: java;"&gt;//        if (System.getSecurityManager() == null) { &lt;br /&gt;//            System.setSecurityManager(new RMISecurityManager()); &lt;br /&gt;//        } &lt;/pre&gt;&lt;br /&gt;We do not want to install a new security manager. Tomcat provides the securitymanager, and lets use the same. Please do use the same if you want the RMI to work.&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Tutorial: &lt;/u&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Server side: &lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/strong&gt; Create an contract, an interface that extends java.rmi.Remote.&lt;br /&gt;&lt;pre class="brush: java;"&gt;public interface IRemoteService extends Remote{ &lt;br /&gt;&lt;br /&gt;    public final String serviceName = &amp;quot;MyRemoteService&amp;quot;; &lt;br /&gt;    public abstract void startDoing() throws RemoteException; &lt;br /&gt;&lt;br /&gt;    public abstract void stopDoing() throws RemoteException; &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/strong&gt; Write an implementation for the Interface.&lt;br /&gt;&lt;pre class="brush: java;"&gt;public class RemoteServiceImpl implements IRemoteService { &lt;br /&gt;    public RemoteServiceImpl(){ &lt;br /&gt;        super(); &lt;br /&gt;    } &lt;br /&gt;    public void startDoing() throws RemoteException { &lt;br /&gt;        return new MyTask().do(); &lt;br /&gt;    } &lt;br /&gt;    public void stopDoing() throws RemoteException { &lt;br /&gt;        return new MyTask().dont(); &lt;br /&gt;    }    &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 3:&lt;/u&gt;&lt;/strong&gt; Either use a startup servlet or any class that is called after the server is up and running and before the remote service is invoked, and initialize the registry. In the blow snippet case, just create a new object some where before service will be invoked. Note in below code, there is no securitymanager present anywhere.&lt;br /&gt;&lt;pre class="brush: java;"&gt;public class InitRemoteService { &lt;br /&gt;    public static boolean isRegistered = false; &lt;br /&gt;    public static IRemoteService service; &lt;br /&gt;    public InitRemoteService(){ &lt;br /&gt;     if(!isRegistered){ &lt;br /&gt;        try { &lt;br /&gt;            service = new RemoteServiceImpl(); &lt;br /&gt;            IRemoteService stub = &lt;br /&gt;                (IRemoteService) UnicastRemoteObject.exportObject(service, 0); &lt;br /&gt;            Registry registry = LocateRegistry.createRegistry(9345); &lt;br /&gt;            registry.rebind(IRemoteService.serviceName, stub); &lt;br /&gt;            System.out.println(&amp;quot;Remote service bound&amp;quot;); &lt;br /&gt;            isRegistered = true; &lt;br /&gt;        } catch (Exception e) { &lt;br /&gt;            System.err.println(&amp;quot;Remote service exception:&amp;quot;); &lt;br /&gt;            e.printStackTrace(); &lt;br /&gt;        } &lt;br /&gt;    } &lt;br /&gt;    } &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Client Side: &lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br/&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Step 1:&lt;/u&gt;&lt;/strong&gt; Write the client as given below in the snippet. You can note, there is no security manager related code either here. It also, lists all the service names in the registry.&lt;br /&gt;&lt;pre class="brush: java;"&gt;try { &lt;br /&gt;    Registry registry = LocateRegistry.getRegistry(HOST,9345); &lt;br /&gt;    String[] names = registry.list(); &lt;br /&gt;    for(String name1 : names){ &lt;br /&gt;        System.out.println(&amp;quot;~~~~&amp;quot; + name1 + &amp;quot;~~~~&amp;quot;); &lt;br /&gt;    } &lt;br /&gt;    IDPRemoteService serv = (IDPRemoteService) registry.lookup(IDPRemoteService.serviceName); &lt;br /&gt;    System.out.println(serv.startDoing()); &lt;br /&gt;} catch (Exception e) { &lt;br /&gt;    System.err.println(&amp;quot;Remoteservice exception:&amp;quot;); &lt;br /&gt;    e.printStackTrace(); &lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Enjoy, using RMI for remote object invocations, esp on servers like Tomcat that does not support EJB's or when EJB level of advanced concept is not required.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-7888745237269490129?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/7888745237269490129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/rmi-tutorial-rmi-and-tomcat.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7888745237269490129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/7888745237269490129'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/rmi-tutorial-rmi-and-tomcat.html' title='RMI Tutorial : RMI and tomcat'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6322231394271781021</id><published>2008-11-11T01:12:00.001-08:00</published><updated>2009-06-26T02:50:51.801-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Properties'/><title type='text'>Accessing resources from Java Class</title><content type='html'>Here is a simple code snippet that can be used to get properties file from a java program. &lt;pre class="brush: java;"&gt;Properties config = new Properties(); &lt;br /&gt;try { &lt;br /&gt;    config.load(new FileInputStream(new File(URLDecoder.decode(getClass().getClassLoader().getResource(CONFIG_FILE_NAME).getFile(), &amp;quot;UTF-8&amp;quot;)))); &lt;br /&gt;} catch (Exception e1) { &lt;br /&gt;    e1.printStackTrace(); &lt;br /&gt;    throw new RuntimeException(e1); &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;This, snippet has never let me down till now in getting a properties file.  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6322231394271781021?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6322231394271781021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/accessing-resources-from-java-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6322231394271781021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6322231394271781021'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/accessing-resources-from-java-class.html' title='Accessing resources from Java Class'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-8091857196894924051</id><published>2008-11-10T06:48:00.001-08:00</published><updated>2008-11-10T06:48:20.461-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Problem writing Object to outputstream'/><category scheme='http://www.blogger.com/atom/ns#' term='Objectoutputstream'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Outputstream writes the same object'/><title type='text'>ObjectOutputStream : Writing the same object over and over again!</title><content type='html'>&lt;p&gt;Well, Well, Well.. You know, I was just writing a very tiny socket application in Java and was stuck for a long time on 'Writing Objects from server to Client!'. I myself can not believe that. With so many samples around on the Internet, I was still stuck. A pretty interesting problem I would like to share. I have a server writing objects to its clients. But the client is always receiving the same object. The first one. The code snippet is given below: &lt;/p&gt;  &lt;p&gt;....   &lt;br /&gt;....    &lt;br /&gt;....    &lt;br /&gt;os = new ObjectOutputStream(socket.getOutputStream());    &lt;br /&gt;....    &lt;br /&gt;....    &lt;br /&gt;.... &lt;/p&gt;  &lt;p&gt;if(toBeSentData.shouldConsume()){   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Object object = toBeSentData.get();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if(null != object){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; os.writeObject(object);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; os.flush();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;You can see, I am flushing the output stream. I debugged through the writeObject code, to find out that my Object was not written at all. Some handle was written. Specifically, in method private void writeObject0(Object obj, boolean unshared) throws IOException, the snippet is present below. &lt;/p&gt;  &lt;p&gt;// handle previously written and non-replaceable objects   &lt;br /&gt;int h;    &lt;br /&gt;if ((obj = subs.lookup(obj)) == null) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; writeNull();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return;    &lt;br /&gt;&lt;strong&gt;} else if (!unshared &amp;amp;&amp;amp; (h = handles.lookup(obj)) != -1) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; writeHandle(h);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return;      &lt;br /&gt;&lt;/strong&gt;} else if (obj instanceof Class) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; writeClass((Class) obj, unshared);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return;    &lt;br /&gt;} else if (obj instanceof ObjectStreamClass) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; writeClassDesc((ObjectStreamClass) obj, unshared);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return;    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;The handles.lookup(obj) was never returning -1. So, the problem is some sort of caching(Not exactly caching) I understood. The only guy who had explained this was Qusay H. Mahmoud in his December 2001 post about Advanced Socket Programming at &lt;a href="http://java.sun.com/developer/technicalArticles/ALT/sockets/"&gt;http://java.sun.com/developer/technicalArticles/ALT/sockets/&lt;/a&gt;    &lt;br /&gt;I really thank him for that, else I would have been stuck with the problemo for god knows How long!! &lt;/p&gt;  &lt;p&gt;I will just copy the last part of the article here. This is what gave me the solution. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;&lt;u&gt;Object Serialization Pitfall&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;    &lt;p&gt;When working with object serialization it is important to keep in mind that the ObjectOutputStream maintains a hashtable mapping the objects written into the stream to a handle. When an object is written to the stream for the first time, its contents will be copied to the stream. Subsequent writes, however, result in a handle to the object being written to the stream. This may lead to a couple of problems: &lt;/p&gt;    &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; * If an object is written to the stream then modified and written a second time, the modifications will not be noticed when the stream is deserialized. Again, the reason is that subsequent writes results in the handle being written but the modified object is not copied into the stream. To solve this problem, call the ObjectOutputStream.reset method that discards the memory of having sent an object so subsequent writes copy the object into the stream.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; * An OutOfMemoryError may be thrown after writing a large number of objects into the ObjectOutputStream. The reason for this is that the hashtable maintains references to objects that might otherwise be unreachable by an application. This problem can be solved simply by calling the ObjectOutputStream.reset method to reset the object/handle table to its initial state. After this call, all previously written objects will be eligible for garbage collection. &lt;/p&gt;    &lt;p&gt;The reset method resets the stream state to be the same as if it had just been constructed. This method may not be called while objects are being serialized. Inappropriate invocations of this method result in an IOException. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Just call the os.reset(); after flush. It worked like a charm for me!!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-8091857196894924051?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/8091857196894924051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/objectoutputstream-writing-same-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/8091857196894924051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/8091857196894924051'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/11/objectoutputstream-writing-same-object.html' title='ObjectOutputStream : Writing the same object over and over again!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5065444366809338931</id><published>2008-10-11T14:45:00.001-07:00</published><updated>2008-10-12T02:42:05.321-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='generate actionscript from java classes'/><category scheme='http://www.blogger.com/atom/ns#' term='xdoc plugin to generate actionscript'/><category scheme='http://www.blogger.com/atom/ns#' term='Action Script Generator'/><category scheme='http://www.blogger.com/atom/ns#' term='AS generator'/><title type='text'>AS Model generator : XDoclet2 plugin to generate the Flex model AS file for the respective java server side value objects</title><content type='html'>&lt;p&gt;My previous post gave an introduction to this plugin for xdoclet2 by writing a tutorial on xdoclet2 and velocity with this plugin as an example. Now, I will explain what this plugin can do. &lt;/p&gt;  &lt;p&gt;First download the latest plugin(as3-plugin.jar) from: &lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4" href="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4"&gt;http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The supported annotations are:&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;em&gt;as3.class&lt;/em&gt; - A class level tag.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;Attributes:&lt;/u&gt;     &lt;br /&gt;&lt;strong&gt;1.a.&lt;/strong&gt; &lt;em&gt;name&lt;/em&gt; - The name of the generated AS class. Should be same as the java class name. Required.     &lt;br /&gt;&lt;strong&gt;1.b.&lt;/strong&gt; &lt;em&gt;generate&lt;/em&gt; - On false, does not generate the AS file for the java class. Default: true.     &lt;br /&gt;&lt;strong&gt;1.c.&lt;/strong&gt; &lt;em&gt;generate-bindable-metadata&lt;/em&gt; - Generates [Bindable] at class level in AS. Default value: true.     &lt;br /&gt;&lt;strong&gt;1.d.&lt;/strong&gt; &lt;em&gt;generate-remote-class-metadata&lt;/em&gt; - Generates [RemoteClass(alias=&amp;quot;..&amp;quot;)] on true. Default value: false. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;em&gt;as3.field&lt;/em&gt; - A Field level tag. &lt;/p&gt;  &lt;p&gt;&lt;u&gt;Attributes:&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2.a. &lt;/strong&gt;&lt;em&gt;type&lt;/em&gt; - The fully qualified flex type to be generated in the AS file. Required.     &lt;br /&gt;&lt;strong&gt;2.b.&lt;/strong&gt; &lt;em&gt;import&lt;/em&gt; - Imports the flex type defined above. Default: false.     &lt;br /&gt;&lt;strong&gt;2.c.&lt;/strong&gt; &lt;em&gt;generate-bindable-field-metadata&lt;/em&gt; - Generate field level [Bindable] in the AS file. Default: false.     &lt;br /&gt;&lt;strong&gt;2.d.&lt;/strong&gt; &lt;em&gt;generate&lt;/em&gt; - Controls generation of the field in as files. Default: true. &lt;/p&gt;  &lt;p&gt;The Java-Flex mapping supported are: &lt;/p&gt;  &lt;p&gt;1. int - Number    &lt;br /&gt;2. double - Number     &lt;br /&gt;3. long - Number     &lt;br /&gt;4. java.lang.Short - Number     &lt;br /&gt;5. java.lang.Byte - Number     &lt;br /&gt;6. java.lang.Integer - Number     &lt;br /&gt;7. java.lang.Double - Number     &lt;br /&gt;8. java.lang.Long - Number     &lt;br /&gt;9. java.lang.Float - Number     &lt;br /&gt;10. java.lang.String - String     &lt;br /&gt;11. java.lang.Character - String     &lt;br /&gt;12. java.util.Collection - mx.collection.ArrayCollection     &lt;br /&gt;13. java.util.Map - Object     &lt;br /&gt;14. java.util.Dictionary - Object     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;For any other type define the as3.field with the flex type, and if the import is necessary. If that does not solve the problem, define it as Object, then cast it in the flex code when necessary. If this too does not solve the problem contact me on my blog. Will add the feature and release the next version. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Usage:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Write a ant build script and invoke xdoclet with target: &lt;/p&gt;  &lt;p&gt;&amp;lt;target name=&amp;quot;generate&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;xdoclet&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;fileset dir=&amp;quot;${basedir}/src&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;include name=&amp;quot;**/*.java&amp;quot;/&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/fileset&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;component classname=&amp;quot;com.ssb.plugin.as3.As3Plugin&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; destdir=&amp;quot;${basedir}/src&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/xdoclet&amp;gt;     &lt;br /&gt;&amp;lt;/target&amp;gt;&lt;/p&gt;  &lt;p&gt;Please look at my previous post for the sample model class which uses all these annotations.    &lt;br /&gt;Download the latest sample (AS3Sample.rar) from the below link and see the build file for details. &lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4" href="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4"&gt;http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5065444366809338931?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5065444366809338931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/as-model-generator-xdoclet2-plugin-to.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5065444366809338931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5065444366809338931'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/as-model-generator-xdoclet2-plugin-to.html' title='AS Model generator : XDoclet2 plugin to generate the Flex model AS file for the respective java server side value objects'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-4473723234277076592</id><published>2008-10-11T14:36:00.001-07:00</published><updated>2008-10-12T02:53:20.753-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VTL'/><category scheme='http://www.blogger.com/atom/ns#' term='velocity basic tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='actionscript generator'/><category scheme='http://www.blogger.com/atom/ns#' term='xdoclet2'/><category scheme='http://www.blogger.com/atom/ns#' term='velocity'/><category scheme='http://www.blogger.com/atom/ns#' term='xdoclet2 plugin tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='actionscript code generator using xdoclet'/><category scheme='http://www.blogger.com/atom/ns#' term='Keeping flex and java model in sync'/><category scheme='http://www.blogger.com/atom/ns#' term='AS generator'/><title type='text'>XDoclet2 Custom Plugin ( Actionscript3 (AS3) model generator from java value objects ) and Velocity Tutorial</title><content type='html'>&lt;p&gt;I work on flex and it was necessary for me to generate the flex side model classes in sync with the java side value objects. I Googled but was not able to find one that is as simple as the one written by Joe Berkovitz of Allurent. It was pretty old code and lacked configuration options for generating AS classes. I decided to write my own plugin for xdoclet2 that can be used to generate the flex code. And, here given below is a tutorial for learning xdoclet2. Since, the template engine it uses is velocity, this post also serves as a tutorial for velocity. Finally, I provide you with a complete working edition of the xdoclet2 plugin, and a sample to use the same. &lt;/p&gt;  &lt;p&gt;Please look at the end of this tutorial to find links to the source, plugin jar and sample files. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;System Configuration&lt;/u&gt;&lt;/strong&gt;     &lt;br /&gt;&lt;em&gt;1. xdoclet2 v1.0.4      &lt;br /&gt;2. velocity 1.5       &lt;br /&gt;3. JDK 5 update 15       &lt;br /&gt;4. ant 1.7.1&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;XDoclet2 &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;XDoclet2 allows you to read the annotations on the java source files, and generate either XML or Java or any other file. It uses velocity template engine for any file type generation, and Jelly template engine for XML generation. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;u&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;&lt;/u&gt;&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;Download the xdoclet2 plugin distribution from &lt;a href="http://sourceforge.net/projects/xdoclet-plugins/"&gt;http://sourceforge.net/projects/xdoclet-plugins/&lt;/a&gt;     &lt;br /&gt;Extract the zip or the tar.gz to an comfortable location. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 2:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Write the sample java class with the annotations that needs to be supported by the plugin. In my case I wrote Model.java. A sample snippet is given below: &lt;/p&gt;  &lt;p&gt;package com.ssb.sample;    &lt;br /&gt;import java.math.BigDecimal;     &lt;br /&gt;import java.math.BigInteger;     &lt;br /&gt;/**     &lt;br /&gt;*     &lt;br /&gt;* @author Shreyas     &lt;br /&gt;* @as3.class name=&amp;quot;Model&amp;quot; generate=&amp;quot;true&amp;quot; generate-bindable-metadata=&amp;quot;true&amp;quot; generate-remote-class-metadata=&amp;quot;true&amp;quot;     &lt;br /&gt;*/     &lt;br /&gt;public class Model {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private int i;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private double d;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private long l;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @as3.field type=&amp;quot;Number&amp;quot; import=&amp;quot;false&amp;quot; generate-bindable-field-metadata=&amp;quot;true&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private BigDecimal bdecimal;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @as3.field type=&amp;quot;mx.flex.BigInt&amp;quot; import=&amp;quot;true&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private BigInteger binteger; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @as3.field type=&amp;quot;mx.flex.BigInt&amp;quot; generate=&amp;quot;false&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private transient BigInteger doNotGeneratebinteger;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; .     &lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 3:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Define Tag validators. This is helpful for validating if the annotations provided are as anticipated. Tag validators extends DocletTag as shown below. The interface itself is annotated using the qtags. &lt;/p&gt;  &lt;p&gt;package com.ssb.plugin.as3.qtags;    &lt;br /&gt;import com.thoughtworks.qdox.model.DocletTag;     &lt;br /&gt;/**     &lt;br /&gt;*     &lt;br /&gt;* @qtags.location class     &lt;br /&gt;* @qtags.once     &lt;br /&gt;*     &lt;br /&gt;*/     &lt;br /&gt;public interface As3ClassTag extends DocletTag{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @qtags.required     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; String getName_();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @qtags.default true     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; String isGenerate();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @qtags.default true     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; String isGenerateBindableMetadata();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @qtags.default false     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; String isGenerateRemoteClassMetadata();     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;&lt;em&gt;There are some points to be noted:&lt;/em&gt;     &lt;br /&gt;&lt;strong&gt;a.&lt;/strong&gt; There is a one to one matching between the name of the interface - As3ClassTag -&amp;#160; and the annotation on the sample class -as3.class-. The First letter is capitalized, the '.' is removed, the next letter is also capitalized, a 'Tag' is appended.     &lt;br /&gt;&lt;strong&gt;b.&lt;/strong&gt; The methods in the interface uses the standard java bean convention. For each attribute in the tag, 'get' or 'is' is prefixed to the attribute name with the first letter capitalized.     &lt;br /&gt;&lt;strong&gt;c.&lt;/strong&gt; 'name' is a special attribute, a '_' should be used at the end of the getter to avoid internal naming collision.     &lt;br /&gt;&lt;strong&gt;d.&lt;/strong&gt; The attribute when contains '-', the methods in the interface nelects it and follows the first letter capitalization rule.     &lt;br /&gt;&lt;strong&gt;e.&lt;/strong&gt; Do not use camel casing in the sample annotation. Use only small letters or hyphens to separate for ease of work. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Definitions of tags:&lt;/em&gt;     &lt;br /&gt;&lt;strong&gt;a.&lt;/strong&gt; qtags.location Whether the tag applies to class level or field level or method level, repectively, we have class, field, method as its values.     &lt;br /&gt;&lt;strong&gt;b.&lt;/strong&gt; qtags.once The tag can be used only once in teh source file.     &lt;br /&gt;&lt;strong&gt;c.&lt;/strong&gt; qtags.required The field is required.     &lt;br /&gt;&lt;strong&gt;d.&lt;/strong&gt; qtags.default The default value of the field. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 4:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Generate the tag validator implementation and tag library. The tag library will be used by our plugin. A ant script is used to generate these items. The target to generate is given below. Please look at source code to get the entire build script. &lt;/p&gt;  &lt;p&gt;&amp;lt;target name=&amp;quot;gen.qtags.impl&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;property name=&amp;quot;xdoclet.qtags.namespace&amp;quot; value=&amp;quot;as3&amp;quot;/&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;xdoclet&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;fileset dir=&amp;quot;src&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;include name=&amp;quot;**/*.java&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/fileset&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;component     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; classname=&amp;quot;org.xdoclet.plugin.qtags.impl.QTagImplPlugin&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; destdir=&amp;quot;${basedir}/src&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /&amp;gt;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;component     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; classname=&amp;quot;org.xdoclet.plugin.qtags.impl.QTagLibraryPlugin&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; destdir=&amp;quot;${basedir}/src&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; packagereplace=&amp;quot;com.ssb.plugin.${xdoclet.qtags.namespace}.qtags&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/xdoclet&amp;gt;     &lt;br /&gt;&amp;lt;/target&amp;gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 5:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Write the xdoclet2 plugin. As3Plugin extends QDoxPlugin. &lt;/p&gt;  &lt;p&gt;package com.ssb.plugin.as3;    &lt;br /&gt;import java.util.*;     &lt;br /&gt;import org.apache.log4j.Logger;     &lt;br /&gt;import org.generama.*     &lt;br /&gt;import com.ssb.plugin.as3.qtags.TagLibrary;     &lt;br /&gt;import com.thoughtworks.qdox.model.*; &lt;/p&gt;  &lt;p&gt;public class As3Plugin extends QDoxPlugin{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private Map&amp;lt;String, String&amp;gt; typeMap = new HashMap&amp;lt;String, String&amp;gt;();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public As3Plugin(VelocityTemplateEngine templateEngine,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; QDoxCapableMetadataProvider metadataProvider,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WriterMapper writerMapper) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Call the superclass constructor.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(templateEngine, metadataProvider, writerMapper);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ..     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ..     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; .. &lt;/p&gt;  &lt;p&gt;In the above snippet, the constructor takes VelocityTeplateEngine as argument. Do not bother how it gets that. The xdoclet is responsible for injecting it to the constructor. First, call the super class constructor. &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Replace .java with .as extensions    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; setFileregex(&amp;quot;.java&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; setFilereplace(&amp;quot;.as&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Set Multiple file output to true.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; setMultioutput(true);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Instantiate the generated tag library.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; new TagLibrary(metadataProvider);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Initialize the the type map     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; initTypeMap();     &lt;br /&gt;The comments are pretty clear for the above code snippet. This ends the constructor. &lt;/p&gt;  &lt;p&gt;The initTypeMap method is shown below. &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Initializes the type map.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; protected void initTypeMap() {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeMap.put(&amp;quot;int&amp;quot;, &amp;quot;Number&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeMap.put(&amp;quot;double&amp;quot;, &amp;quot;Number&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeMap.put(&amp;quot;long&amp;quot;, &amp;quot;Number&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeMap.put(&amp;quot;java.lang.Short&amp;quot;, &amp;quot;Number&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; typeMap.put(&amp;quot;java.lang.Byte&amp;quot;, &amp;quot;Number&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ..     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ..     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ..     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Over ridden method, determines whether the given java class should be converted to as3 or not.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param metadata A java Class.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public boolean shouldGenerate(Object metadata) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; JavaClass javaClass = (JavaClass) metadata;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; boolean ignore = &amp;quot;false&amp;quot;.equalsIgnoreCase(javaClass.getNamedParameter(&amp;quot;as3.class&amp;quot;,&amp;quot;generate&amp;quot;));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (!ignore)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return true;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; else     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return false;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;The above method decides whether AS files should be generated or not for the annotated java file. This is called by xdoclet and the Object argument is a JavaClass type. The getNamedParameter takes the annotation name and the attribute whose value has to be retrieved. If, it is false then do not generate the AS file. &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; protected void populateContextMap(Map map) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super.populateContextMap(map);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; map.put(&amp;quot;tagUtil&amp;quot;, new TagUtil());    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt; The above code initializes the context map by adding tagUtil, so that it can be accessed by velocity template.   &lt;br /&gt;  &lt;p&gt;Now for each of the annotation and its attribute write a public method to get its value. This is present in TagUtil.java. Remember, it is public. Protected will not work, as this will be later used by the Velocity. Here below are sample for two of them: &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Gets the As3 Class name from the annotation as3.class, attribute 'name'     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param metadata The java class.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public String getAs3Name(Object metadata){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; JavaClass javaClass = (JavaClass) metadata;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return javaClass.getNamedParameter(&amp;quot;as3.class&amp;quot;,&amp;quot;name&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Gets the Field type from the annotation as3.field, attribute 'type'     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param metadata The java Field.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public String getTypeName(Object metadata){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; JavaField javaField = (JavaField)metadata;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return getTagValue(&amp;quot;as3.field&amp;quot;, &amp;quot;type&amp;quot;, javaField);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private String getTagValue(String tagName,String tagAttribute, JavaField field){&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return field.getNamedParameter(tagName, tagAttribute);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;This is it!! Really, this is all it takes to write a XDoclet related code for the plugin. Now, we have to integrate it with velocity to generate the output AS files. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;Step 6:&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Write the Velocity template file for Code generation. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Velocity &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Step 1:&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt; Create a As3Plugin.vm file at com.ssb.plugin.as3 package, same package as the plugin. The file name must identical to the plugin name. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;em&gt;Step 2:&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt; Write the velocity code in the vm file. It is shown below as snippets. &lt;/p&gt;  &lt;p&gt;// ${dontedit}    &lt;br /&gt;#set( $class = $metadata )     &lt;br /&gt;#set( $truevalue = &amp;quot;true&amp;quot;) &lt;/p&gt;  &lt;p&gt;The ${} are variables that can hold values in the VTL(Velocity template language). #set is used to assign values. In working with xdoclet, the $metadata is injected from xdoclet and holds the class name. $truevalue is assigned string 'true'; &lt;/p&gt;  &lt;p&gt;package $plugin.getDestinationPackage($class);    &lt;br /&gt;{     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;#foreach($field in $class.getFields())   &lt;br /&gt; #set($import = $plugin.shouldImport($field))    &lt;br /&gt;&amp;#160; #if($import != &amp;quot;false&amp;quot;)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; import $import;    &lt;br /&gt;&amp;#160; #end    &lt;br /&gt;#end    &lt;br /&gt;#if($tagUtil.isGenerateBindableMetadata($class) == $truevalue)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [Bindable]    &lt;br /&gt;#end     &lt;br /&gt;..     &lt;br /&gt;.. &lt;/p&gt;  &lt;p&gt;Other variables that are available to the velocity are $plugin and $tagUtil. $plugin holds the instance of the As3Plugin class. Velocity can be used to invoke java methods through this variable, passing any arguments if required. The getDestinationPackage method is present in the base class of the As3Plugin. It gives the package of the java class. The package of the AS class will be same as this one.    &lt;br /&gt;#foreach is a directive to loop in velocity. Velocity supports #if#elseif#else#end directive also. Any method you see being invoked on $plugin is actually being invoked on As3Plugin java side object. So, shouldImport calls the As3Plugin classes shouldImport method. Similarly, isGenerateBindableMetadata calls the TagUtil classes isGenerateBindableMetadata method.&lt;/p&gt;  &lt;p&gt;Velocity supports writing methods, by defining macro's etc, but that is not needed for writing this template file. That's all is velocity!! Its the most basic stuff in velocity that is being used here. Please refer velocity user manual for more detailed information( &lt;a href="http://velocity.apache.org/engine/devel/user-guide.html"&gt;http://velocity.apache.org/engine/devel/user-guide.html&lt;/a&gt; ). &lt;/p&gt;  &lt;p&gt;Every thing needed for our plugin is now in place. Just compile the classes, include all the resources and build the plugin jar. The build script is provided in the source. &lt;/p&gt;  &lt;p&gt;To use the plugin, write a ant build script as given below: &lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;    &lt;br /&gt;&amp;lt;project name=&amp;quot;Test AS3 Plugin Jar&amp;quot; default=&amp;quot;main&amp;quot;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;property file=&amp;quot;build.properties&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;path id=&amp;quot;xdoclet.task.classpath&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;!-- xdoclet2 runtime dependencies --&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;fileset dir=&amp;quot;${xdoclet.plugin.install.dir}/lib&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;include name=&amp;quot;**/*.jar&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/fileset&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;pathelement location=&amp;quot;${basedir}/lib/as3-plugin.jar&amp;quot;/&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/path&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;!-- Define xdoclet task --&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;taskdef     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; name=&amp;quot;xdoclet&amp;quot; classname=&amp;quot;org.xdoclet.ant.XDocletTask&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; classpathref=&amp;quot;xdoclet.task.classpath&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;target name=&amp;quot;main&amp;quot; depends=&amp;quot;generate&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;target name=&amp;quot;generate&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;xdoclet&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;fileset dir=&amp;quot;${basedir}/src&amp;quot;&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;include name=&amp;quot;**/*.java&amp;quot;/&amp;gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/fileset&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;component classname=&amp;quot;com.ssb.plugin.as3.As3Plugin&amp;quot;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; destdir=&amp;quot;${basedir}/src&amp;quot;/&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/xdoclet&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/target&amp;gt;     &lt;br /&gt;&amp;lt;/project&amp;gt; &lt;/p&gt;  &lt;p&gt;build.properties contain:    &lt;br /&gt;xdoclet.plugin.install.dir = E:/DevToolsInstalled/xdoclet-plugins-dist-1.0.4 &lt;/p&gt;  &lt;p&gt;This completes the tutorial for writing xdoclet2 plugin using velocity template engine. This generates non java files, .as, as output. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Resources:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Go to: &lt;a title="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4" href="http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4"&gt;http://www.mediafire.com/?sharekey=ea4e9d31329795efab1eab3e9fa335cab8df53a76b412bf4&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;1. Download the latest plugin jar (as3-plugin.jar).&lt;/p&gt;  &lt;p&gt;2. Download the latest source (AS3GeneratorSrc.rar) of the plugin. Edit the build.properties to provide the xdoclet2 installation director.    &lt;br /&gt;Run ant on build.xml to generate the as3-plugin.jar in the base directory. &lt;/p&gt;  &lt;p&gt;3. Download the latest sample (AS3Sample.rar) usage. Edit the build.properties to provide the xdoclet2 installation director.    &lt;br /&gt;Run ant on build.xml to generate Model.as, Model2.as at com.ssb.sample. &lt;/p&gt;  &lt;p&gt;4. Download the latest java doc (apidoc.rar).&lt;/p&gt;  &lt;p&gt;Please read my next post to understand the capabilities of the plugin.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-4473723234277076592?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/4473723234277076592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/xdoclet2-custom-plugin-actionscript3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4473723234277076592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4473723234277076592'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/xdoclet2-custom-plugin-actionscript3.html' title='XDoclet2 Custom Plugin ( Actionscript3 (AS3) model generator from java value objects ) and Velocity Tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-655376796298385444</id><published>2008-10-01T09:34:00.001-07:00</published><updated>2008-10-01T09:34:05.819-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Webservice Tutorial using CXF'/><category scheme='http://www.blogger.com/atom/ns#' term='webservice'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='CXF'/><category scheme='http://www.blogger.com/atom/ns#' term='CXF Tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='BlazeBS Turnkey Problem'/><title type='text'>Step by step CXF Webservice Tutorial</title><content type='html'>&lt;p&gt;We had an application running, and a webservice had to be exposed. With some experience in Axis2, I decided to learn some thing new, CXF service. Well Initially, I gave up on CXF service.(Will give the details in some time). So, thought let me use the Axis2 service. But, the only way I knew to use it was deploying the axis as webapp,and then writing and deploying the service as aar. So, a search to find integrating Axis2 with an existing webapp begins! And, with shame, I can tell, I was not able to find any where a clue about doing it. I could have experimented by including there axis distribution lib, and its web.xml content in my applications, but decided to learn some thing newer. And, hence the CXF. &lt;/p&gt;  &lt;p&gt;I was developing a flex app on the blazeds turnkey server that is distributed by adobe. And, the webservice had to be integrated with this existing application. Since, CXF was the one I wanted to learn, I tried using it(as given below in tutorial), but always ended up either with one or other exceptions as given below. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;1. On startup&amp;#160; of server this exception used to occur when all the jars of CXF are put in the WEB-INF/lib folder.&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;SEVERE: Context initialization failed   &lt;br /&gt;org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class pat    &lt;br /&gt;h resource [com/ssb/service/data.xml]; nested exception is java.lang.IllegalArgumentException: Class [org.spring    &lt;br /&gt;framework.scripting.config.LangNamespaceHandler] does not implement the NamespaceHandler interface    &lt;br /&gt;Caused by: java.lang.IllegalArgumentException: Class [org.springframework.scripting.config.LangNamespaceHandler] does no    &lt;br /&gt;t implement the NamespaceHandler interface at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHan&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;em&gt;2. When the spring-XXXX.jars were removed(Google helped me to point out this solution!), and the webapp was started, no problem at all. The server was up and running.&lt;/em&gt; But, on accessing the service as: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://localhost:8400/cxftry/services"&gt;http://localhost:8400/cxftry/services&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This exception was that I had: &lt;/p&gt;  &lt;p&gt;java.lang.NoSuchMethodError: org.springframework.context.ConfigurableApplicationContext.addApplicationListener(Lorg/springframework/context/ApplicationListener;)V   &lt;br /&gt;org.apache.cxf.transport.servlet.CXFServlet.loadSpringBus(CXFServlet.java:104)    &lt;br /&gt;org.apache.cxf.transport.servlet.CXFServlet.loadBus(CXFServlet.java:70)    &lt;br /&gt;org.apache.cxf.transport.servlet.AbstractCXFServlet.init(AbstractCXFServlet.java:90) &lt;/p&gt;  &lt;p&gt;With no information on web about any of these with CXF, I guessed the problem is the appserver, turnkey, that I was using. Though, it uses tomcat 6, not sure why it doesnt work. I downloaded a tomcat 6 server, and put the application on it and it worked like a charm. :o) &lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;u&gt;System Configurations:&lt;/u&gt;&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;1.CXF 2.1.2 &lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;2.JDK 1.5 &lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;3.TOMCAT 6&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Here is the tutorial, to use CXF to expose as a webservice with Java-First methodology. &lt;/p&gt;  &lt;p&gt;1. Download the CXF from &lt;a href="http://cxf.apache.org/download.html"&gt;http://cxf.apache.org/download.html&lt;/a&gt;    &lt;br /&gt;2. Extract to a directory(here, I will call it as CXF_HOME)    &lt;br /&gt;3. Copy paste all the lib(not recomended, go through WHICH_JARS present in CXF_HOME/lib to decide on the jars you need for your application) to WEB-INF/lib directory.    &lt;br /&gt;4. Write your Service Endpoint Interface (SEI), nothing but a java interface that will be exposed as a webservice. &lt;/p&gt;  &lt;p&gt;package com.ssb.service; &lt;/p&gt;  &lt;p&gt;import javax.jws.WebMethod;   &lt;br /&gt;import javax.jws.WebParam;    &lt;br /&gt;import javax.jws.WebService;    &lt;br /&gt;import javax.xml.ws.WebFault; &lt;/p&gt;  &lt;p&gt;import com.ssb.exception.SomeException;   &lt;br /&gt;import com.ssb.model.Data; &lt;/p&gt;  &lt;p&gt;@WebService   &lt;br /&gt;public interface IDataService {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; @WebMethod(operationName=&amp;quot;getData&amp;quot;)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Data&amp;#160; getData(@WebParam(name=&amp;quot;id&amp;quot;)String id) throws SomeException;    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;5. Annotate your Exception with @WebFault if any. &lt;/p&gt;  &lt;p&gt;package com.ssb.exception; &lt;/p&gt;  &lt;p&gt;import javax.xml.ws.WebFault; &lt;/p&gt;  &lt;p&gt;@WebFault(name=&amp;quot;exception&amp;quot;)   &lt;br /&gt;public class SomeException extends Exception { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public String contactInfo = &amp;quot;Sacrosanct Blood.&amp;quot;;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private static final long serialVersionUID = 1L; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; private SomeException() {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public SomeException(String message, Throwable cause) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(message, cause);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public SomeException(String message) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(message);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;6. Annotate your Service Implementation as a webservice. &lt;/p&gt;  &lt;p&gt;package com.ssb.service; &lt;/p&gt;  &lt;p&gt;import javax.jws.WebService; &lt;/p&gt;  &lt;p&gt;import com.ssb.exception.SomeException;   &lt;br /&gt;import com.ssb.model.Data; &lt;/p&gt;  &lt;p&gt;/**   &lt;br /&gt; * @author shreyas.purohit    &lt;br /&gt; *    &lt;br /&gt; */    &lt;br /&gt;@WebService(endpointInterface=&amp;quot;com.ssb.service.IDataService&amp;quot;, serviceName=&amp;quot;dataService&amp;quot;)    &lt;br /&gt;public class DataServiceImpl implements IDataService { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public DataServiceImpl() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public Data getData(String id) throws SomeException{   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Data data = new Data();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return data;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;} &lt;/p&gt;  &lt;p&gt;7. Configure the data.xml for the webservice(com/ssb/service/data.xml). &lt;/p&gt;  &lt;p&gt;&amp;lt;beans xmlns=&amp;quot;&lt;a href="http://www.springframework.org/schema/beans""&gt;http://www.springframework.org/schema/beans&amp;quot;&lt;/a&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xmlns:xsi=&amp;quot;&lt;a href="http://www.w3.org/2001/XMLSchema-instance""&gt;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;/a&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xmlns:jaxws=&amp;quot;&lt;a href="http://cxf.apache.org/jaxws""&gt;http://cxf.apache.org/jaxws&amp;quot;&lt;/a&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; xsi:schemaLocation=&amp;quot;&lt;a href="http://www.springframework.org/schema/beans"&gt;http://www.springframework.org/schema/beans&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;http://www.springframework.org/schema/beans/spring-beans.xsd&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://cxf.apache.org/jaxws"&gt;http://cxf.apache.org/jaxws&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://cxf.apache.org/schemas/jaxws.xsd""&gt;http://cxf.apache.org/schemas/jaxws.xsd&amp;quot;&lt;/a&gt;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160; &amp;lt;import resource=&amp;quot;classpath:META-INF/cxf/cxf.xml&amp;quot; /&amp;gt;   &lt;br /&gt;&amp;#160; &amp;lt;import resource=&amp;quot;classpath:META-INF/cxf/cxf-extension-soap.xml&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;import resource=&amp;quot;classpath:META-INF/cxf/cxf-servlet.xml&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;jaxws:endpoint id=&amp;quot;data&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; implementor=&amp;quot;com.ssb.service.DataServiceImpl&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; address=&amp;quot;/dataService&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;lt;/beans&amp;gt; &lt;/p&gt;  &lt;p&gt;8. Configure web.xml for CXF to work. &lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;   &lt;br /&gt;&amp;lt;!DOCTYPE web-app PUBLIC &amp;quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&amp;quot; &amp;quot;&lt;a href="http://java.sun.com/dtd/web-app_2_3.dtd""&gt;http://java.sun.com/dtd/web-app_2_3.dtd&amp;quot;&lt;/a&gt;&amp;gt;    &lt;br /&gt;&amp;lt;web-app&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;display-name&amp;gt;CXF&amp;lt;/display-name&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;description&amp;gt;CXF Application&amp;lt;/description&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;context-param&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param-name&amp;gt;contextConfigLocation&amp;lt;/param-name&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param-value&amp;gt;classpath:com/ssb/service/data.xml&amp;lt;/param-value&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/context-param&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;listener&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;listener-class&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; org.springframework.web.context.ContextLoaderListener    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/listener-class&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/listener&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;servlet&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;servlet-name&amp;gt;CXFServlet&amp;lt;/servlet-name&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;servlet-class&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; org.apache.cxf.transport.servlet.CXFServlet    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/servlet-class&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/servlet&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;servlet-mapping&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;servlet-name&amp;gt;CXFServlet&amp;lt;/servlet-name&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;url-pattern&amp;gt;/services/*&amp;lt;/url-pattern&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/servlet-mapping&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;welcome-file-list&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;welcome-file&amp;gt;index.html&amp;lt;/welcome-file&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;welcome-file&amp;gt;index.htm&amp;lt;/welcome-file&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/welcome-file-list&amp;gt;    &lt;br /&gt;&amp;lt;/web-app&amp;gt; &lt;/p&gt;  &lt;p&gt;9. Start the server, and access &lt;a href="http://localhost:8080/cxftry/services"&gt;http://localhost:8080/cxftry/services&lt;/a&gt;    &lt;br /&gt;You should be able to see the services. On clicking on it, the wsdl can be seen. &lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;u&gt;The annotations used in the above code is very simple and self explaining.&lt;/u&gt;&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. @WebService :&lt;/strong&gt; Indicates its a webservice. &lt;/p&gt;  &lt;p&gt;Attributes used: &lt;/p&gt;  &lt;p&gt;endpointInterface=Specifies the full name of the SEI that the implementation class implements.   &lt;br /&gt;serviceName=Specifies the name of the published service. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2. @WebMethod&amp;#160;&amp;#160;&amp;#160; :&lt;/strong&gt; Indicates a webservice method. &lt;/p&gt;  &lt;p&gt;Attributes used: &lt;/p&gt;  &lt;p&gt;operationName=Specifies the operation name, i.e the webservice method name. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3. @WebParam&amp;#160;&amp;#160;&amp;#160; :&lt;/strong&gt; Used to give the parameters in the operations a meaningfull name in the published WSDL. &lt;/p&gt;  &lt;p&gt;Attributes used: &lt;/p&gt;  &lt;p&gt;name= Name of the argument to be displayed on the WSDL for the operation. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;4. @WebFault&amp;#160;&amp;#160;&amp;#160; :&lt;/strong&gt; Defines an exception that the operation/web service method can throw. &lt;/p&gt;  &lt;p&gt;Attributes used: &lt;/p&gt;  &lt;p&gt;name= The name to be used in the WSDL. &lt;/p&gt;  &lt;p&gt;This completes a quick tutorial for publishing a Java-First webservice. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-655376796298385444?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/655376796298385444/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/step-by-step-cxf-webservice-tutorial.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/655376796298385444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/655376796298385444'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/10/step-by-step-cxf-webservice-tutorial.html' title='Step by step CXF Webservice Tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6867508498071754419</id><published>2008-09-30T00:20:00.001-07:00</published><updated>2008-09-30T00:22:15.382-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='log4j'/><category scheme='http://www.blogger.com/atom/ns#' term='log4j appender'/><category scheme='http://www.blogger.com/atom/ns#' term='log4j tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='log4j layout'/><title type='text'>Log4j Tutorial: Layout and Appender</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;I was working on an application related to trading. I had to write large amount of data to the disk in CSV format. If the file size increased over an MB, then the file had to roll over. We decided to use the existing log4j framework and use the rolling file appender to get the job done. Well, to say, it seemed easy, but finally had to write the code which i wanted to avoid using something that exists!! &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;First thing is layout :&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;The data written to the file is in CSV format, and does not need any information like debug level, or time or any thing else. So, the data sent to the logger, had to be just written to file with nothing more attached to it. This is do-able using the layouts in log4j. I just extended the SimpleLayout, and over-rided the 'format' method as below. &lt;/p&gt;  &lt;p&gt;public class NoLayout extends SimpleLayout { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; /**   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public NoLayout () {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public String format(LoggingEvent event)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sbuf.setLength(0);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sbuf.append(event.getRenderedMessage());    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sbuf.append(Layout.LINE_SEP);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return sbuf.toString();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;Once the layout was done and the RollingFileAppender was configured to be used in the log4j.xml, then next set of problems came to light. When the file rolls to next file, by default the file is named as fileName.index where index is maximum to configured in XML. We wanted the files to have fileName.index.csv as names. &lt;/p&gt;  &lt;p&gt;I thought this was a simple thing, and it should be configurable some where. The pattern to save the archived file should be configurable. On looking around Google, I saw the Rolling Policy(FixedWindow, with file name pattern configurable) and Triggering Policy(SizeBased, needed if TimeBasedRollingPolicy is not used).    &lt;br /&gt;There website quotes:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;     &lt;br /&gt;To be of any use, a RollingFileAppender instance must have both a RollingPolicy and a TriggeringPolicy set up. However, if its RollingPolicy also implements the TriggeringPolicy interface, then only the former needs to be set up. For example, TimeBasedRollingPolicy acts both as a RollingPolicy and a TriggeringPolicy. &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;   &lt;br /&gt;Some more samples across the web, &lt;/p&gt;  &lt;p&gt;&amp;lt;rollingPolicy class=&amp;quot;org.apache.log4j.rolling.TimeBasedRollingPolicy&amp;quot;&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;FileNamePattern&amp;quot; value=&amp;quot;/wombat/foo.%d{yyyy-MM}.gz&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;lt;/rollingPolicy&amp;gt; &lt;/p&gt;  &lt;p&gt;I thought this can be used and i configured in the log4j.xml, but only to my disappointment log4j does not recognize elements &amp;lt;rollingPolicy/&amp;gt; and &amp;lt;triggeringPolicy/&amp;gt;. But there DTD, log4j.dtd, had these elemets. On looking into the log4j code, specifically, org.apache.log4j.xml.DOMConfigurator, the only elements they recognize are: &lt;/p&gt;  &lt;p&gt;static final String CONFIGURATION_TAG = &amp;quot;log4j:configuration&amp;quot;;   &lt;br /&gt;&amp;#160; static final String OLD_CONFIGURATION_TAG = &amp;quot;configuration&amp;quot;;    &lt;br /&gt;&amp;#160; static final String RENDERER_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;renderer&amp;quot;;    &lt;br /&gt;&amp;#160; static final String APPENDER_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;appender&amp;quot;;    &lt;br /&gt;&amp;#160; static final String APPENDER_REF_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;appender-ref&amp;quot;;&amp;#160; &lt;br /&gt;&amp;#160; static final String PARAM_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;param&amp;quot;;    &lt;br /&gt;&amp;#160; static final String LAYOUT_TAG&amp;#160;&amp;#160;&amp;#160; = &amp;quot;layout&amp;quot;;    &lt;br /&gt;&amp;#160; static final String CATEGORY&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;category&amp;quot;;    &lt;br /&gt;&amp;#160; static final String LOGGER&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;logger&amp;quot;;    &lt;br /&gt;&amp;#160; static final String LOGGER_REF&amp;#160;&amp;#160;&amp;#160; = &amp;quot;logger-ref&amp;quot;;    &lt;br /&gt;&amp;#160; static final String CATEGORY_FACTORY_TAG&amp;#160; = &amp;quot;categoryFactory&amp;quot;;    &lt;br /&gt;&amp;#160; static final String LOGGER_FACTORY_TAG&amp;#160; = &amp;quot;loggerFactory&amp;quot;;    &lt;br /&gt;&amp;#160; static final String NAME_ATTR&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;name&amp;quot;;    &lt;br /&gt;&amp;#160; static final String CLASS_ATTR&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;class&amp;quot;;    &lt;br /&gt;&amp;#160; static final String VALUE_ATTR&amp;#160;&amp;#160;&amp;#160; = &amp;quot;value&amp;quot;;    &lt;br /&gt;&amp;#160; static final String ROOT_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;root&amp;quot;;    &lt;br /&gt;&amp;#160; static final String ROOT_REF&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;root-ref&amp;quot;;    &lt;br /&gt;&amp;#160; static final String LEVEL_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;level&amp;quot;;    &lt;br /&gt;&amp;#160; static final String PRIORITY_TAG&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;priority&amp;quot;;    &lt;br /&gt;&amp;#160; static final String FILTER_TAG&amp;#160;&amp;#160;&amp;#160; = &amp;quot;filter&amp;quot;;    &lt;br /&gt;&amp;#160; static final String ERROR_HANDLER_TAG&amp;#160;&amp;#160;&amp;#160; = &amp;quot;errorHandler&amp;quot;;    &lt;br /&gt;&amp;#160; static final String REF_ATTR&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;ref&amp;quot;;    &lt;br /&gt;&amp;#160; static final String ADDITIVITY_ATTR&amp;#160;&amp;#160;&amp;#160; = &amp;quot;additivity&amp;quot;;&amp;#160; &lt;br /&gt;&amp;#160; static final String THRESHOLD_ATTR&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; = &amp;quot;threshold&amp;quot;;    &lt;br /&gt;&amp;#160; static final String CONFIG_DEBUG_ATTR&amp;#160; = &amp;quot;configDebug&amp;quot;;    &lt;br /&gt;&amp;#160; static final String INTERNAL_DEBUG_ATTR&amp;#160; = &amp;quot;debug&amp;quot;;    &lt;br /&gt;&amp;#160; static final String RENDERING_CLASS_ATTR = &amp;quot;renderingClass&amp;quot;;    &lt;br /&gt;&amp;#160; static final String RENDERED_CLASS_ATTR = &amp;quot;renderedClass&amp;quot;;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&amp;#160; So, there was nothing about the rollingPolicy or triggeringPolicy, though there DTD defines them.    &lt;br /&gt;&amp;#160; So, I thought let me configure it through code. But, the Appender, log.getAppender(name), does not have anyway's to set the rollingpolicy or triggeringpolicy. Wow!!    &lt;br /&gt;&amp;#160; So, a simple requirement, manifested into hours of research, and finaly decided to extend the RollingFileAppender and give an configurable filename extension(The code is given below.). To all my dismay, I see the code of RollingFileAppender.rollOver(), the method every time uses &amp;gt;&amp;gt;&amp;gt; fileName + '.' + index &amp;lt;&amp;lt;&amp;lt; !!!!! (I was expecting a getFileName(index)!)    &lt;br /&gt;&amp;#160; So, I had to take in there code[copy and paste :(]. Now, they are using a private variable 'nextRollover' inside, this method.[Atleast, if it was protected, I could have just ignored it, and used the one from the parent class]. So, even that I had to take in, along with one more method that uses it 'subAppend'. And, finally got my requirement up and running!! Only thing I wanted is a file name to archived file that can be configured.     &lt;br /&gt;&amp;#160; If any one else is stuck in same problem, hope the classes here are of some help for you.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&amp;#160; package org.apache.log4j;    &lt;br /&gt;&amp;#160; import java.io.File;    &lt;br /&gt;&amp;#160; import java.io.IOException;    &lt;br /&gt;&amp;#160; import org.apache.log4j.helpers.CountingQuietWriter;    &lt;br /&gt;&amp;#160; import org.apache.log4j.helpers.LogLog;    &lt;br /&gt;&amp;#160; import org.apache.log4j.spi.LoggingEvent;    &lt;br /&gt;&amp;#160; public class ConfigurableRollingFileAppender extends RollingFileAppender {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public String fileExtension;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected long nextRollover;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param fileExtension the fileExtension to set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public void setFileExtension(String fileExtension) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.fileExtension = fileExtension;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return the fileExtension    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public String getFileExtension() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return fileExtension;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param nextRollover the nextRollover to set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected void setNextRollover(long nextRollover) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.nextRollover = nextRollover;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return the nextRollover    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected long getNextRollover() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return nextRollover;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public ConfigurableRollingFileAppender() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public ConfigurableRollingFileAppender(Layout layout, String filename)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throws IOException {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(layout, filename);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public ConfigurableRollingFileAppender(Layout layout, String filename,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; boolean append) throws IOException {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(layout, filename, append);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * A literal copy paste from the superclass,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * and using the required file name at places necessary.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @Override    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public void rollOver() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; File target;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; File file;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (qw != null) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; long size = ((CountingQuietWriter) qw).getCount();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.debug(&amp;quot;rolling over count=&amp;quot; + size);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //&amp;#160;&amp;#160; if operation fails, do not roll again until    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; maxFileSize more bytes are written    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; nextRollover = size + maxFileSize;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.debug(&amp;quot;maxBackupIndex=&amp;quot;+maxBackupIndex);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; boolean renameSucceeded = true;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // If maxBackups &amp;lt;= 0, then there is no file renaming to be done.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(maxBackupIndex &amp;gt; 0) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Delete the oldest file, to keep Windows happy.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; file = new File(getCompleteFileName(maxBackupIndex));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (file.exists())    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; renameSucceeded = file.delete();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; for (int i = maxBackupIndex - 1; i &amp;gt;= 1 &amp;amp;&amp;amp; renameSucceeded; i--) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; file = new File(getCompleteFileName(i));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (file.exists()) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; target = new File(getCompleteFileName(i + 1));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.debug(&amp;quot;Renaming file &amp;quot; + file + &amp;quot; to &amp;quot; + target);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; renameSucceeded = file.renameTo(target);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(renameSucceeded) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Rename fileName to fileName.1    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; target = new File(getCompleteFileName(1));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.closeFile(); // keep windows happy.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; file = new File(fileName);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.debug(&amp;quot;Renaming file &amp;quot; + file + &amp;quot; to &amp;quot; + target);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; renameSucceeded = file.renameTo(target);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //&amp;#160;&amp;#160; if file rename failed, reopen file with append = true    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (!renameSucceeded) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.setFile(fileName, true, bufferedIO, bufferSize);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(IOException e) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.error(&amp;quot;setFile(&amp;quot;+fileName+&amp;quot;, true) call failed.&amp;quot;, e);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //&amp;#160;&amp;#160; if all renames were successful, then    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (renameSucceeded) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // This will also close the file. This is OK since multiple    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // close operations are safe.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.setFile(fileName, false, bufferedIO, bufferSize);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; nextRollover = 0;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(IOException e) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; LogLog.error(&amp;quot;setFile(&amp;quot;+fileName+&amp;quot;, false) call failed.&amp;quot;, e);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /**    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; This method differentiates RollingFileAppender from its super    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; class.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Copy paste from RollingFileAppender, as the nextRollover attribute is private in RollingFileAppender, and had to be included here.    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @since 0.9.0    &lt;br /&gt;&amp;#160;&amp;#160; */    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; void subAppend(LoggingEvent event) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super.subAppend(event);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(fileName != null &amp;amp;&amp;amp; qw != null) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; long size = ((CountingQuietWriter) qw).getCount();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (size &amp;gt;= maxFileSize &amp;amp;&amp;amp; size &amp;gt;= nextRollover) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; rollOver();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected String removeFileExtensionFromName(String fileName){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return fileName.substring(0, fileName.lastIndexOf(&amp;quot;.&amp;quot;));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected String getCompleteFileName(int index){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return (fileExtension != null &amp;amp;&amp;amp; !fileExtension.trim().equalsIgnoreCase(&amp;quot;&amp;quot;)) ? removeFileExtensionFromName(fileName) + '.' + index + '.' + fileExtension : fileName + '.' + index;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The log4j.xml, can be used this way: &lt;/p&gt;  &lt;p&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; ?&amp;gt;   &lt;br /&gt;&amp;lt;!DOCTYPE log4j:configuration SYSTEM &amp;quot;log4j.dtd&amp;quot;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;log4j:configuration xmlns:log4j=&amp;quot;&lt;a href="http://jakarta.apache.org/log4j/""&gt;http://jakarta.apache.org/log4j/&amp;quot;&lt;/a&gt;&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;appender name=&amp;quot;console&amp;quot; class=&amp;quot;org.apache.log4j.ConsoleAppender&amp;quot;&amp;gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;Target&amp;quot; value=&amp;quot;System.out&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;layout class=&amp;quot;org.apache.log4j.PatternLayout&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;ConversionPattern&amp;quot; value=&amp;quot;%-5p %c{1} - %m%n&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/layout&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/appender&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;appender name=&amp;quot;FILE_APPENDER&amp;quot;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; class=&amp;quot;org.apache.log4j.ConfigurableRollingFileAppender&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;File&amp;quot;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; value=&amp;quot;../PUBLISH_FILE.csv&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;Append&amp;quot; value=&amp;quot;true&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;maxFileSize&amp;quot; value=&amp;quot;1024KB&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;MaxBackupIndex&amp;quot; value=&amp;quot;20&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;param name=&amp;quot;FileExtension&amp;quot; value=&amp;quot;csv&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;layout class=&amp;quot;org.apache.log4j.NoLayout&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/appender&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;root&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;priority value=&amp;quot;info&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;appender-ref ref=&amp;quot;FILE_APPENDER&amp;quot; /&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/root&amp;gt; &lt;/p&gt;  &lt;p&gt;&amp;lt;/log4j:configuration&amp;gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6867508498071754419?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6867508498071754419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/log4j-tutorial-layout-and-appender.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6867508498071754419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6867508498071754419'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/log4j-tutorial-layout-and-appender.html' title='Log4j Tutorial: Layout and Appender'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-725141878644322696</id><published>2008-09-30T00:15:00.001-07:00</published><updated>2008-09-30T00:15:49.019-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Return Types'/><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Abstract Method'/><title type='text'>Java Abstract Methods : Return type</title><content type='html'>&lt;p&gt;Consider an abstract class declaring an abstract method. Let the return type of the method be Object. Now lets say, a class extends this abstract class and defines this method. What should be the return type of this method to override the base abstract method? ;D, it can be anything!!&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;public abstract class AbstractClassA{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public abstract Object getDataForDoingSomething();    &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;public abstract class SClassA extends AbstractClassA{   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public List getDataForDoingSomething() {&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return new ArrayList();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-725141878644322696?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/725141878644322696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/java-abstract-methods-return-type.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/725141878644322696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/725141878644322696'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/java-abstract-methods-return-type.html' title='Java Abstract Methods : Return type'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5083160056989200258</id><published>2008-09-30T00:13:00.001-07:00</published><updated>2008-09-30T00:13:34.524-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='autoboxing'/><category scheme='http://www.blogger.com/atom/ns#' term='Java AutoBoxing Problem'/><title type='text'>AutoBoxing in java : A boon when used carefully!</title><content type='html'>&lt;p&gt;I am sure this is a very known mistake that should be avoided, but, it costed me an hour to figure out why the application I am working on was not behaving appropriately. I was looping through a list to find out an object that has to be removed. And, then the index was to be used to remove the object. The Objects in the list had over-ridden the equals and hashcode method,and I could not use the 'indexOf' or 'remove' on the list to find the object and remove it. My mistake was to use Object Integer instead of native int. Well every thing worked fine, but When called remove on the list, the List was trying to remove the integer object instead of object at that integer index! Solution was simple as you al know!! Just an interesting point to be taken down in my diary. &lt;/p&gt;  &lt;p&gt;private List&amp;lt;Stock&amp;gt; stocksSubscribed = new ArrayList&amp;lt;Stock&amp;gt;(); &lt;/p&gt;  &lt;p&gt;private void removeStockWithStockName(String symbol) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Integer removalIndex = 0;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; for(Stock stock : stocksSubscribed){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(symbol.equalsIgnoreCase(stock.getSymbol())){    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; break;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; removalIndex++;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; stocksSubscribed.remove((int)removalIndex);    &lt;br /&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5083160056989200258?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5083160056989200258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/autoboxing-in-java-boon-when-used.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5083160056989200258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5083160056989200258'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/09/autoboxing-in-java-boon-when-used.html' title='AutoBoxing in java : A boon when used carefully!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-734005771699506429</id><published>2008-07-31T20:52:00.000-07:00</published><updated>2008-07-31T20:52:00.303-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Properties using &apos;:&apos; as key'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Properties Problem'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Properties escaping special charecters'/><title type='text'>Java Properties File - Some less known facts</title><content type='html'>&lt;p&gt;I came across a problem using java properties file, and I think, its a good piece to go here. I am sure, majority of the developer who are new to java(even some oldies) may encounter this issue.&lt;/p&gt;  &lt;p&gt;The properties file contents:&lt;/p&gt;  &lt;p&gt;a0=impl1   &lt;br /&gt;a1:sol1=impl2&lt;/p&gt;  &lt;p&gt;The java program is below:&lt;/p&gt;  &lt;p&gt;public static void main(String[] args) {   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Properties properties = new Properties();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {//Assume, no problemo finding properties file    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; properties.load(Tester.class.getClassLoader().getResourceAsStream(&amp;quot;test.properties&amp;quot;));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(properties.getProperty(&amp;quot;a0&amp;quot;));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(properties.getProperty(&amp;quot;a1:sol1&amp;quot;));&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (FileNotFoundException e) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.printStackTrace();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.printStackTrace();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Surprisingly the output of the following program is:&lt;/p&gt;  &lt;p&gt;a0=impl1   &lt;br /&gt;null&lt;/p&gt;  &lt;p&gt;When you do properties.list(System.out), I was little surprised to see:&lt;/p&gt;  &lt;p&gt;a0=impl1   &lt;br /&gt;a1=sol1=impl2&lt;/p&gt;  &lt;p&gt;The ':' has been converted to '='. &lt;/p&gt;  &lt;p&gt;Finally, with the help of wiki I found that, the name value pairs in the java properties file can be of formats:&lt;/p&gt; a. name=value (This all us know definitely know)  &lt;br /&gt;b. name:value c. name value   &lt;p&gt;And, the solution is to escape the special character using backslash. That is in the properties file,&lt;/p&gt;  &lt;p&gt;a0=impl1   &lt;br /&gt;a1\:sol1=impl2&lt;/p&gt;  &lt;p&gt;Hope this helps someone who is surprised to see 'un-expected' output.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-734005771699506429?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/734005771699506429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/java-properties-file-some-less-known.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/734005771699506429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/734005771699506429'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/java-properties-file-some-less-known.html' title='Java Properties File - Some less known facts'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-4723751553038270010</id><published>2008-07-22T04:39:00.001-07:00</published><updated>2008-07-22T04:39:56.216-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='j2ssh'/><category scheme='http://www.blogger.com/atom/ns#' term='removing user prompt while connecting in j2ssh'/><category scheme='http://www.blogger.com/atom/ns#' term='ConsoleKnownHostskeyVerification'/><title type='text'>j2ssh : On authentication, removing user prompt</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;While doing an SFTP connection with j2ssh client in java, it is possible that you get a message as in:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Do you want to allow this host key? [Yes|No|Always]:&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To remove this message, though not recommended, we have to give a custom implementation of AbstractKnownHostsKeyVerification class. The best possible way is to extend ConsoleKnownHostsKeyVerification and override the methods onUnknownHost or onHostKeyMismatch. And use this AlwaysAllowingConsoleKnownHostsKeyVerification instance while connecting, as in:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;SshClient ssh = new SshClient();&lt;/p&gt;    &lt;p&gt;ssh.connect(hostname,new AlwaysAllowingConsoleKnownHostsKeyVerification());&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The class AlwaysAllowingConsoleHostsKeyVerification is defined below. I understand that this is like a hack in security, but, sometimes, you may like to know it anyway's. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;import com.sshtools.j2ssh.transport.ConsoleKnownHostsKeyVerification;   &lt;br /&gt;import com.sshtools.j2ssh.transport.InvalidHostFileException;    &lt;br /&gt;import com.sshtools.j2ssh.transport.publickey.SshPublicKey; &lt;/p&gt;  &lt;p&gt;public class AlwaysAllowingConsoleKnownHostsKeyVerification extends   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ConsoleKnownHostsKeyVerification { &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public AlwaysAllowingConsoleKnownHostsKeyVerification()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throws InvalidHostFileException {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Don't not do anything else    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; @Override   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void onHostKeyMismatch(String s, SshPublicKey sshpublickey,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SshPublicKey sshpublickey1) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;The host key supplied by &amp;quot; + s + &amp;quot; is: &amp;quot; + sshpublickey1.getFingerprint());    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;The current allowed key for &amp;quot; + s + &amp;quot; is: &amp;quot; + sshpublickey.getFingerprint());    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;~~~Using Custom Key verification, allowing to pass through~~~&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; allowHost(s, sshpublickey, false);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(Exception exception)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; exception.printStackTrace();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; @Override   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void onUnknownHost(String s, SshPublicKey sshpublickey) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;The host &amp;quot; + s + &amp;quot; is currently unknown to the system&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;The host key fingerprint is: &amp;quot; + sshpublickey.getFingerprint());    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.out.println(&amp;quot;~~~Using Custom Key verification, allowing to pass through~~~&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; allowHost(s, sshpublickey, false);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch(Exception exception)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; exception.printStackTrace();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-4723751553038270010?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/4723751553038270010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/j2ssh-on-authentication-removing-user.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4723751553038270010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4723751553038270010'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/j2ssh-on-authentication-removing-user.html' title='j2ssh : On authentication, removing user prompt'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2716848148256276259</id><published>2008-07-03T05:17:00.001-07:00</published><updated>2008-07-03T05:17:46.751-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='toXMLString'/><category scheme='http://www.blogger.com/atom/ns#' term='Convert XML file to String in Java'/><title type='text'>Convert XML file to XML String in java</title><content type='html'>&lt;p&gt;I had to find out a way to read an XML file, and convert it to java String. Below is the code snippet I used. &lt;/p&gt;  &lt;p&gt;public String convertXMLFileToString(String fileName)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try{    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; InputStream inputStream = new FileInputStream(new File(fileName));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; org.w3c.dom.Document doc = documentBuilderFactory.newDocumentBuilder().parse(inputStream);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; StringWriter stw = new StringWriter();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Transformer serializer = TransformerFactory.newInstance().newTransformer();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; serializer.transform(new DOMSource(doc), new StreamResult(stw));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return stw.toString();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; catch (Exception e) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; e.printStackTrace();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return null;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2716848148256276259?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2716848148256276259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/convert-xml-file-to-xml-string-in-java.html#comment-form' title='16 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2716848148256276259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2716848148256276259'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/07/convert-xml-file-to-xml-string-in-java.html' title='Convert XML file to XML String in java'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>16</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2830542388019332755</id><published>2008-06-27T03:24:00.001-07:00</published><updated>2008-06-30T08:41:11.079-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Formatting cells'/><category scheme='http://www.blogger.com/atom/ns#' term='borders'/><category scheme='http://www.blogger.com/atom/ns#' term='Merging cells'/><category scheme='http://www.blogger.com/atom/ns#' term='Jexcel'/><category scheme='http://www.blogger.com/atom/ns#' term='JXL tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='aligment'/><category scheme='http://www.blogger.com/atom/ns#' term='JXL Wrap text'/><category scheme='http://www.blogger.com/atom/ns#' term='Underline cells'/><title type='text'>JExcel Tutorial</title><content type='html'>&lt;p&gt;JExcel API's are used to create and read Excel files. Please go through the documentation's of JXL to find out more in detail. This API is very easy to use. I present a Utility below which does some basic operations using JXL API's. I do not like the checked exceptions that cant be handled, so, this utility wraps the checked exceptions in unchecked exception and throws it. A sample Client program is also given to show the usage of the utility class. The utility class handles the below features of the Excel file writings. I will update the Util as and when i find more features to be used. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Features:&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;1. Create a workbook.    &lt;br /&gt;2. Create a worksheet with given name.     &lt;br /&gt;3. Create Settings with US locale.     &lt;br /&gt;4. Create formatted cell with given font, point size.     &lt;br /&gt;5. Create formatted cell with bold, italic, Underline styles.     &lt;br /&gt;6. Create formatted cell with border and border style.     &lt;br /&gt;7. Create formatted cell with alignment(left, top, bottom etc).     &lt;br /&gt;8. Add label to sheet with or without formatting.     &lt;br /&gt;9. Add Integer to sheet with or without formatting.     &lt;br /&gt;10. Add formula to sheet.     &lt;br /&gt;11. Merge cells.     &lt;br /&gt;12. Find cells on specific data.     &lt;br /&gt;13. Get cell contents.     &lt;br /&gt;14. Wrap text data in Cell. &lt;/p&gt;  &lt;p&gt;Below is the util class. JavaDocs does the needed explanations. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;I am using JXL 2.6.8 release with JDK 5 update 15. &lt;/p&gt;  &lt;p&gt;################################################################# &lt;/p&gt;  &lt;p&gt;package com.ssb.jxl.util; &lt;/p&gt;  &lt;p&gt;import java.io.File;    &lt;br /&gt;import java.io.IOException;     &lt;br /&gt;import java.util.Locale; &lt;/p&gt;  &lt;p&gt;import jxl.Cell;    &lt;br /&gt;import jxl.Range;     &lt;br /&gt;import jxl.Sheet;     &lt;br /&gt;import jxl.Workbook;     &lt;br /&gt;import jxl.WorkbookSettings;     &lt;br /&gt;import jxl.format.Alignment;     &lt;br /&gt;import jxl.format.Border;     &lt;br /&gt;import jxl.format.BorderLineStyle;     &lt;br /&gt;import jxl.format.UnderlineStyle;     &lt;br /&gt;import jxl.write.Formula;     &lt;br /&gt;import jxl.write.Label;     &lt;br /&gt;import jxl.write.WritableCellFormat;     &lt;br /&gt;import jxl.write.WritableFont;     &lt;br /&gt;import jxl.write.WritableSheet;     &lt;br /&gt;import jxl.write.WritableWorkbook;     &lt;br /&gt;import jxl.write.WriteException;     &lt;br /&gt;import jxl.write.biff.RowsExceededException; &lt;/p&gt;  &lt;p&gt;public class JxlUtil {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Class to define a formula.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @author sacrosanctblood     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public static class Formulae{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private String formulae; &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public String getFormulae() {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return formulae;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public void setFormulae(String formulae) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this.formulae = formulae;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * RuntimeException to wrap all the checked exceptions of JXL     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @author sacrosanctblood     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public static class JxlUtilException extends RuntimeException{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private static final long serialVersionUID = -1189965636139763776L;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private Exception _ex;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public JxlUtilException(Exception ex){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; super(ex);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; this._ex = ex;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public Exception getActualJExcelException(){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return _ex;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkBook from the file given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(File name){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workbook = Workbook.createWorkbook(name);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook with a sheet given by sheet name.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheetName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(File name,String sheetName){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workBook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workBook = Workbook.createWorkbook(name);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; createSheet(sheetName, workBook);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workBook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook from file, with the settings given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param setting     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(File name,WorkbookSettings setting){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workbook = Workbook.createWorkbook(name,setting);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook from file, with the settings given and sheetname given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheetName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param setting     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(File name,String sheetName,WorkbookSettings setting){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workBook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workBook = Workbook.createWorkbook(name,setting);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; createSheet(sheetName, workBook);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workBook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook from file name, with the settings given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param setting     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(String name,WorkbookSettings setting){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workbook = Workbook.createWorkbook(new File(name),setting);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook from file name, with the settings given and sheetname given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheetName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param setting     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(String name,String sheetName,WorkbookSettings setting){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workbook = Workbook.createWorkbook(new File(name),setting);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; createSheet(sheetName, workbook);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a WritableWorkbook from file name and sheet name given.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheetName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableWorkbook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableWorkbook createWorkBook(String name,String sheetName){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workbook = Workbook.createWorkbook(new File(name));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; createSheet(sheetName, workbook);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return workbook;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates settings with US locale.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WorkbookSettings     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WorkbookSettings createSettings(){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WorkbookSettings wbSettings = new WorkbookSettings();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Locale locale = Locale.US;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; wbSettings.setLocale(locale);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return wbSettings;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates sheet in the workbook with given name.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheetName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param workBook     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void createSheet(String sheetName,WritableWorkbook workBook){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workBook.createSheet(sheetName, workBook.getNumberOfSheets());     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a cell format.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param pointSize     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param fontName Can be null, default : Times     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param isBold     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param italic     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param underLineStyle Can be null, default : No Underline     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableCellFormat     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableCellFormat createFormattedCell(int pointSize, jxl.write.WritableFont.FontName fontName, boolean isBold, boolean italic, UnderlineStyle underLineStyle){ &lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableFont font = new WritableFont(null!=fontName?fontName:jxl.write.WritableFont.TIMES,&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;pointSize,&lt;/p&gt;    &lt;p&gt;isBold?WritableFont.BOLD:WritableFont.NO_BOLD,&lt;/p&gt;    &lt;p&gt;italic,&lt;/p&gt;    &lt;p&gt;null!=underLineStyle?underLineStyle:UnderlineStyle.NO_UNDERLINE&lt;/p&gt;    &lt;p&gt;);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableCellFormat writableCellFormat = new WritableCellFormat(font);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return writableCellFormat;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a cell format.       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param pointSize       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param fontName Can be null, default : Times       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param isBold       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param italic       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param underLineStyle Can be null, default : No Underline       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param border Can be null, default : ALL       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param lineStyle Can be null, default : THICK       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableCellFormat       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableCellFormat createFormattedCell(int pointSize,jxl.write.WritableFont.FontName fontName, boolean isBold, boolean italic, UnderlineStyle underLineStyle, Border border, BorderLineStyle lineStyle){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableFont font = new WritableFont(null!=fontName?fontName:jxl.write.WritableFont.TIMES, pointSize, isBold?WritableFont.BOLD:WritableFont.NO_BOLD, italic,null!=underLineStyle?underLineStyle:UnderlineStyle.NO_UNDERLINE);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableCellFormat writableCellFormat = new WritableCellFormat(font);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null == lineStyle){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; lineStyle = BorderLineStyle.THICK;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null == border){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; border = Border.ALL;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writableCellFormat.setBorder(border, lineStyle);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return writableCellFormat;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Creates a cell format.       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param pointSize       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param fontName Can be null, default : Times       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param isBold       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param italic       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param underLineStyle Can be null, default : No Underline       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param border Can be null, default : ALL       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param lineStyle Can be null, default : THICK       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param alignment Can be null, default : CENTRE       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return WritableCellFormat       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public WritableCellFormat createFormattedCell(int pointSize,jxl.write.WritableFont.FontName fontName, boolean isBold, boolean italic, UnderlineStyle underLineStyle, Border border, BorderLineStyle lineStyle, Alignment alignment){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableFont font = new WritableFont(null!=fontName?fontName:jxl.write.WritableFont.TIMES, pointSize, isBold?WritableFont.BOLD:WritableFont.NO_BOLD, italic,null!=underLineStyle?underLineStyle:UnderlineStyle.NO_UNDERLINE);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableCellFormat writableCellFormat = new WritableCellFormat(font);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null == lineStyle){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; lineStyle = BorderLineStyle.THICK;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null == border){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; border = Border.ALL;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null == alignment){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; alignment = Alignment.CENTRE;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writableCellFormat.setBorder(border, lineStyle);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; writableCellFormat.setAlignment(alignment);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return writableCellFormat;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Adds the Label cell to sheet at given row and column.       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param column       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param data       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param format Can be null       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void addCellToSheet(int column, int row, String data,WritableCellFormat format,WritableSheet sheet){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null != format){&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new Label(column, row, data, format));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }else{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new Label(column, row, data));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (RowsExceededException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Adds Integer cell to sheet at given row and column.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param column     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param data     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param format Can be null.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void addCellToSheet(int column, int row, Integer data,WritableCellFormat format,WritableSheet sheet){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null != format){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new jxl.write.Number(column, row, data, format));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }else{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new jxl.write.Number(column, row, data));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (RowsExceededException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Adds a formula to sheet at given row and column.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param column     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param data     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param format Can be null.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void addCellToSheet(int column, int row, Formulae data,WritableCellFormat format,WritableSheet sheet){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(null != format){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new Formula(column, row, data.getFormulae(), format));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }else{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sheet.addCell(new Formula(column, row, data.getFormulae()));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (RowsExceededException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Merges cell between two ranges([col1,row1] to [col2,row2])     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param col1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param col2     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row2     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return Range     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Range mergeCells(WritableSheet sheet,int col1, int row1, int col2, int row2){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return sheet.mergeCells(col1, row1, col2, row2);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (RowsExceededException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Finder on data to retrieve a cell.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param data     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param isLabelCell     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return Cell     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public Cell find(Sheet sheet, String data,boolean isLabelCell){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return isLabelCell?sheet.findLabelCell(data):sheet.findCell(data);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Gets the content of Cell a given row and column.     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param sheet     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param col     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param row     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @return String     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public String getCellContents(Sheet sheet, int col, int row){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Cell componentCell = sheet.getCell(col, row);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return componentCell.getContents();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;/**     &lt;br /&gt; * Set the Wrap property to true.      &lt;br /&gt; *       &lt;br /&gt; * @param format      &lt;br /&gt; */      &lt;br /&gt;public void setWrapTrue(WritableCellFormat format){      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; format.setWrap(true);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}      &lt;br /&gt;/**      &lt;br /&gt; * Set the Wrap property to false.      &lt;br /&gt; *       &lt;br /&gt; * @param format      &lt;br /&gt; */      &lt;br /&gt;public void setWrapFalse(WritableCellFormat format){      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; try {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; format.setWrap(false);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; /**       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * Flushes the buffer, by writing the data to file and closing the workbook.       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; * @param book       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; */       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public void flush(WritableWorkbook book){       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; book.write();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; try {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; book.close();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (WriteException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } catch (IOException e) {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new JxlUtilException(e);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;#####################################################&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;JxlClient .java&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;package com.ssb.jxl.client; &lt;/p&gt;  &lt;p&gt;import jxl.format.Alignment;    &lt;br /&gt;import jxl.format.Border;     &lt;br /&gt;import jxl.write.WritableCellFormat;     &lt;br /&gt;import jxl.write.WritableWorkbook; &lt;/p&gt;  &lt;p&gt;import com.ssb.jxl.util.JxlUtil; &lt;/p&gt;  &lt;p&gt;public class JxlClient {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private static final JxlUtil util = new JxlUtil();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public static void main(String[] args) {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(args.length == 0){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; args = new String[2];     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; args[0] = &amp;quot;default.xls&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; args[1] = &amp;quot;defaultSheet&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(args.length == 1){     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; String[] tempArgs = new String[2];     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tempArgs[0] = args[0];     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tempArgs[1] = &amp;quot;defaultSheet&amp;quot;;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; args = tempArgs;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Create workbook and worksheet with default settings     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableWorkbook workBook = util.createWorkBook(args[0], args[1]);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.mergeCells(workBook.getSheet(args[1]), 0, 1, 4, 1);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableCellFormat centerAlignedAllBoldformattedCell = util.createFormattedCell(10, null, true, false, null, null, null, Alignment.CENTRE);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; WritableCellFormat bottomBoldFormatedCell = util.createFormattedCell(6, null, false, false, null, Border.BOTTOM,null);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Header     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(0, 1, &amp;quot;Header&amp;quot;, centerAlignedAllBoldformattedCell, workBook.getSheet(args[1]));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; //Column 1,2,3,4,5     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(0, 2, &amp;quot;Subtitle1&amp;quot;, bottomBoldFormatedCell, workBook.getSheet(args[1]));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(1, 2, &amp;quot;Subtitle2&amp;quot;, bottomBoldFormatedCell, workBook.getSheet(args[1]));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(2, 2, &amp;quot;Subtitle3&amp;quot;, bottomBoldFormatedCell, workBook.getSheet(args[1]));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(3, 2, &amp;quot;Subtitle4&amp;quot;, bottomBoldFormatedCell, workBook.getSheet(args[1]));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.addCellToSheet(4, 2, &amp;quot;Subtitle5&amp;quot;, bottomBoldFormatedCell, workBook.getSheet(args[1])); &lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; util.flush(workBook);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2830542388019332755?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2830542388019332755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/jexcel-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2830542388019332755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2830542388019332755'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/jexcel-tutorial.html' title='JExcel Tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-6001655993057261377</id><published>2008-06-25T00:08:00.000-07:00</published><updated>2008-06-25T00:11:11.133-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sample JMS program'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS Consumer'/><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMQ jndi.properties'/><category scheme='http://www.blogger.com/atom/ns#' term='Using JMS with ActiveMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS Message Listener'/><category scheme='http://www.blogger.com/atom/ns#' term='JMS Producer'/><title type='text'>JMS with activeMQ</title><content type='html'>Now that we know basics of ActiveMQ, it better to know JMS too. There are a lot of resources on web for learning JMS, the best one being the sun's JMS tutorial that ships along the J2EE tutorial. So, I wont put too many details in this JMS sample code. The code is self explanatory, and is given just to continue upon the prev post on ActiveMQ. I will be using the JNDI properties file explained in the prev post for publishing and consuming messages.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The jndi.properties is as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;# START SNIPPET: jndi&lt;br /&gt;&lt;br /&gt;java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;br /&gt;&lt;br /&gt;# use the following property to configure the default connector&lt;br /&gt;java.naming.provider.url = tcp://localhost:61616&lt;br /&gt;&lt;br /&gt;# use the following property to specify the JNDI name the connection factory&lt;br /&gt;# should appear as.&lt;br /&gt;#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry&lt;br /&gt;connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry&lt;br /&gt;&lt;br /&gt;# register some queues in JNDI using the form&lt;br /&gt;# queue.[jndiName] = [physicalName]&lt;br /&gt;queue.MyQueue = example.MyQueue&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# register some topics in JNDI using the form&lt;br /&gt;# topic.[jndiName] = [physicalName]&lt;br /&gt;topic.MyTopic = example.MyTopic&lt;br /&gt;&lt;br /&gt;# END SNIPPET: jndi&lt;br /&gt;&lt;br /&gt;This property file should be in the class path of the application. The queue is created dynamically.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JMS Producer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class JMSProducer implements Runnable{&lt;br /&gt;     private static final Log LOG = LogFactory.getLog(JMSProducer.class);&lt;br /&gt;&lt;br /&gt;        public JMSProducer() {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        //Run method implemented to run this as a thread.&lt;br /&gt;        public void run(){&lt;br /&gt;            Context jndiContext = null;&lt;br /&gt;            ConnectionFactory connectionFactory = null;&lt;br /&gt;            Connection connection = null;&lt;br /&gt;            Session session = null;&lt;br /&gt;            Destination destination = null;&lt;br /&gt;            MessageProducer producer = null;&lt;br /&gt;            String destinationName = null;&lt;br /&gt;            final int numMsgs;           &lt;br /&gt;            destinationName = "MyQueue";&lt;br /&gt;            numMsgs = "5";                   &lt;br /&gt;            LOG.info("Destination name is " + destinationName);&lt;br /&gt;&lt;br /&gt;            /*&lt;br /&gt;             * Create a JNDI API InitialContext object&lt;br /&gt;             */&lt;br /&gt;            try {&lt;br /&gt;                jndiContext = new InitialContext();&lt;br /&gt;            } catch (NamingException e) {&lt;br /&gt;                LOG.info("Could not create JNDI API context: " + e.toString());&lt;br /&gt;                System.exit(1);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            /*&lt;br /&gt;             * Look up connection factory and destination.&lt;br /&gt;             */&lt;br /&gt;            try {&lt;br /&gt;                connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");&lt;br /&gt;                destination = (Destination)jndiContext.lookup(destinationName);&lt;br /&gt;            } catch (NamingException e) {&lt;br /&gt;                LOG.info("JNDI API lookup failed: " + e);&lt;br /&gt;                System.exit(1);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            /*&lt;br /&gt;             * Create connection. Create session from connection; false means&lt;br /&gt;             * session is not transacted.create producer, set the text message, set the co-relation id and send the message.&lt;br /&gt;             */&lt;br /&gt;            try {&lt;br /&gt;                connection = connectionFactory.createConnection();&lt;br /&gt;                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);&lt;br /&gt;                producer = session.createProducer(destination);&lt;br /&gt;                TextMessage message = session.createTextMessage();&lt;br /&gt;                for (int i = 0; i &lt; numMsgs; i++) {&lt;br /&gt;                    message.setText("A message is being sent with number " + (i + 1));&lt;br /&gt;                    message.setJMSCorrelationID("" + i);&lt;br /&gt;                    LOG.info("Sending message: " + message.getText());&lt;br /&gt;                    producer.send(message);&lt;br /&gt;                }&lt;br /&gt;               &lt;br /&gt;            } catch (JMSException e) {&lt;br /&gt;                LOG.info("Exception occurred: " + e);&lt;br /&gt;            } finally {&lt;br /&gt;                if (connection != null) {&lt;br /&gt;                    try {&lt;br /&gt;                        connection.close();&lt;br /&gt;                    } catch (JMSException e) {&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;JMS Consumer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public class JMSConsumer implements Runnable{&lt;br /&gt;     private static final Log LOG = LogFactory.getLog(JMSConsumer.class);&lt;br /&gt;   &lt;br /&gt;     public void run() {&lt;br /&gt;    Context jndiContext = null;&lt;br /&gt;        ConnectionFactory connectionFactory = null;&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        Session session = null;&lt;br /&gt;        MessageConsumer consumer = null;&lt;br /&gt;        Destination destination = null;&lt;br /&gt;        String sourceName = null;&lt;br /&gt;        final int numMsgs;       &lt;br /&gt;        sourceName= "MyQueue";&lt;br /&gt;        numMsgs = "1";&lt;br /&gt;        LOG.info("Source name is " + sourceName);&lt;br /&gt;        /*&lt;br /&gt;         * Create a JNDI API InitialContext object&lt;br /&gt;         */&lt;br /&gt;        try {&lt;br /&gt;            jndiContext = new InitialContext();&lt;br /&gt;        } catch (NamingException e) {&lt;br /&gt;            LOG.info("Could not create JNDI API context: " + e.toString());&lt;br /&gt;            System.exit(1);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        /*&lt;br /&gt;         * Look up connection factory and destination.&lt;br /&gt;         */&lt;br /&gt;        try {&lt;br /&gt;            connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");&lt;br /&gt;            destination = (Destination)jndiContext.lookup(sourceName);&lt;br /&gt;        } catch (NamingException e) {&lt;br /&gt;            LOG.info("JNDI API lookup failed: " + e);&lt;br /&gt;            System.exit(1);&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;       &lt;br /&gt;        try {&lt;br /&gt;            connection = connectionFactory.createConnection();&lt;br /&gt;            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);           &lt;br /&gt;            consumer = session.createConsumer(destination);&lt;br /&gt;            connection.start();&lt;br /&gt;            try {&lt;br /&gt;                Thread.sleep(2000);&lt;br /&gt;            } catch (InterruptedException e) {&lt;br /&gt;                // TODO Auto-generated catch block&lt;br /&gt;                e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;            MessageListener listener = new MyQueueMessageListener();&lt;br /&gt;        consumer.setMessageListener(listener );   &lt;br /&gt;    //Let the thread run for some time so that the Consumer has suffcient time to consume the message&lt;br /&gt;     try {&lt;br /&gt;                    Thread.sleep(5000);&lt;br /&gt;                } catch (InterruptedException e) {&lt;br /&gt;                    // TODO Auto-generated catch block&lt;br /&gt;                    e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;        } catch (JMSException e) {&lt;br /&gt;            LOG.info("Exception occurred: " + e);&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                try {&lt;br /&gt;                    connection.close();&lt;br /&gt;                } catch (JMSException e) {&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;MessageListener&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public class MyQueueMessageListener implements MessageListener {&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    public MyQueueMessageListener() {&lt;br /&gt;        // TODO Auto-generated constructor stub&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /* (non-Javadoc)&lt;br /&gt;     * @see javax.jms.MessageListener#onMessage(javax.jms.Message)&lt;br /&gt;     * This is called on receving of a text message.&lt;br /&gt;     */&lt;br /&gt;    public void onMessage(Message arg0) {&lt;br /&gt;        if(arg0 instanceof TextMessage){&lt;br /&gt;            try {&lt;br /&gt;            //Print it out&lt;br /&gt;                System.out.println("Recieved message in listener: " + ((TextMessage)arg0).getText());&lt;br /&gt;               &lt;br /&gt;                System.out.println("Co-Rel Id: " + ((TextMessage)arg0).getJMSCorrelationID());&lt;br /&gt;                try {&lt;br /&gt;            //Log it to a file&lt;br /&gt;                    BufferedWriter outFile = new BufferedWriter(new FileWriter("MyQueueConsumer.txt"));&lt;br /&gt;                    outFile.write("Recieved message in listener: " + ((TextMessage)arg0).getText());&lt;br /&gt;                } catch (IOException e) {&lt;br /&gt;                    // TODO Auto-generated catch block&lt;br /&gt;                    e.printStackTrace();&lt;br /&gt;                }&lt;br /&gt;            } catch (JMSException e) {&lt;br /&gt;                // TODO Auto-generated catch block&lt;br /&gt;                e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;        }else{&lt;br /&gt;            System.out.println("~~~~Listener : Error in message format~~~~");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Application to run Consumer and producer&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;public class SimpleApp {&lt;br /&gt;&lt;br /&gt;//Run the producer first, then the consumer&lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        runInNewthread(new JMSProducer());&lt;br /&gt;        runInNewthread(new JMSConsumer());                       &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void runInNewthread(Runnable runnable) {&lt;br /&gt;        Thread brokerThread = new Thread(runnable);&lt;br /&gt;        brokerThread.setDaemon(false);&lt;br /&gt;        brokerThread.start();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-6001655993057261377?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/6001655993057261377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/jms-with-activemq.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6001655993057261377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/6001655993057261377'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/jms-with-activemq.html' title='JMS with activeMQ'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-5782167761527233244</id><published>2008-06-24T10:09:00.000-07:00</published><updated>2008-06-24T10:25:38.053-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Temporary and permanent queue'/><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMQ'/><category scheme='http://www.blogger.com/atom/ns#' term='Network of  brokers'/><category scheme='http://www.blogger.com/atom/ns#' term='failover protocol on client side'/><title type='text'>ActiveMQ 5.1.0 tutorial</title><content type='html'>It is always good to know at least one message brokers. ActiveMQ is one of those top brokers used actively industry wide. So, here is a small tutorial or tips to use ActiveMQ along with java messaging service.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Installations&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I am using the following configuration on my system:&lt;br /&gt;&lt;br /&gt;1. Windows XP&lt;br /&gt;2. JDK 5 update 15&lt;br /&gt;3. ActiveMQ 5.1.0&lt;br /&gt;&lt;br /&gt;Download activeMQ from &lt;a href="http://activemq.apache.org/"&gt;http://activemq.apache.org/&lt;/a&gt;. Unzip to any suitable location. And the installation is done!!!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Directory Structure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After you unzip, there are few basic files you need to know.&lt;br /&gt;&lt;br /&gt;a. The bin folder contains the batch file, activemq.bat, using which you can start the server. It also contains activemq-admin.bat, using which you can get more details about activemq, like a listing of queues etc.&lt;br /&gt;&lt;br /&gt;b. The conf folder contains the activemq.xml configuring the ActiveMQ broker. Here is where we can configure the transports, permanent queues etc.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Creating Temporary Queues&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Firt run bin/activemq.bat. This should start ActiveMQ listening at port 61616. There is an admin console(http://localhost:8161/admin) that can be used to monitor the ActiveMQ server. It can also be used to create queues, but these are temporary queues. That means, once the server is shutdown, and restarted, the queues will have to be re created.&lt;br /&gt;&lt;br /&gt;ActiveMQ is primarily build for creating queues dynamically. But, it is possible to create queues permanently in ActiveMQ 4.1 or above.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Creating Permanent Queues&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The conf/activemq.xml is called broker configuration. By adding the below in that creates a permanent queue, i.e on restart of the server, the queue does exist. You dont have to create it again.&lt;br /&gt;&lt;br /&gt;&amp;lt;beans&amp;gt;&lt;br /&gt; &amp;lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" /&amp;gt;&lt;br /&gt; &amp;lt;broker xmlns="http://activemq.apache.org/schema/core"&amp;gt;&lt;br /&gt;   &amp;lt;destinations&amp;gt;&lt;br /&gt;     &amp;lt;queue physicalName="test.activemq.queue" /&amp;gt;&lt;br /&gt;   &amp;lt;/destinations&amp;gt;&lt;br /&gt; &amp;lt;/broker&amp;gt;&lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Creating Dynamic Queues and configuration&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are two ways to create queues, and configure ActiveMQ dynamically.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a. Programatically, in java code.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;b. Using JNDI&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The preferred approach is JNDI. But, there is nothing wrong in knowing the first one either.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;a. Programmatic usage in ActiveMQ&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  // Create a ConnectionFactory&lt;br /&gt;  ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");&lt;br /&gt;&lt;br /&gt;  // Create a Connection&lt;br /&gt;  Connection connection = connectionFactory.createConnection();&lt;br /&gt;  connection.start();&lt;br /&gt;&lt;br /&gt;  // Create a Session&lt;br /&gt;  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);&lt;br /&gt;&lt;br /&gt;  // Create the Queue&lt;br /&gt;  Destination destination = session.createQueue("test.prog.queue");&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;b. Using JNDI&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  Here, jndi.properties is used to configure. This should be present in the CLASSPATH for the queues, connection factory to be configured correctly.&lt;br /&gt;  This is taken from the activeMQ website and modified.&lt;br /&gt;&lt;br /&gt;  java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;br /&gt;&lt;br /&gt;  # use the following property to configure the default connector&lt;br /&gt;  java.naming.provider.url = tcp://localhost:61616&lt;br /&gt;&lt;br /&gt;  # use the following property to specify the JNDI name the connection factory&lt;br /&gt;  # should appear as.&lt;br /&gt;  connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry&lt;br /&gt;&lt;br /&gt;  # register some queues in JNDI using the form&lt;br /&gt;  # queue.[jndiName] = [physicalName]&lt;br /&gt;  queue.jndiqueue.test = test.prog.queue&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  # register some topics in JNDI using the form&lt;br /&gt;  # topic.[jndiName] = [physicalName]&lt;br /&gt;  #topic.MyTopic = example.MyTopic&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Changing the ActiveMQ listening port&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Copy and paste the conf/activemq.xml, and rename to newBroker.xml. change the port address in the XML:&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- The transport connectors ActiveMQ will listen to --&amp;gt;&lt;br /&gt;       &amp;lt;transportConnectors&amp;gt;&lt;br /&gt;           &amp;lt;transportConnector name="openwire" uri="tcp://localhost:51616" discoveryUri="multicast://default"/&amp;gt;&lt;br /&gt;           &amp;lt;transportConnector name="ssl" uri="ssl://localhost:51617"/&amp;gt;&lt;br /&gt;           &amp;lt;transportConnector name="stomp" uri="stomp://localhost:51613"/&amp;gt;&lt;br /&gt;           &amp;lt;transportConnector name="xmpp" uri="xmpp://localhost:51222"/&amp;gt;&lt;br /&gt;       &amp;lt;/transportConnectors&amp;gt;&lt;br /&gt;&lt;br /&gt;Run the activeMQ batch file with command:&lt;br /&gt;&lt;br /&gt;activemq xbean:newBroker.xml&lt;br /&gt;&lt;br /&gt;Or place the newBroker.xml in some other directory, say, c:\configs\activemq\newBroker.xml.&lt;br /&gt;&lt;br /&gt;Run:&lt;br /&gt;&lt;br /&gt;activemq xbean:file:c:/configs/activemq/newBroker.xml&lt;br /&gt;&lt;br /&gt;which will start the broker at new ports.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Points to remember:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;a. Below exception indicates you are using backslashes in the file: at commandline. change to forward slashes, it will resolve the exception.&lt;br /&gt;&lt;br /&gt;ERROR: java.net.URISyntaxException: Illegal character in opaque part at index 13&lt;br /&gt;: xbean:file:E:\soft\activemq\apache-activemq-5.1.0\conf\newBroker.xml&lt;br /&gt;java.net.URISyntaxException: Illegal character in opaque part at index 13: xbean&lt;br /&gt;:file:E:\soft\activemq\apache-activemq-5.1.0\conf\newBroker.xml&lt;br /&gt;       at java.net.URI$Parser.fail(URI.java:2816)&lt;br /&gt;       at java.net.URI$Parser.checkChars(URI.java:2989)&lt;br /&gt;     &lt;br /&gt;b. Keep the port number in check, a very large value will also result in a out of range exception.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Running two brokers on same machine&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Other than changing the port as shown above, a new datastore has to be given. This is configured in the below XML snippet in the newBroker.xml.&lt;br /&gt;&lt;br /&gt;&amp;lt;persistenceAdapter&amp;gt;&lt;br /&gt;           &amp;lt;amqPersistenceAdapter syncOnWrite="false" directory="${activemq.base}/newBrokerdata" maxFileLength="20 mb"/&amp;gt;&lt;br /&gt;&amp;lt;/persistenceAdapter&amp;gt;&lt;br /&gt;&lt;br /&gt;Also, though not required, you can change the jetty servlet engine port of the newBroker.xml as below to say 8162.&lt;br /&gt;&lt;br /&gt;&amp;lt;jetty xmlns="http://mortbay.com/schemas/jetty/1.0"&amp;gt;&lt;br /&gt;       &amp;lt;connectors&amp;gt;&lt;br /&gt;           &amp;lt;nioConnector port="8162"/&amp;gt;&lt;br /&gt;       &amp;lt;/connectors&amp;gt;&lt;br /&gt;       &amp;lt;handlers&amp;gt;&lt;br /&gt;           &amp;lt;webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/&amp;gt;&lt;br /&gt;           &amp;lt;webAppContext contextPath="/demo" resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true"/&amp;gt;&lt;br /&gt;           &amp;lt;webAppContext contextPath="/fileserver" resourceBase="${activemq.base}/webapps/fileserver" logUrlOnStart="true"/&amp;gt;&lt;br /&gt;       &amp;lt;/handlers&amp;gt;&lt;br /&gt;   &amp;lt;/jetty&amp;gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Network of Brokers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We can have a network of brokers for load balancing and support even if one of the brokers fail due to any reason, say, network problem.&lt;br /&gt;&lt;br /&gt;The network of broker can be established in two ways:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a. Statically listing the ips of the other broker.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;b. using auto discovery mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Both the configuration uses the networkConnector element in the broker xml configuration.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;a. For statically listing the ips, the below xml can be used in our newBroker.xml&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- The store and forward broker networks ActiveMQ will listen to --&amp;gt;&lt;br /&gt;       &amp;lt;networkConnectors&amp;gt;&lt;br /&gt;           &amp;lt;!-- by default just auto discover the other brokers --&amp;gt;&lt;br /&gt;           &amp;lt;!-- &amp;lt;networkConnector name="default-nc" uri="multicast://default"/&amp;gt; --&amp;gt;&lt;br /&gt;           &amp;lt;!-- Example of a static configuration:&lt;br /&gt;           &amp;lt;networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)"/&amp;gt;&lt;br /&gt;           --&amp;gt;&lt;br /&gt;           &amp;lt;networkConnector name="newBroker" uri="static://(tcp://localhost:61616)"/&amp;gt;&lt;br /&gt;       &amp;lt;/networkConnectors&amp;gt;&lt;br /&gt;     &lt;br /&gt;If you observe the console, then the following line confirms that our brokers are running as a network of brokers.&lt;br /&gt;&lt;br /&gt;INFO  DemandForwardingBridge         - Network connection between vm://localhost#0 and tcp://localhost/127.0.0.1:61616(localhost) has been established.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt; b. For auto discovrey mode, you can use the following XML.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- The store and forward broker networks ActiveMQ will listen to --&amp;gt;&lt;br /&gt;        &amp;lt;networkConnectors&amp;gt;&lt;br /&gt;            &amp;lt;!-- by default just auto discover the other brokers --&amp;gt;&lt;br /&gt;            &amp;lt;networkConnector name="default-nc" uri="multicast://default"/&amp;gt;&lt;br /&gt;            &amp;lt;!-- Example of a static configuration:&lt;br /&gt;            &amp;lt;networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)"/&amp;gt;&lt;br /&gt;            --&amp;gt;&lt;br /&gt;       &amp;lt;/networkConnectors&amp;gt;&lt;br /&gt;     &lt;br /&gt;   Yes, you guessed right, this is the default configuration.&lt;br /&gt; &lt;br /&gt;   Remenber to have the below xml snipet with discoveryUri attribute in all your brokers. By default, this is present.&lt;br /&gt; &lt;br /&gt;   &amp;lt;transportConnector name="openwire" uri="tcp://localhost:51616" discoveryUri="multicast://default"/&amp;gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Client using failover over a network of broker&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The failover protocol has to be used on the client side, so that, if any of the broker in the network of brokers fail, then the client can use an alternative broker which is up and running.&lt;br /&gt;&lt;br /&gt;This is also just a configuration.&lt;br /&gt;&lt;br /&gt;For our example, this will be in jndi.properties as:&lt;br /&gt;&lt;br /&gt;  java.naming.provider.url = failover:(tcp://localhost:61616,tcp://localhost:51616)&lt;br /&gt;&lt;br /&gt;Or in code as:&lt;br /&gt;String localURI = "tcp://localhost:61616";&lt;br /&gt;String remoteURI = "tcp://localhost:51616";&lt;br /&gt;ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover:("+localURI+","+"remoteURI)");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-5782167761527233244?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/5782167761527233244/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/activemq-510-tutorial.html#comment-form' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5782167761527233244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/5782167761527233244'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/activemq-510-tutorial.html' title='ActiveMQ 5.1.0 tutorial'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-1420295383420636909</id><published>2008-06-02T23:45:00.000-07:00</published><updated>2008-06-03T00:00:32.608-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='New ways to contribute towards saving nature'/><category scheme='http://www.blogger.com/atom/ns#' term='Environment'/><category scheme='http://www.blogger.com/atom/ns#' term='Nature'/><title type='text'>Taking care of yourself, will take care of nature</title><content type='html'>Hmm.. I am a weird guy, who also is into some amount of technical things. If I get depressed or find nothing else to do, I start reading technical books(Weird!!). Majorly, into java; but nothing specific as Java. It can be VB, C#, Shell script, php or whatever that can be typed on a computer and can be interpreted/compiled and executed.&lt;br /&gt;&lt;br /&gt;I had written this blog so as to maintain a personal diary of things I need to remember, which I deem important or weird and should be noted down.&lt;br /&gt;&lt;br /&gt;But, I have come to a realization that there is some thing which is more important than these; which is why i am here typing this blog and is of a category, which i have never done before in my life. My Organization, well, not in my profile, Tavant Technologies, have started a drive 'for' the cause of Mother nature. We have a team called Green Team, which does the job of causing awareness among the employees of our organization regarding environment. And, I feel it is very important for every one to be a part of this campaign as a whole with interest creeping out from deepness of each heart.  And I think, may be i can show its important by putting this content on my very very very personal diary.&lt;br /&gt;&lt;br /&gt;Here is a 'typing' dedicated for the our mother. May be this is a beginning and will give me enough enthu to write about other things i think about, namely, Life.&lt;br /&gt;&lt;br /&gt;How many of us really care for the environment? In my estimate 99 out of 100 people will say they do care for the environment. Yes and that is true!! But, out of these 99, how many do actually contribute towards caring for nature? I think may be 10. Why is this big difference between numbers?  People who care for the environment is greater than the number of people who contribute towards it. Hmm.. I think everyone should think about it for just 20 sec. Nothing more, I know, you don't have time for more than that to spare. Yeah, but you can definitely spare an hour sitting in front of TV or a computer playing games or eating ice-creams on the street or just sitting in front of your desk thinking about past or chatting with a friend of yours about someone who is not yours. Good, keep it up.&lt;br /&gt;&lt;br /&gt;Well, you really don't have to give time for taking care of it. You just take care of yourself, that is more than sufficient. Let me put in some of my thoughts here, as in, how to achieve that.&lt;br /&gt;&lt;br /&gt;I used to see my friends copy in B.E examinations. They used to write half the book in about 20 half the A4 size sheets, with no space left any where and still quite readable. Very very good thinking. I mean, not copying, but an innovative thinking for a different cause(of not getting caught!!) leading to saving some amount of paper. There is a lesson to learn here. To save paper we can&lt;blockquote&gt; &lt;span style="font-style: italic;"&gt;start educating people to write in small handwriting's.&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;The smaller it gets the lesser the amount of paper used to convey the same information. No extra effort required, just decrease the font size with which you type, and leave less margins around the paper.&lt;br /&gt;&lt;br /&gt;My friend Satish always used to take printouts of the books to read. When i questioned he said it irritates his eyes to read on the system. He wears spectacles already. Then, i realized may be he is actually saving nature. we can &lt;blockquote&gt;&lt;span style="font-style: italic;"&gt;stop reading E-Books for hours on the computer. Better, take printouts on recycled papers, with 2 or 4 sheets per page and read.&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt; The later has relatively higher advantages than consumption of higher power.&lt;br /&gt;&lt;br /&gt;All of us have become a host for a fungus called 'diseases', from diabetes to heart problem. Major reason being our working style, the food we eat and laziness we have in us. If you want to stay alive a day more, start exercising. Even walking will do. But, before you start, voluntarily, &lt;blockquote&gt;&lt;span style="font-style: italic;"&gt;switch off the main supplies of your home for one hour in the evening. Then, go out to a park and have some fresh air.&lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Also, with keeping health of your own in mind, &lt;blockquote&gt;&lt;span style="font-style: italic;"&gt;start eating non-fried, non-microwaved food. The more you eat food like fruits, salad etc, &lt;/span&gt;&lt;/blockquote&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;the more healthier you get. Also, you indirectly help in reducing the power, the oil consumed and also, the air polluted due to frying. These may look small, but, never forget even an ocean is made up of  droplets of water.&lt;br /&gt;&lt;br /&gt;Though, these are very few ways, but can be definitely done with some conscious effort.&lt;br /&gt;If there are more thing you know, which are very very simple,and can be done without spending sufficient time on it, do post a comment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-1420295383420636909?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/1420295383420636909/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/taking-care-of-your-self-will-take-care.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1420295383420636909'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1420295383420636909'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/06/taking-care-of-your-self-will-take-care.html' title='Taking care of yourself, will take care of nature'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-2204103781414355763</id><published>2008-05-18T00:59:00.000-07:00</published><updated>2008-05-18T01:10:57.045-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Flex 3'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex dragging components'/><category scheme='http://www.blogger.com/atom/ns#' term='Flex 3 issues with datagrid header'/><title type='text'>Flex Flex Flex..</title><content type='html'>After one full year I am back in blogging.. I have been working in Flex for this whole year, and there are some things that i would like to make a note off:&lt;br /&gt;&lt;br /&gt;1. All the Hboxes, VBoxes finally extends &lt;span style="font-weight: bold;"&gt;FlexSprite&lt;/span&gt;, There are two methods on it. startDrag(), stopDrag(). You can use these on MouseUp and MouseDown events for dragging and dropping of UI components.&lt;br /&gt;&lt;p&gt;&lt;br /&gt; private function initDrags():void {&lt;br /&gt;   setVBEvents();&lt;br /&gt;           }&lt;br /&gt;&lt;/p&gt;          &lt;br /&gt;&lt;p&gt;            private function setVBEvents():void {&lt;br /&gt; bv.addEventListener(MouseEvent.MOUSE_DOWN, dragVB);//bv is the VBox&lt;br /&gt; bv.addEventListener(MouseEvent.MOUSE_UP, dragVB);//bv is the VBox&lt;br /&gt;              }&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;           private function dragVB(info:MouseEvent):void {&lt;br /&gt;if (info.type == "mouseDown") {&lt;br /&gt; bv.startDrag();&lt;br /&gt;                } else {&lt;br /&gt;                    bv.stopDrag();&lt;br /&gt;               }&lt;br /&gt;           }&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;2. In Flex 3, if you want 'resize' to work, with initial flex app having width,height=0 use percentage instead. i.e. width,height=0% in the Application tag.&lt;br /&gt;&lt;br /&gt;3. In Flex 3, if you experience problem in making DataGrids header disappear, try headerHeight=0 on creationComplete of DG.&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&amp;lt;mx:datagrid dataprovider="{this.dataProvider}" style="font-weight: bold;"&amp;gt;&lt;span style="font-weight: bold;"&gt;creationComplete="dg1.headerHeight=0"&lt;/span&gt; &amp;lt;/span&amp;gt;id="dg1"&amp;gt;&lt;br /&gt;               &amp;lt;mx:columns&amp;gt;&lt;br /&gt;   &amp;lt;mx:datagridcolumn datafield="time" width="50" id="u-129"&amp;gt;        backgroundColor="#7169e1" color="white" /&amp;gt;&lt;br /&gt;                       &amp;lt;mx:datagridcolumn datafield="price" width="60" id="u-1211"&amp;gt;        backgroundColor="#7169e1" color="white"/&amp;gt;&lt;br /&gt;                       &amp;lt;mx:datagridcolumn datafield="qty" width="60" id="u-1213"&amp;gt;backgroundColor="#7169e1" color="white"/&amp;gt;&lt;br /&gt;               &amp;lt;/mx:columns&amp;gt;&lt;br /&gt;           &amp;lt;/mx:DataGrid&amp;gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-2204103781414355763?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/2204103781414355763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/05/flex-flex-flex.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2204103781414355763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/2204103781414355763'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2008/05/flex-flex-flex.html' title='Flex Flex Flex..'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-326276421262979055</id><published>2007-07-15T09:44:00.000-07:00</published><updated>2007-07-15T09:50:03.957-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='filter'/><category scheme='http://www.blogger.com/atom/ns#' term='filtering result'/><category scheme='http://www.blogger.com/atom/ns#' term='filtering collection'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Filtering the result in hibernate</title><content type='html'>The filtering in hibernate can be acheived in two ways.&lt;br /&gt;One, applying the filtering on the session before a finder or any query is hit.&lt;br /&gt;Two, applying the filtering on the collection which is a persistent set after the query is hit.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;For the first one,&lt;/span&gt;&lt;br /&gt;An entry has to be made in the hbm xml's defing the filter, the parameters it take and the persistent collection on which the filter has to be applied to. Then before hitting the query on the session, we enable the filter on the session. Once the filter is enabled, any query on the session resulting in the persistent collection on which the filtering has been enable will be filtered on the filtering condition specified.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;Example.hbm.xml&lt;br /&gt;-------------------&lt;br /&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;&amp;lt;class&amp;gt;&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;&amp;lt;set name="exampleTwo" inverse="true"&amp;gt;&lt;br /&gt;           &amp;lt;key&amp;gt;&lt;br /&gt;               &amp;lt;column name="EXAMPLETWO_ID" precision="12" scale="0" /&amp;gt;&lt;br /&gt;           &amp;lt;/key&amp;gt;&lt;br /&gt;           &amp;lt;one-to-many class="ExampleTwo" /&amp;gt;&lt;br /&gt;           &amp;lt;filter name="CaseOneFilter" condition="ACTIVE_IND = :CaseOneFilterParam"/&amp;gt;&lt;br /&gt;&amp;lt;/set&amp;gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;filter-def name="CaseOneFilter"&amp;gt;&lt;br /&gt;       &amp;lt;filter-param name="CaseOneFilterParam" type="char"/&amp;gt;&lt;br /&gt;&amp;lt;/filter-def&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;&lt;br /&gt;In Code,&lt;br /&gt;we enable the filter as:&lt;br /&gt;session.enableFilter("CaseOneFilter").setParameter("CaseOneFilterParam",'Y');&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;For the second case,&lt;/span&gt;&lt;br /&gt;Once we hit a finder and get a hook on a persistent object, we can create a filter on the session. The collection associated with this persistent object on which filtering has to be applied is sent to this newly created filter on the session. This results in getting a collection which is filtered on the conditions specified in the filter.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public static &amp;lt;T&amp;gt; Collection&amp;lt;T&amp;gt; filterCollection(Collection&amp;lt;T&amp;gt; collection, Session session,String filterCondition) {&lt;br /&gt;       Query filterQuery = s.createFilter(collection, filterCondition);&lt;br /&gt;       return filterQuery.list();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;This can be called as:&lt;br /&gt;/**&lt;br /&gt;* Assuming pk to be perisitent object, session to be hibernate session.&lt;br /&gt;*&lt;br /&gt;*/&lt;br /&gt;filterCollection(pk.getChildrens(), session, "select this.attribute where this.id = 23");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-326276421262979055?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/326276421262979055/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/07/filtering-result-in-hibernate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/326276421262979055'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/326276421262979055'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/07/filtering-result-in-hibernate.html' title='Filtering the result in hibernate'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-1326198804557900312</id><published>2007-07-15T08:26:00.000-07:00</published><updated>2007-07-15T08:30:57.638-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Criteria query'/><category scheme='http://www.blogger.com/atom/ns#' term='Result Transformer'/><category scheme='http://www.blogger.com/atom/ns#' term='Eager fetching in hibernate'/><title type='text'>Eager fetching in Hibernate using Criteria queries</title><content type='html'>One of the easiest way of eager fetching is using the setFetchMode function present with Criteria API's. The whole clutter of reflection which i presented below can be removed by using this.&lt;br /&gt;But the criteria queries when doing eager loading gives duplicate resultsets, what i mean is if the parent table has one row and the child table associated with it has say 2 rows then on doing an eager fetch we receive 2 parent Objects representing the parent table. This is because, eager fetching is nothing but putting 'sql join' on the underlying tables. And, as a result of this outer joins we get duplicate results. To get distinct results we have to use resultTransformer. The same code is given below.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;Class Example{//Associated with Table EXAMPLE in Example.hbm.xml&lt;br /&gt;private String attributeOne;&lt;br /&gt;private ExampleTwo exampleTwo; //A foreign one to one relation with ExampleTwo&lt;br /&gt;//Getters and Setters&lt;br /&gt;}&lt;br /&gt;.&lt;br /&gt;Class ExampleTwo{//Associated with Table EXAMPLE_TWO in Example.hbm.xml&lt;br /&gt;private String attributeOne;&lt;br /&gt;//Getters and Setters&lt;br /&gt;}&lt;br /&gt;.&lt;br /&gt;Criteria criteria = session.createCriteria(Example.class); //Create the criteria query&lt;br /&gt;List&lt;string&gt; fetchList=new ArrayList&lt;string&gt;();&lt;br /&gt;fetchList.add(exampleTwo);&lt;br /&gt;initializeFetchList(Criteria criteria, List&lt;string&gt; fetchList); //initialize&lt;br /&gt;List&lt;example&gt; exmpleList = criteria.list() //Executing this gives us List of Example Objects with pre-fetched ExampleTwo Objects in it.&lt;br /&gt;.&lt;br /&gt;.&lt;br /&gt;  public void initializeFetchList(Criteria criteria, List&lt;string&gt; fetchList){&lt;br /&gt;&lt;br /&gt;    for (String entityAttribute : fetchList)    {&lt;br /&gt;      criteria.setFetchMode(entityAttribute, FetchMode.JOIN);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);&lt;br /&gt;  }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-1326198804557900312?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/1326198804557900312/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1326198804557900312'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/1326198804557900312'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/07/eager-fetching-in-hibernate-using.html' title='Eager fetching in Hibernate using Criteria queries'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-4577546565534955549</id><published>2007-04-08T23:48:00.000-07:00</published><updated>2007-04-09T00:00:48.363-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Criteria query'/><category scheme='http://www.blogger.com/atom/ns#' term='Reflection'/><category scheme='http://www.blogger.com/atom/ns#' term='Eager fetching in hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><title type='text'>Using hibernate and reflection to generate queries on any table with eager fetching of the specified attributes representing the foreign key relations</title><content type='html'>&lt;span style="font-weight: bold; font-style: italic;"&gt;Below is the code attached with appropriate comments:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;package reflection;&lt;br /&gt;&lt;br /&gt;import java.lang.reflect.Method;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Collection;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.Map;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import org.hibernate.Criteria;&lt;br /&gt;import org.hibernate.Hibernate;&lt;br /&gt;import org.hibernate.Session;&lt;br /&gt;import org.hibernate.criterion.Expression;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt; * @author SacrosanctBlood&lt;br /&gt; *&lt;br /&gt; *&lt;br /&gt; * &amp;lt;p&amp;gt;&lt;br /&gt; * This utility class is used to execute an hibernate query on a single entity class, with any number of conditions&lt;br /&gt; * (equals conditions only, but can be extended)on the attributes of the class. It also fetches the Objects given in the&lt;br /&gt; * list which would otherwise be fetched lazily.&lt;br /&gt; * &amp;lt;/p&amp;gt;&lt;br /&gt; */&lt;br /&gt;public class HibernateQueryUtil {&lt;br /&gt;    /**&lt;br /&gt;     * This method returns the result of the find query on the given input class.&lt;br /&gt;     *&lt;br /&gt;     * @param session&lt;br /&gt;     *            The hibernate session in which the query will be executed. This can not be null.&lt;br /&gt;     * @param clazz&lt;br /&gt;     *            The entity class which is mapped to a table in database, on which the query is executed. This can not&lt;br /&gt;     *            be null.&lt;br /&gt;     * @param conditions&lt;br /&gt;     *            A map of attributeName = attributeValue for the attributes in the class. These represents the&lt;br /&gt;     *            conditions for the fetch query. This can be null.&lt;br /&gt;     * @param fetchList&lt;br /&gt;     *            A list of attributes in the class representing a foreign relationship that needs to be fetched&lt;br /&gt;     *            eagerly. This can be null.&lt;br /&gt;     * @return List A list of the resultant Objects of the type clazz which have been eagerly initialized according to&lt;br /&gt;     *         the fetchList. The List can be empty dependent on the query executed.&lt;br /&gt;     * @throws IllegalArgumentException&lt;br /&gt;     *             Thrown when&lt;br /&gt;     *             &amp;lt;li&amp;gt;Clazz is not valid&amp;lt;/li&amp;gt;&lt;br /&gt;     *             &amp;lt;li&amp;gt;Attributes are not present in clazz&amp;lt;/li&amp;gt;&lt;br /&gt;     *             &amp;lt;li&amp;gt;Attributes in fetchList is not valid.&amp;lt;/li&amp;gt;&lt;br /&gt;     */&lt;br /&gt;    public static List find(Session session, Class clazz, Map&amp;lt;String, Object&amp;gt; conditions, List&amp;lt;String&amp;gt; fetchList)&lt;br /&gt;            throws IllegalArgumentException {&lt;br /&gt;        Set&amp;lt;String&amp;gt; attributes = null;&lt;br /&gt;        attributes = initializeAttributes(conditions);&lt;br /&gt;        String entityName = clazz.getSimpleName();&lt;br /&gt;        List result = null;&lt;br /&gt;        if (entityName != null) {&lt;br /&gt;            Criteria criteria = session.createCriteria(clazz);&lt;br /&gt;            if (conditions != null) {&lt;br /&gt;                checkIfAttributesExistInClass(clazz, attributes);&lt;br /&gt;                addCriterions(criteria, conditions, attributes);&lt;br /&gt;            }&lt;br /&gt;            result = executeQuery(criteria);&lt;br /&gt;            if (fetchList != null &amp;&amp;amp; result != null) {&lt;br /&gt;                checkIfAttributesExistInClass(clazz, fetchList);&lt;br /&gt;                List&amp;lt;String&amp;gt; methodsToInvoke = convertFetchListToMethodToInvokeList(fetchList);&lt;br /&gt;                checkIfMethodsExistInClass(clazz, methodsToInvoke);&lt;br /&gt;                initializeFetchList(clazz, methodsToInvoke, result);&lt;br /&gt;            }&lt;br /&gt;        } else {&lt;br /&gt;            throw new IllegalArgumentException("Class " + clazz.getName() + " is not valid");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return result;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * This method eagerly initializes each of the attributes for each Object in the resultList.&lt;br /&gt;     *&lt;br /&gt;     * @param clazz&lt;br /&gt;     * @param methodsToInvoke&lt;br /&gt;     * @param resultlist&lt;br /&gt;     * @throws IllegalArgumentException&lt;br /&gt;     */&lt;br /&gt;    private static void initializeFetchList(Class clazz, List&amp;lt;String&amp;gt; methodsToInvoke, List resultlist)&lt;br /&gt;            throws IllegalArgumentException {&lt;br /&gt;        // called methods have no argument(They are just getter methods)&lt;br /&gt;        Class params[] = {};&lt;br /&gt;        Object paramsObj[] = {};&lt;br /&gt;        for (Object resultObject : resultlist) {&lt;br /&gt;            if (clazz.isInstance(resultObject)) {&lt;br /&gt;                for (String aMethod : methodsToInvoke) {&lt;br /&gt;                    try {&lt;br /&gt;                        // get the method&lt;br /&gt;                        Method thisMethod = clazz.getDeclaredMethod(aMethod, params);&lt;br /&gt;                        // invoke the method on the object and initiliaze in Hibernate&lt;br /&gt;                        Hibernate.initialize(thisMethod.invoke(resultObject, paramsObj).toString());&lt;br /&gt;                    } catch (Exception e) {&lt;br /&gt;                        e.printStackTrace();&lt;br /&gt;                        throw new IllegalArgumentException(&lt;br /&gt;                                "Error while invoking method to initiliaze in HibernateQueryUtil:initilizeFetchList");&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            } else {&lt;br /&gt;                throw new IllegalArgumentException(&lt;br /&gt;                        "The resultant Objects of the hibernate query are not the same as the Class "&lt;br /&gt;                                + clazz.getSimpleName());&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * This method checks if the methodToInvoke is present in the given Class.&lt;br /&gt;     *&lt;br /&gt;     * @param clazz&lt;br /&gt;     * @param methodsToInvoke&lt;br /&gt;     * @throws IllegalArgumentException&lt;br /&gt;     */&lt;br /&gt;    private static void checkIfMethodsExistInClass(Class clazz, Collection&amp;lt;String&amp;gt; methodsToInvoke)&lt;br /&gt;            throws IllegalArgumentException {&lt;br /&gt;&lt;br /&gt;        for (String thisMethod : methodsToInvoke) {&lt;br /&gt;&lt;br /&gt;            try {&lt;br /&gt;                clazz.getDeclaredMethod(thisMethod);&lt;br /&gt;            } catch (SecurityException e) {&lt;br /&gt;                throw new IllegalArgumentException("Method with name " + thisMethod + " is not accessible");&lt;br /&gt;            } catch (NoSuchMethodException e) {&lt;br /&gt;                throw new IllegalArgumentException("Method with name " + thisMethod + " does not exist");&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * This method converts the fetchList which is just a list of attributes in class, to the corresponding getter&lt;br /&gt;     * method on the attribute. This method is later invoked in &amp;lt;i&amp;gt;initializeFetchList&amp;lt;/i&amp;gt;.&lt;br /&gt;     *&lt;br /&gt;     * @param fetchList&lt;br /&gt;     * @return List A list containing methods to be invoked.&lt;br /&gt;     */&lt;br /&gt;    private static List&amp;lt;String&amp;gt; convertFetchListToMethodToInvokeList(List&amp;lt;String&amp;gt; fetchList) {&lt;br /&gt;        List&amp;lt;String&amp;gt; convertedList = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;        for (String thisAttribute : fetchList) {&lt;br /&gt;            String firstLetterInUpperCase = String.valueOf(thisAttribute.charAt(0)).toUpperCase();&lt;br /&gt;            String getterMethodString = "get" + firstLetterInUpperCase + thisAttribute.substring(1);&lt;br /&gt;            convertedList.add(getterMethodString);&lt;br /&gt;        }&lt;br /&gt;        return convertedList;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * This method returns a Set of the attributes present in the Class given as an input to &amp;lt;i&amp;gt;find&amp;lt;/i&amp;gt; method.&lt;br /&gt;     *&lt;br /&gt;     * @param attributes&lt;br /&gt;     * @return Set All the attributes.&lt;br /&gt;     */&lt;br /&gt;    private static Set&amp;lt;String&amp;gt; initializeAttributes(Map&amp;lt;String, Object&amp;gt; attributes) {&lt;br /&gt;        Set&amp;lt;String&amp;gt; keys = null;&lt;br /&gt;        if (attributes != null)&lt;br /&gt;            keys = attributes.keySet();&lt;br /&gt;        return keys;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     * @param clazz&lt;br /&gt;     * @param attributes&lt;br /&gt;     * @throws IllegalArgumentException&lt;br /&gt;     */&lt;br /&gt;&lt;br /&gt;    private static void checkIfAttributesExistInClass(Class clazz, Collection&amp;lt;String&amp;gt; attributes)&lt;br /&gt;            throws IllegalArgumentException {&lt;br /&gt;&lt;br /&gt;        for (String thisAttribute : attributes) {&lt;br /&gt;            try {&lt;br /&gt;                clazz.getDeclaredField(thisAttribute);&lt;br /&gt;            } catch (NoSuchFieldException e) {&lt;br /&gt;                throw new IllegalArgumentException("Column with name " + thisAttribute + " does not exist");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     * This method add new criterions for the criteria object.&lt;br /&gt;     *&lt;br /&gt;     * @param criteria&lt;br /&gt;     * @param columns&lt;br /&gt;     * @param keys&lt;br /&gt;     */&lt;br /&gt;    private static void addCriterions(Criteria criteria, Map&amp;lt;String, Object&amp;gt; columns, Collection&amp;lt;String&amp;gt; keys) {&lt;br /&gt;        for (String thisAttribute : keys) {&lt;br /&gt;            Object thisAttributValue = columns.get(thisAttribute);&lt;br /&gt;            // equals operator by default&lt;br /&gt;            criteria.add(Expression.eq(thisAttribute, thisAttributValue));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /**&lt;br /&gt;     *&lt;br /&gt;     * @param criteria&lt;br /&gt;     * @return List Result of executing the query&lt;br /&gt;     */&lt;br /&gt;    private static List executeQuery(Criteria criteria) {&lt;br /&gt;        List result = null;&lt;br /&gt;        if (criteria != null) {&lt;br /&gt;            result = criteria.list();&lt;br /&gt;        }&lt;br /&gt;        return result;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;Below is a client that uses this utility class:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;package client;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.HashMap;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.List;&lt;br /&gt;import java.util.Map;&lt;br /&gt;import java.util.Set;&lt;br /&gt;&lt;br /&gt;import org.hibernate.Hibernate;&lt;br /&gt;import org.hibernate.Session;&lt;br /&gt;import org.hibernate.SessionFactory;&lt;br /&gt;import org.hibernate.cfg.Configuration;&lt;br /&gt;&lt;br /&gt;import entity.data.Data;&lt;br /&gt;import entity.datachildren.DataChildren;&lt;br /&gt;&lt;br /&gt;import reflection.HibernateQueryUtil;&lt;br /&gt;&lt;br /&gt;public class Client {&lt;br /&gt; public static void main(String[] args) throws Exception{&lt;br /&gt;     SessionFactory factory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;     Session session = factory.openSession();&lt;br /&gt;     //case 1:  get all the Data.&lt;br /&gt;     List list = HibernateQueryUtil.find(session, Data.class, null,null);&lt;br /&gt;     Iterator iter = list.iterator();&lt;br /&gt;     while(iter.hasNext()){&lt;br /&gt;         Data data = (Data)iter.next();&lt;br /&gt;     }&lt;br /&gt;     //case 2: get Data with dataId = 3 and dataBy = "ABC"&lt;br /&gt;     Map&amp;lt;String, Object&amp;gt; conditions = new HashMap&amp;lt;String, Object&amp;gt;();&lt;br /&gt;     map.put("dataId", new Integer(3));&lt;br /&gt;     conditions.put("dataBy", "ABC");&lt;br /&gt;    &lt;br /&gt;     // also fetch Data Childrens&lt;br /&gt;     List&amp;lt;String&amp;gt; fetchList = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;     fetchList.add("dataChildrens");&lt;br /&gt;     // list = HibernateQueryUtil.find(session, Data.class, map,null); throws LazyInitializeException&lt;br /&gt;     list = HibernateQueryUtil.find(session, Data.class, conditions,fetchList);//initializes so no problem&lt;br /&gt;    &lt;br /&gt;     session.close();&lt;br /&gt;     Set ds = null;&lt;br /&gt;     iter = list.iterator();&lt;br /&gt;     while(iter.hasNext()){&lt;br /&gt;         Data data = (Data)iter.next();&lt;br /&gt;         System.out.println(data.getDataId() + " " + data.getDataBy());&lt;br /&gt;         ds = data.getDataChildrens();&lt;br /&gt;         Iterator dIter = ds.iterator();&lt;br /&gt;         while(dIter.hasNext()){&lt;br /&gt;             System.out.println("LP: " + ((DataChildren)dIter.next()).getDataChildrenName());&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;   &lt;br /&gt;  &lt;br /&gt;    &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;Hope this was helpful..&lt;span style="font-weight: bold; font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-4577546565534955549?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/4577546565534955549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/04/using-hibernate-and-reflection-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4577546565534955549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/4577546565534955549'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/04/using-hibernate-and-reflection-to.html' title='Using hibernate and reflection to generate queries on any table with eager fetching of the specified attributes representing the foreign key relations'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-117506494939722978</id><published>2007-03-28T00:53:00.000-07:00</published><updated>2007-03-28T01:23:03.910-07:00</updated><title type='text'>Step by step tutorial to use Rampart with axis2 web service for implementing security.</title><content type='html'>Given below is a tutorial to use axis2 in implementing web services with security(This shows sync/Blocking call client along with Rampart security). This tutorial extends the previous tutorials to add security features to the web services using rampart module. For more details regarding any aspect of the tutorial, the axis2 or rampart  documents will assist you.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;My Configuration:(same as previous)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a) AXIS2 1.1.1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;b) JDK 1.5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;c) ANT 1.7.0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;d) TOMCAT 5.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Before proceeding, please read the installation doc of axis2 and rampart to do a proper installation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 0: Set the following paths in your system.(This step is very important)&lt;/span&gt;&lt;br /&gt;a) AXIS2_HOME = "your axis2 installation(unzipped) directory"&lt;br /&gt;b) JAVA_HOME = "your jdk installation path"&lt;br /&gt;c) PATH = "add ant, axis2/bin to this"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1: Extract the rampart-1.1.zip.&lt;/span&gt; Before doing anything more copy the %AXIS2_HOME%/lib to %AXIS2_HOME%/lib.1. Run the ant task on build.xml present in extracted folder. Now rebuild the whole axis2(i.e run the ant task in %AXIS2_HOME%/webapp). Deploy this in your server. Rename the lib to lib.2, and lib.1 to lib.[This is to run WSDL2JAVA and JAVA2WSDL tool, other wise the tools doesn't run and the reason is that the path AXIS2_CLASS_PATH becomes too long(I am running on Win 2000)]&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2: Create your service interface and impl class&lt;/span&gt;. Generate the WSDL using java2wsdl, generate the skeleton and stubs using wsdl2java, code the skeleton. Build the "MyRampartService.aar" and deploy on the server. Test the service. Use the client service stub to code a basic client, run the client to see its working. This step has set up a web service and a client in a usable state. Next, step goes through the rampart part.&lt;br /&gt;The service and skeleton are given below for reference.&lt;br /&gt;--------------Interface-------------------&lt;br /&gt;package axis2.adb.sync.rampart;&lt;br /&gt;public interface MyRampartService {&lt;br /&gt;public String getSecretText(String codeword);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;-------------Impl class-------------------&lt;br /&gt;package axis2.adb.sync.rampart;&lt;br /&gt;public class MyRampartServiceImpl implements MyRampartService {&lt;br /&gt;    public String getSecretText(String codeword) {&lt;br /&gt;        if(codeword.equalsIgnoreCase("apache"))&lt;br /&gt;            return "You have done a good choice to build an application";&lt;br /&gt;        return "You have done a bad choice to build application";&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;-------------Skeleton Class----------------&lt;br /&gt;/**&lt;br /&gt; * MyRampartServiceSkeleton.java&lt;br /&gt; *&lt;br /&gt; * This file was auto-generated from WSDL&lt;br /&gt; * by the Apache Axis2 version: 1.1.1 Jan 09, 2007 (06:20:51 LKT)&lt;br /&gt; */&lt;br /&gt;package axis2.adb.sync.rampart;&lt;br /&gt;import axis2.adb.sync.rampart.MyRampartService;&lt;br /&gt;import axis2.adb.sync.rampart.MyRampartServiceImpl;&lt;br /&gt;import axis2.adb.sync.rampart.xsd.GetSecretTextResponse;&lt;br /&gt;public class MyRampartServiceSkeleton implements MyRampartServiceSkeletonInterface {&lt;br /&gt;MyRampartService myService = new MyRampartServiceImpl();&lt;br /&gt;    public axis2.adb.sync.rampart.xsd.GetSecretTextResponse getSecretText(axis2.adb.sync.rampart.xsd.GetSecretText param2){&lt;br /&gt;        GetSecretTextResponse res = new GetSecretTextResponse();&lt;br /&gt;        res.set_return(myService.getSecretText(param2.getParam0()));&lt;br /&gt;        return res;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3: This step uses the example from the rampart sample05. &lt;/span&gt;The intention is to encrypt the data in XML's which are exchanged between the client and the server. Copy %AXIS2_HOME%/repository to a convenient location. Copy  %AXIS2_HOME%/conf/axis2.xml to %COPIED_LOCATION%/repository/modules/client.axis2.xml. Copy the rampart-1.1/samples/Keys to "resources" directory created on running the WSDL2JAVA on previous step. We will be using the same keystore which rampart has provided for encrypting the message. you use the "keytool" that is a part of JDK to create your own keystore. Add the rampart lib also to your classpath to compile and run the client. Copy from the sample05 directory org/apache/rampart/samples/sample05/PWCBHandler.java into your source directory(remember to change the package in PWCBHandler.java, if you put it in some other package). This is the callback handler that is called on the client and the server side for verifying the password.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 4: Modify the resources/services.xml and %COPIED_LOCATION%/repository/modules/client.axis2.xml to enter Rampart configuration.&lt;/span&gt;&lt;br /&gt;Add the below into the services.xml.&lt;br /&gt;&amp;lt;serviceGroup&amp;gt;&lt;br /&gt;&amp;lt;service name="MyRampartService"&amp;gt;&lt;br /&gt;......&lt;br /&gt;......&lt;br /&gt;&amp;lt;module ref="rampart" /&amp;gt;&lt;br /&gt;    &amp;lt;parameter name="InflowSecurity"&amp;gt;&lt;br /&gt;      &amp;lt;action&amp;gt;&lt;br /&gt;        &amp;lt;items&amp;gt;Encrypt&amp;lt;/items&amp;gt;&lt;br /&gt;        &amp;lt;passwordCallbackClass&amp;gt;axis2.adb.sync.rampart.callbackhandler.PWCBHandler&amp;lt;/passwordCallbackClass&amp;gt;&lt;br /&gt;        &amp;lt;decryptionPropFile&amp;gt;service.properties&amp;lt;/decryptionPropFile&amp;gt;&lt;br /&gt;      &amp;lt;/action&amp;gt;&lt;br /&gt;    &amp;lt;/parameter&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;parameter name="OutflowSecurity"&amp;gt;&lt;br /&gt;      &amp;lt;action&amp;gt;&lt;br /&gt;        &amp;lt;items&amp;gt;Encrypt&amp;lt;/items&amp;gt;&lt;br /&gt;        &amp;lt;encryptionUser&amp;gt;client&amp;lt;/encryptionUser&amp;gt;&lt;br /&gt;        &amp;lt;encryptionPropFile&amp;gt;service.properties&amp;lt;/encryptionPropFile&amp;gt;&lt;br /&gt;      &amp;lt;/action&amp;gt;&lt;br /&gt;    &amp;lt;/parameter&amp;gt;&lt;br /&gt;&amp;lt;/service&amp;gt;&lt;br /&gt;&amp;lt;/serviceGroup&amp;gt;&lt;br /&gt;&lt;br /&gt;Add the below into the client.axis2.xml just before the "phases" definitions.&lt;br /&gt;&amp;lt;module ref="rampart" /&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;parameter name="OutflowSecurity"&amp;gt;&lt;br /&gt;      &amp;lt;action&amp;gt;&lt;br /&gt;        &amp;lt;items&amp;gt;Encrypt&amp;lt;/items&amp;gt;&lt;br /&gt;        &amp;lt;encryptionUser&amp;gt;service&amp;lt;/encryptionUser&amp;gt;&lt;br /&gt;        &amp;lt;encryptionPropFile&amp;gt;client.properties&amp;lt;/encryptionPropFile&amp;gt;&lt;br /&gt;      &amp;lt;/action&amp;gt;&lt;br /&gt;    &amp;lt;/parameter&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;parameter name="InflowSecurity"&amp;gt;&lt;br /&gt;      &amp;lt;action&amp;gt;&lt;br /&gt;        &amp;lt;items&amp;gt;Encrypt&amp;lt;/items&amp;gt;&lt;br /&gt;        &amp;lt;passwordCallbackClass&amp;gt;axis2.adb.sync.rampart.callbackhandler.PWCBHandler&amp;lt;/passwordCallbackClass&amp;gt;&lt;br /&gt;        &amp;lt;decryptionPropFile&amp;gt;client.properties&amp;lt;/decryptionPropFile&amp;gt;&lt;br /&gt;      &amp;lt;/action&amp;gt;&lt;br /&gt;    &amp;lt;/parameter&amp;gt;&lt;br /&gt;&lt;br /&gt;Now, parameter OutFlowSecurity represents the action to be taken on the outgoing XML's. In our case it is to encrypt. The encryption property file client.properties is present in keys directory. It gives the details of the keystore file, the password to that keystore, the keystore type and the provider.&lt;br /&gt;&lt;br /&gt;The parameter InFlowSecurity represents the action to be taken on the incoming XML's. It provides with the decryption property file which is same as the encryption property file in client.axis2.xml, the action item is same as the OutFlowSecurity action item and the password callbackhandler class. &lt;span style="font-style: italic; font-weight: bold;"&gt;I am using the one which came with samples provided with apache rampart.Its given below.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;import org.apache.ws.security.WSPasswordCallback;&lt;br /&gt;import javax.security.auth.callback.Callback;&lt;br /&gt;import javax.security.auth.callback.CallbackHandler;&lt;br /&gt;import javax.security.auth.callback.UnsupportedCallbackException;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;public class PWCBHandler implements CallbackHandler {&lt;br /&gt;    public void handle(Callback[] callbacks) throws IOException,&lt;br /&gt;            UnsupportedCallbackException {&lt;br /&gt;        for (int i = 0; i &amp;lt; callbacks.length; i++) {&lt;br /&gt;            WSPasswordCallback pwcb = (WSPasswordCallback)callbacks[i];     &lt;br /&gt;            String id = pwcb.getIdentifer();&lt;br /&gt;            if("client".equals(id)) {&lt;br /&gt;                pwcb.setPassword("apache");&lt;br /&gt;            } else if("service".equals(id)) {&lt;br /&gt;                pwcb.setPassword("apache");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 5: Edit build.xml.&lt;/span&gt;&lt;br /&gt;Search for target "jar.all" and add the following beneath the first copy element.&lt;br /&gt;&amp;lt;copy toDir="${classes}" failonerror="false"&amp;gt;&lt;br /&gt;    &amp;lt;fileset dir="${resources}/keys"&amp;gt;&lt;br /&gt;        &amp;lt;include name="*.jks"/&amp;gt;&lt;br /&gt;        &amp;lt;include name="*.properties"/&amp;gt;&lt;br /&gt;    &amp;lt;/fileset&amp;gt;&lt;br /&gt;&amp;lt;/copy&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 6: Build and deploy service.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Run ant command on this build.xml and deploy the service on axis2 in tomcat. Do not forget to restart the tomcat server if hotupdate is off.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 7: Edit the client and run. &lt;/span&gt;The client code is given below with appropriate comments. We do not have to configure the client using the XML, it can be done through code also. The below client uses the code when useRampartThroughCode is set to true. Please note that when this is used you do not have to configure the inflowsecurity and outflow security in the client.axis2.xml. Add the "resource/keys" on to the classpath before you run the client.&lt;br /&gt;&lt;br /&gt;package axis2.adb.sync.rampart.client;&lt;br /&gt;import java.rmi.RemoteException;&lt;br /&gt;import org.apache.axis2.AxisFault;&lt;br /&gt;import org.apache.axis2.context.ConfigurationContext;&lt;br /&gt;import org.apache.axis2.context.ConfigurationContextFactory;&lt;br /&gt;import org.apache.axis2.description.Parameter;&lt;br /&gt;import org.apache.rampart.handler.WSSHandlerConstants;&lt;br /&gt;import org.apache.rampart.handler.config.InflowConfiguration;&lt;br /&gt;import org.apache.rampart.handler.config.OutflowConfiguration;&lt;br /&gt;import axis2.adb.sync.rampart.MyRampartServiceStub;&lt;br /&gt;import axis2.adb.sync.rampart.xsd.GetSecretText;&lt;br /&gt;import axis2.adb.sync.rampart.xsd.GetSecretTextResponse;&lt;br /&gt;&lt;br /&gt;public class MyRampartServiceServiceClient {&lt;br /&gt;private static boolean useRampartThroughCode = false; // set this to true if you do not want to configure client using client.axis2.xml for using rampart.&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        MyRampartServiceStub stub = null;&lt;br /&gt;        ConfigurationContext configContext = null;&lt;br /&gt;        try {&lt;br /&gt;        // put your appropriate repository path in first arg, and path to client.axis2.xml in second arg.&lt;br /&gt;            configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("Axis2WithRampart/repository", "Axis2WithRampart/repository/modules/client.axis2.xml");&lt;br /&gt;            //create the stub&lt;br /&gt;            stub = new MyRampartServiceStub(configContext,"http://localhost:8080/axis2/services/MyRampartService");&lt;br /&gt;            if(useRampartThroughCode){&lt;br /&gt;            //set the outflow security through code&lt;br /&gt;            stub._getServiceClient().getOptions().setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, getOutflowConfiguration());&lt;br /&gt;            //set the inflow security through code&lt;br /&gt;            stub._getServiceClient().getOptions().setProperty(WSSHandlerConstants.INFLOW_SECURITY, getInflowConfiguration());&lt;br /&gt;            }&lt;br /&gt;            // invoke the service&lt;br /&gt;            String returnText = getSecretTextFromRampartService(stub,"apache");&lt;br /&gt;            // print it out&lt;br /&gt;            System.out.println("Return Text: " + returnText);&lt;br /&gt;        } catch (AxisFault e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (RemoteException re){&lt;br /&gt;            re.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;       &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private static String getSecretTextFromRampartService(MyRampartServiceStub stub, String string) throws RemoteException {&lt;br /&gt;    //create the request payload&lt;br /&gt;        GetSecretText req = new GetSecretText();&lt;br /&gt;    //set the parameter in the payload&lt;br /&gt;        req.setParam0(string);&lt;br /&gt;    //invoke service and get response&lt;br /&gt;        GetSecretTextResponse res = stub.getSecretText(req);&lt;br /&gt;    //return the response string.&lt;br /&gt;        return res.get_return();&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    private static Parameter getOutflowConfiguration() {&lt;br /&gt;&lt;br /&gt;        OutflowConfiguration ofc = new OutflowConfiguration();&lt;br /&gt;    //set the action item&lt;br /&gt;        ofc.setActionItems("Encrypt");&lt;br /&gt;    //set the encryption user&lt;br /&gt;        ofc.setEncryptionUser("service");&lt;br /&gt;    //set the property file; remember if the properties is not in classpath then it will not find this.&lt;br /&gt;        ofc.setEncryptionPropFile("client.properties");&lt;br /&gt;        // return the Parameter&lt;br /&gt;        return ofc.getProperty();&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;    private static Parameter getInflowConfiguration() {&lt;br /&gt;        InflowConfiguration ifc = new InflowConfiguration();&lt;br /&gt;    //set the action item&lt;br /&gt;        ifc.setActionItems("Encrypt");&lt;br /&gt;    //set the password callback class&lt;br /&gt;        ifc.setPasswordCallbackClass("axis2.adb.sync.rampart.callbackhandler.PWCBHandler");&lt;br /&gt;    //set the property file; remember if the properties is not in classpath then it will not find this.&lt;br /&gt;        ifc.setDecryptionPropFile("client.properties");&lt;br /&gt;        //return the parameter&lt;br /&gt;        return ifc.getProperty();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 8: The output.&lt;/span&gt;&lt;br /&gt;You will see the output:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Return Text: You have done a good choice to build an application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can use the tcpmon tool to capture the XML exchanges. Then, you can observe the encrypted contents of the request and response messages.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NOTE: I am using the keystore's and the password callback handlers provided with rampart distribution for explaining this tutorial.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-117506494939722978?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/117506494939722978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-tutorial-to-use-rampart.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117506494939722978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117506494939722978'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-tutorial-to-use-rampart.html' title='Step by step tutorial to use Rampart with axis2 web service for implementing security.'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-117491974155108020</id><published>2007-03-26T08:30:00.000-07:00</published><updated>2007-03-27T12:03:05.186-07:00</updated><title type='text'>Step by step tutorial of web service with axis2 and tomcat in java - part2</title><content type='html'>Given below is a tutorial to use axis2 in implementing web services(This shows Async/Non-Blocking call client). This tutorial extends the previous tutorial of blocking client call of web service. For more details regarding any aspect of the tutorial, the axis2 documents will assist you.&lt;br /&gt;(Just for Information: The web service gives the Lucky number of a person based on date of birth, and lucky color based on lucky number of user.)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;My Configuration:(same as previous)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;a) AXIS2 1.1.1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;b) JDK 1.5&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;c) ANT 1.7.0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;d) TOMCAT 5.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Before proceeding, please read the installation doc of axis2 to do a proper installation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 0: Set the following paths in your system.(This step is very important)&lt;/span&gt;&lt;br /&gt;a) AXIS2_HOME = "your axis2 installation(unzipped) directory"&lt;br /&gt;b) JAVA_HOME = "your jdk installation path"&lt;br /&gt;c) PATH = "add ant, axis2/bin to this"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1: Create your service interface and class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In my case:&lt;br /&gt;--------------Interface-------------------&lt;br /&gt;package axis2.adb.async;&lt;br /&gt;import java.util.Date;&lt;br /&gt;public interface MyNewService {&lt;br /&gt;public String getLuckyColor(int luckNumber);&lt;br /&gt;public int getLuckyNumber(Date birthDate);&lt;br /&gt;}&lt;br /&gt;--------------Implementation--------------&lt;br /&gt;package axis2.adb.async;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.HashMap;&lt;br /&gt;import java.util.Map;&lt;br /&gt;public class MyNewServiceImpl implements MyNewService {&lt;br /&gt;static Map luckyColor = null;&lt;br /&gt;static{&lt;br /&gt;   luckyColor =  new HashMap();&lt;br /&gt;   luckyColor.put(new Integer(0), "Red");&lt;br /&gt;   luckyColor.put(new Integer(1), "Blue");&lt;br /&gt;   luckyColor.put(new Integer(2), "Yellow");&lt;br /&gt;   luckyColor.put(new Integer(3), "Pink");&lt;br /&gt;   luckyColor.put(new Integer(4), "Orange");&lt;br /&gt;   luckyColor.put(new Integer(5), "Black");&lt;br /&gt;   luckyColor.put(new Integer(6), "Green");&lt;br /&gt;   luckyColor.put(new Integer(7), "Brown");&lt;br /&gt;   luckyColor.put(new Integer(8), "White");&lt;br /&gt;   luckyColor.put(new Integer(9), "Grey");&lt;br /&gt;}&lt;br /&gt;   public String getLuckyColor(int luckNumber) {&lt;br /&gt;       if(luckNumber &lt; number =" birthDate.getDate()" lucknumber =" 0;"&gt; 0){&lt;br /&gt;           luckNumber += number % 10;&lt;br /&gt;           number /= 10;&lt;br /&gt;           if(number == 0)&lt;br /&gt;               if(luckNumber &gt; 9){&lt;br /&gt;                   number = luckNumber;&lt;br /&gt;                   luckNumber = 0;&lt;br /&gt;               }&lt;br /&gt;                 &lt;br /&gt;       }&lt;br /&gt;       return luckNumber;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2: Generate the WSDL file using the command:&lt;/span&gt;&lt;br /&gt;java2wsdl -cp ./bin -cn axis2.adb.async.MyNewService -of ./resource/MyNewService.wsdl&lt;br /&gt;See the previous tutorial for more explanation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3: Generate the Skeleton and stub using the below command. I will be using the ADB(Axis data binding). &lt;/span&gt;You can use XMLBean or JiBx or AXIOM also.&lt;br /&gt;&lt;br /&gt;wsdl2java -uri ./resource/MyNewService.wsdl -p axis2.adb.async -d adb -a -ss -sd -ssi -g -o . -S axis2ADBAsync&lt;br /&gt;Here, the changes from the previous tutorial include:&lt;br /&gt;   a)-a switch instead of -s. -a is used for Async web Service.&lt;br /&gt;   b)-g switch generates the Client side stub along with the Skeleton.&lt;br /&gt;   c)-S switch allows you to provide the output folder&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 4: Put the business logic inside the skeleton.&lt;/span&gt; The code is explained with appropriate comments.&lt;br /&gt;&lt;br /&gt;package axis2.adb.async;&lt;br /&gt;import java.util.Calendar;&lt;br /&gt;import axis2.adb.async.MyNewService;&lt;br /&gt;import axis2.adb.async.MyNewServiceImpl;&lt;br /&gt;import axis2.adb.async.xsd.GetLuckyColorResponse;&lt;br /&gt;import axis2.adb.async.xsd.GetLuckyNumberResponse;&lt;br /&gt;/**&lt;br /&gt;* MyNewServiceSkeleton java skeleton for the axisService&lt;br /&gt;*/&lt;br /&gt;public class MyNewServiceSkeleton implements MyNewServiceSkeletonInterface {&lt;br /&gt;   MyNewService myService = new MyNewServiceImpl();&lt;br /&gt;   /**&lt;br /&gt;    * Auto generated method signature&lt;br /&gt;    *&lt;br /&gt;    * @param param4&lt;br /&gt;    *&lt;br /&gt;    */&lt;br /&gt;   public axis2.adb.async.xsd.GetLuckyColorResponse getLuckyColor(&lt;br /&gt;           axis2.adb.async.xsd.GetLuckyColor param4)&lt;br /&gt;   {&lt;br /&gt;       //create the response payload&lt;br /&gt;       GetLuckyColorResponse res = new GetLuckyColorResponse();&lt;br /&gt;       //get the parameter&lt;br /&gt;       int luckyNumber = param4.getParam0();&lt;br /&gt;       //businesslogic&lt;br /&gt;       String luckyColor = myService.getLuckyColor(luckyNumber);&lt;br /&gt;       //put result in payload&lt;br /&gt;       res.set_return(luckyColor);&lt;br /&gt;       //return payload&lt;br /&gt;       return res;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   /**&lt;br /&gt;    * Auto generated method signature&lt;br /&gt;    *&lt;br /&gt;    * @param param6&lt;br /&gt;    *&lt;br /&gt;    */&lt;br /&gt;   public axis2.adb.async.xsd.GetLuckyNumberResponse getLuckyNumber(&lt;br /&gt;           axis2.adb.async.xsd.GetLuckyNumber param6)&lt;br /&gt;&lt;br /&gt;   {&lt;br /&gt;       //create the response payload&lt;br /&gt;       GetLuckyNumberResponse res = new GetLuckyNumberResponse();&lt;br /&gt;       //get parameter&lt;br /&gt;       Calendar dOfB = param6.getParam0();&lt;br /&gt;       //businesslogic&lt;br /&gt;       int luckyNumber = myService.getLuckyNumber(dOfB.getTime());&lt;br /&gt;       //put result in response payload&lt;br /&gt;       res.set_return(luckyNumber);&lt;br /&gt;       //return the payload&lt;br /&gt;       return res;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 5: Create ".aar" file which has to be deployed inside axis2 using the below command.&lt;/span&gt;&lt;br /&gt;The build.xml file is created in Step 3.&lt;br /&gt;&lt;br /&gt;ant build.xml&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 6: Deploy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A new folder build is created inside the current directory. The MyNewService.aar file is present in \build\lib. Upload this using the axis2 admin page. Refer previous tutorial for more details.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 7: Test the service.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;type http://localhost:8080/axis2/services/MyNewService?wsdl in address bar. you should get the WSDL file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 8: Code the Client using the generated Stub.&lt;/span&gt; The code is explained with appropriate comments.&lt;br /&gt;&lt;br /&gt;package axis2.adb.async.client;&lt;br /&gt;import java.rmi.RemoteException;&lt;br /&gt;import java.util.Calendar;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import javax.xml.namespace.QName;&lt;br /&gt;import org.apache.axis2.AxisFault;&lt;br /&gt;import org.apache.axis2.context.ConfigurationContext;&lt;br /&gt;import org.apache.axis2.context.ConfigurationContextFactory;&lt;br /&gt;import axis2.adb.async.MyNewServiceStub;&lt;br /&gt;import axis2.adb.async.MyNewServiceCallbackHandler;&lt;br /&gt;import axis2.adb.async.xsd.GetLuckyColor;&lt;br /&gt;import axis2.adb.async.xsd.GetLuckyNumber;&lt;br /&gt;&lt;br /&gt;public class MyNewServiceClient {&lt;br /&gt;   private static int luckyNumber = 100; //assume some large number&lt;br /&gt;   private static String luckyColor = null;&lt;br /&gt;   private static boolean twoWayListnerEnabled = false; //When true a asynchronous dual channel non-blocking service will be used&lt;br /&gt;&lt;br /&gt;   public static void main(String[] args) {&lt;br /&gt;       MyNewServiceStub stub = null;&lt;br /&gt;       ConfigurationContext configContext = null;&lt;br /&gt;       try {&lt;br /&gt;           if(twoWayListnerEnabled){&lt;br /&gt;           //Since this is the client, addressing module has to be engaged. Copy the "repository" directory, present in %AXIS2_HOME%, to a convenient place and give its path as first argument to the below method. Copy the axis2.xml from %AXIS2_HOME%/conf into convenient location, and give its path as second argument. Edit the axis2.xml to change the port to say, 8082.&lt;br /&gt;               configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository", "repository/modules/axis2.xml");&lt;br /&gt;               stub = new MyNewServiceStub(configContext,"http://localhost:8080/axis2/services/MyNewService");&lt;br /&gt;           }else{&lt;br /&gt;               stub = new MyNewServiceStub(null,"http://localhost:8080/axis2/services/MyNewService");&lt;br /&gt;           }&lt;br /&gt;           // set the call back handler. Note that call back methods given override the ones in CallBackhandler abstract class.          &lt;br /&gt;           MyNewServiceCallbackHandler myNewServiceCallBackHandle = new MyNewServiceCallbackHandler(){&lt;br /&gt;                   public void receiveResultgetLuckyNumber(&lt;br /&gt;                           axis2.adb.async.xsd.GetLuckyNumberResponse param43) {&lt;br /&gt;                       luckyNumber = param43.get_return();&lt;br /&gt;                  }&lt;br /&gt;                   public void receiveResultgetLuckyColor(&lt;br /&gt;                           axis2.adb.async.xsd.GetLuckyColorResponse param41) {&lt;br /&gt;                       luckyColor = param41.get_return();&lt;br /&gt;                  }&lt;br /&gt;       };&lt;br /&gt;       if(twoWayListnerEnabled){&lt;br /&gt;       //engage the module, and setUseSeparateListner to true.&lt;br /&gt;           stub._getServiceClient().engageModule(new QName("addressing"));&lt;br /&gt;           stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(1000);&lt;br /&gt;           stub._getServiceClient().getOptions().setUseSeparateListener(true);&lt;br /&gt;       }&lt;br /&gt;       //call the service&lt;br /&gt;           getLuckyNumberFromService(stub,myNewServiceCallBackHandle,new Date(1987,12,21));&lt;br /&gt;       // Since async call, poll the luckyNumber to see if a value is populated. This is just an example,  in practice, should not poll this way. Here it is required cas' the number is an input to the next service all.&lt;br /&gt;           do{&lt;br /&gt;               try {&lt;br /&gt;                   Thread.sleep(1000);&lt;br /&gt;               } catch (InterruptedException e) {&lt;br /&gt;                   if(luckyNumber != 100){&lt;br /&gt;                       break;&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;           }while(luckyNumber == 100);&lt;br /&gt;       //call the next service&lt;br /&gt;           getLuckyColorFromService(stub,myNewServiceCallBackHandle,luckyNumber);&lt;br /&gt;       // again poll to see if lucky color has been populated.&lt;br /&gt;           do{&lt;br /&gt;               try {&lt;br /&gt;                   Thread.sleep(1000);&lt;br /&gt;               } catch (InterruptedException e) {&lt;br /&gt;                   if(luckyColor != null){&lt;br /&gt;                       break;&lt;br /&gt;                   }&lt;br /&gt;               }&lt;br /&gt;           }while(luckyColor == null);&lt;br /&gt;       //print them&lt;br /&gt;           System.out.println("Lucky Number: "  + luckyNumber);&lt;br /&gt;           System.out.println("Lucky Color: "  + luckyColor);&lt;br /&gt;         &lt;br /&gt;       } catch (AxisFault e) {&lt;br /&gt;           e.printStackTrace();&lt;br /&gt;       } catch (RemoteException re){&lt;br /&gt;           re.printStackTrace();&lt;br /&gt;       }finally{&lt;br /&gt;       //do the clean up.&lt;br /&gt;           try {&lt;br /&gt;               if(twoWayListnerEnabled){&lt;br /&gt;                   stub._getServiceClient().disengageModule(new QName("addressing"));&lt;br /&gt;                   stub._getServiceClient().cleanup();&lt;br /&gt;               }&lt;br /&gt;               stub.cleanup();&lt;br /&gt;               if(twoWayListnerEnabled){&lt;br /&gt;                   System.exit(0);&lt;br /&gt;               }&lt;br /&gt;           } catch (AxisFault e) {&lt;br /&gt;           //ignore this&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;   private static void getLuckyColorFromService(MyNewServiceStub stub, MyNewServiceCallbackHandler myNewServiceCallBackHandle, int luckyNumber) throws RemoteException {&lt;br /&gt;   //create request payload&lt;br /&gt;       GetLuckyColor req = new GetLuckyColor();&lt;br /&gt;   //set the parameter&lt;br /&gt;       req.setParam0(luckyNumber);&lt;br /&gt;   // do an async call&lt;br /&gt;       stub.startgetLuckyColor(req, myNewServiceCallBackHandle);&lt;br /&gt;   }&lt;br /&gt;   private static void getLuckyNumberFromService(MyNewServiceStub stub, MyNewServiceCallbackHandler callBackForGetLuckyNumber, Date date) throws RemoteException {&lt;br /&gt;   //create request payload&lt;br /&gt;       GetLuckyNumber req = new GetLuckyNumber();&lt;br /&gt;&lt;br /&gt;       Calendar dOb = Calendar.getInstance();&lt;br /&gt;       dOb.setTime(date);&lt;br /&gt;   //set the parameter&lt;br /&gt;       req.setParam0(dOb);&lt;br /&gt;   //do an async call&lt;br /&gt;       stub.startgetLuckyNumber(req, callBackForGetLuckyNumber);&lt;br /&gt;     &lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 9: Execute the client.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;java MyNewServiceClient&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;output :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Lucky Number: 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Lucky Color: Yellow&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hope, this tutorial was use full enough. Here, ADB databinding was used and no security implemented. Next will try to get an Webservice up with security implementation.&lt;br /&gt;Adios!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-117491974155108020?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/117491974155108020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-tutorial-of-web-service.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117491974155108020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117491974155108020'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-tutorial-of-web-service.html' title='Step by step tutorial of web service with axis2 and tomcat in java - part2'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-117491943383933990</id><published>2007-03-26T08:28:00.000-07:00</published><updated>2007-03-26T08:30:33.846-07:00</updated><title type='text'>using tcpmon with axis2 webservices and tomcat</title><content type='html'>Using tcpMon utility with web services is very easy. Download the jar file from h**p://ws.apache.org/commons/tcpmon/download.cgi. Extract it. Run the tcpmon.bat. This will launch the tcpmon UI. Give the host name (localhost) and the target port# (8080). Give the listener port# to 8081 and say add. This will create a new tab. On this tab, there are two text frames. The top one shows the request, and the bottom one shows the response.&lt;br /&gt;In the client, use the target end point uri with port 8081 instead of 8080(my tomcat server listens to this). This will allow you to see the request and response messages in this small and powerful utility. There is more to this tool, which you can read from the user guide.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-117491943383933990?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/117491943383933990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/using-tcpmon-with-axis2-webservices.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117491943383933990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117491943383933990'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/using-tcpmon-with-axis2-webservices.html' title='using tcpmon with axis2 webservices and tomcat'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-117485161743087923</id><published>2007-03-25T13:25:00.000-07:00</published><updated>2007-03-25T12:54:58.170-07:00</updated><title type='text'>Step by step Web Services with Axis2 Tutorial in Java</title><content type='html'>It was very hard for me to get a good tutorial on developing web services with axis2 on the internet. After some effort I was able to deploy a axis2 web service. I hope this tutorial below will help you for bringing up the web service using axis2 a lot easier.(This shows sync/blocking call client).&lt;br /&gt;The tutorial shows how to get your web service up as quickly as possible, with out giving intrinsic details. For more details regarding any aspect of the tutorial, the axis2 documents will assist you.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;My Configuration:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;a) AXIS2 1.1.1&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;b) JDK 1.5&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;c) ANT 1.7.0&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;d) TOMCAT 5.5&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Before proceeding, please read the installation doc of axis2 so that it will work with tomcat with no problems. The below steps &lt;span style="font-style: italic;"&gt;assumes &lt;/span&gt;that the axis2 is configured with tomcat and is running in the tomcat container.  You can test the same by visiting &lt;span style="font-style: italic;"&gt;http://localhost:8080/axis2/&lt;/span&gt; url, and then clicking on the validate link.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 0: Set the following paths in your system.(This step is very important)&lt;/span&gt;&lt;br /&gt;a) AXIS2_HOME = "your axis2 installation(unzipped) directory"&lt;br /&gt;b) JAVA_HOME = "your jdk installation path"&lt;br /&gt;c) PATH = "add ant, axis2/bin to this"&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1: Create your service class.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In my case:&lt;br /&gt;&lt;br /&gt;package axis2.adb;&lt;br /&gt;public class MyService {&lt;br /&gt;public String sayWelcomeToAxis2(String userName){&lt;br /&gt;    return "Hi " + userName + "\nWelcome to the world of Axis2";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;You can actually use an interface to define the service contracts, which your service will implement. But, as i said, the goal is to set the webservice up as fast and in as simple way as possible.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2: Generate the WSDL file using the command:&lt;/span&gt;&lt;br /&gt;java2wsdl -cp ./bin -cn axis2.adb.MyService -of ./META-INF/MyService.wsdl&lt;br /&gt;&lt;br /&gt;here -cp gives the classpath, in my case the class files are present in 'bin' folder. -cn is the class name with package and -of is the output file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3: Generate the Skeleton using the below command. I will be using the ADB(Axis data binding). You can use XMLBean or JiBx or AXIOM also.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;wsdl2java -uri ./META-INF/MyService.wsdl -p axis2.adb -d adb -s -ss -sd -ssi -o .&lt;br /&gt;&lt;br /&gt;here uri provides you with the WSDL file path, -p specifies the package, -d gives the data binding(ADB in my case), -s sync call, -ss creates the server side code (skeleton and related files), -sd creates a service descriptor (services.xml file), -ssi switch creates an interface for the service skeleton.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 4: Put the business logic inside the skeleton.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;package axis2.adb;&lt;br /&gt;import axis2.adb.MyService;&lt;br /&gt;import axis2.xsd.SayWelcomeToAxis2Response;&lt;br /&gt;/**&lt;br /&gt; * MyServiceSkeleton java skeleton for the axisService&lt;br /&gt; */&lt;br /&gt;public class MyServiceSkeleton implements MyServiceSkeletonInterface {&lt;br /&gt;    MyService myService = new MyService();&lt;br /&gt;    /**&lt;br /&gt;     * Auto generated method signature&lt;br /&gt;     *&lt;br /&gt;     * @param param2&lt;br /&gt;     *&lt;br /&gt;     */&lt;br /&gt;    public axis2.xsd.SayWelcomeToAxis2Response sayWelcomeToAxis2(&lt;br /&gt;            axis2.xsd.SayWelcomeToAxis2 param2)&lt;br /&gt;    {&lt;br /&gt;        //create the response obj&lt;br /&gt;        SayWelcomeToAxis2Response res = new SayWelcomeToAxis2Response();&lt;br /&gt;        //set the response payload&lt;br /&gt;        res.set_return(myService.sayWelcomeToAxis2(param2.getUserName()));&lt;br /&gt;        // return the response&lt;br /&gt;        return res;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 5: Create the Client Stub using the command below.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;wsdl2java -uri ./resources/MyService.wsdl -p axis2.adb.client -d adb -s -o .&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 6: Code the Client using the generated Stub.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;package axis2.adb.client;&lt;br /&gt;import java.rmi.RemoteException;&lt;br /&gt;import org.apache.axis2.AxisFault;&lt;br /&gt;public class MyServiceClient {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;    try {&lt;br /&gt;    //create the stub&lt;br /&gt;        MyServiceStub stub = new MyServiceStub("http://localhost:8080/axis2/services/MyService");&lt;br /&gt;    // webservice call happens inside this method&lt;br /&gt;        sayWelcome(stub);&lt;br /&gt;    } catch (AxisFault e) {&lt;br /&gt;        e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;    }&lt;br /&gt;    private static void sayWelcome(MyServiceStub stub) {&lt;br /&gt;    //create the request payload&lt;br /&gt;    MyServiceStub.SayWelcomeToAxis2 req = new MyServiceStub.SayWelcomeToAxis2();  &lt;br /&gt;    //set the parameter&lt;br /&gt;    req.setUserName("SacroSanctBlood");&lt;br /&gt;    MyServiceStub.SayWelcomeToAxis2Response res = null;&lt;br /&gt;    try {&lt;br /&gt;    //get the response(This example shows a blocking call)&lt;br /&gt;        res = stub.sayWelcomeToAxis2(req);&lt;br /&gt;    //show the output&lt;br /&gt;        System.out.println(res.get_return());&lt;br /&gt;    } catch (RemoteException e) {&lt;br /&gt;        e.printStackTrace();&lt;br /&gt;    }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 7: Create ".aar" file which has to be deployed inside axis2 using the below command.&lt;/span&gt;&lt;br /&gt;The build.xml file is created in Step 3.&lt;br /&gt;&lt;br /&gt;ant build.xml&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 8: Deploy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A new folder build is created inside the current directory. The MyService.aar file is present in \build\lib. Upload this using the axis2 admin page.&lt;br /&gt;Type, http://localhost:8080/axis2/. Click on Administration. Login using the username/password, by default it is admin/axis2. (present in %AXIS2_HOME%/conf/axis2.xml) Use the Upload Service tool present in the left side of page. Upload the MyService.aar.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 9: Test the service.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;type http://localhost:8080/axis2/services/MyService?wsdl in addressbarr. you should get the WSDL file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 10: Execute the client.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;java MyServiceClient&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;output :&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;Hi SacroSanctBlood&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;Welcome to the world of Axis2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Hope, this tutorial was use full enough.&lt;br /&gt;Next time, will try to put up the async/non-blocking version of the web service.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-117485161743087923?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/117485161743087923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-web-services-with-axis2.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117485161743087923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/117485161743087923'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/03/step-by-step-web-services-with-axis2.html' title='Step by step Web Services with Axis2 Tutorial in Java'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116791603022335012</id><published>2007-01-04T04:48:00.000-08:00</published><updated>2007-01-04T05:31:49.896-08:00</updated><title type='text'>Java : Sorting the table rows on a particular column</title><content type='html'>&lt;span style="font-style: italic;"&gt;Assumption:&lt;/span&gt;&lt;br /&gt;    1. A table with a already sorted order is getting displayed on the screen.&lt;br /&gt;    2. you know the ID of each of the  in the table.&lt;br /&gt;    3. The each row of the table is an object in an array.&lt;br /&gt;&lt;br /&gt;I am not writing the code as such, but just presenting the idea of sorting the table based on the column header clicked. One way is using common controls, which i rather not use. I am trying to present the most simplest idea of sorting.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Firstly&lt;/span&gt;, write the scriplets in which we write a comparator for each column we want to sort and sort the collection using the same.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Next &lt;/span&gt;write the javascript function for each of the sorting required which sets the corresponding  to the value required from the sorted collection.&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Lastly&lt;/span&gt;, call the function on click event of the column header.&lt;br /&gt;&lt;br /&gt;I briefly write code snippets to make the idea more clear.&lt;br /&gt;&lt;br /&gt;[%//scriplets&lt;br /&gt;ExampleForm exampleForm = (ExampleForm)request.getAttribute("exampleForm");&lt;br /&gt;List rowObjects = exampleForm.getRowObjects();&lt;br /&gt;&lt;br /&gt;Collection.sort(rowObjects, new Comparator(){&lt;br /&gt;                       public int compare(Object a, Object b) {&lt;br /&gt;                           RealObject objectOne = (RealObject)a;&lt;br /&gt;                           RealObject objectTwo = (RealObject)b;&lt;br /&gt;&lt;br /&gt;                           [On Condiditions] return 1 or -1 or 0&lt;br /&gt;&lt;br /&gt;                       }&lt;br /&gt;                       });&lt;br /&gt;%]&lt;br /&gt;&lt;br /&gt;function sortTypeOne(){//javascript&lt;br /&gt;document.getElementById('td00') = [%= rowObjects.get(0).getRowData() %]&lt;br /&gt;document.getElementById('td10') = [%= rowObjects.get(1).getRowData() %]&lt;br /&gt;   .&lt;br /&gt;   .&lt;br /&gt;  [continue from here as many td's you want; You can also use struts to iterate over the collection here and setting the corresponding  to the value required. The data inside the getElementById() can also be filled when you iterate using struts.{logic:iterate tag}]&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[%// scriplets&lt;br /&gt;Collection.sort(rowObjects, new Comparator(){&lt;br /&gt;                       public int compare(Object a, Object b) {&lt;br /&gt;                           RealObject objectOne = (NewRealObject)a;&lt;br /&gt;                           RealObject objectTwo = (NewRealObject)b;&lt;br /&gt;&lt;br /&gt;                           [On New Condiditions] return 1 or -1 or 0&lt;br /&gt;&lt;br /&gt;                       }&lt;br /&gt;                       });&lt;br /&gt;&lt;br /&gt;%]&lt;br /&gt;&lt;br /&gt;function sortTypeTwo(){//javascript&lt;br /&gt;document.getElementById('td00') = [%= rowObjects.get(0).getRowData() %]&lt;br /&gt;document.getElementById('td01') = [%= rowObjects.get(1).getRowData() %]&lt;br /&gt;   .&lt;br /&gt;   .&lt;br /&gt;  [continue from here as many td's you want; You can also use struts to iterate over the collection here and setting the corresponding  to the value required. The data inside the getElementById() can also be filled when you iterate using struts.{logic:iterate tag}]&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Table structure approximately is shown below.&lt;br /&gt;&lt;br /&gt;[table]&lt;br /&gt;   [tr]&lt;br /&gt;       [th onclick="sortTypeOne()"/]&lt;br /&gt;       [th onclick="sortTypeTwo()"/]&lt;br /&gt;       .&lt;br /&gt;       .&lt;br /&gt;       .&lt;br /&gt;   [/tr]&lt;br /&gt;   [tr]&lt;br /&gt;       [td id='td00'/]&lt;br /&gt;       [td id='td01'/]&lt;br /&gt;       .&lt;br /&gt;       .&lt;br /&gt;       .&lt;br /&gt;   [/tr]&lt;br /&gt;[/table]&lt;br /&gt;&lt;br /&gt;replace '[' or ']' respectively with '&lt;' or '&gt;'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-116791603022335012?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/116791603022335012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/01/java-sorting-table-rows-on-particular.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116791603022335012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116791603022335012'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2007/01/java-sorting-table-rows-on-particular.html' title='Java : Sorting the table rows on a particular column'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116598860682691834</id><published>2006-12-12T21:34:00.000-08:00</published><updated>2006-12-12T21:43:26.833-08:00</updated><title type='text'>Comparing two column's Data in Excel and coloring the Cells that differ</title><content type='html'>The following code below compares adjacent cells in 2 column's (D and E) and colors only those cells in column E that have a different data than column D :&lt;br /&gt;&lt;hr /&gt;Sub validateFields()&lt;br /&gt;    Dim dColumn As Variant&lt;br /&gt;    Dim eColumn As Variant&lt;br /&gt;       &lt;br /&gt;    Set dColumn = Range("D:D")&lt;br /&gt;    Set eColumn = Range("E:E")&lt;br /&gt;   &lt;br /&gt;    Dim cellIndex As Integer&lt;br /&gt;    cellIndex = 2&lt;br /&gt;   &lt;br /&gt;     Do While dColumn.Cells(cellIndex).Value &lt;&gt; ""&lt;br /&gt;        If dColumn.Cells(cellIndex) &lt;&gt; eColumn.Cells(cellIndex) Then&lt;br /&gt;            With eColumn.Cells(cellIndex).Interior&lt;br /&gt;                    .ColorIndex = 36&lt;br /&gt;                    .Pattern = xlSolid&lt;br /&gt;            End With&lt;br /&gt;        Else&lt;br /&gt;            With eColumn.Cells(cellIndex).Interior&lt;br /&gt;                    .ColorIndex = 0&lt;br /&gt;                    .Pattern = xlSolid&lt;br /&gt;            End With&lt;br /&gt;        End If&lt;br /&gt;      cellIndex = cellIndex + 1&lt;br /&gt;     Loop&lt;br /&gt;   &lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Private Sub Worksheet_Activate()&lt;br /&gt;    Call validateFields&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;This assumes that the first column has the header, so, ignores it.&lt;br /&gt;(cellIndex = 2 initialization)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-116598860682691834?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/116598860682691834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/12/comparing-two-columns-data-in-excel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116598860682691834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116598860682691834'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/12/comparing-two-columns-data-in-excel.html' title='Comparing two column&apos;s Data in Excel and coloring the Cells that differ'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116471037552989564</id><published>2006-11-28T02:34:00.000-08:00</published><updated>2006-11-28T02:39:35.536-08:00</updated><title type='text'>View thumbnails on Windows!!</title><content type='html'>If due to some reason if the thumbnails  can not be viewed on your system, which happens mainly because of installing a new application on Windows 2000, say, then you can use the below registry fix. Just copy paste it on to a new notepad, save it as .reg and then just double click on it to apply.&lt;br /&gt;&lt;hr size="3"&gt;&lt;br /&gt;&lt;br /&gt;REGEDIT4&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.gif]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.gif\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.gif\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpg]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpg\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpg\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.art]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.art\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.art\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.bmp]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.bmp\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.bmp\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.dib]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.dib\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.dib\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpe]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpe\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpe\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpeg]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpeg\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.jpeg\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.png]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.png\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.png\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tif]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tif\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tif\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tiff]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tiff\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.tiff\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.wmf]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.wmf\ShellEx]&lt;br /&gt;&lt;br /&gt;[HKEY_CLASSES_ROOT\.wmf\ShellEx\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}]&lt;br /&gt;@="{7376D660-C583-11d0-A3A5-00C04FD706EC}"&lt;br /&gt;&lt;br /&gt;&lt;hr size="3"&gt; Just refresh for the changes to apply!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-116471037552989564?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/116471037552989564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/view-thumbnails-on-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116471037552989564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116471037552989564'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/view-thumbnails-on-windows.html' title='View thumbnails on Windows!!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116377770351846070</id><published>2006-11-17T07:31:00.000-08:00</published><updated>2006-11-17T07:35:03.526-08:00</updated><title type='text'>Converting Float to Double in a not so common way!!!!</title><content type='html'>I was working on a project and i had this strange but common problem. I was getting a value from an external system which was a primitive float. But, in our system it was all double. I had to convert the float to double without losing any precision. I tried to cast it directly into double but it didn't work. As, say, for example, if i was trying to convert 39.355F to double, then it turned out to be 39.35497... It always used to change the precision and in my case i didn't want it to change due to some processing i would be doing on it later. You could say i could have just rounded it off, but, in my case it wouldn't work. So, here i found a nice cute way to convert float to double as it is with out change in even a single digit also. It may seem it is not needed but believe me some times this all you can do. At least, this is what i could figure out when deadline was on my head.&lt;br /&gt;&lt;hr /&gt;&lt;br /&gt;public static double floatToDouble (float converThisNumberToFloat) {&lt;br /&gt;&lt;br /&gt; String floatNumberInString = String.valueOf(converThisNumberToFloat);&lt;br /&gt; double floatNumberInDouble = Double.parseDouble(floatNumberInString);&lt;br /&gt;     return floatNumberInDouble;&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;hr /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-116377770351846070?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/116377770351846070/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/converting-float-to-double-in-not-so.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116377770351846070'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116377770351846070'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/converting-float-to-double-in-not-so.html' title='Converting Float to Double in a not so common way!!!!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116367938979747633</id><published>2006-11-16T04:06:00.000-08:00</published><updated>2006-11-16T04:16:29.806-08:00</updated><title type='text'>Some usefull registry tweaks for developer!</title><content type='html'>&lt;span style="font-weight: bold;"&gt;To get command prompt on the right click:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Open regedit.exe from Run menu&lt;br /&gt;&lt;br /&gt;2. Navigate to&lt;br /&gt;&lt;br /&gt;HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell&lt;br /&gt;&lt;br /&gt;and create a key called "Command Prompt".&lt;br /&gt;&lt;br /&gt;3. Set the default string to "Command Prompt" or simply "CMD", since this text will come when you right click on a &lt;span style="font-weight: bold;"&gt;FOLDER.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;4. Create a new key within the newly created command prompt named "command," and set the default string to&lt;br /&gt;&lt;br /&gt;cmd.exe /k pushd %L&lt;br /&gt;&lt;br /&gt;5. Refresh By pressing F5.&lt;br /&gt;&lt;br /&gt;PS: This works on NT based System. Also, the right click should be on a &lt;span style="font-weight: bold;"&gt;FOLDER. &lt;/span&gt;If you open the folder and the click on the screen area, then it won't work.&lt;br /&gt;&lt;br /&gt;&lt;hr /&gt;&lt;hr /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;To Get Tabbed browsing in Command Prompt:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Open regedit.exe from Run menu&lt;br /&gt;&lt;br /&gt;2. Navigate to&lt;br /&gt;&lt;br /&gt;HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Command Processor&lt;br /&gt;&lt;br /&gt;3. Set PathCompletionChar = 0X9&lt;br /&gt;&lt;br /&gt;4. Set CompletionChar = 0X9&lt;br /&gt;&lt;br /&gt;PS: 0X9 is Hex digit 9.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/36956413-116367938979747633?l=sacrosanctblood.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sacrosanctblood.blogspot.com/feeds/116367938979747633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/some-usefull-registry-tweaks-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116367938979747633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/36956413/posts/default/116367938979747633'/><link rel='alternate' type='text/html' href='http://sacrosanctblood.blogspot.com/2006/11/some-usefull-registry-tweaks-for.html' title='Some usefull registry tweaks for developer!'/><author><name>SacrosanctBlood</name><uri>http://www.blogger.com/profile/01706617283053130814</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_UNFnHMPP82E/TOm9-vlf_SI/AAAAAAAAAao/lGJrwmMBTIY/S220/mine.PNG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-36956413.post-116315389479003097</id><published>2006-11-10T02:16:00.000-08:00</published><updated>2006-11-10T02:18:14.796-08:00</updated><title type='text'>Anonymity in Code too not allowed!</title><content type='html'>So, here i go into the java world. The only world which am into presently. You write code, tons of java code. There area few who would not like to give there source code to other. As, they feel that its there work, they have put lots of hour of effort into it, have optimized the code to the maximum extent possible and why should some other guy with very little effort get to know what they have done. So, if you think you can just provide the class file to them and not the source java file, again you are wrong. Reverse-engineering is present in this world, and this applies to java code too. You just have to input the class file to the tool and with in few seconds the whole source is at your disposal. I found 3 tools which did the same, two free and one paid.&lt;br /&gt;&lt;br /&gt;I will start from the least user friendly one.&lt;br /&gt;&lt;br /&gt;1. The javap tool that comes with the JDK itself. This is a command line tool. But, the decompiled code is not too easy to follow. I tried it with all the command line options present. I wouldn't suggest this tool unless you really want to know the whole inside of the code, i mean at the byte code level.&lt;br /&gt;&lt;br /&gt;2. The next tools is also a free tool, Cavaj. This is really cool, and much more easier to use than the ugly command line version of the javap. You just have to open the class file and the Cavaj does the rest.
