Unification of Java Weeds in a Standards Garden

After my post the other day in relation to building proper web UI architecture in PHP, my brain reverted to thinking about the complexities of web application development in Java and how in spite of standards, the amount of organic homegrown stuff that’s out there has muddied the water to the extent that it’s difficult to separate the wheat from the chaffe.  Sun has tried it’s darndest to follow the elephant and clean up behind it, but there is an increasingly sordid history of great ideas (Hibernate, Spring) that gained enough community momentum where Sun felt that these innovative platforms and their imitators should be unified behind a single standard.  In fact, it’s increasingly difficult to find parts of Java that were invented by Sun.

I haven’t been architecting Java solutions for a living in nearly a year now, and last I checked the state of the world was more or less:

  • EJB had assimilated Hibernate and other ORM solutions as something now called JPA, which was neccesary and useful to standardize;
  • EJB had also taken elements of Spring to invert the once ubiquitous locator pattern and adopt dependency injection as the standard for satisfying collaborator relationships.  Of course, the Sun solution aimed to solve specific problems in EJB, and had less interest in solving the more general need for standardization around DI-based application frameworks;
  • JSF was crashing and burning in the web tier, with Gavin King once again trying to pick up the pieces and simplifying the entire stack through Web Beans.

So to distill it down – middleware in Java was actually a pleasurable place to work, and the web tier was still a torture chamber.

Note: I’m leaving Velocity, Struts, Spring, and Tapestry out of the mix here.  That’s not to say that there isn’t value in some of these frameworks.  Tapestry was architecturally sound but hinders rapid development.  Struts and Spring both require siginificant configuration, and Velocity is…like Smarty for PHP.  All of them did so many things differently that it would be difficult to standardize around any one of them.  Additionally, the only one that could arguably be standardized within the exiting JEE stack is Spring – which attempts to solve many of the problems of front and middle-tier integrations.

Per my post from the other day, I really feel that the age of the server-based Web UI framework is dead.  MVC will always be a necessity, but re-usable controls and architectures that try to solve all of the world’s problems with different delivery mechanisms be it HTML or JSON are at a dead end – it’s simply not scalable.  So my attention turned to an article by James Strachan about JSR-311 and how he feels it could be the standard to solve much of the worlds problems.  JSR-311 addresses the JAX-RS standard for delivery of RESTful services.  This has long been needed from Sun given the narrow nature of the JAX-WS spec, but James has the right idea.

…Having had a horrid time using Tapestry and Hibernate together on some projects in the past, I’m kinda over the whole concept of server side UI web frameworks personally (I’m putting my flame-proof suite on now). I kinda think if you want to do complex rich web UIs, use wizards or complex flows, just use GWT or JavaScript on the client (or Flex/Flash for video or crazy highly graphical widgets) and keep the server side fairly simple and very RESTful….

So, I’m not the only crazy one out there.  That’s comforting.  But is a standard that serves as the foundation for tools to deliver RESTful services the answer?  From an architecture perspective, I’ve always been of the mindset that RESTful services, particular with its HTTP metaphors is just a DAO pattern exposed as services.  This is a pretty fine grain for me, but as Seam in Java and LINQ in .Net are beginning to prove – the value of coarse grained business services as provided typically by Session Beans in EJB may be a bit overstated.  So, does it make sense to build web frameworks that are really geared towards SaaS, and allow frameworks like Spring or Velocity or, hell even simple XSLT – take the helm when more traditional request-response mechanisms are needed?

And even more so, a cursory review of the JAX-RS doesn’t really present any options for consuming the services produced by implementers.  That’s somewhat understandable given that the product is typically vanilla XML or JSON or Text or whatever.  When I wrote my own RESTful service implementation using Spring a few years back, I made sure that XSD was attached and available when the service was XML.  This made it easy to write JAXB clients if your consumer was another Java application.  Slowing down development by forcing homogeneous consumers to parse the response as DOM seems like a likely outcome of not having SOME way of addressing this issue.

Taken together, I’m on board with the idea that JSR-311 could be a good foundation for a web framework that treats the client as being smart, rather than the dumb terminal approach of the past.

PHP Prado, Yii, and Building UI Architecture in the Right Place

I’ve been spending a minuscule amount of time as of late scrutinizing PHP frameworks – largely because it’s so damn difficult to build anything that can be deployed to a cheap hosting provider in Java or .Net.  In my travels these last few years, my conclusion is that Java is just terrible at handling web UI architecture and that the servlet architecture is horribly broken.  But you already knew that.

ASP.Net is fascinating in that it really tries to port good classic MVP modeling to a web architecture.  But we live in a world today that needs two models of web application development – one that focuses intently on transactional operations and can adhere to the infrastructure that ASP.Net or even Java Server Faces provide, or one that is totally dependent on the faclities of the browser.  Where Microsoft and Sun/JBoss/OSS have gone totally off the deep end is in the latter case by trying to solve client side issues on the server.

So I looked at PHP Prado the other day, and saw that it’s more or less a direct port of the ASP.Net architecture.  Fair enough.  I can’t see how it can be performant or scale – it’s taking the pig of ASP and adding a significant hassle in backing it with a scripting language.  But as I dove deeper and tried to find out how it supported AJAX, I saw that it made the same mistakes that ASP and JSF had made by trying to adapt the server-supported client UI architecture into a model where the server really had very little to do with the presentation.

I’m now off and looking for a PHP framework that doesn’t attempt to solve the problem in this way.  Microsoft has already figured out that it’s incredibly complicated to accomodate both paradigms of web development throug a UI architecture that was initially developed to run from the server and has built ASP.Net MVC and WCF to support a model where the coupling is much looser.  Maybe someday, Java will get it (though I will cop to not knowing what people in the Spring world are doing, and they tend to be a bit ahead of the curve in these matters).  I’m now looking at PHP Yii, and it looks like another dreaded rails-inspired framework.  However, if it’s not trying to boil the ocean with complex UI architecture and tell the browser to handle things as it may, perhaps I can be won over to the rails-religion yet.

Simplifying XML-based RESTful services in Elgg

elgg is a PHP-based social networking wonder that we’ve been using at Medullan for some internal stuff lately.  One of my interests was to see what type of tooling could be built around it – desktop widgets, firefox extensions, etc.  It appeared they had a RESTful API of sorts, but the service results were always rendered through the standard HTML view.  Everything I found seemed to say I was stuck with this.  Not so.

If you attach a querystring parameter to your request called view, elgg will output your RESTful service result to any of the supported formats – HTML, XML, JSON, FOAF, etc.

So if I have a method called “print” exposed as documented by elgg, I can have the result returned to me as XML very easily:

http://localhost:8080/elgg/pg/api/rest?method=print&view=xml