4

How can I pass parameters to java using php?

I'm trying do like this :

This is my php code

The id is posted from my view .

$id=$_POST['id'];
$Plb_Entrance = Yii :: t('report','ENTRANCE');
$Plb_Block = Yii :: t('report','BLOCK'); 
$sql=sprintf("SELECT *  from table WHERE id='".id."'");

$this->format='pdf';
$this->locale='en';
$this->reportfile='jr_print';
$this->params="
    <parameter name='Plb_Entrance'><![CDATA[$Plb_Entrance]]</parameter>
    <parameter name='Plb_Block'><![CDATA[$Plb_Block]]></parameter>
    <parameter name='pQueryCondition'><![CDATA[$sql]]></parameter>";
       **this one is normal i passed to jasperserver one**

This is my java code - now I want to pass the value from php to this java code

Map params = new HashMap();
params.put("Plb_Entrance", "**This value is passing from php**");
params.put("Plb_Block", "BLOCK");
params.put("pQueryCondition","ROW");

so is it posible?

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
yong
  • 53
  • 1
  • 5
  • Have you looked at this project? https://github.com/marianol/JasperServer-for-PHP – Michael Härtl Mar 31 '13 at 11:08
  • Which java technology are you using on the server-side? plain servlets, jsps, any other? – skirsch Mar 31 '13 at 11:09
  • yup.i want to use it on server-side, when passed the parameter the php code will help me to pass the parameter to java and the java code will pass it to jasperserver. just a normal java application.. – yong Mar 31 '13 at 11:15
  • michael hartl , if direct using php to jasperserver i knew it..coz now i want to make direct print when the parameter successful pass to the jasperserver so i using this java coding to help mi. – yong Mar 31 '13 at 11:20
  • 1
    Check this, I was using JSON to pass data between php and java - http://blog.loftdigital.com/blog/pdf-doc-xls-odf-from-php – Zdenek Machek Mar 31 '13 at 12:05
  • @ZdenekMachek your array $parameters = null is for passing the parameter to the java right? so for my param i just place it into the array and pass to the java is it? – yong Apr 01 '13 at 03:39
  • well, maybe not nicest way how to do it, but these parameters are translated to json, passed to java and loaded there: if(!is_null($parameters)){ $serialliazedParams = addslashes(json_encode($parameters)); $command .= " \"".$serialliazedParams."\""; } exec($command, $output, $returnValue); then in Java: JSONObject jsonObject = JSONObject.fromObject(args[3]); configBrean = (DynaBean) JSONObject.toBean( jsonObject ); – Zdenek Machek Apr 01 '13 at 13:29
  • @ZdenekMachek i cannot get the parameter using JSONObject jsonObject = JSONObject.fromObject(args[3]); configBrean = (DynaBean) JSONObject.toBean( jsonObject ); coding, no result display when i print out the out put..i try to pass this <![CDATA[ENTRANCE]]><\\/parameter><![CDATA[BLOCK]]> – yong Apr 04 '13 at 10:18

1 Answers1

1

For integration., you may use messaging, like STOMP and jms. It is valid to expose java application as an REST API and call it it using curl/php lib.

Here, you have an example for expose your java application as Servlet using Jetty. http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty

Here, a simple and detailed tutorial with curl/PHP tutorial. http://codular.com/curl-with-php

Andre Pastore
  • 2,841
  • 4
  • 33
  • 44
  • oic..but can i have some example? – yong Mar 31 '13 at 11:56
  • I updated my post, appending some example links. Tell us if it helps. Did you understand the architecture I proposed? If you determine each application role, you just need to expose necessary services. – Andre Pastore Apr 02 '13 at 18:06