June 10, 2010

Using Vaadin with embedded Grizzly

Grizzly is a framework for building fast and incredibly scalable server applications. It takes advantage of the new Java IO API (NIO) and offers an extended framework for web applications, which includes an embeddable Servlet container.

Vaadin is a Rich Internet Application technology built on top of the Google Web Toolkit. Vaadin Applications run within Servlet Sessions. As such they are very easily deployed in just about every Servlet Container. So, it should be possible to deploy it in an embedded Grizzly Servlet Container.

And that is exactly what I did. I used Grizzly 1.9.18 and Vaadin 6.3.3.

The source code below shows how it's done:

GrizzlyWebServer grizzly = new GrizzlyWebServer();
ServletAdapter sa; 
String servletClassName = "com.vaadin.terminal.gwt.server.ApplicationServlet";
try {
    Servlet s = (Servlet)Class.forName(servletClassName).newInstance();
    sa = new ServletAdapter();
} catch (...) {
sa.addContextParameter("productionMode", "false");
sa.setProperty(ServletAdapter.LOAD_ON_STARTUP, "1");
sa.addInitParameter("application", "my.domain.MyApplication");
grizzly.addGrizzlyAdapter(sa, new String[]{"/MyApp","/VAADIN"});

I have marked 4 important lines in the code:
  1. the line where the root folder is set;
  2. the line where the context path is set;
  3. the line where your Vaadin application is deployed;
  4. the line where the ServletAdapter instance that contains your Vaadin application, is deployed within Grizzly.
The root folder must be set to the folder that contains the Vaadin Web library. Vaadin also requires you to specify a servlet mapping that maps * (all files) in the servlet's context folder to your application (when configured with web.xml you would need to add a servlet-mapping element). Grizzly does not support servlet mappings yet. You can only map all files ("*") in the context folder of the servlet to a servlet instance. Fortunately, that is all we need. That's why the context folder of the Vaadin Servlet containing your Vaadin application is explicitly set to folder "MyApp".
The third line I marked instructs the Vaadin Servlet to load your Vaadin application class. I guess I don;t need to explain why that is important.
Finally, on the last line, the Vaadin Servlet is deployed on the embedded Grizzly Server. It is essential that you add the string "/VAADIN" to map the path /VAADIN (which is used the Ajax application that the java code of your Vaadin Application is rendered to by the Google Web Toolkit) to the Vaadin widgets and themes that are inside the Vaadin Web library.

Vaadin runs great inside Grizzly. It allows for building fast and rich user interfaces that run in a browser in embedded environments (such as the dashboard of a car, for example). You could build embedded systems that can be controlled through a standard web interface.

As for the image at the top: I combined the logo of Grizzly with the Vaadin Logo, which I rotated 90 degrees so I could fit it on the poor bear's face. It does make the bear look like an owl, doesn't it? That bear suddenly looks a lot smarter. I hope the designers of the logo's don't mind my playful joke here.

I am using Grizzly and Vaadin to build an HTTP proxy server that runs on your desktop. This proxy server can be used to filter web content, but also to monitor and analyze HTTP traffic sent from and received by your desktop. Vaadin provides a wealth of rich UI widgets (trees, grids, charts, you name it) I can use for that purpose. And Grizzly provides an easy and very fast way for me to embed a thin web application layer on my proxy server. I have named my little pet project "Yapser" (Yet Another Proxy SERver) and made it open source from the start. My project is hosted on Google Code: http://code.google.com/p/yapser/. If you feel like participating, you're more than welcome of course!

June 08, 2010

How did the homo sapiens get extinct? Because of Type n Walk...

As a species, we are doomed. A couple of decades, and that's it. We're done for! Here's the explanation:

The life styles of the current and next generations will become more and more dependent on being online and on being in constant touch with other people through social media. Work and private life will get more and more intertwined. Office hours will disappear. We will probably develop stronger legs because we will always be on the go, and develop stronger multitasking abilities (women have have an advantage on men for that matter...).

City population will get denser and denser, as will the city traffic. Taking part in traffic will become ever more dangerous. Taking the above mentioned human species developments into account, we will be taking part in traffic while interacting with friends, colleagues, shops, et cetera. Do you catch my drift?

The iPhone app "Type n Walk" will hardly reduce the risk. I believe it will even speed up our extinction. According to the NY Times article (see link above), Finland is installing crossing signals in the street so they are visible to people looking down... The Fins will go extinct first.

Now, Unless the gadgets and online services we are getting so dependent on will really get smart in the sense that they can intelligently and autonomously act on behalf of us and that they can be controlled by thought in stead of by index finger we may have a chance of surviving our own stupidity.

Posted via web from Mark's odds 'n ends