Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts

2008-11-17

I have used Wicket for small web application

More than week ago I have started implementing first module for Medical Diagnostic Expert System. It's quite simple application for manual data entry and editing. There is one catch - forms have to be flexible in some way and dynamically configurable. The whole project will work as web application, so data entry editor will work in that way too.

As this is the new fresh project I have possibility to use the newest Java features and frameworks. The multi tier architecture application will use Spring for easy separation of concerns between layers. That plus JPA on top of Hibernate should be sufficient for future development of modules and expansions (the final project boundary is blurry).

I thought about using Spring MVC framework, but after little research I decided to use Wicket, to set up user interface. Wicket is using view component model, with main page component containing other components and controls with event handlers. Binding controls is made by marking special wicket attributes in html template. Additional markup is not intrusive, so even raw html template viewed in web browser is looking good (sounds like Tapestry). The basic ideas are similar to that used in ASP.NET. Developing in Wicket is more Java code centric than in other popular frameworks, with clean separation of html template design.

For quick start up I have used QWicket generated application template and tailored it to work with JPA and my core module. Application should work under Postresql database, but for easy of deployment of prototype for testing purposes I stayed with preconfigured HSQLDB. Switching back to Postgres is just as easy, as changing few lines in properties file.

I'm unexperienced Wicket user but development goes quite smooth. Using documentation, tutorials and books is really helpful at that stage. As far so good. I'm finishing UI prototype and can concentrate now on implementing core module functionalities.

2008-10-06

Good method of web frameworks comparison for programmers

If you are programmer and want to choose the web frameworks suitable for your project, one of the best ways of framework evaluation (not fastest) is writing simple prototype that uses concepts similar to your project requirements. Opinions of other experienced frameworks users also counts, but sometimes framework selection is based on personal preferences. Thanks to prototype code all framework sweet spots and "need to be done" areas are easily exposed. Prototyping gives also practical measure of framework impact on overall development productivity.

Last week I have done little research about new trends in Java web frameworks, and found very good and detailed frameworks comparison based on prototyping on a Peter Thomas blog.
Here are articles comparing Wicket framework to Spring MVC, JSF and GWT.
Good job Peter Thomas!

By the way, I have found many Wicket positives in his articles, that I give that framework a try in my next project requiring component based UI.

2008-01-06

web.py update 5 - DbUtils pooling and apache MPM module

My application using web.py is still growing. One day happened something suprising. After testing on internal WSGI server, I deployed application at testing machine with Apache, and started checking. Login screen appeared and everything was looking ok. But after login I waited very long time and nothing happened. After couple of minutes (long timeout?) application finished request with exception inside DBUtils code. I've checked logs, another browser- still the same.

I googled exception code and found that it's something related with exhausted connection pool. Application grows and communication with database complicates too. I've add additional code closing connections. Still nothing.
Then I have found some interesting posts about DBUtils connection pooling method and problem related to apache MPM module.

Apache MPM modules are directly handling HTTP requests. DBUtils creates pool for application process. My default Apache configuration was MPM prefork. That means every http request is handled by one single threaded MPM process. DBUtils created pool for every apache handler process- that exhausted database connections.

There is simple solution if you use dedicated apache server- using MPM worker that works better with DBUtils multi threaded pooling.
Once again, the day was saved.

2007-11-26

web.py update 4 - apache cgi configuration

Finally I decided to put my web.py application on test server. I updated python to 2.5, and installed needed packages.

Then I decided to configure application as fast-CGI under existing Apache2 installation with bunch of other running applications. Short and good installation manual can be found at webpy page.

I tried to configure fast-CGI and then CGI setup, but something went wrong. All configuration examples are using url rewriting, and my Apache does not have proper module. I could of course install mod-rewrite for apache, but I realized that I don't need it yet. Simple web.py application should work even without mod-rewrite. It could be nice feature on constrained hosted systems.

After needed modifications my apache config file for CGI looks like that:

<VirtualHost *:80>
ServerName mywebpyapp.domain.com

Alias /static /var/www/mywebpyapp/static
ScriptAliasMatch ^/(.*) /var/www/mywebpyapp/run-cgi.py/$1

<Directory "/var/www/mywebpyapp">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


and my separate CGI script run-cgi.py:

#!/usr/local/bin/python2.5
import cgitb; cgitb.enable()
import sys
import web, app.controller

def cgidebugerror():
_wrappedstdout = sys.stdout
sys.stdout = web._oldstdout
cgitb.handler()
sys.stdout = _wrappedstdout

web.internalerror = cgidebugerror

#web.webapi.internalerror = web.debugerror
web.config.db_parameters = dict(dbn='postgres', user='user', pw='password', db='myappdb',host='localhost',port='5432')
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)

if __name__ == "__main__":
urls=app.controller.urls
web.run(urls, globals(), web.reloader)


So my application is working now behind apache and it is ready for production deployment.

2007-10-29

web.py update 3 (and tough bugs)

My new application on web.py framework works great. I eliminated slowness issue during installation of new web.py environment.
It was caused by opening db connection without pooling- and it took really long time (about 10 s). So next time I properly installed DBUtils. Run tests and found exception raised by web.py database. I had to make quick fix in my web.py installation - changed name of one of parameters in DBUtils function call.

Few days ago I tested web.py session support and authentication in my application. It worked good, when something broke next day. I had feeling that session isn't properly stored or recalled- and my authorization module redirected me to login page. Access logs showed me that actually I requested only login page, not any other. Strange. I was looking for bug in web.py, but there had to be another reason I thought at end.
I used another web browser- in my case IE. Login and session worked well, better than under Firefox. The reason causing problem was performance enhancing plugin for firefox I installed few days ago to tune in new Firefox. It used strange caching algorithm, and every time I hit some application page login page was loaded. Probably it was first page cached by plugin. I uninstalled it and reviewed other browser modifications.

Once again experience shows that the most time consuming bugs are simple and just hidden in area assumed for sure as free of bugs (in my case I was looking in server app, but bug was caused by browser client modification).

2007-10-22

Additional insights about Web.py (update 2) - sessions and slowly pages

I have used default branch of web.py framework for prototyping purposes. As my web app needs sessions and there is no bult in session support, I tried to use flup and beaker modules. Meanwhile I realized that there is another branch of web.py with simple sessions.
It is handling session storage on database or files, and has typical session api (although simpler than beaker). It is all what I needed.
If you are using bzr already you can get web.py with sessions directly from repository:

bzr branch http://bazaar.launchpad.net/~karol.tarcak/webpy/webpy.sessions.branch webpy

Another issue is slowly page generation. I think it's matter of using uncached templates, but this is unevitable during development process. Maybe database connection also adds its workload, I have to check it. Now every page loads in about 10 seconds- it's slower than compiling jsp page on the same machine. I'm going to investigate the subject and return to process of happy-snappy coding.

Maybe you found anything what can speed up page generation- please share your experiences. I'm waiting for comments.

2007-10-16

Prototyping with Web.py - the light web framework

Welcome again

Last week I started in cooperation with my friend small personal investment tracking application project. It's still in designing stage, maybe I will write something about that later.

I decided to write basic functional prototype using python, having in mind that it can be production environment. Because it is going to be a web application I reviewed current python web frameworks.

There are interesting solutions like Django or Pylons, but I would prefer to use simple but flexible frameworks for that scale of project. So I decided to use web.py - simple framework made by creators of reddit.com.


Web.py has really simple skeleton connecting together http server, controller engine and built in but loosely coupled database module and template engine. It needs minimum configuration to run. In default mode it uses WSGI http server, with option to switch to fastcgi on apache or lighttpd. The same with other modules. You can use other full fledged db framework or better known templating engine. There are no fancy helpers and component support, but it's easy to include existing solutions.

It reminds me another web framework having similar attributes - java Maverick. It have more features, but the same spirit of simplicity.

If you are ready to use light web framework try one of these, or find something like that. Bigger and having more features not always means better.