Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Stardust/Knowledge Base/Integration/UI/UIMashup/PHP Example
< Stardust | Knowledge Base | Integration | UI/UIMashup
Introduction
This example assumes that the reader is familiar with the use of the External Web Application type provided by Stardust. The example model referenced here may be downloaded from this location.
External PHP Page
<?php $PARAMS = (isset($HTTP_POST_VARS)) ? $HTTP_POST_VARS : $_GET; global $baseUri; $baseUri=$_GET['ippPortalBaseUri']; global $inData; $inData = $_GET['ippInteractionUri']."/inData"; global $outData; $outData = $_GET['ippInteractionUri']."/outData"; ?> <html> <head> <script type="text/javascript" src="<?php print "$baseUri"; ?>/plugins/processportal/IppProcessPortal.js""></script> </head> <body> <?php $url_contents = file_get_contents($inData); $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->load($inData); $xpath = new DOMXPath($doc); $rootNamespace = $doc->lookupNamespaceUri($doc->namespaceURI); $xpath->registerNamespace('x', $rootNamespace); $xpath->registerNamespace('Student', 'http://www.infinity.com/bpm/model/ExternalMashupModel/Student'); $xpath->registerNamespace('ns5', 'http://www.infinity.com/bpm/model/ExternalMashupModel/Student'); $nodelist = $xpath->query("//x:inDataValues/x:parameter/x:xml/Student:Student"); foreach ($nodelist as $node) { //echo $node->nodeName." ", $node->nodeValue." "; $nodelistchildren = $node->childNodes; foreach ($nodelistchildren as $nodeChild) { echo $nodeChild->nodeName." ", $nodeChild->nodeValue." "; } echo "<br>"; } $url = $outData."/Student2"; $xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Student:Student xmlns:Student=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\"><Id xmlns:ns5=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"\">576</Id><FirstName xmlns:ns5=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"\">Amit</FirstName><LastName xmlns:ns5=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"\">Kapoor</LastName><Age xmlns:ns5=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"\">35</Age><Address xmlns:ns5=\"http://www.infinity.com/bpm/model/ExternalMashupModel/Student\" xmlns=\"\"><Street1>14/19 Karol Bagh</Street1><Street2>Connaught Place</Street2><City>Delhi</City><State>DL</State><Zip>11001</Zip></Address></Student:Student>"; // Start curl $ch = curl_init(); // Clean up string $putString = stripslashes($xmlString); // Put string into a temporary file $putData = tmpfile(); // Write the string to the temporary file fwrite($putData, $putString); // Move back to the beginning of the file fseek($putData, 0); $headers = array( 'Accept: application/xml', 'Content-Type: application/xml', ); // Headers curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Binary transfer i.e. --data-BINARY curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); // Using a PUT method i.e. -XPUT curl_setopt($ch, CURLOPT_PUT, true); // Instead of POST fields use these settings curl_setopt($ch, CURLOPT_INFILE, $putData); curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putString)); $output = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else { $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); switch($returnCode){ case 200: break; default: $result = 'HTTP CODE -> ' . $returnCode; print $result; } } // Close the file fclose($putData); // Stop curl curl_close($ch); ?> <br> <button onclick="InfinityBpm.ProcessPortal.completeActivity()">Complete your activity instance now</button> </body> </html>