|
From: SQUILLACE M. <msq...@so...> - 2005-09-22 13:15:43
|
Jost,
> What about extending java_require() so that it can
> load jar files from a given directory?
That would be great, and more so if one could mix directories and single
jar files in the same call!
...
> If it requires an int then I think we wouldn't see the
ClassCastException.
> php ints (which are actually longs) are transferred as <L
v=3D"longval"/>.
> coerce can convert the longval into a int, but it cannot convert
> it into a java.lang.Integer.
...
> In general we cannot auto-convert a long to a
> java.lang.Integer without altering the value. If such
> a conversion is necessary I think the user must do
> this, for example by calling "new
> java("java.lang.Integer", $phpLongValue);"
I'm sure you are right, but still don't understand what I am supposed to
do ... here are a few snippets and their outcome.
1) Let's start with a method invocation where all required parameters
are missing:
<?php
$qMgr =3D new Java('com.ibm.mq.MQQueueManager');
$sdlq =3D $qMgr->accessQueue();
?>
Script output:
=20
Fatal error: Uncaught [class java.lang.Exception:
java.lang.Exception:
Invoke failed: [class com.ibm.mq.MQQueueManager]->accessQueue. Cause:
java.lang.NoSuchMethodException: accessQueue(). Candidates: [public=20
synchronized com.ibm.mq.MQQueue com.ibm.mq.MQQueueManager.accessQueue
=20
java.lang.String,int,java.lang.String,java.lang.String,java.lang.String)
throws com.ibm.mq.MQException, public synchronized com.ibm.mq.MQQueue
com.ibm.mq.MQQueueManager.accessQueue(java.lang.String,int) throws=20
com.ibm.mq.MQException]]
thrown in /opt/phpexe/jbridge/mqt.php on line 3
/var/log/php-java-bridge.log:
Java.lang.NoSuchMethodException: accessQueue(). Candidates: [public=20
synchronized com.ibm.mq.MQQueue com.ibm.mq.MQQueueManager.accessQueue
=20
java.lang.String,int,java.lang.String,java.lang.String,java.lang.String)
throws com.ibm.mq.MQException, public synchronized com.ibm.mq.MQQueue
com.ibm.mq.MQQueueManager.accessQueue(java.lang.String,int) throws=20
com.ibm.mq.MQException]=20
at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:966)
at php.java.bridge.Request.handleRequests(Request.java:190)
at php.java.bridge.JavaBridge.run(JavaBridge.java:142)
at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:20)
2) What I think the snippet should look like:
<?php
$qMgr =3D new Java('com.ibm.mq.MQQueueManager');
$mqc =3D new JavaClass('com.ibm.mq.MQC');
$openOptions =3D $mqc->MQOO_INPUT_AS_Q_DEF | $mqc->MQOO_OUTPUT;
// gettype($openOptions) returns 'integer' at this point (value:17)
$sdlq =3D $qMgr->accessQueue('SYSTEM.DEFAULT.LOCAL.QUEUE',
$openOptions);
?>
Script output:
=20
Fatal error: Uncaught [class java.lang.Exception:
java.lang.Exception:=20
Invoke failed: [class com.ibm.mq.MQQueueManager]->accessQueue(class
java.lang.String,
class java.lang.Long). Cause: java.lang.IllegalArgumentException:=20
java.lang.ClassCastException@181edf4]
thrown in /opt/phpexe/jbridge/mqt.php on line 6
/var/log/php-java-bridge.log:
java.lang.IllegalArgumentException:
java.lang.ClassCastException@12d3205
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:978)
at php.java.bridge.Request.handleRequests(Request.java:190)
at php.java.bridge.JavaBridge.run(JavaBridge.java:142)
at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:20)
3) Let's try with a java.lang.Integer:
<?php
$qMgr =3D new Java('com.ibm.mq.MQQueueManager');
$mqc =3D new JavaClass('com.ibm.mq.MQC');
$openOptions =3D $mqc->MQOO_INPUT_AS_Q_DEF | $mqc->MQOO_OUTPUT;
// gettype($openOptions) returns 'integer' at this point (value:17)
$inte =3D new Java('java.lang.Integer', $openOptions);
$sdlq =3D $qMgr->accessQueue('SYSTEM.DEFAULT.LOCAL.QUEUE', $inte);
?>
Script output:
=20
Fatal error: Uncaught [class java.lang.Exception:
java.lang.Exception:
Invoke failed: [class com.ibm.mq.MQQueueManager]->accessQueue(class
java.lang.String,=20
class java.lang.Integer). Cause: java.lang.IllegalArgumentException:=20
java.lang.ClassCastException@2f1921]
thrown in /opt/phpexe/jbridge/mqt.php on line 7
/var/log/php-java-bridge.log:
java.lang.IllegalArgumentException:
java.lang.ClassCastException@2f1921
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at php.java.bridge.JavaBridge.Invoke(JavaBridge.java:978)
at php.java.bridge.Request.handleRequests(Request.java:190)
at php.java.bridge.JavaBridge.run(JavaBridge.java:142)
at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:20)
In the "candidates" list from the first snippet there is a=20
com.ibm.mq.MQQueueManager.accessQueue(java.lang.String,int)
confirming what one can read from the documentation, where the method is
defined like this:
public synchronized MQQueue accessQueue(String queueName, int
openOptions)
IMHO it really looks like the method is expecting an int for the second
parameter.
If coerce converts the longvals to int, why the error in the second
snippet?
If the method expected a java.lang.Integer instead, why the error in the
last snippet?
Massimo
|