|
From: <php...@li...> - 2009-01-09 01:00:17
|
Hi folks,
I am using the php-java-bridge to make some remote web services calls.
I'm using the webapp version of the bridge, and I have confirmed it is
working (by visiting localhost:8080/JavaBridge/test.php). I am running
Apache Tomcat 5.5.25 (I also tried on tomcat 5.5.17). It is an older
version of the java bridge (I don't know how to tell what version it is,
but the copyright notice only goes to 2007). This code is running on
x86_64 GNU/Linux, with PHP 5.2.6.
The web service returns a set of bytes, and then my php class needs to
write those bytes to a file (it's a PDF or jpg):
-----------------------
$reportBody = $this->retrieveReport($reportFilename);
if(strlen($reportBody) == 0) {
return "ERROR: unable to retrieve report";
}
// write file
$handle = fopen($pdfDirectory . "/" . $reportFilename,"wb");
if(fwrite($handle,$reportBody) == FALSE) {
...
}
-----------------------
Unfortunately, I'm not able to get the bytes to show up. Instead, in
the file, I get this value:
[[o:array_of_B]:"[B@3a0b2771"]
I looked around the mailing list and found this post:
http://sourceforge.net/mailarchive/message.php?msg_id=215BBBD9D2B80E4E98225471640045918A3356%40CHEXV3.CHBOSTON.ORG
which seemed to indicate I should be able to use 'java_values' to decode
this file.
Using java_values doesn't seem to help--I still see the array_of_B value.
Trying to find the length of the bytes:
error_log($reportBody->length);
causes this error:
"PHP Notice: Trying to get property of non-object "
Use a plain old string works fine:
$str = new java("java.lang.String", "hello");
error_log($str);
outputs "hello".
The same code works on another X86_64 server running Tomcat 5.5.17. The
version of JavaBridge.war is, as far as I can tell, the same (it's the
same size). The same web service is being accessed from this server.
The only difference that I can see is that the other has 'java.so'
uncommented in the php.ini file--why would that matter if I'm using the
web version of the bridge?
Any other suggestions would be appreciated. I've googled around, but
there doesn't seem to be much information regarding byte streams passed
between php and java.
Thanks,
Dan
|
|
From: <php...@li...> - 2009-01-09 15:15:34
|
Hi, > [[o:array_of_B]:"[B@3a0b2771"] it is an array of class B (whatever B is) rather than a byte array or a String. Please see: echo java_inspect($javaObject); for details. You can convert any java object to a string using java_cast($obj, "S") provided it contains a toString() method. Please see the PHP/Java Bridge API for details: http://php-java-bridge.sourceforge.net/pjb/docs/php-api/index.html Regards, Jost Boekemeier |
|
From: <php...@li...> - 2009-01-11 17:48:32
|
Hi Jost, Thanks for the information. I added a statement: echo java_inspect($reportBody); And this is what I saw in my output: -------------------- [class [B: Constructors: Fields: Methods: public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public java.lang.String java.lang.Object.toString() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll() Classes: ] -------------------- To my untrained eye, that looks like the methods and fields of a plain old java object, not an array of bytes. I then just made the call to java_values explicit: $reportBody = java_values($reportBody); and the file was saved as expected. Thanks again for your help! Dan On 1/9/2009 8:15 AM, php...@li... wrote: > Hi, > >> [[o:array_of_B]:"[B@3a0b2771"] > > it is an array of class B (whatever B is) rather than a byte array or a String. Please see: > > echo java_inspect($javaObject); > > for details. > > You can convert any java object to a string using java_cast($obj, "S") provided it contains a toString() method. Please see the PHP/Java Bridge API for details: http://php-java-bridge.sourceforge.net/pjb/docs/php-api/index.html > > > Regards, > Jost Boekemeier > > > > > > > ------------------------------------------------------------------------------ > Check out the new SourceForge.net Marketplace. > It is the best place to buy or sell services for > just about anything Open Source. > http://p.sf.net/sfu/Xq1LFB > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users |
|
From: <php...@li...> - 2009-01-12 14:09:14
|
Hi,
did I understand this correctly that
$reportBody = java_values(getReportBody());
doesn't work but
$reportBody = getReportBody();
$reportBody = java_values($reportBody);
does?
If that's the case, you have found a bug in the PHP evaluator.
Regards,
Jost Boekemeier
|
|
From: <php...@li...> - 2009-01-12 16:19:29
|
Hi Jost, I'm sorry, I was sloppy in my email. What worked was: $reportBody = getReportBody(); $reportBody = java_values($reportBody); ... processing ... What didn't work (on one server, but did work on the other for reasons unknown to me) was: $reportBody = getReportBody(); ... processing ... Hope this helps. Dan On 1/12/2009 7:09 AM, php...@li... wrote: > Hi, > > did I understand this correctly that > > $reportBody = java_values(getReportBody()); > > doesn't work but > > $reportBody = getReportBody(); > $reportBody = java_values($reportBody); > > does? > > If that's the case, you have found a bug in the PHP evaluator. > > > Regards, > Jost Boekemeier > > > > > > ------------------------------------------------------------------------------ > Check out the new SourceForge.net Marketplace. > It is the best place to buy or sell services for > just about anything Open Source. > http://p.sf.net/sfu/Xq1LFB > _______________________________________________ > php-java-bridge-users mailing list > php...@li... > https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users |