Wednesday, August 29, 2007

[Arch] What is an ESB?

Well, good question. Dealing with a lot of middleware technologies in the last month, I was trying to get a clean description about what an ESB actually is. What is e.g., the conceptional difference between Mule and Service Mix (not to mention about the commercial products like Tibco and Sonic)?

You can actually get an impression, when you read what they write about the other projects respectively, e.g.:
We even get some nice side-blows like: "so if you already have an investment in some Mule configuration or code, you can reuse it inside ServiceMix along with any other JBI components". Good to know, that I can operate Mule within Service Mix, whatever might be the reasion I would want to do that. If we still do not know what an ESB is, and what we would use it for, I recommend the talk of Mark Richards:

Mark Richards poses the question: is it a
  • Pattern?
  • Product?
  • Architecture Component?
  • Hardware component?
Well, maybe all of that, check out his nice video presentation. In this talk he gives some general ideas and also talks about the two mentioned Open Source competitors, SOA, decoupling and all the other nice buzzwords.

Monday, August 27, 2007

[Tech] Combine Hibernate and Wicket

In the previous post, Alex gives an overview about Wicket and what advantages and disadvantages this component based framework has. The majority of web applications are very data intensive, where simple CRUD (Create, Read, Update, Delete) operations needed. Apart from this, many software projects use the popular ORM (Object Relational Mapping) Tool Hibernate in association with annotated domain objects. Such a tool close (or better "try" to close) the gap between the object oriented world and the relational world. To combine these two different worlds is not a trivial task. Consider object oriented appraches like inheritance, polymorphism and other points.

Back to the blog issue! Wicket is an component oriented web framework, commemorating on Swing. On the back end you have Hibernate, often used to implement the DAOs in an application. Currently finished a data driven web application, using Databinder, a simple bridge from Wicket to Hibernate. As a classical MVC framework, Wicket uses models in order to populate data in forms and vice versa. What are the most uses cases of data driven solutions:
  • Show a list of data
  • Filter a list of data
  • Show details of data
  • CRUD operations of objects
  • and some other features
Databinder is a library providing different types of wicket models and view components enables an easy Hibernate integration. For example a data form, containing a number input components for the user and a submit button. Submitting the form entails a model update in the database out of the box. Another use case is to set up a query (Hibernate Query) to receive a list of objects. The list is wrapped in a HibernateListModel which can be populated in an easy way. In order to illustrate the main functionality of databinder, consider the following code snippet, taking from the databinder examples.
@Entity
public class Graffito implements Serializable {
private Integer id;
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}

Each databinder application must provide an implementation of the DataApplication, which enhances the WebApplication object from wicket. Databinder must know about the managed annoated data objects, by add all annotated classes to the applicaiton.
public class GraffitiApplication extends DataApplication {
@Override
public Class getHomePage() {
return TheWall.class;
}

@Override
protected void configureHibernate(AnnotationConfiguration config) {
super.configureHibernate(config);
config.addAnnotatedClass(Graffito.class);
}
}

Now databinder is ready to use and manage your domain objects in components, like DataForm, DataPanels, Tables and the like. The following code snippet provides a data form to display domain object details.
    public class MyForm extends DataForm {
public MyForm(String id) {
super(id, Graffito.class);
add(new TextField("text"));
@Override
protected void onSubmit() {
super.onSubmit();
clearPersistentObject();
setResponsePage(OrderList.class);
}


Databinder provides a HibernateListModel enables the developer to create list models by using the powerful Criteria API of Hibernate or Hibernate Query Language. The generated list model can then be populated in a list, by using property list view for instance.
IModel lastFive = new HibernateListModel(Graffito.class, new ICriteriaBuilder() {
public void build(Criteria criteria) {
criteria.addOrder(Order.desc("id")).setMaxResults(5);
}});

// show previous scrawls in list
add(new PropertyListView("graffiti", lastFive) {
@Override
protected void populateItem(ListItem item) {
item.add(new RenderedLabel("text", true)
.setFont(spidershank)
.setColor(orange));
}});
The aim of this blog was not to introduce in databinder, rather I want to give a short overview of an interesting integration library between wicket and hibernate.

Tuesday, August 14, 2007

[Tech] Wicked Wicket

In the last years, the "market" of Web-frameworks was probably the most active one. I know hardly any other domain, where we can find such a number of different frameworks and tools. There are probable hundreds of different web-frameworks out there; just the Apache Software Foundation has: Struts, Tapestry, Cocoon, Wicket, Turbine (? never knew what this is good for), myFaces. So about 6, if I have not forgotten anything, plus a wide range of subprojects dealing with specific problems or providing taglibs or components.

So what to choose?

Actually it seems, that there are three streams of framwork concepts:
  • The "traditional" ones based on JSP (or PHP alike), HTML; i.e., more or less extending JSP like Struts or building upon template engines like Velocity
  • Special-purpose frameworks like Cocoon, that have a stronger focus on XML processing or content management
  • Application-oriented frameworks like Google Web Toolkit or Apache Wicket.
I recently had a look at the "new kid on the block" Wicket, that is recently graduated from the Apache incubator:

The general idea of Wicket is to provide a very clean separation between html/css presentation layer and application logic. As a consequence each "webpage" is a duo of one html page and one Java class. The Java class looks a little bit like a Swing class, in the sense, that visual components are initialised and assembled like in a Swing project. One could create a text-box and put it into a form component for example.

However, the concrete visual appearence is controled by a html document aside, in which html code is used with wicket id-attributes that reference to the Java code. The consequence is, that the html code is pretty clean, there is actually no logic in it, and the complete logic in in Java classes. Wicket also abstracts from the Servlet session, so that the developer never needs to actually touch the "naked" Servlet API.

Additionally Wicket has a lot of additional features like a validation framework, support for authorisation and authentication and the like. Wicket is additionally very Java-oriented, meaning that there is hardly any (XML) based configuration required to get a Wicket application up and running.

That said, the documentation is currently problematic and rather "example-driven". Also the examples are not particularly well documented and partly difficult to understand. Also to website and wiki is rather confusing from my point of view.

To get started I suggest to check out:
  • First check the Homepage. Unfortunately information there is rather brief. Also the examples are only a small extract of the actually available examples
  • Download the recent Wicket distribution or get it from the SVN. IN the distribution you also find a large number (of hardly documented) examples
  • The Framework documentation is an index about documentation on the Wiki.
  • The Wicket Tutorial (Platinum Solutions)
  • Wicket Javadoc
  • Additionally I highly recommend the Maven 2 archetype from the Jetty group to get started. I explained that in a recent post.
  • Additionally Wicket in Action is on the way for the patient ones.
My first impression about Wicket is a quite good one, however there are issues, that make me a little bit doubtful: one thing is the fact, that Wicket keeps a quite "fat" session, which might make problems with scalability.

On the conceptional level however, I am not sure if I like the HTML/Java duo with each page. Somehow I feel it is odd when I write something like this (from the Wicket documentation):



Why do I have to write additionally a html document then, where these two components appear again like so



Quite redundant, isn't it? In the Java class I made already clear, that I want a form and a text-field, so just render it!

I see that this attempt gives a lot of freedom how to render webpages. I am not sure though, if the better strategy in many cases might be to stick to the Swing concept of "Layout Managers". I.e. to refer to the example before: A layout manager (that I can select and customise) decides how the components are arranged on the page. As far as I see it, this is the strategy of the Google Web-toolkit. This approach avoids the beforementioned redundancy by also providing a clean separation between logic and presentation layer.

Comments anyone?

:-)