views:

117

answers:

2

Hey guys,

I have a GWT application which I would like to run from within a Joomla layout. The concept seems to work fine and the application loads up correctly. Joomla uses an iFrame to achieve this and just sends off the url which will kick start the GWT application.

The issue I am having is that I require certain information from Joomla, which I pass as parameters in the url. Since a GWT application starts up from an HTML page, giving me no way to access those parameters, I am instead firing off a request to a Servlet, the idea being that I can grab those parameters, save it in the session and then serve the GWT applications HTML page.

The concept works fine. I grab the parameters, put them into a map, that map goes into a basic bean and I store the bean as a session attribute with the code:

request.getSession().setAttribute("sessionBean", sessionBean);

The Servlet then serves out the GWT HTML page, which in turn loads up the application, and the first thing it does is fire off an RPC call. The issue I am having is in my RemoteServiceServlet handling that call, I attempt to fetch my SessionBean with the following code:

SessionBean sessionBean = (SessionBean) this.getThreadLocalRequest().getSession().getAttribute("sessionBean");

I get null, and looking closer realise that it has in fact created a new session. I know this by comparing the id's of the two sessions. Any subsequent further RPC calls all have access to the last session but the one I stored my SessionBean in is gone!

It is all one deployed war file, cookies are enabled, and it acts this way both in development and production mode.

I figure I am probably misunderstanding the way sessions are handled! Any ideas as to why the GWT RPC call creates a new session? Or maybe if I am going about this completely wrong, how to get these needed parameters into a session?

Any help or ideas will be greatly appreciated!

Thanks in advance!

Xandel

+1  A: 

In gwt you can get the url-parameters by:

Window.Location.getQueryString()
pathed
Ha! As easy as that! :) Thanks very much pathed! As for the new session situation, although I don't need to bother about it now do you maybe have any ideas why it wasn't working? Thanks again!
Xandel
Of what i can see there shouldn't be any problem with your sesssion, maybe it is configure wrong. Firefox has a good tool to view cookies named "Web Developer", there you can se if you get your session-cookie.
pathed
A: 

Hi Xandel, I have the same problem, the session created at the beginning is different that the one used when doing a RPC Call.

This is a filter that filters everything (filetr-mapping = /*). It will create a timer if it's null in the session or reschedule it if it's not null to handle session timeout.

First Request to the web application gives me a session with an id = some string.

First request with a RPC call gives me a different session that will be used during the rest of the time for the user.

Do you have any idea how to handle this? Thanks a lot

@Override

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) req;
HttpSession session = httpRequest.getSession();

Timer t = (Timer) session.getAttribute("SESSION_TIMEOUT_TIMER");
if (t == null) {
    synchronized (session) {                    
        t = (Timer) session.getAttribute("SESSION_TIMEOUT_TIMER");
        if (t == null) {
            t = new Timer()
            ...
        }
    }
} else {
    ...
}
chain.doFilter(req, res);

}

Arthur
Actually, I'd like to use the same sessionid for both the filter and the RPC Calls. Do you have any idea to tell RemoteService from GWT to use a specific jsessionid?
Arthur
Hi there Arthur, trying to jog my memory on this - GWT's RPC calls seemed to handle their own session almost separately from normal requests. I avoided this by ONLY using RPC calls to my server from my application. Do you have to have that initial non-rpc request?
Xandel