PDA

View Full Version : Accessing the PHP Session from a Servlet/Bean


domdorn
05-30-2010, 10:26 PM
Hi,

I need to access the PHP Session from a Servlet/Filter.
Basically I need to set two values
and in another case I have to invalidate these values/destroy the php session.

the PHP code would be

$_SESSION["userId"] = 5432;
$_SESSION["username"] = "domdorn";

and

unset($_SESSION["userId"]);
unset($_SESSION["username"]);

how can I do that in Java in a filter?

domdorn
06-10-2010, 02:15 AM
Ok, I've got it working after HOURS of work, debugging & reverse engineering.
The key was to copy the QuercusServlet and expose the QuercusContext as a Attribute in the ServletContext so its accessible in Servlets, Filters, etc.

I simply added
config.getServletContext().setAttribute("quercusContext", quercus);
on line 573 of QuercusServlet.

I will blog about the exact things I've done, but it would be really a good idea to think about how to make quercus more open. Declaring stuff protected / private is fine, as long as you at least provide some getters...

sblommers
06-10-2010, 10:09 AM
Good work man! (but reverse engineering? :D)
Isn't the context exposed as of version 4.0.7+?

Best regards,
Sebastiaan

domdorn
06-10-2010, 12:28 PM
>(but reverse engineering? )
a lot of digging through the code etc.
> Isn't the context exposed as of version 4.0.7+?
at least its not documented somewhere... at least not somewhere I could find it!
If you know how to get access to it, please tell me.

domdorn
06-10-2010, 04:08 PM
blog post ready:
http://dominikdorn.com/2010/06/access-quercus-php-session-from-java-servlets-filters-beans/

any comments appreciated :)