function requestBags() { /* Generate a random number for the purchase order*/ $randNum = rand() % 99; /* Requested date is two weeks from today*/ $reqDate = mktime(0, 0, 0, date("m"), date("d") + 14, date("Y")); $reqDateStr = date("Y/m/d", $reqDate); /* The payload string*/ $requestPayloadString = <<<XML <po:Order xmlns:po="http://www.back_packers.com/ws/purchaseorder"> <po:OrderId>po-{$randNum}</po:OrderId> <po:ReqDate>{$reqDateStr}</po:ReqDate> <po:Design> <po:FileName>design.jpg</po:FileName> <po:Image><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include></po:Image> </po:Design> </po:Order> XML; try { global $request_str; global $response_str; /* Load the design*/ $f = file_get_contents("./design.jpg"); /* Build the message*/ $requestMessage = new WSMessage($requestPayloadString, array("to" => "http://localhost/solutions/store/manuf_service.php", "action" => "http://www.back_packers.com/purchaseOrder", "attachments" => array("myid1" => $f))); /* Load certificates and keys*/ $rec_cert = ws_get_cert_from_file("keys/bob_cert.cert"); $my_cert = ws_get_cert_from_file("keys/alice_cert.cert"); $my_key = ws_get_key_from_file("keys/alice_key.pem"); /* Load policy file*/ $policy_xml = file_get_contents("policy.xml"); $policy = new WSPolicy($policy_xml); /* Ceate a security token with reqd configurations*/ $sec_token = new WSSecurityToken(array("user" => "Alice", "password" => "abcd!1234", "passwordType" => "Digest", "privateKey" => $my_key, "certificate" => $my_cert, "receiverCertificate" => $rec_cert)); /* Create a new client*/ $client = new WSClient(array("useWSA" => TRUE, "useMTOM" => FALSE, "policy" => $policy, "securityToken" => $sec_token)); /* Request*/ $responseMessage = $client->request($requestMessage); /* to track the messages */ $request_str = $client->getLastRequest(); $response_str = $client->getLastResponse(); $request_str = format_xml($request_str); $response_str = format_xml($response_str); /* Print the response*/ print "<div id=\"message\">More Backpacks requested : The purchase order number is {$responseMessage->str}</div>"; } catch (Exception $e) { if ($e instanceof WSFault) { printf("Soap Fault: %s\n", $e->Reason); } else { printf("Message = %s\n", $e->getMessage()); } } }
/** * Send any string to browser as file * * @param string $string String content for save as file * @param string $filename Filename * @param array $vars Vars with some options */ function download_as_file($string, $filename = "observium_export.xml", $vars = array()) { //$echo = ob_get_contents(); ob_end_clean(); // Clean and disable buffer $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext == 'xml') { header('Content-type: text/xml'); if ($vars['formatted'] == 'yes') { $string = format_xml($string); } } else { header('Content-type: text/plain'); } header('Content-Disposition: attachment; filename="' . $filename . '";'); header("Content-Length: " . strlen($string)); header("Pragma: no-cache"); header("Expires: 0"); echo $string; // Send string content to browser output exit(0); // Stop any other output }
<?php } // The code for the customerOrders operation invocation and rendering results as HTML if ($demo_no == 4) { // prepare the input parameters // ---------- Start of the customerOrders Client Invocation Logic ---------------------------------- $request = <<<XML <customerOrders> </customerOrders> XML; try { $client = new WSClient(array("to" => DEMO4_ENDPOINT)); $responseMessage = $client->request($request); $response = $responseMessage->str; /* format the xml to looks little clear */ $response = format_xml($response); } catch (Exception $e) { $error = TRUE; if ($e instanceof WSFault) { $response = "Soap Fault: " . $e->Reason; } else { $response = "Message = " . $e->getMessage(); } } // ---------- End of the customerOrders Client Invocation Logic ---------------------------------- ?> <h2> Get Orders for all the customers</h2> <!-- rendering logic to the rendering as a table --> <form method="GET">
function dict_diff($lemma_id, $set_id) { $res = sql_query("SELECT dr.rev_id, dr.rev_text, s.timestamp, s.comment, u.user_shown_name AS user_name FROM dict_revisions dr LEFT JOIN rev_sets s ON (dr.set_id=s.set_id) LEFT JOIN `users` u ON (s.user_id=u.user_id) WHERE dr.set_id<={$set_id} AND dr.lemma_id={$lemma_id} ORDER BY dr.rev_id DESC LIMIT 2"); $r1 = sql_fetch_array($res); $r2 = sql_fetch_array($res); $old_rev = format_xml($r2['rev_text']); $new_rev = format_xml($r1['rev_text']); $out = array('lemma_id' => $lemma_id, 'old_ver' => $r2['rev_id'], 'new_ver' => $r1['rev_id'], 'old_user_name' => $r2['user_name'], 'new_user_name' => $r1['user_name'], 'old_timestamp' => $r2['timestamp'], 'new_timestamp' => $r1['timestamp'], 'comment' => $r1['comment'], 'new_rev_xml' => $new_rev, 'diff' => php_diff($old_rev, $new_rev), 'prev_set' => 0, 'next_set' => 0); $res = sql_query("SELECT set_id FROM dict_revisions WHERE lemma_id={$lemma_id} AND set_id<{$set_id} ORDER BY set_id DESC LIMIT 1"); if (sql_num_rows($res) > 0) { $r = sql_fetch_array($res); $out['prev_set'] = $r[0]; } $res = sql_query("SELECT set_id FROM dict_revisions WHERE lemma_id={$lemma_id} AND set_id>{$set_id} ORDER BY set_id ASC LIMIT 1"); if (sql_num_rows($res) > 0) { $r = sql_fetch_array($res); $out['next_set'] = $r[0]; } return $out; }
$url_postfix = "?wsdl"; if (array_key_exists("generate_type", $_POST) && $_POST["generate_type"] == "wsdl2") { $url_postfix = "?wsdl2"; } //then read it from the localhost.. $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $service_url . $url_postfix); curl_setopt($curl, CURLOPT_HTTPGET, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_USERAGENT, "wsf/php codegen"); $result = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($status == 200) { //$xml = htmlspecialchars($result); $xml = format_xml($result); include_once GESHI_PATH . 'geshi.php'; $geshi =& new GeSHi($xml, "xml"); $highlighted = $geshi->parse_code(); echo $highlighted; } //echo $service_code; unlink(USER_SERVICES_PATH . $service_file_name); $_SESSION["service_code_index"] = $service_code_index; ?> </div> </td> <td> </td> <td> </td> <tr> <td> </td>
public function test_format_xml() { $xml = '<root><element>foo</element></root>'; $expected = <<<XML <?xml version="1.0"?> <root> <element>foo</element> </root> XML; $this->assertEquals($expected, format_xml($xml)); }