From: <php...@li...> - 2011-01-26 15:10:05
|
Greetings everyone, I take part in a fairly big project, several different companies take part on it. The main platform is made in PHP, but usual corporative madness means that some parts of the project will be made in Java (looks like some companies would go bankrupt if they produce some PHP code :p). So far, we've been able to call java from our main php framework with php/java bridge, which seems to be fairly easy with php/java bridge. But in order to avoid duplicating some work, the java code should be able to call objects that exist in the main PHP, which are not able to do yet. We try this in the php file: require_once("http://localhost:8080/JavaBridge/java/Java.inc"); class FooPHPClass { function greet() { return "I'm a FooPHPClass function"; } } java_context()->setAttribute('FooPHPClass', java_closure(new FooPHPClass()), 100); $hw = new java("helloworld"); java_call_with_continuation(); echo $hw->hello(); In the java side, we are trying this: public class helloworld { public String hello() { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine e = manager.getEngineByName("php-invocable"); String v = ""; try { Invocable i = (Invocable) e; // This needs to call the class defined in the original PHP thread Object FooPHPClass = e.getContext().getAttribute("FooPHPClass", 100); v = (String) i.invokeMethod(FooPHPClass, "greet", new Object[] { new String() }); e.eval((Reader) null); // release the continuation, flush output } catch (javax.script.ScriptException ex) { } catch (java.lang.NoSuchMethodException ex) { } return "Invoke result: " +v; } } With this, running the php file in apache, we get a Java exception with the message: "java.lang.IllegalStateException: PHP script did not pass its continuation to us!". I don't really know how to proceed to make it work, since I'm really new to the php/java bridge. |