PDA

View Full Version : Java PHP session sharing


eneset
03-18-2011, 08:10 AM
I can access Java session from PHP.

Is there a way to access PHP session data from Java code running in the same WAR as Quercus?

Thanks in advance.

Egor.

domdorn
03-18-2011, 10:41 PM
I blogged about this some time ago
http://dominikdorn.com/2010/06/access-quercus-php-session-from-java-servlets-filters-beans/

however, you'll have to take special care of not getting in a deadlock.. I have this code somewhere and its deadlocking all few days, so I'm restarting the java server every day and it works.

it's probably not best practice but it works.

eneset
03-19-2011, 02:57 AM
This post is a first thing that I found in Google :)

It is a bit of a hack. Is there an official way?

I am trying to give birth to a monster. Grails app running on
Tomcat using third party commercial PHP application for
user management, recurring payments and affiliate program.

eneset
03-19-2011, 03:48 AM
This was easier than I thought.

PHP applications usually have one common include file with
config. So, I just inserted the following code in this include
file:

$session = quercus_servlet_request()->getSession(true);
$session->setAttribute("_SESSION", $_SESSION);

Now all I need to do in Java is to call:
session.getAttribute("_SESSION")

domdorn
03-24-2011, 06:37 PM
there will be an java api for accessing php sessions, but not in the near future.

glad it worked with your solution!

Dominik

sinoea
10-31-2011, 10:57 PM
Hi there,
I get a java.lang.ClassNotFoundException: 'org.apache.catalina.session.StandardSession'...
when I use the following code in my PHP files:
$session = quercus_servlet_request()->getSession(true);

I then refresh the browser and everything works fine, but what is the problem actually?
I shouldn't have to refresh the browser to make it work, I must have missed something.

I am using Tomcat5.5, Apache HTTP 2.2 and Java 6.

Here below is the error message:


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

com.caucho.quercus.QuercusRuntimeException: java.lang.ClassNotFoundException: 'org.apache.catalina.session.StandardSession' is not a known Java class: java.lang.ClassNotFoundException: org.apache.catalina.session.StandardSession
com.caucho.quercus.module.ModuleContext.getJavaCla ssDefinition(ModuleContext.java:324)
com.caucho.quercus.marshal.MarshalFactory.create(M arshalFactory.java:254)
com.caucho.quercus.marshal.MarshalFactory.create(M arshalFactory.java:78)
com.caucho.quercus.env.JavaInvoker.init(JavaInvoke r.java:251)
com.caucho.quercus.env.JavaInvoker.getHasRestArgs( JavaInvoker.java:305)
com.caucho.quercus.env.JavaOverloadMethod.overload (JavaOverloadMethod.java:76)
com.caucho.quercus.env.AbstractJavaMethod.overload (AbstractJavaMethod.java:99)
com.caucho.quercus.program.JavaClassDef.introspect (JavaClassDef.java:932)
com.caucho.quercus.program.JavaClassDef.init(JavaC lassDef.java:858)
com.caucho.quercus.QuercusContext.getJavaClassDefi nition(QuercusContext.java:857)
com.caucho.quercus.env.Env.getJavaClassDefinition( Env.java:4542)
com.caucho.quercus.env.Env.wrapJava(Env.java:4720)
com.caucho.quercus.env.Env.wrapJava(Env.java:4680)
com.caucho.quercus.marshal.JavaMarshal.unmarshal(J avaMarshal.java:107)
com.caucho.quercus.env.JavaInvoker.callMethod(Java Invoker.java:739)
com.caucho.quercus.env.JavaOverloadMethod.callMeth od(JavaOverloadMethod.java:179)
com.caucho.quercus.program.JavaClassDef.callMethod (JavaClassDef.java:658)
com.caucho.quercus.env.JavaValue.callMethod(JavaVa lue.java:327)
com.caucho.quercus.expr.AbstractMethodExpr.eval(Ab stractMethodExpr.java:97)
com.caucho.quercus.expr.ObjectMethodExpr.eval(Obje ctMethodExpr.java:97)
com.caucho.quercus.expr.AbstractMethodExpr.evalCop y(AbstractMethodExpr.java:63)
com.caucho.quercus.expr.BinaryAssignExpr.eval(Bina ryAssignExpr.java:88)
com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
com.caucho.quercus.env.Env.executePage(Env.java:39 40)
com.caucho.quercus.env.Env.include(Env.java:5421)
com.caucho.quercus.expr.FunIncludeExpr.eval(FunInc ludeExpr.java:90)
com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
com.caucho.quercus.env.Env.executePage(Env.java:39 40)
com.caucho.quercus.env.Env.include(Env.java:5421)
com.caucho.quercus.expr.FunIncludeExpr.eval(FunInc ludeExpr.java:90)
com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:84)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:84)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
com.caucho.quercus.env.Env.executePage(Env.java:39 40)
com.caucho.quercus.env.Env.include(Env.java:5421)
com.caucho.quercus.env.Env.includeOnce(Env.java:53 74)
com.caucho.quercus.expr.FunIncludeOnceExpr.eval(Fu nIncludeOnceExpr.java:92)
com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.statement.IfStatement.execute(I fStatement.java:84)
com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
com.caucho.quercus.env.Env.executePage(Env.java:39 40)
com.caucho.quercus.env.Env.include(Env.java:5421)
com.caucho.quercus.expr.FunIncludeExpr.eval(FunInc ludeExpr.java:90)
com.caucho.quercus.expr.Expr.evalTop(Expr.java:523 )
com.caucho.quercus.statement.ExprStatement.execute (ExprStatement.java:67)
com.caucho.quercus.statement.BlockStatement.execut e(BlockStatement.java:105)
com.caucho.quercus.program.QuercusProgram.execute( QuercusProgram.java:413)
com.caucho.quercus.page.InterpretedPage.execute(In terpretedPage.java:89)
com.caucho.quercus.env.Env.executePageTop(Env.java :3951)
com.caucho.quercus.env.Env.executeTop(Env.java:389 2)
com.caucho.quercus.servlet.QuercusServletImpl.serv ice(QuercusServletImpl.java:188)
com.caucho.quercus.servlet.QuercusServlet.service( QuercusServlet.java:594)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :96)
org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
org.tuckey.web.filters.urlrewrite.RuleChain.handle Rewrite(RuleChain.java:176)
org.tuckey.web.filters.urlrewrite.RuleChain.doRule s(RuleChain.java:145)
org.tuckey.web.filters.urlrewrite.UrlRewriter.proc essRequest(UrlRewriter.java:92)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter .doFilter(UrlRewriteFilter.java:381)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.





Hope you can help.

Thanks.

domdorn
11-29-2011, 01:09 PM
have you tried with tomcat 7? tomcat 5.5 is quite outdated.