Archive for the ‘Java’ Category

Echo2: how to log users out and close their session

Tuesday, December 26th, 2006

The nicest thing about Echo is that is abstracts you from the “page” thing and makes you quickly forgot that you are actually inside a web environment.

Anyway you can’t forget your environment as it influences your design and code decisions.

This is the case of session invalidation and logout actions. I’ve written a small page on the nextapp wiki and I want to propose it here for the search engines’ sake :)
So: how do you log your users out and invalidate their sessions? As always, it depends on what you need to achieve.

The easy and quick way
As you know, Echo2 applications state is synchronized with the model stored into each user’s session. So, if you just want to force the user to start from the beginning, changing the screen will be sufficient

ApplicationInstance.getActive().getDefaultWindow().setContent(new WelcomeMessageScreen());

In no way the user will be able to interact with previously rendered components, so security is safe.

Advantage:

  • quick: you could already have a “welcome” screen, so “closing” your application is just the line above

Disadvantage:

  • the session is still open

The servlet way
If the easy way is not enough because you want to invalidate user’s session as soon as the user logs out, you may implement a short servlet.

public class LogoutServlet extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + “/”);
}
}

Note: you can’t invalidate the session INSIDE the Echo application, because that will cause a “session expired” message; you need to invalidate the session outside the application. Although it may look weird, it’s actually better as your application SHOULD NOT know in any way that it is running inside an “servlet container” (because Echo abstracts you from that). Having a “Logout Servlet” does not solve the problem, but isolates the session invalidation logic into a known, separate place.

Advantage:

  • more control: session is invalidated programmatically.

Disadvantage:

  • the above code may look reusable, but what if you need to dispose other resources as well? Read on

The servlet + session listener way
Suppose you also need to log how long a session lasted and/or to dispose other resources and/or to do something else when a user logs in and out.
Then you need to implement the interface !HttpSessionListener and to register it into your servlet container.
An empty one looks like:

public class MySessionListener implements HttpSessionListener {
private static final Log log = LogFactory.getLog(SessionListener.class);

public void sessionCreated(HttpSessionEvent arg0) {
log.debug(”new session created”);
}

public void sessionDestroyed(HttpSessionEvent arg0) {
log.debug(”a session was destroyed”);
}

}

Code the two methods according to your needs. As you may have noticed, the “logout servlet” may be reused quite easily, while the above listener may be more specific to your application.

Advantage:

  • total control: forget for a while the beauty of Echo abstracting you from the web thing and brush up your servlet knowledge

Disadvantage:

  • more code to write and maintain

I usually go with the third method, leaving the listener empty until I need it. The cold face of the hammer of gold looks at me, but I don’t care about such a tiny piece of code

Echo2: impressive!

Sunday, December 17th, 2006

As you may know, I had a talk at JUGMilano about Echo2.

To show the juggers some of the Echo capabilities, I’ve built Echo2Impress, a simple echo application that shows slides, just as OpenOffice Impress does.

Ah! How cool it was to present Echo with Echo! :)

If you want to give Echo a try or if you are just curious about it, take a look at Echo2Impress and its blank presentation project.
Hope you like it ;)

Echo2: an enterprise app review

Wednesday, November 29th, 2006

Following two posts on the echo2 forums, Matt Brooks has written a nice review about his experience using a stack made of Echo2, JBoss, EJB3 and ServiceMix ESB.

Matt’s app seems really cool. Its loading page is the cooooooolest thing ever seen so far in the ajax multiverse!

Taken from the architectural point of view, it’s a nice reading especially because I’ve heard too many “w00t!”s while I’m not aware of any good enterprise application (but Google’s, of course).

I haven’t looked for them actually, but I think I should have heard of them, at least from the javaposse guys, who are well aware of RIAs (as one of them is from Google and as they’ve interviewed the GWT team).

Am I wrong? Or blind? Or this ajax plane is actually taking too much time to take off?

By the way, even my two apps are going to be released in the next few months. But they won’t be public. Argh! I wanna go public!

Echo2 speech @ JUG Milano

Wednesday, November 22nd, 2006

On December, the 5th, I’ll have my very first public speech!! I’m very excited about that. I’m even worried, actually.

I’ve just completed a draft of the slide show. Although a very busy period, I’ll hope to have time to add some more info about the projects related to Echo2 such as HSE, the Extras and EchoPointNG.

So: do you have a dinner planned for the 5th of December? No? Do you want to learn something more about JSF (by Michele Sciabarrą) and Echo2? Do you like pizza? :)

Hurry up! Get the details!

I’m onto the Gentoo train

Sunday, October 22nd, 2006

With the struts-1.3.5 ebuild, nichoj offered me access to the Gentoo java overlay.

An overlay is an alternative branch of the official portage tree, where experimental ebuilds are made available to testers and people in a hurry to use an application or have a library.

Of course, “happy” is not a word worth describing my pride.

There are still a LOT of things I have to learn. But I got the patience: hope my team mates have enough of it, too.

Echo2: web apps like desktop apps

Friday, September 15th, 2006

Echo2 is a wonderful graphical toolkit that lets you create web applications giving them the look of the traditional desktop ones. Its API is very similar to the Swing one: indeed you can consider it a web-oriented subset of Swing.

I was told (that’s an italian programmer’s experience) that the customer will never see nor understand the difference between a desktop application and your Echo2 + Tomcat + browser combo (his customer believes that’s Visual Basic).

The system requirements are the only someway negative aspect of Echo: you will need at least Firefox from version 1.0 or Internet Explorer version 6. Anyway, if your customers run IE6 they won’t ever enjoy some graphical features because the browser is not capable of rendering them. PNG transparency in particular. IE7 seems to render PNG correctly (finally!). Check it using Browsershots.

The first thing you need is the Echo2 framework itself. The upcoming version 2.1.0 has introduced many improvements and it is the base for the Echo2 Extras package. The main classes of the Extras package are the menu bar pane, the accordion pane and the tab pane.

The community has then release EchoPoingNG, a set of additional components (mainly extensions of the official ones) with many interesting features. The drop down calendar is my favourite!

If you run Gentoo, I’ve just submitted three ebuilds for:

Check them out!

Which java? 4-5-6?

Monday, April 3rd, 2006

While GNU Classpath is finally reaching its first release, Sun has recently released the 2nd beta of Mustang - Java 6.

For what I know, most and major applications (I’m talking about banking apps) still runs on Java 1.4, so it’s still worth developing with it.

If you were to choose the Java version of your next webapp or client, will you choose Java 5 (maybe hoping and waiting for Harmony), will you prefer 1.4 (planning to develop it with Classpath) or will you get yourself “on the edge” and use the latest build of Mustang?

I would prefer 1.4 as I don’t feel to trust Harmony that much…

I fear Sun is mistaken

Saturday, December 3rd, 2005

Surely you read a lot about new Sun’s marketing show.
Let’s go to the source of the news. Sun.com shows a big banner stating “Free and Open Source Software: Sun announces […blah…blah…] software with Solaris at no cost“.

Let’s forget for a moment that “free” that at the beginning could mean FOSS but in the end means “gratis” and therefore confuses who must still understand the difference.

I see the following scenarios:

  • Think of you as a business company: whatever you think about free(dom) software, probably its cost is not a problem.
    Usually that money is part of the project budget.
    So you won’t be interested.
  • Now think of you as a student who knows nothing about free(dom) software. You are probably used in using cracks and keygens to enable your illegal software copies. And you are proud of that.
    So you won’t be interested.
  • Now think of you as a fellow. That software could be gratis, but it’s not free(dom). You already have similar softwares and they are free.
    So you won’t be interested.

So, now: where is Sun going? Who could be interested?
Let me say: I really think of Sun as one of the biggest friend of free(dom) software between large business companies.
But they are talking about money, not about features, nor about reliability, nor about interoperability, nor about extendability…

I really fear they hope to gain fame and respect from an inexistent community that uses its software just because it’s gratis, without even asking if it is free or not.
I really fear their huge investment will just be forgotten in a couple of months.
I really fear we’ll lose a friend and I hope I’m mistaken.