<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>spring-framework &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/spring-framework/</link>
	<description>Feed of posts on WordPress.com tagged "spring-framework"</description>
	<pubDate>Sun, 29 Nov 2009 16:07:41 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Spring bean circular dependency]]></title>
<link>http://pragmaticoder.wordpress.com/2009/11/28/spring-bean-circular-dependency/</link>
<pubDate>Sat, 28 Nov 2009 05:11:24 +0000</pubDate>
<dc:creator>huanchh</dc:creator>
<guid>http://pragmaticoder.wordpress.com/2009/11/28/spring-bean-circular-dependency/</guid>
<description><![CDATA[Ever needs to invoke some other business service method from another service bean, which in turns ca]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Ever needs to invoke some other business service method from another service bean, which in turns calls your method?</p>
<p>Configuring the services this way</p>
<pre class="brush: xml;">

&#60;bean class=&#34;ServiceA &#34;&#62;                                                                 

      &#60;property name=&#34;IserviceB&#34; ref=&#34;serviceB&#34; /&#62;

      ……

&#60;/bean&#62;

&#60;bean class=&#34;ServiceB&#34;&#62;                                                            

      &#60;property name=&#34;IServiceA&#34; ref=&#34;serviceA&#34; /&#62;

      ……

&#60;/bean&#62;
</pre>
<p>Will not work as the two beans try wait for other one to initialize.</p>
<p>Alternatively, implement the application context aware interface, which allows one bean to get access to the application context, as well as all the beans by its “id” attribute.</p>
<pre class="brush: xml;">public class ServiceA implements IServiceA, ApplicationContextAware{

   private ApplicationContext applicationContext;

   public void setApplicationContext(ApplicationContext applicationContext) {

            this.applicationContext = applicationContext;

  }

   public void fooBar()

   {

      IServiceB = (IServiceB)applicationContext.getBean(&#34;ServiceB&#34;);

   }

}
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SpringSource Tool Suite Installation &amp; Configuration]]></title>
<link>http://tecnoesis.wordpress.com/2009/11/26/springsource-tool-suite-installation-configuration/</link>
<pubDate>Wed, 25 Nov 2009 20:06:15 +0000</pubDate>
<dc:creator>Rajani Ramsagar</dc:creator>
<guid>http://tecnoesis.wordpress.com/2009/11/26/springsource-tool-suite-installation-configuration/</guid>
<description><![CDATA[  SpringSource Tool Suite(STS) Installation &amp; Configuration:   At the time of this post, the lat]]></description>
<content:encoded><![CDATA[  SpringSource Tool Suite(STS) Installation &amp; Configuration:   At the time of this post, the lat]]></content:encoded>
</item>
<item>
<title><![CDATA[SpringSource Tool Suite]]></title>
<link>http://tecnoesis.wordpress.com/2009/11/24/springsource-tool-suite-sts/</link>
<pubDate>Tue, 24 Nov 2009 08:57:24 +0000</pubDate>
<dc:creator>Rajani Ramsagar</dc:creator>
<guid>http://tecnoesis.wordpress.com/2009/11/24/springsource-tool-suite-sts/</guid>
<description><![CDATA[  What is SpringSource Tool Suite (STS)? SpringSource Tool Suite has been a much awaited release fro]]></description>
<content:encoded><![CDATA[  What is SpringSource Tool Suite (STS)? SpringSource Tool Suite has been a much awaited release fro]]></content:encoded>
</item>
<item>
<title><![CDATA[Things to know about Spring Download, Installation &amp; Configuration]]></title>
<link>http://tecnoesis.wordpress.com/2009/11/23/spring-download-installation-configuration/</link>
<pubDate>Mon, 23 Nov 2009 13:36:25 +0000</pubDate>
<dc:creator>Rajani Ramsagar</dc:creator>
<guid>http://tecnoesis.wordpress.com/2009/11/23/spring-download-installation-configuration/</guid>
<description><![CDATA[    Things to know about download/installation/configuration of Spring Framework:   The Spring Frame]]></description>
<content:encoded><![CDATA[    Things to know about download/installation/configuration of Spring Framework:   The Spring Frame]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Download &amp; Installation]]></title>
<link>http://tecnoesis.wordpress.com/2009/11/23/spring-download-installation/</link>
<pubDate>Mon, 23 Nov 2009 13:25:37 +0000</pubDate>
<dc:creator>Rajani Ramsagar</dc:creator>
<guid>http://tecnoesis.wordpress.com/2009/11/23/spring-download-installation/</guid>
<description><![CDATA[    Spring Framework Download &amp; Installation:    At the time of this post, the latest Spring Fra]]></description>
<content:encoded><![CDATA[    Spring Framework Download &amp; Installation:    At the time of this post, the latest Spring Fra]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Form to Raw HTML/DOM]]></title>
<link>http://jeungun.wordpress.com/2009/11/20/spring-form-to-raw-htmldom/</link>
<pubDate>Fri, 20 Nov 2009 18:23:22 +0000</pubDate>
<dc:creator>Jose  Asuncion</dc:creator>
<guid>http://jeungun.wordpress.com/2009/11/20/spring-form-to-raw-htmldom/</guid>
<description><![CDATA[(For Spring 2.5.6) Ever wondered how Spring Form tags look like after they are compiled? I think usi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>(For Spring 2.5.6)  </p>
<p>Ever wondered how Spring Form tags look like after they are compiled? I think using raw HTML/DOM with Spring MVC&#8217;s form controllers can be very useful. I personally like to use them to avoid using the onFormChange() function in the controller. For one this request is done server side and it feels unnatural to me. Although I have to admit that requesting a form change using Spring MVC almost feels like making an AJAX call (servlets are really that fast), the look and feel of the real thing is second to none. </p>
<p>So I thought, why not use raw html to bind input from form fields to a command class using  Spring controllers? You&#8217;d have to know the raw html equivalent of Spring forms first. So without any further ado: </p>
<pre class="brush: xml;">
&#60;form:form commandName=&#34;FootballTeam&#34; method=&#34;POST&#34;&#62;

&#60;/form:form&#62;

&#60;form id=&#34;FootballTeam&#34; action=&#34;/createNewTeam&#34; method=&#34;POST&#34;&#62; 

&#60;/form&#62;
</pre>
<p>/createNewTeam maps to the Spring Controller that handles the form.</p>
<pre class="brush: xml;">
&#60;form:input path=&#34;teamName&#34;/&#62;

&#60;input id=&#34;teamName&#34; name=&#34;teamName&#34; type=&#34;text&#34; value=&#34;&#34;/&#62;
</pre>
<p>Input type: text box</p>
<pre class="brush: xml;">

&#60;form:select path=&#34;league&#34;&#62;
		&#60;form:options items=&#34;${leagues}&#34;/&#62;&#60;br/&#62;
&#60;/form:select&#62;

&#60;select id=&#34;league&#34; name=&#34;league&#34;&#62;
     &#60;option value=&#34;Bundesliga&#34;&#62;Bundesliga&#60;/option&#62;
     &#60;option value=&#34;ZweiteLiga&#34;&#62;ZweiteLiga&#60;/option&#62;
     &#60;option value=&#34;OberLiga&#34;&#62;OberLiga&#60;/option&#62;
&#60;/select&#62; 
</pre>
<p>So I guess there&#8217;s no need to override the referenceData() method in the controller for a select option. </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Framework Introduction]]></title>
<link>http://tecnoesis.wordpress.com/2009/11/20/introduction-to-spring/</link>
<pubDate>Thu, 19 Nov 2009 19:21:03 +0000</pubDate>
<dc:creator>Rajani Ramsagar</dc:creator>
<guid>http://tecnoesis.wordpress.com/2009/11/20/introduction-to-spring/</guid>
<description><![CDATA[  Chapter 2: Introduction to Spring   Spring Framework: The Spring framework is a comprehensive laye]]></description>
<content:encoded><![CDATA[  Chapter 2: Introduction to Spring   Spring Framework: The Spring framework is a comprehensive laye]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring and Dwr Integration]]></title>
<link>http://mohisays.wordpress.com/2009/11/17/spring-and-dwr-integration/</link>
<pubDate>Tue, 17 Nov 2009 10:59:40 +0000</pubDate>
<dc:creator>Asif</dc:creator>
<guid>http://mohisays.wordpress.com/2009/11/17/spring-and-dwr-integration/</guid>
<description><![CDATA[Currently I am Working as a technical lead of a spring based project. And surprising this is the fir]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Currently I am Working as a technical lead of a spring based project. And surprising this is the first commercial spring based project for me. I had a very little idea on how to use Ajax/ DWR on Spring. So, I browse a lot on this topics and found some helpful sites related to this. But, no sites provide exact step to step procedure of doing this. So, I decided to write this blog.</p>
<p><strong>For whom this blog is:</strong></p>
<p>Those who have basic information on Spring Framework and DWR.</p>
<p>Direct Web Remoting ( DWR) is a Java Library that enables developer  to expose their Java Methods to JavaScript. Through this developer can call java methods from client side javascript code. It act as an alternative of Ajax for java programmer. You can get more on DWR here: <a href="http://directwebremoting.org/dwr/index.html">http://directwebremoting.org/dwr/index.html</a>.</p>
<p><strong><span style="text-decoration:underline;">Case:</span></strong></p>
<p>Here I am using DWR to display some values from database against a combo box values. For Example , there is a combo box giving a list of emploryees name from database. Whenever user select a value from the combo box, it will show the age and grade of the particular employee at two text boxes on same form. I will not show all the details of the code here.</p>
<p><strong><span style="text-decoration:underline;">Steps:</span></strong></p>
<p>To use DWR with Spring, you need to follow this three steps:</p>
<ol>
<li>Enable and configure DWR at your project.</li>
<li>Write your java code</li>
<li>Expose the Java Code for JavaScript</li>
<li>Call the JavaCode from JavaScript</li>
</ol>
<ol>
<li><strong><span style="text-decoration:underline;">Enable and configure DWR at your project:</span></strong></li>
</ol>
<p><strong><span style="text-decoration:underline;"> </span></strong></p>
<p>Configured your project for dwr support means adding the library files and configuring the beans through xml configuration.</p>
<p>download dwr library from <a href="http://directwebremoting.org/dwr/download.html">http://directwebremoting.org/dwr/download.html</a>.  Though beta version 3 is available you should download stable version 2.0.5. Add this library to you spring project.</p>
<p>To configure the dwr at you project you need to change the xml files as follows:</p>
<ul>
<li>Namespace: you need to enter following xml namespace      on beans tag of your <strong>application-context.xml</strong> files:</li>
</ul>
<p style="text-align:center;"><em>xmlns:dwr=<a href="http://www.directwebremoting.org/schema/spring-dwr">http://www.directwebremoting.org/schema/spring-dwr</a></em></p>
<p>Add the following two xml locations at xsi:schemaLocation attribute of beans tag:</p>
<p style="text-align:center;"><em>http://www.directwebremoting.org/schema/spring-dwr </em></p>
<p style="text-align:center;"><em>http://www.directwebremoting.org/schema/spring-wr-2.0.xsd</em></p>
<p>Typically your beans tag should like this:</p>
<p><em>&#60;beans xmlns=”http://www.springframework.org/schema/beans”</em></p>
<p><em>xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”</em></p>
<p><em>xmlns:p=”http://www.springframework.org/schema/p”</em></p>
<p><em>xmlns:aop=”http://www.springframework.org/schema/aop”</em></p>
<p><em><strong> xmlns:dwr=”http://www.directwebremoting.org/schema/spring-dwr”</strong></em></p>
<p><em>xmlns:tx=”http://www.springframework.org/schema/tx”</em></p>
<p><em>xsi:schemaLocation=”http://www.springframework.org/schema/beans<br />
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</em></p>
<p><em>http://www.springframework.org/schema/aop<br />
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd</em></p>
<p><em><strong> http://www.directwebremoting.org/schema/spring-dwr</strong></em></p>
<p><em><strong> http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd</strong></em></p>
<p><em>http://www.springframework.org/schema/tx<br />
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd”&#62;</em></p>
<ul>
<li>Now,  add this two tag’s at your      application-context.xml file:</li>
</ul>
<p><em>&#60;dwr:controller debug=&#8221;true&#8221; /&#62;</em></p>
<p><em>&#60;dwr:configuration&#62;&#60;/dwr:configuration&#62;</em></p>
<ul>
<li>Add      the following bean definitions to application-conext.xml file&#62;</li>
</ul>
<p><em>&#60;bean class=&#8221;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&#8221;&#62;</em></p>
<p><em>&#60;property&#62;</em></p>
<p><em>&#60;props&#62;</em></p>
<p><em>&#60;prop key=&#8221;/engine.js&#8221;&#62;dwrController&#60;/prop&#62;</em></p>
<p><em>&#60;prop key=&#8221;/util.js&#8221;&#62;dwrController&#60;/prop&#62;</em></p>
<p><em>&#60;prop key=&#8221;/interface/**&#8221;&#62;dwrController&#60;/prop&#62;</em></p>
<p><em>&#60;prop key=&#8221;/call/**&#8221;&#62;dwrController&#60;/prop&#62;</em></p>
<p><em>&#60;/props&#62;</em></p>
<p><em>&#60;/property&#62;</em></p>
<p><em>&#60;/bean&#62;</em></p>
<p>This will enable you map the different files while calling from client side. You will use this files later on.</p>
<ul>
<li>Add a      dwr mapping on your <strong>web.xml</strong> files like this:</li>
</ul>
<p><em>&#60;servlet-name&#62;dwr&#60;/servlet-name&#62;</em></p>
<p><em>&#60;servlet-class&#62;org.directwebremoting.spring.DwrSpringServlet&#60;/servlet-class&#62;</em></p>
<p><em>&#60;init-param&#62;</em></p>
<p><em>&#60;param-name&#62;debug&#60;/param-name&#62;</em></p>
<p><em>&#60;param-value&#62;true&#60;/param-value&#62;</em></p>
<p><em>&#60;/init-param&#62;</em></p>
<p><em>&#60;/servlet&#62;</em></p>
<p><em>&#60;servlet-mapping&#62;</em></p>
<p><em>&#60;servlet-name&#62;dwr&#60;/servlet-name&#62;</em></p>
<p><em>&#60;url-pattern&#62;/dwr/*&#60;/url-pattern&#62;</em></p>
<p><em>&#60;/servlet-mapping&#62;</em></p>
<p>Now, you are ready to add your dwr code. Test if the configuration file browsing to following address:</p>
<p><a href="http://localhost:8080/mydwr/dwr">http://localhost:8080/mydwr/dwr</a></p>
<p>this will show  the following message:</p>
<h2>No Classes known to DWR:</h2>
<p><strong><span style="text-decoration:underline;">2. Write      Your Java Code:</span></strong></p>
<p>Create a folder called dwr on source package. Add Java Classes to add functionality of your javacode. In our case the function may like this:</p>
<p><em>public class employeejs</em></p>
<p><em>{</em></p>
<p><em>// private property for DataAccess object</em></p>
<p><em>public int getAge(string empid)</em></p>
<p><em>{</em></p>
<p><em>//implementation<br />
}</em></p>
<p><em>public string getGrade(string empid)</em></p>
<p><em>{</em></p>
<p><em>//implementation<br />
}</em></p>
<p><em>}</em></p>
<ol>
<li><strong><span style="text-decoration:underline;">Expose      this bean for JavaScript:</span></strong></li>
</ol>
<p><strong><span style="text-decoration:underline;"> </span></strong></p>
<p>To expose the above class to JavaScript, you need to publish this class and methods by using <strong>dwr:remote</strong> and <strong>dwr:include</strong> tag.</p>
<p><strong>dwr:remote</strong> enable java classes to access remotely while <strong>dwr:include</strong> exposes the method accessible remotely.. These are uses as a bean attribute defined at dwr.jar library. In our case, the xml definition at application-context.xml should look like this:</p>
<p><em>&#60;bean</em></p>
<p><em>class=&#8221;dwr. employeejs &#8220;&#62;</em></p>
<p><em>&#60;property name=&#8221;empdao&#8221; ref=&#8221;employeedao&#8221;&#62;&#60;/property&#62;</em></p>
<p><em>&#60;dwr:remote javascript=&#8221;emp&#8221;&#62;</em></p>
<p><em>&#60;dwr:include method=&#8221;getAge&#8221;/&#62;</em></p>
<p><em>&#60;dwr:include method=&#8221; getGrade &#8220;/&#62;</em></p>
<p><em>&#60;/dwr:remote&#62;</em></p>
<p><em>&#60;/bean&#62;</em></p>
<p>Here, class means the name of Java class. On property tag you can initialize any property needed. We initialize the <em>dataaccess</em> object. Javascript attribute of <em>dwr:remote</em> define the <em>javascript</em> class name of the java class. Here it is emp. Which means this <em>employeejs</em> class will be called from JavaScript as <em>emp </em>.</p>
<p>You can optionally use <strong>&#60;dwr:convert&#62;</strong> tag to convert any java object to javascript data types if needed. The conversion doesn’t need for primitive data types. I wouldn’t describe this tag at this blog.</p>
<p>Now, the <a href="http://localhost:8080/mydwr/dwr">http://localhost:8080/mydwr/dwr</a> &#8211; url should show the following message:</p>
<h2>Classes known to DWR:</h2>
<ul>
<li><a href="http://localhost:8080/CPA/dwr/test/equip">emp</a> (dwr.employeejs)</li>
</ul>
<p>That means you are ready to call it from JavaScript.</p>
<ol>
<li><strong><span style="text-decoration:underline;">Call the JavaCode from JavaScript</span></strong></li>
</ol>
<p>To Call the Java Method from JavaScript you need to include the following script pages at your jsp page:</p>
<p><em>&#60;script type=&#8217;text/javascript&#8217; src=&#8217;/&#60;&#60;home folder&#62;&#62;/dwr/interface/emp.js&#8217;&#62;&#60;/script&#62;</em></p>
<p><em>&#60;script type=&#8217;text/javascript&#8217; src=&#8217;/&#60;&#60;home folder&#62;&#62;/dwr/engine.js&#8217;&#62;&#60;/script&#62;</em></p>
<p><em>&#60;script type=&#8217;text/javascript&#8217; src=&#8217;/&#60;&#60;home folder&#62;&#62;/dwr/util.js&#8217;&#62;&#60;/script&#62;</em></p>
<p>Where , emp is the remote class name defined at <strong>&#60;dwr:remote&#62; </strong>tag.</p>
<p>Now, call the javascript remote method by following codes:</p>
<p><em>&#60;script&#62;</em></p>
<p><em>function myunit(i)</em></p>
<p><em>{</em></p>
<p><em>emp.getAge(i,function handleGetData(str) {</em></p>
<p><em>document.getElementById(&#8220;Age&#8221;).value=str;</em></p>
<p><em>});</em></p>
<p><em>emp.getGrade(i,function handleGetData(str) {</em></p>
<p><em>document.getElementById(&#8220;Grade&#8221;).value=str;</em></p>
<p><em>});</em></p>
<p><em>}</em></p>
<p><em>&#60;/script&#62;</em></p>
<p>You need to pass 1 more parameter to Java Function. This parameter will act as a out parameter. <em>getAge </em> took only one parameter; but we call it with two parameters.  The second one is out parameter. It is a javascript function with a single parameter. Java code will return the value at this single parameter.</p>
<p>Now, you can call this function again any method you require.</p>
<p>Hope, this will help you on using the dwr on spring framework. For, any query, you can reach me at <a href="mailto:mohi.khan@gmail.com">mohi.khan@gmail.com</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Bean - Order of injecting properties]]></title>
<link>http://polimetla.com/2009/11/13/spring-bean-order-of-injecting-properties/</link>
<pubDate>Fri, 13 Nov 2009 21:43:59 +0000</pubDate>
<dc:creator>polimetla</dc:creator>
<guid>http://polimetla.com/2009/11/13/spring-bean-order-of-injecting-properties/</guid>
<description><![CDATA[Problem Statement: We need to start some task, after injecting all properties. How to resolve this? ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Problem Statement: We need to start some task, after injecting all properties. How to resolve this?</p>
<p>Solution: Dont / Never depend on order of injecting values into bean. It is not controlled.</p>
<pre class="brush: java;">

import org.springframework.beans.factory.InitializingBean;

public class BeanName implements InitializingBean
{

public void afterPropertiesSet() throws Exception
  {
    System.out.println( &#34;It will be called after completion of properties setting.&#34;);
    //do whatever is required here.
  }

}
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Struts2 + JPA + Spring +DOJO]]></title>
<link>http://chinnuchoudary.wordpress.com/2009/11/13/struts2-jpa-spring-dojo/</link>
<pubDate>Fri, 13 Nov 2009 05:21:52 +0000</pubDate>
<dc:creator>chinnuchoudary</dc:creator>
<guid>http://chinnuchoudary.wordpress.com/2009/11/13/struts2-jpa-spring-dojo/</guid>
<description><![CDATA[]]></description>
<content:encoded><![CDATA[<div class='snap_preview'></div>]]></content:encoded>
</item>
<item>
<title><![CDATA["Eat your own dog food" ou use TDD.]]></title>
<link>http://robsonvf.wordpress.com/2009/11/07/eat-your-own-dog-food-ou-use-tdd/</link>
<pubDate>Sat, 07 Nov 2009 04:21:40 +0000</pubDate>
<dc:creator>robsonvf</dc:creator>
<guid>http://robsonvf.wordpress.com/2009/11/07/eat-your-own-dog-food-ou-use-tdd/</guid>
<description><![CDATA[como já diria Joel Spolsky&#8230; este blog já está fedendo a cupim (não, Joel não disse isso, na ve]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>como já diria <a href="http://joelonsoftware.com/" target="_blank">Joel Spolsky</a>&#8230; este blog já está fedendo a cupim (não, Joel não disse isso, na verdade do que se trata dele terminou nas reticências e tinha a ver com o titulo do post) mas tudo bem, esta é uma rapidinha que, se <a href="http://twitter.com/irobson" target="_blank">eu</a> tivesse um numero consideravel de seguidores no twitter, seria um twitt&#8230; mas, como eu não gosto do twitter e nem quero que você me siga, vai pra cá mesmo.</p>
<p>Tudo que você faz, o faz como se você mesmo fosse usar? Pense nisso antes de construir a próxima linha de código lá no seu trabalho, esqueça seu chefe chato (não que o meu seja, caso o mesmo leia este post&#8230;) e codifique como se você mesmo fosse seu próprio usuário, como se você dependesse do seu próprio sistema para realizar seu trabalho.</p>
<p>Afinal de contas meu caro colega, os usuários gostariam tanto, mas tanto, que o que tu faz realmente funcionasse, que eles seriam capazes de te dar um beijo nas nadegas a cada dia de caixa fechado sem bug no sistema. E eu, sendo o cara que irá dar manutenção no seu código, adoraria tanto ver uma suite de testes unitários bem construidos quando o pegasse, que seria capaz de.. te pagar uma Polar bem gelada no boteco mais badalado da cidade baixa aqui de POA.</p>
<p>&#8220;Ah, mas eu já escrevo todo aquele código e testo tudo no main..  ainda tenho que escrever testes unitários pra ele?&#8221; Amigão, se tu quiser não precisa mais escrever este código todo.. escreva apenas os testes então. Ééé, isso mesmo. Esqueça aquela coisa toda logo de cara e vá direto aos seus @Test.. apenas coloque na cabeça: só entregue este código depois que os testes passarem! Se por acaso, tu ter que codificar um pouco para os testes passarem, beleza, tu faz classe a classe, mas espere, a classe não precisa existir para tu escreve-la pela primeira vez no seu teste&#8230; deixe o Eclipse chorar mesmo, só depois tu cria, ou melhor, rode a droga do teste sem a classe, para tu VER na tela que nada funciona sem a presença da maldita classe. É bem simples, não precisa ler um livro para começar.. são regrinhas básicas: da direita (seus testes) &#60;simula erro&#62; para a esquerda (implementação de uma pequena porção de código) &#60;testa&#62;.</p>
<p>&#8220;Mas quando eu sei que não preciso mais testar?&#8221; Quem disse que não precisa mais testar? Sempre que tu tocar aí tu vai testar, a unica diferença é que não precisará mais se preocupar com o que já está testado, pois se der algum tipo de erro, tu saberá exatamente onde consertar. Eu mesmo, sei quando não preciso mais testar quando o código que eu preciso para entregar a minha estória está pronto e é suficiente, pois de acordo com o TDD, se ele já está pronto, é porque existe um teste para ele!</p>
<p>Finalizando.. &#8220;eat your own dog food&#8221; .. estou ficando louco ou:</p>
<p>a propósito (falando em loucos), aproveitando a presença do <a href="http://twitter.com/SpringRod" target="_blank">Rod Johnson</a> na <a href="http://thedevelopersconference.com.br" target="_blank">TDC</a>, nos diga Rod: o que faz a SpringSource, usar PHP no seu portal?<a href="http://www.springsource.com/index.php"> http://www.springsource.com/index.php</a>, Por quê não o nosso amigo SpringMVC?</p>
<p>E que calor infernal em Porto Alegre&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Tool Selections on Web Services Consumption]]></title>
<link>http://mf9it.wordpress.com/2009/11/01/tool-selections-on-web-services-consumption/</link>
<pubDate>Sun, 01 Nov 2009 21:26:07 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/11/01/tool-selections-on-web-services-consumption/</guid>
<description><![CDATA[Tool Selection Spring WS: It provides easy to use features, like the WebServiceTemplate, which reduc]]></description>
<content:encoded><![CDATA[Tool Selection Spring WS: It provides easy to use features, like the WebServiceTemplate, which reduc]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring WS Consumer With XSD]]></title>
<link>http://mf9it.wordpress.com/2009/10/31/spring-ws-consumer-with-xsd/</link>
<pubDate>Sat, 31 Oct 2009 16:46:34 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/31/spring-ws-consumer-with-xsd/</guid>
<description><![CDATA[This is one of the posts on &#8220;Web Services and Spring WS&#8220;. In this post, I would like to ]]></description>
<content:encoded><![CDATA[This is one of the posts on &#8220;Web Services and Spring WS&#8220;. In this post, I would like to ]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring WS Consumer With WSDL]]></title>
<link>http://mf9it.wordpress.com/2009/10/30/spring-ws-consumer-with-wsdl/</link>
<pubDate>Sat, 31 Oct 2009 00:07:06 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/30/spring-ws-consumer-with-wsdl/</guid>
<description><![CDATA[This is one of the posts on &#8220;Web Services and Spring WS&#8220;. In the &#8220;Consuming Web Se]]></description>
<content:encoded><![CDATA[This is one of the posts on &#8220;Web Services and Spring WS&#8220;. In the &#8220;Consuming Web Se]]></content:encoded>
</item>
<item>
<title><![CDATA[Quicknotes on Spring MVC Conventions]]></title>
<link>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-spring-mvc-conventions/</link>
<pubDate>Fri, 30 Oct 2009 03:03:20 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-spring-mvc-conventions/</guid>
<description><![CDATA[Spring MVC implementations support the idea of &#8220;convention over configuration&#8220;. However,]]></description>
<content:encoded><![CDATA[Spring MVC implementations support the idea of &#8220;convention over configuration&#8220;. However,]]></content:encoded>
</item>
<item>
<title><![CDATA[Quicknotes on Spring MVC Views]]></title>
<link>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-spring-mvc-views/</link>
<pubDate>Fri, 30 Oct 2009 02:25:13 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-spring-mvc-views/</guid>
<description><![CDATA[Benefits Spring MVC View provides a strategy for rending model, and decouples controller from view i]]></description>
<content:encoded><![CDATA[Benefits Spring MVC View provides a strategy for rending model, and decouples controller from view i]]></content:encoded>
</item>
<item>
<title><![CDATA[Quicknotes on Annotated Controllers]]></title>
<link>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-annotated-controllers/</link>
<pubDate>Fri, 30 Oct 2009 02:03:56 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/29/quicknotes-on-annotated-controllers/</guid>
<description><![CDATA[Spring MVC Controllers support annotation, starting from Spring 2.5. In fact, the annotated POJO con]]></description>
<content:encoded><![CDATA[Spring MVC Controllers support annotation, starting from Spring 2.5. In fact, the annotated POJO con]]></content:encoded>
</item>
<item>
<title><![CDATA[Software Professionals - Walk-In Interview]]></title>
<link>http://thewalkin.wordpress.com/2009/10/29/software-professionals-2/</link>
<pubDate>Thu, 29 Oct 2009 14:10:45 +0000</pubDate>
<dc:creator>The Editor</dc:creator>
<guid>http://thewalkin.wordpress.com/2009/10/29/software-professionals-2/</guid>
<description><![CDATA[DSRC requires Software Professionals (Walk-In Interviews) Looking for dynamic Software Professionals]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>DSRC requires Software Professionals (Walk-In Interviews)</p>
<p><strong>Looking for dynamic Software Professionals for the following skills:</strong></p>
<p>&#8212; Java &#8211; Technical Architect:<br />
a). 7-10 years experience in J2EE Design and Architecture, UML, OOAD, Design Patterns, EJB, Struts, JSP, EJB, JDBC, JNDI, Web Services, Weblogic App Server<br />
b). Struts Framework, Jakarta Tiles framework, Hibernate, Spring Framework, Eclipse 3.0, Solaris 9, Rational ClearCase, Rational ClearQuest, Oracle Database<br />
c). Knowledge of SOA &#38; SCA. Sun Certification Enterprise Architect would be preferred<br />
&#8212; Mainframe-Developers / Sr. Developers : 3-8 years experience with extensive Real Time Project experience in COBOL, JCL, VSAM, CICS, DB2, IMS DB/DC, ASSEMBLER, PL/I</p>
<p>Walk-In on 31st October, 2009 between 9 am and 7 pm at:</p>
<p><strong>Quality Inn Centurian Hotel</strong><br />
Opposite to Akaswani, Shivaji Nagar, Pune -411 005<br />
Tel: 020 25510600<br />
Fax:020-2552 0400</p>
<p>If you are unable to come on the above date, please forward your resume to<strong> jobs@dsrc.co.in</strong></p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Declarative Transaction and RunTimeException]]></title>
<link>http://pragmaticoder.wordpress.com/2009/10/28/spring-declarative-transaction-and-runtimeexception/</link>
<pubDate>Wed, 28 Oct 2009 01:24:58 +0000</pubDate>
<dc:creator>huanchh</dc:creator>
<guid>http://pragmaticoder.wordpress.com/2009/10/28/spring-declarative-transaction-and-runtimeexception/</guid>
<description><![CDATA[Using SPRING declarative transaction, learned today that Spring only rolls back transaction for an U]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Using SPRING declarative transaction, learned today that Spring only rolls back transaction for an Unchecked Exception .</p>
<p>For example, suppose in the SPRING application context we have a business service that declares its transaction boundary using SPRING AOP.  In the example below, the <em>create</em> method has transaction definition of &#8220;Propagation_required&#8221;.   The business service has a DAO called <em>artistDAO </em>injected into it.</p>
<p>&#60;!&#8211; persistence service&#8211;&#62;</p>
<pre class="brush: xml;">

    &#60;bean id=&#34;businessService&#34; class=&#34;org.springframework.transaction.interceptor.TransactionProxyFactoryBean&#34;&#62;
        &#60;property name=&#34;transactionManager&#34; ref=&#34;transactionManager&#34; /&#62;
        &#60;property name=&#34;transactionAttributes&#34;&#62;
            &#60;props&#62;
                &#60;prop key=&#34;create*&#34;&#62;PROPAGATION_REQUIRED&#60;/prop&#62;
            &#60;/props&#62;
        &#60;/property&#62;
        &#60;property name=&#34;target&#34;&#62;
            &#60;bean class=&#34;com.myexample.BusinessService&#34;&#62;
               &#60;property name=&#34;artistDAO&#34; ref=&#34;artistDAO&#34;/&#62;
            &#60;/bean&#62;
        &#60;/property&#62;
    &#60;/bean&#62;
</pre>
<p>In the code, throw a checked exception in the create method</p>
<pre class="brush: java;">

public class BusinessService{
private ArtistDAO artistDAO;
public void create()throws Exception{
Artist artist1 = new Artist(&#34;Victor Huang 11&#34;);
Artist artist2 = new Artist(&#34;Victor Huang 12&#34;);
Artist artist3 = new Artist(&#34;Victor Huang 13&#34;);
artistDAO.create(artist1);
artistDAO.create(artist2);
if(1 == 1)
{throw new Exception(&#34;hello&#34;);}
artistDAO.create(artist3);
</pre>
<p>We declared a transaction and we tried to insert three entities into the database: artist 1, artist 2, and artist 3.  An exception was thrown, so the transaction should roll back right?</p>
<p>Wrong!  As a result, artist with name &#8220;Victor Huang 11&#8243; and &#8220;Victor Huang 12&#8243; still get inserted.  Even though the create() method was declared to be in a transaction, Spring does not roll back the insertion of artist 1 and artist 2 entities.</p>
<p>&#160;</p>
<p><img class="alignnone size-full wp-image-32" title="ScreenHunter_60 Oct. 27 21.19" src="http://geekybear.files.wordpress.com/2009/10/screenhunter_60-oct-27-21-19.gif?w=242&#038;h=249" alt="ScreenHunter_60 Oct. 27 21.19" width="242" height="249" /></p>
<p>Had the exception being an unchecked exception, none of the entities would get inserted.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:9px;width:1px;height:1px;">
<pre>PROPAGATION_REQUIRED</pre>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring Declarative Transaction and RunTimeException]]></title>
<link>http://geekybear.wordpress.com/2009/10/28/spring-declarative-transaction-and-runtimeexception/</link>
<pubDate>Wed, 28 Oct 2009 01:24:58 +0000</pubDate>
<dc:creator>huanchh</dc:creator>
<guid>http://geekybear.wordpress.com/2009/10/28/spring-declarative-transaction-and-runtimeexception/</guid>
<description><![CDATA[Using SPRING declarative transaction, learned today that Spring only rolls back transaction for an U]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Using SPRING declarative transaction, learned today that Spring only rolls back transaction for an Unchecked Exception .</p>
<p>For example, suppose in the SPRING application context we have a business service that declares its transaction boundary using SPRING AOP.  In the example below, the <em>create</em> method has transaction definition of &#8220;Propagation_required&#8221;.   The business service has a DAO called <em>artistDAO </em>injected into it.</p>
<p>&#60;!&#8211; persistence service&#8211;&#62;</p>
<pre class="brush: xml;">

    &#60;bean id=&#34;businessService&#34; class=&#34;org.springframework.transaction.interceptor.TransactionProxyFactoryBean&#34;&#62;
        &#60;property name=&#34;transactionManager&#34; ref=&#34;transactionManager&#34; /&#62;
        &#60;property name=&#34;transactionAttributes&#34;&#62;
            &#60;props&#62;
                &#60;prop key=&#34;create*&#34;&#62;PROPAGATION_REQUIRED&#60;/prop&#62;
            &#60;/props&#62;
        &#60;/property&#62;
        &#60;property name=&#34;target&#34;&#62;
            &#60;bean class=&#34;com.myexample.BusinessService&#34;&#62;
               &#60;property name=&#34;artistDAO&#34; ref=&#34;artistDAO&#34;/&#62;
            &#60;/bean&#62;
        &#60;/property&#62;
    &#60;/bean&#62;
</pre>
<p>In the code, throw a checked exception in the create method</p>
<pre class="brush: java;">

public class BusinessService{
private ArtistDAO artistDAO;
public void create()throws Exception{
Artist artist1 = new Artist(&#34;Victor Huang 11&#34;);
Artist artist2 = new Artist(&#34;Victor Huang 12&#34;);
Artist artist3 = new Artist(&#34;Victor Huang 13&#34;);
artistDAO.create(artist1);
artistDAO.create(artist2);
if(1 == 1)
{throw new Exception(&#34;hello&#34;);}
artistDAO.create(artist3);
</pre>
<p>We declared a transaction and we tried to insert three entities into the database: artist 1, artist 2, and artist 3.  An exception was thrown, so the transaction should roll back right?</p>
<p>Wrong!  As a result, artist with name &#8220;Victor Huang 11&#8243; and &#8220;Victor Huang 12&#8243; still get inserted.  Even though the create() method was declared to be in a transaction, Spring does not roll back the insertion of artist 1 and artist 2 entities.</p>
<p>&#160;</p>
<p><img class="alignnone size-full wp-image-32" title="ScreenHunter_60 Oct. 27 21.19" src="http://geekybear.wordpress.com/files/2009/10/screenhunter_60-oct-27-21-19.gif" alt="ScreenHunter_60 Oct. 27 21.19" width="242" height="249" /></p>
<p>Had the exception being an unchecked exception, none of the entities would get inserted.</p>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:9px;width:1px;height:1px;">
<pre>PROPAGATION_REQUIRED</pre>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring SimpleFormController going directly to successView instead of formView]]></title>
<link>http://developertips.wordpress.com/2009/10/27/spring-simpleformcontroller-going-directly-to-successview-instead-of-formview/</link>
<pubDate>Tue, 27 Oct 2009 13:49:07 +0000</pubDate>
<dc:creator>developertips</dc:creator>
<guid>http://developertips.wordpress.com/2009/10/27/spring-simpleformcontroller-going-directly-to-successview-instead-of-formview/</guid>
<description><![CDATA[Using a form to submit to another form goes directly to successView instead of your formView. Here]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Using a form to submit to another form goes directly to successView instead of your formView.</p>
<p>Here&#8217;s an example:</p>
<p><span style="text-decoration:underline;">SomeJsp.jsp</span></p>
<pre>&#60;form name="someForm" action="someForm.htm" method="post"&#62;
&#60;input type="button" onClick="javascript:someForm.submit();" value="Submit"&#62;&#60;/input&#62;
&#60;/form&#62;
</pre>
<p><span style="text-decoration:underline;">SomeFormController.java</span></p>
<pre>public class SomeFormController extends SimpleFormController {
}
</pre>
<p><span style="text-decoration:underline;">spring-servlet.xml</span></p>
<pre style="padding-left:30px;">&#60;bean name="/someForm.htm" class="SomeFormController"&#62;
&#60;property name="formView" value="testForm"/&#62;
&#60;property name="successView" value="newForm"/&#62;
&#60;/bean&#62;
</pre>
<p>&#8230;.</p>
<p>If you have code similar to the snippet above, you will find that when you click on the &#8220;Submit&#8221; button in <em>SomeJsp.jsp</em>, instead of going to the formView page (in this case <em>testForm</em>) it will go directly to the successView (<em>newForm</em>).</p>
<p>You will notice that your <em>SomeFormController </em>never executed its <em>showForm()</em> method and went directly to its <em>processFormSubmission() </em>and <em>onSubmit()</em> methods.</p>
<p>I don&#8217;t know what the real reason is behind this, but it seems like because the first form submission in <em>SomeJsp.jsp</em>, is a &#8220;post&#8221; method, the Spring container immediately does a post to the second form (<em>newForm</em>).</p>
<p>To acquire the results you want, simply use a FORM GET on the first form, like this:</p>
<p><span style="text-decoration:underline;">SomeJsp.jsp</span></p>
<pre>&#60;form name="someForm" action="someForm.htm" <span style="color:#ff0000;">method="get"</span>&#62;
&#60;input type="button" onClick="javascript:someForm.submit();" value="Submit"&#62;&#60;/input&#62;
&#60;/form&#62;</pre>
<pre style="padding-left:30px;">
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Web Services and Spring WS]]></title>
<link>http://mf9it.wordpress.com/2009/10/25/web-services-and-spring-ws/</link>
<pubDate>Mon, 26 Oct 2009 01:59:40 +0000</pubDate>
<dc:creator>MF</dc:creator>
<guid>http://mf9it.wordpress.com/2009/10/25/web-services-and-spring-ws/</guid>
<description><![CDATA[In the next couple days, I will like to share some examples on how to consume web services and how t]]></description>
<content:encoded><![CDATA[In the next couple days, I will like to share some examples on how to consume web services and how t]]></content:encoded>
</item>
<item>
<title><![CDATA[EHCache with Spring Framework and JPA (Hibernate)]]></title>
<link>http://poppenjans.wordpress.com/2009/10/21/ehcache-with-spring-framework-and-jpa-hibernate/</link>
<pubDate>Wed, 21 Oct 2009 20:50:39 +0000</pubDate>
<dc:creator>poppenjans</dc:creator>
<guid>http://poppenjans.wordpress.com/2009/10/21/ehcache-with-spring-framework-and-jpa-hibernate/</guid>
<description><![CDATA[Hibernate has two kinds of caches for objects. The first-level cache is coupled with the Session obj]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hibernate has two kinds of caches for objects. The first-level cache is coupled with the Session object and used by default in order to decreases the amount of database queries and updates within one session. The second-level cache is associated with the Session Factory and can be reused between sessions. Hibernate has a bit more in store, namely the query cache. The query cache is used to store query results. Both the second-level cache and the query cache are not enabled by default and some configuration is required before they can be used. This post focuses on making EHCache work in configuration with Spring Framework and Hibernate as the JPA provider, so here it is what we need to make EHCache cooperate.</p>
<h3>Enabling second-level cache</h3>
<p>First, following properties should be set up in persistence.xml:</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">&#60;property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/&#62;
&#60;property name="hibernate.cache.use_second_level_cache" value="true"/&#62;
</code></pre>
<p>The first one sets up the cache provider and the second on enables the usage of the second-level cache. For instance creation net.sf.ehcache.hibernate.EhCacheProvider can be used.</p>
<p>Once you have decided which objects you would like to cache time to configure it in ehcache.xml which should be placed in the classpath. The name of the cache should be after the fully qualified name of the domain object you wish to cache.</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">&#60;cache name="org.poppenjans.domain.Doll"
       maxElementsInMemory="100"
       eternal="false"
       timeToIdleSeconds="2000"
       timeToLiveSeconds="6000"
       overflowToDisk="false"
       /&#62;
</code></pre>
<p>The ehcache.xml should also include defaultCache configuration which is mandatory and which is used for caches created programatically.</p>
<p>The last thing is to configure the entity to be cached. This should be done using @Cache annotation (or alternatively in the XML mapping file).</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">
@org.hibernate.annotations.Cache(usage=org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
</code></pre>
<p>For the description of concurrency strategies please see <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-cache-readonly">Hibernate&#8217;s documentation</a>.</p>
<h3>Enabling query cache</h3>
<p>The query cache stores results of queries. It is important to note that it actually stores identifiers of entities being the result of a query and not the actual state of entities. Therefore if you intend to query for entities (not scalar values) you should also enable the second-level cache for these entities. Otherwise a query to the database will be executed each time to retrieve these entities, even though their ids are present in the query cache. These means the entities<br />
should be at least annotated with @Cache and preferably have a decent cache configuration in ehcache.xml. In case no configuration is provided the defaultCache configuration will be used.</p>
<p>First, following property needs to be set in persistence.xml:</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">
&#60;property name="hibernate.cache.use_query_cache" value="true"/&#62;
</code></pre>
<p>Furthermore to configure a query to be cached the &#8220;cacheable&#8221; property needs to be set.</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">
Query query = em.createQuery("select d from Doll d order by d.name");
query.setHint("org.hibernate.cacheable", true);
</code></pre>
<h3>Cache statistics</h3>
<p>Cache statistics needs to be enabled by setting up another property in persistence.xml.</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">
&#60;property name="hibernate.generate_statistics" value="true"/&#62;
</code></pre>
<p>The Statistics object can be obtained from the CacheManager. For a single instance following code can be used to obtain<br />
statistics of a cache called org.poppenjans.domain.Doll:</p>
<pre><code style="font:normal normal normal 1.1em/normal 'Courier New', Courier, Fixed;">
CacheManager cacheManager = CacheManager.getInstance();
System.out.print(cacheManager.getCache("org.poppenjans.domain.Doll").getStatistics());
</code></pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Spring MVC validation]]></title>
<link>http://geekybear.wordpress.com/2009/10/18/validation-in-spring-mvc-controller/</link>
<pubDate>Sun, 18 Oct 2009 16:39:57 +0000</pubDate>
<dc:creator>huanchh</dc:creator>
<guid>http://geekybear.wordpress.com/2009/10/18/validation-in-spring-mvc-controller/</guid>
<description><![CDATA[Sometimes one has to perform validations directly in the Spring controller in addition to using vali]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Sometimes one has to perform validations directly in the Spring controller in addition to using validators.   This works differently depending on whether one is using MultiActionController or SimpleFormController.  Just some code snippet of doing validation in controller.<br />
<strong><br />
Example 1: Using MutiActionController, Just want to show errors on the header</strong></p>
<pre class="brush: java;">

public ModelAndView doSomething(HttpServletRequest request, HttpServletResponse response)throws Exception

{

ArrayList errors = new ArrayList();

try{

if(something)

{

throw new Exception(getApplicationContext().getMessage(&#34;messageKey&#34;, null, null));

}

//do something

}catch(Exception e)

{

errors.add(getApplicationContext().getMessage(&#34;messageKey&#34;, new String[]{e.getMessage()}, null));

}

if (errors.size() &#62; 0) {

mav = new ModelAndView(&#34;error.htm&#34;);

request.setAttribute(&#34;errors&#34;, errors);

}

}
</pre>
<p><strong><br />
Example 2: Simple Form Controller</strong></p>
<pre class="brush: java;">

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {

try

{

//do something bad and throws exception

throw new Exception(getApplicationContext().getMessage(&#34;messageKey&#34;, null, null));

}catch(Exception e)

{

errors.addError(new ObjectError(getCommandName(), new String[]{&#34;messageKey&#34;},  new String[]{e.getMessage()}, null));

}

if(errors.hasErrors())

{

ModelAndView errorMav = new ModelAndView(getFormView());

errorMav.addAllObjects(errors.getModel());

errorMav.addObject(getCommandName(), address);

return errorMav;

}else

{

return new ModelAndView(&#34;redirect:/success.htm&#34;);

}

}
</pre>
<p>By the way, it seems like there is no way in Spring to display just regular messages (non-errors).<br />
Check out this <a href="http://jira.springframework.org/browse/SPR-2657?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel">forum.</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[OAuth with Client Libraries (GData, Twitter4J) and Spring MVC]]></title>
<link>http://jeungun.wordpress.com/2009/10/03/oauth-with-client-libraries-gdata-twitter4j-and-spring-mvc/</link>
<pubDate>Sat, 03 Oct 2009 16:30:52 +0000</pubDate>
<dc:creator>Jose  Asuncion</dc:creator>
<guid>http://jeungun.wordpress.com/2009/10/03/oauth-with-client-libraries-gdata-twitter4j-and-spring-mvc/</guid>
<description><![CDATA[This is a refactored version of my post, Quick and Dirty Oauth for Twitter4J OAuth for Web Apps This]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is a refactored version of my post, <a href="http://jeungun.wordpress.com/2009/09/03/quick-and-dirty-twitter4j-oauth-for-web-apps/">Quick and Dirty Oauth for Twitter4J OAuth for Web Apps</a></p>
<p>This is also  the result of my work on a <a href="http://jeungun.wordpress.com/2009/10/02/problem-with-getting-a-gdata-unauthorized-request-token/">a problem I had with getting a unauthorized request tokens using GData</a>.</p>
<p>Basically I found that</p>
<p>1. Whatever you do (regardless if you&#8217;re using Servlets or Spring MVC), never maintain state in a servlet or a Spring MVC controller because GData and Twitter4J client libraries maintain state.</p>
<p>2. It&#8217;s impossible to wire them in Spring because they maintain state.</p>
<p>I think the best way to use Spring for OAuth is by using a MultiActionController with two methods:</p>
<blockquote><p><strong>authorization()</strong><br />
to print the authorization url</p>
<p><strong>callback() </strong><br />
where the provider will go after the user has authorized it to allow the consumer to access the user&#8217;s account in the provider</p></blockquote>
<p>Here&#8217;s what it looks like:</p>
<pre class="brush: java;">
public class OAuthAuthorizeController extends MultiActionController {
public ModelAndView authorize(HttpServletRequest request,
			HttpServletResponse response){

       //authorization code here

}

public ModelAndView callback(HttpServletRequest request,
			HttpServletResponse response){
       //callback code here

}
}
</pre>
<p>With OAuth client libraries there is less need for url rewriting and doing manual get requests.</p>
<p>But the best way to implement the libraries in your code is to program them to an interface, encapsulating what varies because each client library is used differently.</p>
<pre class="brush: java;">
public interface Provider {
public String getAuthUrl() throws OAuthProviderException;
public UserOAuthAccessToken getAccessToken(String token,String tokenSecret)
}
</pre>
<p>The rationale behind this is that the Spring controller we have shouldn&#8217;t have to know what provider he is dealing with. This makes code loosely coupled.</p>
<p>So if you want your controller to deal with GData or Twitter using the Twitter4J and GData libraries, implement the Provider interface and code in the implementation:</p>
<pre class="brush: java;">
public class GoogleDocs/Twitter4JClient implements Provider {
     public String getAuthUrl(){
        //GData or Twitter4J specific code here
     }
    public UserOAuthAccessToken getAccessToken(){
       //GData or Twitter4J specific code here
    }
}
</pre>
<p><a href="http://code.google.com/apis/documents/docs/3.0/developers_guide_java.html#AuthOAuth">GData specific code</a> can be found here<br />
Twitter4J well <a href="http://jeungun.wordpress.com/2009/09/03/quick-and-dirty-twitter4j-oauth-for-web-apps/">here</a>. Haha.</p>
<p>Use an abstract factory method to return the specific implementation to the controllers:</p>
<pre class="brush: java;">
private Provider getProvider(String providerRequested){
	Provider provider = null;
	if (providerRequested is googledocs){
		provider = new GoogleDocs();
	}
        if (providerRequested is Twitter) {
               provider = new Twitter4JClient();
        }
	return provider;
}
</pre>
<p>This is what the Spring MVC controller will look like when it&#8217;s done:</p>
<pre class="brush: java;">
public class OAuthAuthorizeController extends MultiActionController {
public ModelAndView authorize(HttpServletRequest request,
			HttpServletResponse response){

         Provider provider = getProvider(&#34;Twitter&#34;/&#34;GoogleDocs&#34;);
         String authUrl = provider.getAuthUrl();
         return new ModelAndView(&#34;view&#34;,&#34;authUrl&#34;,authUrl);

}

public ModelAndView callback(HttpServletRequest request,
			HttpServletResponse response){
       Provider provider = getProvider(&#34;GoogleDocs&#34;/&#34;Twitter&#34;);
       UserOAuthAccessToken accessToken = provider.getOAuthAccessToken();
       //some other logic you have to do
}
private Provider getProvider(String providerRequested){
	Provider provider = null;
	if (providerRequested is googledocs){
		provider = new GoogleDocs();
	}
        if (providerRequested is Twitter) {
               provider = new Twitter4JClient();
        }
	return provider;
}
}
</pre>
</div>]]></content:encoded>
</item>

</channel>
</rss>
