From: <php...@li...> - 2010-06-21 08:16:15
|
> From the examples, to reference the PHP script I should use something like:ScriptEngine > scriptEngine = new ScriptEngineManager().getEngineByName( "php-invocable" ); Not exactly. For a servlet environment it is: php.java.script.servlet.EngineFactory.getInvocablePhpScriptEngine() The difference is that the ScriptEngineManager has no information about the servlet environment, so you cannot use the servlet context from a script allocated from the ScriptEngineManager. The JSR 223 script spec isn't very well designed. Implementations have to use their own workarounds. To quote Per Bothner: "Embarrassingly, I was a not-very-active member of the JSR-223 expert group. It would have been better if we could have thought a little more about scripting staticly-typed languages, but we didn't have time", see http://per.bothner.com/blog/2009/JavaFX-scripting-changes/ > scriptEngine.eval( new URLReader( "http://localhost/test.php" ); > This does not make sense to me I wasn't part of the JSR 223 expert group, so I don't know why they require you to pass a specific Reader, instead of a file or URL/URI. The URLReader is an adapter, it packages up the URI location so that it can be passed through the JSR 223 API. > as my PHP script is not browseable The java_call_with_continuation() makes it invocable from the remote continuation. It calls java_context()->call(this), so that Java can call that.cont.call(this.cont). If you open a local script via: reader = new java.io.FileReader(FILE); eng.eval(reader); the implementation hides the above "magic". > I'd prefer not to access my script via a new request to Tomcat It doesn't open a URLConnection back to tomcat. PHP uses a persistent connection to a ContextRunner: Client requests JSP. JSP creates ScriptEngine. ScriptEngine opens URLConnection to Apache/PHP. PHP script calls java method java_context() which invokes the bridge machinery in the back end (a java thread is spawned) and ->call() transfers the control from the PHP- to the current Java continuation, which may call procedures from the PHP continuation or transfer control back. I fail to understand your difficulties. If you mean the FileReader utility from EngineFactory; it is there to allow you to create a "one shot" reader for a given reader without having to look at the file system. The PHP file is created with the .class file during JSP compilation, so that PHP can take advantage of its internal cache/compilation mechanism (PHP compiles to opcode and caches it). > If I try to pass in a URL as a file rather than http Why don't you simply use a FileReader? Regards, Jost Bökemeier |