From: <php...@li...> - 2011-02-23 21:26:27
|
Hello, I'm new at php-java-bridge (and in java). I made a class in Java CXF to invoke a webservice with ws-security (something that is difficult in PHP). The class is the following in short: package be.icthealth.ehealth; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; import org.apache.log4j.Level; import org.apache.ws.security.handler.WSHandlerConstants; import org.apache.cxf.endpoint.dynamic.DynamicClientFactory; import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; import org.apache.cxf.endpoint.Client; import java.util.HashMap; import java.util.Map; import java.io.File; import java.net.URL; //import java.lang.reflect.Method; /** * * @author Koen Thomeer, MD, http://koen.thomeer.be */ public class Codage { /** * @param request the class EncodeRequest * @return response the class Response * @throws Exception */ public Object[] encode(Object request) throws Exception { //throw new Exception("test"); // configure logging BasicConfigurator.configure(); Logger.getLogger("org").setLevel(Level.WARN); java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING); //code that I did leave out// // call the Codage Object[] response = client.invoke("encode", request); return response; } } The PHP code to call is the following (in short, it is nested in a function; $input is a PHP Instance): define("JAVA_PREFER_VALUES", false); require_once("http://localhost:8080/JavaBridgeWS/java/Java.inc"); try { $Codage = java("be.icthealth.ehealth.Codage"); $java_input = java_closure($input); $java_output = $Codage->encode($java_input); $output = java_values($java_output); print_r($output); } catch (JavaException $e) { // in case of an error, process the fault echo $e; } The error in the HTTPD log is the following: [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP Fatal error: Couldn't execute method java_InternalException::__set in Unknown on line 0 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP Stack trace: [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 1. {main}() /project/wmailer-test/www/secure/test/codage_test.php:0 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 2. EH_encode() /project/wmailer-test/www/secure/test/codage_test.php:5 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 3. JavaClass->encode() /project/wmailer-test/www/secure/test/codage5.php:219 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 4. Java->__call() http://localhost:8080/JavaBridgeWS/java/Java.inc:0 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 5. java_AbstractJava->__call() http://localhost:8080/JavaBridgeWS/java/Java.inc:1999 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 6. java_JavaProxy->__call() http://localhost:8080/JavaBridgeWS/java/Java.inc:1851 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 7. java_Client->invokeMethod() http://localhost:8080/JavaBridgeWS/java/Java.inc:1752 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 8. java_Client->getResult() http://localhost:8080/JavaBridgeWS/java/Java.inc:560 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 9. java_Client->getWrappedResult() http://localhost:8080/JavaBridgeWS/java/Java.inc:366 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 10. java_Arg->getResult() http://localhost:8080/JavaBridgeWS/java/Java.inc:360 [Wed Feb 23 22:17:37 2011] [error] [client 84.196.244.172] PHP 11. java_ThrowExceptionProxyFactory->checkResult() http://localhost:8080/JavaBridgeWS/java/Java.inc:235 Questions: 1. What I'm doing wrong? I don't understand the log. 2. Where I've to put the keystore, properties file, etc? Thx, Koen -- *Koen Thomeer*, MD, MSc http://koen.thomeer.be |
From: <php...@li...> - 2011-02-23 23:02:24
|
Hi, your java code has thrown an unchecked exception (error or runtime exception). After that your php code has tried to set a non-existing property on it. Any unchecked exception crossing the container boundary must be declared, otherwise the behaviour is undefined. Please see our FAQ for details. Your code contains several problems. Your java object backed by a php instance doesn't have any public methods. This may or may not be what you want. And you call a method as if it were a procedure. Won't work, so I assume that the code you have shown isn't the code you actually use. Either encode is actually static or the php code you have posted is missing a new statement. Regards, Jost Bökemeier |
From: <php...@li...> - 2011-02-24 13:53:09
|
Many thanks for the help! 1. I don't understand the remark: "Your java object backed by a php instance doesn't have any public methods." => the method is public (but I did forget the 'static'). 2. I changed the code of java: public static Object[] encode(Object request) throws RuntimeException, Exception { -> I added static: that was logic -> I added RuntimeException, like in the FAQ. But the error stays the same... 2011/2/24 <php...@li...> > Hi, > > your java code has thrown an unchecked exception (error or runtime > exception). After that your php code has tried to set a non-existing > property on it. > > Any unchecked exception crossing the container boundary must be declared, > otherwise the behaviour is undefined. Please see our FAQ for details. > > Your code contains several problems. Your java object backed by a php > instance doesn't have any public methods. This may or may not be what you > want. And you call a method as if it were a procedure. Won't work, so I > assume that the code you have shown isn't the code you actually use. Either > encode is actually static or the php code you have posted is missing a new > statement. > > Regards, > Jost Bökemeier > > ------------------------------------------------------------------------------ > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT > data > generated by your applications, servers and devices whether physical, > virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > -- *Koen Thomeer*, MD, MSc http://koen.thomeer.be |
From: <php...@li...> - 2011-02-24 21:40:03
|
Hi, > 1. I don't understand the remark: > "Your java object backed by a php > instance doesn't have any public methods." It's a java.lang.Object which implements no interfaces. Not very useful unless your library detects that it is a proxy and directly calls its invocation handler. Please see the java_closure() API for details at http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure > public static Object[] encode(Object request) throws RuntimeException, > Exception { > > -> I added static: that was logic > -> I added RuntimeException, like in the FAQ. In this case your code will work and I have no explanation for this issue either. But if your library is smart enough to call $java_input's invocation handler, please have a look at your PHP code called from the invocation handler. It probably calls a library method which throws an unchecked exception. The problem is simply that an unchecked exception has been returned from a Java call but not thrown. (You can get around this by setting JAVA_PREFER_VALUES, but I think you know that). Be it as it may, if you only want to add a sec header to your soap request, you can do this in PHP as well. Or implement it in Java and call the entire method from PHP. Regards, Jost Bökemeier |
From: <php...@li...> - 2011-02-24 23:06:07
|
Thanks for the answer. IMHI, the manual about java_closure() is not always obvious. ex: 1. function toString() {return "helloWorld";}; 2. $object = java_closure<http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure> (); 3. echo "Java says that PHP says: $object\n"; In this example, no arguments are passed in the java_closure() function. What does java_closure() transform? Only the last object? It is not clear in the manual. ex: 1. function hello() {return "hello";}; 2. echo (string)java_closure<http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure> (null, "hello"); In this example, I think the function hello() is transformed, because "hello" is the second argument. It is a good idea, to change the first line in ... return "helloWorld";}; to prevent confusion with the second argument of java_closure() (PHP developpers are KISS-thinkers :-)). The manual talks about a keymap: maybe give an example? Why is the first argument null? Now, for my case. What is $input? In PHP two classes are declared: class encodeRequest { /** * @var string */ public $applicationName; /** * @var array[1, unbounded] of (object)OriginalDataType */ public $originalData; } class OriginalDataType { /** * @var string */ public $id; /**&; * @var boolean */ public $randomize; /** * @var string */ public $inputData; } $data = new OriginalDataType(); $data->id = 1; $data->randomize= false; $data->inputData = "blabla"; $input = new encodeRequest(); $input->applicationName = "WWM"; $input->originalData = $data; So $input is an instance of the encodeRequest class. I want this PHP instance be transformed in a Java instance. I thought that $java_input = java_closure($input); would do the trick? Sincerely, Koen 2011/2/24 <php...@li...> > Hi, > > > 1. I don't understand the remark: > > "Your java object backed by a php > > instance doesn't have any public methods." > > It's a java.lang.Object which implements no interfaces. Not very > useful unless your library detects that it is a proxy and directly > calls its invocation handler. Please see the java_closure() API for > details at > http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure > > > public static Object[] encode(Object request) throws RuntimeException, > > Exception { > > > > -> I added static: that was logic > > -> I added RuntimeException, like in the FAQ. > > In this case your code will work and I have no explanation for this > issue either. > > But if your library is smart enough to call $java_input's invocation > handler, please have a look at your PHP code called from the > invocation handler. It probably calls a library method which throws an > unchecked exception. > > The problem is simply that an unchecked exception has been returned > from a Java call but not thrown. (You can get around this by setting > JAVA_PREFER_VALUES, but I think you know that). > > > Be it as it may, if you only want to add a sec header to your soap > request, you can do this in PHP as well. Or implement it in Java and > call the entire method from PHP. > > > Regards, > Jost Bökemeier > > > ------------------------------------------------------------------------------ > Free Software Download: Index, Search & Analyze Logs and other IT data in > Real-Time with Splunk. Collect, index and harness all the fast moving IT > data > generated by your applications, servers and devices whether physical, > virtual > or in the cloud. Deliver compliance at lower cost and gain new business > insights. http://p.sf.net/sfu/splunk-dev2dev > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users > -- *Koen Thomeer*, MD, MSc http://koen.thomeer.be |
From: <php...@li...> - 2011-02-25 20:12:42
|
Hi, java_closure reifies an environment for java. It needs a signature. It does not make attributes available. Those are availabe through methods declared in the interface. This explains the error message: You have tried to change a non-existent attribute. It failed. And the next set! tried to modify the failure report. Regards, Jost Bökemeier |
From: <php...@li...> - 2011-02-25 21:09:30
|
Hello! 1. function toString() {return "helloWorld";}; 2. $object = java_closure<http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure> (); 3. echo "Java says that PHP says: $object\n"; In this example, no arguments are passed in the java_closure() function. What does java_closure() transform? The current environment. 1. function hello() {return "hello";}; 2. echo (string)java_closure<http://php-java-bridge.sourceforge.net/pjb/docs/php-api/java/_JavaProxy.inc.html#functionjava_closure> (null, "hello"); In this example, I think the function hello() is transformed, The current environment, which all its procedures renamed to "hello". The manual talks about a keymap: maybe give an example? Why is the first argument null? java_closure(null, array("foo"=>"hello")); maps "foo" calls to "hello" procedures of the current environment. You are looking for: java_closure($phpObj, null, array(java("my.Interface1"), java("my.Interface2")...)); Peter |