views:

322

answers:

1

I am building an app using SOAP/web services to interact with a Java API. All was going swimmingly until now.

I need to pass an output stream as a param to a Java method from PHP. I am pretty sure I need to use PHP output buffering and fwrite, I am just not sure how to go about it.

I know you can use Java in php by using $myJavaFromPHP = new Java ... but I would prefer not to do it that way if at all possible*.

If it helps any, the parameter specs in java is a base64 encoded, content-type of application/octet-stream.

So, is this possible? If so, what is the best way to do it?

*I am trying to do this in regular PHP, w/ no dependencies. But if using PHP's Java class is the only way to do it, how?

+1  A: 

You somehow need a running Java Virtual Machine to execute the Java code. If it is already running "somewhere" you need to call that, and if you need help with that you must describe your environment better.

If the output is rather small it might be beneficial to have a small Java method which invokes the API you need, and collect the output in a String (using a ByteArrayOutputStream or a StringWriter) which you then return to the PHP caller.

Thorbjørn Ravn Andersen