Thursday, October 26, 2006

Java alpha-numeric security image generator (CAPTCHA) libraries

I've been asked this question more than once. Are there any Java based libraries out there that can generate those skew alpha-numeric images to block bots from entering certain parts of my web-site?

Yes, of course, there are! Look at:


Thursday, October 05, 2006

Web 2.0 and scalability issues of Servlet Containers

We are often told that client side polling in a typical web-app is a poor design choice but often they don't explain why it is so. Of course, at a high level we know that each client request is associated with a server thread and the thread and it's allocated resources are blocked until the client request finishes. Therefore if we have too many polling type requests which are "no-op"s, we are potentially tying down a lot of server resources essentially serving a bunch of "no-ops" while eating a chunk of memory each.

With web 2.0 we are going to have these type of scenarios, whether we like it or not! So is there a better way? Is anybody doing anything about it? Here are two very interesting articles for anyone looking for answers to these questions:

http://blogs.sun.com/andi/entry/comet_basics



http://www.webtide.com/downloads/whitePaperAjaxJetty.html

EL expression not evaluated! ${msg} appears as ${msg} in the output!

If your JSP is printing your ${whatever} el expressions as they are, verify that:


  1. You are using a JSP2.0 compliant servlet container.

  2. Your web.xml starting tag looks like this:

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">



Sunday, October 01, 2006

Spring Error - ModelAndView [ModelAndView: materialized View is [null]

I've been struggling with this stupid error for an hour now. Well, don't they all look stupid after they are resolved! If you searched on this exception, read on, you might just find the solution here :).
I kept getting the following exception in my controller and I just couldn't figure out what I had done wrong.

javax.servlet.ServletException: ModelAndView [ModelAndView: materialized View is [null]; model is {org.springframework.validation.BindException.recipe=org.springframework.validation.BindException: BindException: 0 errors, recipe=com.foo.bar.Recipe@cf710e}] neither contains a view name nor a View object in servlet with name 'action'
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:919)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:705)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:386)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:346)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:445)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:356)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:226)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:627)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
at org.mortbay.jetty.Server.handle(Server.java:269)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:430)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:687)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:492)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:199)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:339)
at org.mortbay.jetty.nio.HttpChannelEndPoint.run(HttpChannelEndPoint.java:270)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)

After much googling, I found nothing. Finally I turned on the DEBUG logging for spring and tried to solve it the hard way - logically.
Long story short, here's why I was getting the exception:


I had a bean mapping as follows:

<bean id="barManager"
class="com.foo.ui.controller.BarManager"
autowire="byName">
<property name="commandName" value="bar" />
<property name="commandClass"
value="com.foo.dao.Bar" />
</bean>

I also had a URL mapping as follows:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/barlink.html">barManager</prop>
</props>
</property>
</bean>
I kept getting the above exception when I tried to access http://localhost:8080/myapp/barlink.html
The solution to the problem was adding the following line to the barManager definition:
<property name="formView" value="bars" />
Also, the value "bars" MUST map to an existing view name. In my case, it mapped to bars.jsp.

After adding this, the definition looks like this:
<bean id="barManager"
class="com.foo.ui.controller.BarManager"
autowire="byName">
<property name="commandName" value="bar" />
<property name="commandClass"
value="com.foo.dao.Bar" />
<property name="formView" value="bars" />
</bean>


That's it. It took me an hour and a half to figure out and about 15 min to write this. Hopefully this will save you some time :).

This page is powered by Blogger. Isn't yours?