0

How to find the desktop id for current request from a servlet filter

asked 2011-03-02 08:42:52 +0800

martinso gravatar image martinso
15

Can this be done? The Executors class does not seem to work here.

/Martin Söderström

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2011-03-02 09:27:24 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

As far as I know, that's impossible because ZK hasn't even started processing the request yet when your filter is invoked (ZK uses a Servlet, so it starts processing the request only after all filters have finished).
You didn't mention the use case for your filter, but you might want to consider using ZK listeners instead.
If you implement ExecutionInit and/or ExecutionCleanup you might be able to do what you want.

Note that Execution is the ZK equivalent of a HTTP request.

link publish delete flag offensive edit

answered 2011-03-02 09:36:25 +0800

martinso gravatar image martinso
15

The request I'm interested in could for instance be a button click event request from the client. So I'm thinking that I can safely assume that there is a deskop associated with the request. My idea is that the information in the request must be enough to locate the desktop id since ZK is able to do further down the "request filter / servlet chain". Either the data can be located somehow from knowing the session id, or it is embedded in the request in some other form, was my reasoning. Does this make sense?

link publish delete flag offensive edit

answered 2011-03-02 09:40:03 +0800

martinso gravatar image martinso
15

Basically, the use case we have is that have parts of the client web page that is completely outside of ZK (using other web technologies) but that we want to somehow "align" with the ZK part of the page on a per desktop basis.

link publish delete flag offensive edit

answered 2011-03-02 09:47:55 +0800

martinso gravatar image martinso
15

Aha, now I see a dtid parameter in the POST request. This might be just what I'm looking for.

link publish delete flag offensive edit

answered 2011-03-02 10:10:33 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

Ok, I assumed you wanted to actually modify the desktop.

You are correct, dtid is the desktop id parameter. However, just because it exists doesn't mean that a valid desktop exists.
If you want to ensure there is a valid desktop available for the request, here's how to do it:

HttpSession httpSession = ... // get it from somewhere
ServletContext servletContext = ... // get if from somewhere
String desktopId = ... // read it from dtid parameter

WebApp webApp = WebManager.getWebApp(servletContext); // You don't have to do this in every request, you can read webApp in Filter.init
Session zkSession = SessionsCtrl.getSession(webApp, httpSession);
if (zkSession != null) {
  if (zkSession instanceof SessionCtrl) {
    SessionCtrl sessionCtrl = (SessionCtrl) zkSession;
    Desktop desktop = sessionCtrl.getDesktopCache().getDesktop(desktopId);
    if (desktop != null) {
      // Now you know you have a valid desktop and session for this request
      // Remember that modifying the desktop is NOT safe
    }
  }
}

Note that you cannot modify the desktop safely, so by using this method you can only check that you have a valid desktop.

If you actually want to change something or interact with the desktop, you'll have to use UiEngine updates. But that is very error prone and I really think it's a bad idea unless you know exactly what you are doing. Especially because you would be effectively doing two ZK updates in one HTTP request (one in Filter, one in Servlet). I've implemented a Servlet 3.0 API asynchronous server push using manual UiEngine updates (without the regular ZK server push), so I know from experience that it can be very difficult to get things like that work without problems.

link publish delete flag offensive edit

answered 2011-03-02 10:32:10 +0800

martinso gravatar image martinso
15

Thanks for that thorough explanation, gekkio. I will not try to modify the desktop from the filter, all I want is way to pair ZK requests from a certain browser tab with other XMLHttpRequest request from the same tab but generated from the other web framework on the page (acutally also a server push implementation :)).

Anyway, thanks a million for taking your time.

/Martin

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-02 08:42:52 +0800

Seen: 444 times

Last updated: Mar 02 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More