Simple RESTful URLs with JSPs

Bill de hOra posted an interesting question the other day, that has to do with mapping views to requests, cleanly, in a RESTful way, as Sam Ruby framed it:

it’s easy to forget that Servlets were Java’s response to CGI, way back when. Here’s is the link for Stefan’s entry:

http://www.innoq.com/blog/st/2007/08/15/java_web_frameworks.html

I’m wondering how would one produce a URL space for a blog style archive, using Servlets+JSP, and do so in a way that isn’t a CGI/RPC explicit call? That is, the URLs don’t end up like this:

http://www.innoq.com/blog/entry.jsp?id=java_web_frameworks

with one constraint – “just a servlet” that pulls java_web_frameworks.html direct from a “2007/08/15” folder on the filesystem and byapsses JSP is out. All the response is to be generated via JSP. Would we need to a create framework, however ‘micro’?

In Django world, answering such a question is rather easy. And for PHP hackers, you’re probably saying, hey, use .htaccess to route requests, but in Java, this question becomes a bit more complicated.

A Java developer would want solve two problems here: enable “clean” RESTful URLs, and do as little Java coding as possible by distributing responsibility for defining views to a templating language. Hopefully empowering someone who knows just HTML/CSS to work their magic. The benefits to such an approach can’t be underestimated. We we went down such a path at Knight Ridder with the Cofax CMS and it empowered a lot of creativity with little resources on hand (lots of folks know HTML/CSS/JS, few know Java).

Carbon Five discusses an approach that decomposes path info into parameters for Spring MVC controllers: Parameterized REST URLs with Spring MVC. This solves problem one. It still routes requests to a Controller defined in Java, and I’ve seen far too many not solve problem two, which leaves a design where you have a Request, that maps to a Controller that maps to a single View. But this leaves you with an *excellent* foundation to solve the second problem.

Sam Ruby points to URLRewriteFilter as one possible solution. This potentially solves both problems.

Stefan Tilkov explains how to decompose path info and use RequestDispatcher as a solution. In Sam Ruby’s comments, I suggested just such an approach and it’s worked great for me in previous (and current) projects. This potentially solves both problems.

BTW, if you’re interested in a templating language, outside of JSP (and who isn’t?), consider FreeMarker. A huge project I’m helping design and develop is having terrific success with it and Spring MVC. Real magic starts to happen when you decouple Requests from Views. A shortcut to this in Spring MVC is implementing a RequestToViewNameTranslator.

Moving to a Mac?

There’s a possibility I’ll be switching to a MacBook Pro as my development machine at work. A few years ago, before OS-X, a switch like this would have made me feel a little worried. I’m productive in Windows. One of the reasons why is how I arrange my Windows environment to mirror, in a sense, the Linux and Solaris machines I typically develop software for. OS-X eliminates that distinction. As for software, I use a stack of free and open source applications that have analogs on OS-X.

Eclipse (has a Mac distribution)

Sun’s Java SE SDK (has a Mac distribution)

Python (has a Mac distribution)

ActivePerl (has a Mac distribution)

WinSCP and PuTTY (Fugu and Cyberduck)

Notepad++ (Textwrangler)

Emacs (has a Mac distribution)

wikidPad (runs on a Mac)

Cygwin (OS-X has Terminal :))

IfranView (iPhoto)

Inkscape (has a Mac distribution)

Subversion (has a Mac distribution)

Trac (server side, browser accessed application)

Here’s a thing that’s been disturbing me about Facebook and Social Networking services…

Tim Berners-Lee, as quoted by Jon Udell in a piece that greatly influenced me back in the day, called the web “a shared information space through which people and machines could communicate.” . The original piece in which Tim Berners-Lee said that is still up for all to read, titled “The World Wide Web: Past, Present and Future”. I found the piece by typing the quote in Google. Give it a try.

As we share our knowledge, collectively with one another, across blogs, message forums, email lists, and any other services that permit indexing, and reinforce that knowledge via hyperlinking, we are, collectively, building a space that benefits humanity.

It is this collective space that helped me learn what I needed to learn to build a career.

And all this happens, not because of altruistic reasons, but because the architecture of the Web empowers, via the hyperlink, a certain form of communication and collaboration.

The conversations that occur on Facebook, and on most social networking services, happen in the public-private.

In places not indexed by Google, not indexed by Yahoo!, yet are public to selected communities that have access and privilege to them. Gated communities. Islands.

Certainly, there has always been places out of reach of search engines (and there will always be a need for some), but until the last few years, the call from the digerati was to surface these databases of knowledge to the public, behind whatever proprietary walls that may have kept them out of reach. Whether they be newspaper archives, or email lists.

Don’t get me wrong – there’s a lot celebrate when it comes to social networking services. I’m a participant in more than a few, to be sure.

But if they come to define the Web, as they are to some in the media, then I fear we are taking a great step backward.

Been Nutso Busy

Sorry for the sudden lack of conversing and blogging as of late. My day job has been keeping me really busy. That, along with physical therapy (which has stalled btw – I’m going to try epidural steroid injections next), has really been kicking my ass.

In addition to all this, the past month or so, Philly Future started to crash uncontrollably. Drupal’s aggregator isn’t built to scale, in terms of size, as I have painfully found out. It took some major indexing, cache tuning, and aggregator module tweaking, to stabilize things. Along the way I learned quite a bit about MySQL and Drupal. Enough to know that I need look for a replacement for the aggregator or majorly refactor its database usage. Even so, I plan to submit the improvements I made to the community. They’re going to give us a few more months I think.

Some days I still can relate to Chris Gardner’s character in “The Pursuit of Happyness”, where instead of traveling a myriad of buses, perfectly timed, each day to negotiate making it to my place, the job, or school, six hours on public transportation, now it is balancing work, home, health, and passions like Philly Future. A far better situation. But still not enough time to do it all.

Movable Type 4.0 Is Going to Rock

Movable Type 4.0 Beta Launches, Platform To Be Open Sourced

Burningbird » Movable Type: The Princess Time Forgot

rc3.org: Movable Type 4

I’m excited to see the participatory media functionality being added to MT. A while back I wrote a piece that was a little controversial – “del.icio.us is going to die, so is Digg, so is Flickr”. I believe that personal blogging solutions will evolve to enable us to host our own social networks (they do already in a sense). PC computing history leans towards personal empowerment.

I’ve tried more blogging solutions then almost anyone. Folks tend to break things down into false choices, thinking that a marketplace can only sustain one ore two options, when over the past few years, I think it’s been obvious that in the blogging ecosphere not only can two or more options co-exist – they can thrive.

While I’ve used WordPress and Drupal on other projects, I’ve kept Movable Type as my personal blogging solution, and it has been my recommendation to use it in various projects of differing scope. It’s always come through for me.

No solution is perfect. Don’t believe the hype. These are just tools to keep in your toolbox. Loyalty to a hammer over a screwdriver makes no sense.

This is a good day for blogging. And a good day for freelancers and corporate developers everywhere that require a reliable, flexible, content management solution.

David Van Couvering: “I think I’m not alone in this belief”

From David Van Couvering ‘s Blog: Technology as a positive force:

You may have read my blog about my concerns around technology. At the same time, I also believe that if you are conscious and committed and vigilant about how you use it, technology can be a huge enabler for helping make a difference in people’s lives. That was actually one of the key reasons I chose computers as a career path when I first started in the mid-eighties.

You are not alone David.

Warstories

Paul Tyma, a senior engineer at Google, developed and maintains Mailinator, a nifty service that helps you avoid the hassle of associating your personal email address with services you never intend to revisit during registration.

A few months ago he posted about the architecture behind Mailinator and the decisions that went into it. It’s a great read.

Getting SciTE to do Python-like folding for text files

Just add the following to SciTEGlobal.properties:

file.patterns.text=*.txt
filter.text=Text (txt)|
lexer.$(file.patterns.text)=python

Saved for future reference. Oh, what am I becoming I sometimes wonder… I am digging Vim over Emacs these days. Here is a guide to text folding in Vim.

Placeblogger launches

Placeblogger, an effort by The Center for Citizen Media, Pressthink, and Lisa William’s H20town launched on New Years. It’s focussed on sharing with you blogs that cover a geographical region. I believe this will grow to be an important service over time. And I gotta admit – it is great to see so many ideas expressed from Philly Future adopted in a national effort. (disclaimer – they might make me an honorary adviser due to influence). Read Pressthink for more.

Norgs stories: The Web Disintermediates (wait for it…)

One of the ideas that gets branded about whenever slumping circulation numbers are screamed from headlines, CD sales are found to be tanking, movie ticket sales slumping, or broadcast TV viewers disappearing, is the notion that because the Web disintermediates the middle-man between content creator and content consumer, people are going to the Web and abandoning “traditional” media.

There is some truth in that to be sure, but there is also truth in that human nature abhors a vacuum. We seek out sources of information and entertainment we decide to trust. And as such, the Web has always created a new opportunity for intermediaries, bundlers of information and entertainment, and aggregators to help manage the flow we partake in each day.

A simple out of the box example – What is a good link blogger like Eschaton, other then an aggregator of sorts?

How about YouTube? What of Google or Yahoo!?

Something to chew on as you read the following stories:

paidContent.org: Why Aggregation & Context and Not (Necessarily) Content are King in Entertainment (source for the graphic)

Philly Future: MyFox Philadelphia – Fox News Wants Your Blog

Philly Future: DigPhilly.com – NBC 10 Wants Your Blog (includes a who-who in local social media efforts)

Washington Post: Howard Kurtz: At the Inquirer, Shrink Globally, Slash Locally?

Center for Citizen Media: Newspaper as Blog Portal

GigaOM: The Content Aggregators and the Fat Belly