In this presentation, Prabath Siriwardena, the lead developer of the WSO2 Identity Solution, gives a comprehensive introduction to “OpenID”.
You can find more of his posts about OpenID in his blog http://blog.facilelogin.com/
Jonathan Marsh, VP of Business Development of WSO2, recently released three screencasts explaining the features of WSO2 Mashup Server and how you can use these features in building your own Mashups.
The first screencast targeted at newbies to introduce the mashup concept and WSO2 Mashup Server and the next two videos present you the topics like “Scraping Web Pages” and “Service Composition” which are useful in building advance mashups.
You can view the high quality version of these videos from wso2.org. Here are the links
WSO2 WSF/PHP comes with a comprehensive set of test cases. It covers the most of the basic/concrete scenarios supported by WSF/PHP. You can find these test cases inside the “src/tests” directory of WSF/PHP source package. Or you can find the latest test-suite from the SVN location.
Here are some aspects covered in the test-suit.
Scenario | Test Cases For Client | Test Cases For Service |
Basic Functionality | echo_client*.phptmath_*.phpt | samples/echo_service*.php samples/math_service.php |
Basic Schema Types | BasicDataTypes/*.phpt | services/BasicTypesDoclitBSvc/*.php |
Complex Schema Types | cmplxDataTypes/*.phpt | services/ComplexDataTypesWSvc/*.php services/ComplexDataTypesBSvc/*.php |
WSDL/Schema Variations | wsdl_mode/*.phpt | services/wsdl_mode/*.php |
WSDL Generation with Annotations | wsdl_generation/*.phpt | services/wsdl_generation/*.php |
Reliable Messaging | echo_rm*.phpt | samples/echo_service_rm*.php |
Security | echo_encrypt_client*.phptecho_signing_client*.phpt | encrypt_service*.phpsigning_service*.php |
MTOM | mtom_*.phpt | samples/mtom/*.php |
(Note that Here ‘*’ is used as a wild card represent 0 or many characters)
Steps to Run Tests
pear run-tests -r
This will execute all the test cases under the ‘tests’ directory and finally give a summery of the test results.
pear run-tests samples/echo_client.phpt
If you like to add test cases for the WSF/PHP scenarios, follow this comprehensive guideline titled Writing Simple phpt Test Scripts For PHP Web Services.
Here is a simple categorization of the WSF/PHP samples. You can access all the wsf/php samples from http://labs.wso2.org/wsf/php/solutions/samples/index.html.
Sample Category | Example Client Source Code | Example Service Source Code | Online Demo |
Beginners | echo_client.php | echo_service.php | Demo |
REST | echo_client_rest.php | echo_service_with_rest.php | Demo |
WSDL Mode (Contract First) | wsdl_11_client.php | wsdl_11_service.php | Demo |
WSDL Generation (Code First) | doclit_client.php | doclit_service.php | Demo |
MTOM Attachments | mtom_download_client.php | mtom_download_service.php | Demo |
Security | encryption_client.php | encryption_service.php | Demo |
Reliable Messaging | echo_client_rm.php | echo_service_rm.php | Demo |
Data Services | CustomerDetailsClient.php | CustomerDetailsService.php | Demo |
If you have downloaded the WSF/PHP binaries or souce code package you can find all these samples, inside the ‘samples’ directory
We use ‘GROUP BY’ SQL construct to query the data with aggregating some rows according to a field. For an example say if your blog database store your blogs in a table call ‘Blog’ and it has ‘Date’ as a field. If so
SELECT count(*) FROM Blog GROUP BY Date
will give you a set of numbers that represent the number of blog you posted each day.
SELECT Date, count(*) FROM Blog GROUP BY Date
will give you a map of ‘date’ to ‘number of blog posted for that date’ without much trouble.Â
Anyway the problem is most of the databases of blogs don’t just keep the ‘date’ for a blog, rather it keep both ‘date and time’ (say in a field called ‘Time’). But you still want to group by date. You may use the MySQL ‘DATE’ function to convert the ‘Date and Time value’ to just ‘Date’ and use it in GROUP BY statement.
SELECT Date, count(*) FROM Blog GROUP BY DATE(Time)
If you take Drupal for a blog database, it save the time of the blog entry as a unix timestamp. So you have to derive the Date from the timestamp using the infamous FROM_UNIXTIME mysql function,
In Drupal the database table name to store blog is ‘node’ and the field name to store the create time is ‘created’ . So your query to get statistics of Drupal would be something like this.
SELECT DATE( FROM_UNIXTIME(`created`)), count(*) FROM `node` GROUP BY DATE( FROM_UNIXTIME(`created`))
Rather than converting the timestamp to SQL Date format, You can convert Date to timestamp and your sql statement may look little mathematical.
SELECT ROUND( ( UNIX_TIMESTAMP( NOW( ) ) - `created` ) / ( 24 *60 *60 ) ), count( * ) FROM `node` GROUP BY ROUND( ( UNIX_TIMESTAMP( NOW( ) ) - `created` ) / ( 24 *60 *60 ) )
In fact the expression “UNIX_TIMESTAMP( NOW( ) ) – `created` ) / ( 24 *60 *60 )” derives a number that represent the age of the post in days.
So this way you can derive statistics of your data with the use of ‘GROUP BY” construct. The ability to write complex queries in SQL syntax like this is really useful, specially when you access a remote database through a web services (i.e. Data Services) or using database drivers, you have to minimize the number of sql queries to execute as minimum as possible.
Here are some of the other aggregate function that you may use with GROUP BY, http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
A PHP variable has a value and a type. In most practice cases we consider only about the value of the variable. But there may be times we have to consider the type of the variable as well.
For an example value NULL (or 0 or whatever of following you like to call it) can be assigned to a variable with different types like this.
$x = NULL; | NULL data type. Yea it is the real NULL. |
$x = 0; | Integer data type. |
$x = 0.0; | Float data type. |
$x = FALSE; | Boolean data type. |
$x = “”; | String data type. |
You can check the operator ‘===’ (triple equal operator) to check equality of both their values and types simultaneously.
You can have a good idea about this by looking at the following piece of code.
// lets check the equality of NULL and 0 with // double equal operator if(NULL == 0) { echo "NULL == 0 is TRUE</br>"; } else { echo "NULL == 0 is FALSE</br>"; } // now lets check the equality of NULL and 0 with // triple equal operator if(NULL === 0) { echo "NULL === 0 is TRUE</br>"; } else { echo "NULL === 0 is FALSE</br>"; }
This will eventually print the following result.
NULL == 0 is TRUE NULL === 0 is FALSE
PHP variables including class variables get the NULL value and NULL type by default. So if no one assign them a value it remains NULL.
So in a case you have to check for unused variables (or for “NULL”-ness of a variable) you should always use the triple equal operator (===) with NULL token. Otherwise you may mistakenly treat not NULL things like ‘0’ or empty string (“”) as null that may have been valid data for your application.
Web Service can response with a Fault in 2 occasions.
There is a slightly difference in the content of SOAP 1.1 and SOAP 1.2. But they mainly contain the following elements.
Sending SOAP Faults
In WSF/PHP you have the WSFault class to deal with SOAP faults. You can send a fault in your service logic by throwing an instance of WSFault class like this.
/** * divide mathematical operation * @param int $dividend * (maps to xs:int) * @param int $divisor * (maps to xs:int) * @return float $result * (maps to xs:float) */ function divide($dividend, $divisor) { // dividing from 0 is invalid, we wil *throw* fault in such cases.. if($divisor == 0) { throw new WSFault("Sender", "dividing from 0 is invalid"); } $result = (float)$dividend/$divisor; return array("result" => $result); }
Here I have throw an WSFault whenever I encounter my divisor is zero. And the WSF/PHP will take care of building the SOAP message according to the given version (default is to SOAP 1.2) and send back to the client.
Handling SOAP Faults
Similar to the service, client API also treat the SOAP fault as an instance of WSFault. So whenever you do a web service request, put inside try, catch block so you can catch exception in case of fault is received. Here is an example of handling fault while calling the divide operation in the above example.
// creating the client, we retrieved the wsdl from service url + ?wsdl $client = new WSClient(array( "wsdl" => "http://localhost/myblog/fault_service.php?wsdl")); $proxy = $client->getProxy(); try { // calling the operation $response = $proxy->divide(array("dividend" => 5, "divisor" => 0)); // printing the result echo $response["result"]; } catch(Exception $e) { // if the instance is WSFault we print the code and the reason if ($e instanceof WSFault) { printf("Soap Fault Reason: %s\n", $e->Reason); printf("Soap Fault Code: %s \n", $e->Code); } else { printf("Message = %s\n",$e->getMessage()); } }
As you can see WSF/PHP covers the complexity of building and handling SOAP faults, Rather it gives you an API with the use of PHP Exception Construct that you already familiar with.
You can watch a Screencast on How to Consume a Web Service Using WSF/PHP from WSO2 Oxygent Tank developer portal.
There I have presented the steps you need to follow to consume a web service. I choose US National Digital Forecasting database Web Service as my example service to write the demo client.
This screencast contains,