You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Vinicius Carvalho <vi...@gmail.com> on 2006/08/31 02:28:46 UTC

Exception not being caught by engine

Hello there (my other email java.vinicius@gmail.com is under maintenance for
over 3 days now...).
I've built a chat system using Tapestry and Spring (thanks to all the help
I've got here), and now I'm just giving it the final touch. I'm not being
able to capture an exception on my service, I'll try to explain my
architecture in the best way my bad english can :P

I have a ChatServer class which handle all the rooms on the system. This
class is managed by spring, so it's a Stateless class. I have created an
Tapestry Engine Service, to handle ajax submissions, it's called
ChatListenerService (and it is used by the ChatListenerComponent), its main
responsibility is just to trigger the listener associated to the component
get the response (a list of messages) and render it in xml: here's a
snippet:

  try{
            chatListener.trigger(cycle);
            Object[] args = cycle.getListenerParameters();
            messages = (Collection)args[0];
        }catch(ChatServerException e){
            WebSession session = cycle.getInfrastructure
().getRequest().getSession(true);
            session.invalidate();
            ErrorMessage message = new ErrorMessage();
            message.setCause(e.getMessage());
            message.setRedirect(Boolean.TRUE);
            messages = new ArrayList();
            messages.add(message);
        }
        PrintWriter writer = response.getPrintWriter(new
ContentType("text/xml"));
        response.setHeader("Cache-Control", "no-cache");
        String xml = generateMessageOutput(messages);
        writer.write(xml);
        writer.flush();

I think this is pretty straight forward. I try to call the listener, if it
throws an exception, I invalidate the user session, and put an error message
for it (the client side handles message types: User, Error and System).

My Page listener is as simple as this:

public void onMessageReceive(IRequestCycle cycle){
        try{
            cycle.setListenerParameters(new
Object[]{getChatServer().deQueueMessage(getUser())});
        }catch (ChatServerException e) {
            logger.error(e);
            throw e;
        }
        getUser().setLastRequest(Calendar.getInstance());
    }

once again pretty straight, I have ChatServer injected on my page, it
dequeues all messages from it from the given user, and set it on the request
cycle.

Now, what's strange is that, the exception never reaches the
ChatListenerService. I have some logging that I've omitted there, that shows
the step by step when on debug mode, and I get service -> onMessageReceive
-> catch block from page, but not the catch from the engine.

The exception is a subclass of RunTimeException. I was wondering that could
be some kind of Tapestry's proxy feature of how dealing with exceptions or
something like that.

Does anyone has any idea of what could be avoiding the exception to be
caught?

Best Regards