From: <php...@li...> - 2006-09-15 20:09:50
|
Hi, I am looking at using the PHP Java Bridge to help to transfer a whole lot of JSP pages into a PHP-based CMS. Installation went fine. The JSP pages are well structured with a set of java classes as a backend, such that the JSP page basically has to call a method with the HttpServletRequest request object as argument, and returns arrays of data to display on the page. Therefore it doesn't seem too difficult to imagine making a PHP module/class which simply calls the same java method via the PHP Java Bridge, then does the layout pretty much like the JSP file used to. HOWEVER the first stumbling block is that because we're no longer operating in a JSP sort of context, we don't appear to have an HttpServletRequest to pass to the backend any more, which we require to get hold of the URL string, cookies, etc. I'm not keen (at this stage) on reprogramming all the java classes to use an alternative source of input data, if it would be possible to get hold of a HttpServletRequest that we can pass in as before. I had a look at creating one programmatically (faking it), but it's not a class but an interface, and there are potentially some issues with session ids etc that I don't know about. Is it clear what I am trying to achieve? Does anyone have any hints for how to create a HttpServletRequest, get hold of one, or otherwise pass URI/cookie/session data through to our backend, that is used to receiving HttpServletRequest objects? Many thanks, Stephen Brandon |
From: <php...@li...> - 2006-09-16 09:49:58
|
Hi Stephen, > module/class which simply calls the same java method > via the PHP Java > Bridge, then does the layout pretty much like the > JSP file used to. Yes, this should work fine. > HOWEVER the first stumbling block is that because > we're no longer > operating in a JSP sort of context, we don't appear > to have an > HttpServletRequest to pass to the backend any more You can access the HttpServletRequest from here: http://php-java-bridge.sourceforge.net/documentation/PHP-API/html/java_8c.html#doc26 and http://php-java-bridge.sourceforge.net/server/documentation/API/php/java/servlet/Context.html#getHttpServletRequest() > Is it clear what I am trying to achieve? You haven't mentioned if you run PHP within your servlet engine or within Apache or IIS. If you run PHP within your servlet engine, $request = java_context()->getHttpServletRequest(); will just work. If you run PHP in a HTTP server and only forward the embedded php java() statements, things will be more difficult, because the bridge doesn't pass all information to the back-end. For example a request GET http://host.com/foo/bar.php?param=... will cause the bridge to send a HTTP PUT request: PUT http://127.0.0.1:8080/foo/bar.phpjavabridge This means that you currently cannot retrieve the method() and the params from the request. -- But the bridge could forward them, if you need this. Regards, Jost Boekemeier ___________________________________________________________ Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de ___________________________________________________________ Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de |
From: <php...@li...> - 2006-09-16 22:04:35
|
Jost - thanks for the informative reply. I am running PHP in apache, and forwarding JSP pages (and the java bridge) through to Tomcat. So according to what you say below, that's not going to work well for me in any case. However I tried to get java_context()->getHttpServletRequest() anyway, just to experiment and see if that would get me anything interesting. Unfortunately that's raising exceptions: <?php $request = java_context()->getHttpServletRequest(); echo $request->toString(); $uri = $request->getRequestURI(); ?> displays: [o(String):"org.apache.coyote.tomcat4.CoyoteRequestFacade@1707653"] Fatal error: Uncaught [o(Exception):"java.lang.Exception: Invoke failed: [o(CoyoteRequestFacade)]->getRequestURI. Cause: java.lang.NullPointerException Responsible VM: 1.4.2_06@http://java.sun.com/" at: #-10 org.apache.coyote.tomcat4.CoyoteRequestFacade.getRequestURI (CoyoteRequestFacade.java:346) #-9 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) #-8 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) #0 [internal function]: Java->__call('getRequestURI', Array) #1 /httpd/www.mydomain.com/htdocs/test_java_bridge.php(32): Java- >getRequestURI() #2 {main}] thrown in /httpd/www.mydomain.com/htdocs/test_java_bridge.php on line 32 Is that the expected behaviour, even considering I am forwarding the embedded php java() statements? I have a feeling that I am going to need to implement my own HttpServletRequest in any case - why, because I'll probably be implementing what used to be full JSP pages as in-page modules within a CMS (Joomla or Typo3, probably). Thus the URLs of the new system will be a lot different to the old system (the CMS will use parts of the URL for its own navigation, which I won't want to pass through to our java backend), and I will probably have to construct "fake" HttpServletRequests to match what the backend is expecting. Just out of interest, how would I get Tomcat to interpret the php pages instead of apache? - Is there an easy way to implement this with our current setup (we have stock apache running php, passing jsp pages to Tomcat on port 8080 with jk)? - Can one pass php pages through to Tomcat using the same mechanism as for JSP? - If so, would this cause much of a performance hit? Thanks for any help Cheers, Stephen Brandon On 16 Sep 2006, at 10:49, php...@li... wrote: > You haven't mentioned if you run PHP within your > servlet engine or within Apache or IIS. If you run PHP > within your servlet engine, > > $request = java_context()->getHttpServletRequest(); > > will just work. > > If you run PHP in a HTTP server and only forward the > embedded php java() statements, things will be more > difficult, because the bridge doesn't pass all > information to the back-end. For example a request > > GET http://host.com/foo/bar.php?param=... > will cause the bridge to send a HTTP PUT request: > PUT http://127.0.0.1:8080/foo/bar.phpjavabridge > > This means that you currently cannot retrieve the > method() and the params from the request. -- But the > bridge could forward them, if you need this. > > > Regards, > Jost Boekemeier |
From: <php...@li...> - 2006-09-17 14:44:30
|
> anyway, just to experiment and see if that would get > me anything > interesting. Unfortunately that's raising > exceptions: yes, the servlet doesn't wait for the context anymore, so after one Java() statement the request object is recycled. I have removed the context.waitFor() after 2.0.8 (see line 330 in http://php-java-bridge.cvs.sourceforge.net/php-java-bridge/php-java-bridge/server/php/java/servlet/PhpJavaServlet.java?revision=1.25&view=markup) because the request object isn't really useful at the moment anyway. It doesn't carry any information about the original request, etc. But we could forward the necessary request options and let the servlet wait for the Context, if needed. > <?php > $request = > java_context()->getHttpServletRequest(); > echo $request->toString(); > $uri = $request->getRequestURI(); > ?> > > [o(String):"org.apache.coyote.tomcat4.CoyoteRequestFacade@1707653"] > Fatal error: Uncaught > [o(Exception):"java.lang.Exception: Invoke > failed: [o(CoyoteRequestFacade)]->getRequestURI. > Cause: > java.lang.NullPointerException After the first line the servlet and its associated request object is recycled by tomcat and the bridge runs with a context server which is more than 50 times faster than sending PUT request. You can switch off the pipe and socket context server by running tomcat with the java options: -Dphp.java.bridge.no_pipe_server=true -Dphp.java.bridge.no_socket_server=true (see http://php-java-bridge.sourceforge.net/server/documentation/API/php/java/bridge/http/PipeContextServer.html and http://php-java-bridge.sourceforge.net/server/documentation/API/php/java/bridge/http/SocketContextServer.html) > Is that the expected behaviour, even considering I > am forwarding the > embedded php java() statements? Yes. Even if the Pipe-/SocketContextServer is switched off and the bridge must send a PUT request for each individual Java() statement, the request and response objects are recycled by the servlet engine. This means that you can't store any values there, each PHP Java() statement is executed in a fresh context, only the session store stays the same. > I have a feeling that I am going to need to > implement my own > HttpServletRequest in any case This shouldn't be too difficult. However, I think this is a feature which should also go into the bridge code. I will create a new 3.2.x branch and add this feature there. > Just out of interest, how would I get Tomcat to > interpret the php > pages instead of apache? > - Is there an easy way to implement this with our > current setup (we > have stock apache running php, passing jsp pages to > Tomcat on port > 8080 with jk)? Just forward both, the PHP and the JSP requests. This will invoke the FastCGI machinery, which isn't much slower than Apache (according to my tests it is even faster than Apache's worker MPM). Jost ___________________________________________________________ Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de |
From: <php...@li...> - 2006-09-16 12:14:37
|
Can't the <a href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequestWrapper.html">ServletRequestWrapper</a> be used for this? ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |