<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to do Everything Wrong with Servlets</title>
	<atom:link href="http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-do-everything-wrong-with-servlets</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:42:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-7458</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 31 Mar 2011 15:56:23 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-7458</guid>
		<description>@Rajiv,

Glad to hear from you and happy to offer my thoughts on making servlets more testable. I will start a dialog on email.</description>
		<content:encoded><![CDATA[<p>@Rajiv,</p>
<p>Glad to hear from you and happy to offer my thoughts on making servlets more testable. I will start a dialog on email.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajiv Mordani</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-7450</link>
		<dc:creator>Rajiv Mordani</dc:creator>
		<pubDate>Wed, 30 Mar 2011 22:54:27 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-7450</guid>
		<description>Hi Misko,
    I am the Servlet spec lead and I will try to address some of the issues that you have listed above - 

For initialization of resources like Database connection you can use CDI / Resource injection to inject the data source for example. Similarly you can use CDI to inject all kinds of managed beans into servlets. So that will take care of initialization issues you list above like Christian noted above.

Another issue that you list about constructor - In servlet 3.0 we added ways to add an &quot;initialized&quot; servlet during context initialization phase dynamically. It is restricted but there is a way to do it.

For the single instance of a Servlet in the VM - sessions are useful for storing state. There used to be a SingleThreadedModel which did basically what you are suggesting. We deprecated that because there are a lot of issues with that.

We can talk more to see what we can improve in 3.1 for &quot;testability&quot; if that&#039;s the main issue you are trying to address or about any other issues. Let me know.

- Rajiv</description>
		<content:encoded><![CDATA[<p>Hi Misko,<br />
    I am the Servlet spec lead and I will try to address some of the issues that you have listed above &#8211; </p>
<p>For initialization of resources like Database connection you can use CDI / Resource injection to inject the data source for example. Similarly you can use CDI to inject all kinds of managed beans into servlets. So that will take care of initialization issues you list above like Christian noted above.</p>
<p>Another issue that you list about constructor &#8211; In servlet 3.0 we added ways to add an &#8220;initialized&#8221; servlet during context initialization phase dynamically. It is restricted but there is a way to do it.</p>
<p>For the single instance of a Servlet in the VM &#8211; sessions are useful for storing state. There used to be a SingleThreadedModel which did basically what you are suggesting. We deprecated that because there are a lot of issues with that.</p>
<p>We can talk more to see what we can improve in 3.1 for &#8220;testability&#8221; if that&#8217;s the main issue you are trying to address or about any other issues. Let me know.</p>
<p>- Rajiv</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Gruber</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-880</link>
		<dc:creator>Christian Gruber</dc:creator>
		<pubDate>Thu, 16 Apr 2009 01:40:40 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-880</guid>
		<description>One of the reasons I&#039;ve been loving Tapestry5 is that I can build &quot;misko-friendly&quot; apps. &#160;My components and pages don&#039;t have to inherit from anything (not even interfaces), pages, components and services are all injectable dependencies and declare their dependencies quite nicely, etc. &#160;I want a reference to another page? &#160;I inject it. &#160;I want a DAO? &#160;I inject it. &#160; It also does really nice things like byte-code manipulate the classes at load-time (for pages and gui components) so that I don&#039;t have to write a lot of boiler plate and then test it - it&#039;s taken care of and the boiler-plate code weaving is well tested, so it&#039;s SEP (somebody else&#039;s problem). &#160;This means that my gui component classes are almost entirely consisting of declarations of dependencies (@Inject private MyFoo myFoo;) declarations of properties with getters and setters taken care of for me if they&#039;re default boiler plate javabean style (@Property private MyLoopContent currentContent;) and actual methods which do something.The above means that I only have to write tests to test that which is unique about the class - Tapestry 5 pages and components follow SRP (well, they can - they&#039;re not forced to break SRP), are easy to read, all abide by consistent convention, etc.Anyway - small plug for T5, but even if you&#039;re not using T5, it&#039;s a great proof that what Misko&#039;s talking about isn&#039;t just fantasy - you really can have frameworks which let you do this, and you can hammer out existing frameworks to be more like this.</description>
		<content:encoded><![CDATA[<p>One of the reasons I&#8217;ve been loving Tapestry5 is that I can build &#8220;misko-friendly&#8221; apps. &nbsp;My components and pages don&#8217;t have to inherit from anything (not even interfaces), pages, components and services are all injectable dependencies and declare their dependencies quite nicely, etc. &nbsp;I want a reference to another page? &nbsp;I inject it. &nbsp;I want a DAO? &nbsp;I inject it. &nbsp; It also does really nice things like byte-code manipulate the classes at load-time (for pages and gui components) so that I don&#8217;t have to write a lot of boiler plate and then test it &#8211; it&#8217;s taken care of and the boiler-plate code weaving is well tested, so it&#8217;s SEP (somebody else&#8217;s problem). &nbsp;This means that my gui component classes are almost entirely consisting of declarations of dependencies (@Inject private MyFoo myFoo;) declarations of properties with getters and setters taken care of for me if they&#8217;re default boiler plate javabean style (@Property private MyLoopContent currentContent;) and actual methods which do something.The above means that I only have to write tests to test that which is unique about the class &#8211; Tapestry 5 pages and components follow SRP (well, they can &#8211; they&#8217;re not forced to break SRP), are easy to read, all abide by consistent convention, etc.Anyway &#8211; small plug for T5, but even if you&#8217;re not using T5, it&#8217;s a great proof that what Misko&#8217;s talking about isn&#8217;t just fantasy &#8211; you really can have frameworks which let you do this, and you can hammer out existing frameworks to be more like this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-878</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 15 Apr 2009 17:44:14 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-878</guid>
		<description>@Przemek,

You are right on the money. I should probably talk more about this in a separate blog, but your conclusion are valid. As far as benefits go, you will find that the code is (1) easier to test (2) modifying the code becomes easier since you con deliver new date directly to the class which needs it without having to pass it through the stack or resolve to Globals.</description>
		<content:encoded><![CDATA[<p>@Przemek,</p>
<p>You are right on the money. I should probably talk more about this in a separate blog, but your conclusion are valid. As far as benefits go, you will find that the code is (1) easier to test (2) modifying the code becomes easier since you con deliver new date directly to the class which needs it without having to pass it through the stack or resolve to Globals.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Przemek</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-877</link>
		<dc:creator>Przemek</dc:creator>
		<pubDate>Tue, 14 Apr 2009 22:02:05 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-877</guid>
		<description>A lot of good advice regarding servlet-like frameworks. But I&#039;m not sure, where most of the evil really lies - in API or in particular apps? A very interresting question for me is: how to design those APIs in a better way?But this was not my main reason to comment your article. I was particularly puzzled by the piece about data travelling through the stack - called procedural-style by you. What? Methods with parameters are not OO? I&#039;m a big fan of objects for 9 years and I haven&#039;t expected many more surprises on that field, I have to confess - the credit goes to you, Misko :) I spent a while trying to understand your point and finally I think now I got it :) But please correct me, if I don&#039;t. I think you would design a webapp in a following way:when a request comes in, a web of request-scoped objects are created, with all necessary data taken from HTTP request.Then, a method of a root request object is called and all of real processing happens. Then, results are collected and transformed into HTTP response.I hope I guessed, what you&#039;ve meant. If yes, this could be extrapolated with very interresting consequences for whole OO programming (at least, if you want pure OO). In particular, following rules would apply:use arguments only in constructors and factory methodswhen you need an argument in other method, turn it into method-object (AKA command pattern)use all data you have to build a graph of request objects, then call a single method on it, to let it do its workI&#039;m sure, I&#039;ve still omitted many other interresting consequences, but these already challenge many of mine habits (and popular beliefs).Therefore I start to be curious, what benefits can give me this style of programming, to justify the transition.If I got the point of &quot;Java is OO, use it in that way&quot; correctly, could you enumerate few of the benefits?Or, please, correct me, if I misunderstood you.</description>
		<content:encoded><![CDATA[<p>A lot of good advice regarding servlet-like frameworks. But I&#8217;m not sure, where most of the evil really lies &#8211; in API or in particular apps? A very interresting question for me is: how to design those APIs in a better way?But this was not my main reason to comment your article. I was particularly puzzled by the piece about data travelling through the stack &#8211; called procedural-style by you. What? Methods with parameters are not OO? I&#8217;m a big fan of objects for 9 years and I haven&#8217;t expected many more surprises on that field, I have to confess &#8211; the credit goes to you, Misko <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I spent a while trying to understand your point and finally I think now I got it <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But please correct me, if I don&#8217;t. I think you would design a webapp in a following way:when a request comes in, a web of request-scoped objects are created, with all necessary data taken from HTTP request.Then, a method of a root request object is called and all of real processing happens. Then, results are collected and transformed into HTTP response.I hope I guessed, what you&#8217;ve meant. If yes, this could be extrapolated with very interresting consequences for whole OO programming (at least, if you want pure OO). In particular, following rules would apply:use arguments only in constructors and factory methodswhen you need an argument in other method, turn it into method-object (AKA command pattern)use all data you have to build a graph of request objects, then call a single method on it, to let it do its workI&#8217;m sure, I&#8217;ve still omitted many other interresting consequences, but these already challenge many of mine habits (and popular beliefs).Therefore I start to be curious, what benefits can give me this style of programming, to justify the transition.If I got the point of &#8220;Java is OO, use it in that way&#8221; correctly, could you enumerate few of the benefits?Or, please, correct me, if I misunderstood you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sakuraba</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-862</link>
		<dc:creator>Sakuraba</dc:creator>
		<pubDate>Thu, 09 Apr 2009 09:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-862</guid>
		<description>I agree with all of the statements, however is this a real issue? Most of us are using something like SpringMVC and dont touch Servlets at all.</description>
		<content:encoded><![CDATA[<p>I agree with all of the statements, however is this a real issue? Most of us are using something like SpringMVC and dont touch Servlets at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah Happy</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-858</link>
		<dc:creator>Sarah Happy</dc:creator>
		<pubDate>Thu, 09 Apr 2009 00:39:33 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-858</guid>
		<description>Personally I use a ServletContextListener to create an application object, most of which is testable outside of the servlet container, and in the servlets I look up the application object in the context attributes, and pass the request and response down to it, making the servlets very simple wiring.  The container provided request and response objects typically do not remain visible past the first call level either.</description>
		<content:encoded><![CDATA[<p>Personally I use a ServletContextListener to create an application object, most of which is testable outside of the servlet container, and in the servlets I look up the application object in the context attributes, and pass the request and response down to it, making the servlets very simple wiring.  The container provided request and response objects typically do not remain visible past the first call level either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shantanu Kumar</title>
		<link>http://misko.hevery.com/2009/04/08/how-to-do-everything-wrong-with-servlets/comment-page-1/#comment-857</link>
		<dc:creator>Shantanu Kumar</dc:creator>
		<pubDate>Wed, 08 Apr 2009 21:24:27 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=435#comment-857</guid>
		<description>Servlets are certainly bad candidates for testing. I generally test them by passing test config through constructor, and launching them through an embedded Jetty container.Today I attended a talk by Neal Ford at JAX 09 at Bangalore, where he showed how we can use MockRunner to test classes that depend on infrastructure.MockRunner URL:&#160;&lt;a href=&quot;http://mockrunner.sourceforge.net/&quot; rel=&quot;nofollow&quot;&gt;http://mockrunner.sourceforge.net/&lt;/a&gt;Cool stuff!</description>
		<content:encoded><![CDATA[<p>Servlets are certainly bad candidates for testing. I generally test them by passing test config through constructor, and launching them through an embedded Jetty container.Today I attended a talk by Neal Ford at JAX 09 at Bangalore, where he showed how we can use MockRunner to test classes that depend on infrastructure.MockRunner URL:&nbsp;<a href="http://mockrunner.sourceforge.net/" rel="nofollow">http://mockrunner.sourceforge.net/</a>Cool stuff!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

