Thursday, February 28, 2008

WSDL to PHP Classes

If you look at the PHP SOAP mailing list, most of user problems are related to complex types in WSDL. One big usability drawback of PHP SOAP extension is it does not have good tools to generate PHP classes from the WSDL at hand (contract first approach). Now, you no longer need to worry about it, as WSF/PHP team is working on a static code generation tool [More info in PHP WS blog]. Good news is that it comes to you free of charge. I think this will greatly enhance user experience with PHP Web Services. They are planning to have an initial cut of the tool in version 1.2.1. Nightly builds and svn should give you an snapshot of it. With the pace of development going on with WSF/PHP, there is a high possibility of having it as a standard PHP extension in the near future.

Tuesday, February 19, 2008

Format war is over

The battle for industry standard between Toshiba's HD DVD and Sony's Blu-ray format ended today after Toshiba's official announcement of stop making its high definition DVD's (having seen major players choosing rival Blu-ray format)

What is the situation of the people who bought HD DVD devices? Apparently there are over 1m users over worldwide.

Now that the battle is over, at least the new customers don't need to worry about which format to go with. With no more competition, can we expect the prices to go down? This move may bring the prices of Blu-ray players and devices down due to additional profit from patent and mass volume sale.

Sunday, February 17, 2008

Grand Challenges for Engineering/Sciences

Recently, the US National Academy of Engineering announced top 14 grand challenges we face in the 21st century. They have focused on the problems that should be (can be) solved (solvable) in the near future.

The list:
-Advance health informatics
-Engineer better medicines
-Make solar energy economical
-Provide access to clean water
-Reverse-engineer the brain
-Advance personalized learning
-Engineer the tools of scientific discovery
-Manage the nitrogen cycle (What this basically means is to find ways to reproduce nitrogen to maintain the bio-geochemical cycle which is being altered by increased use of fertilizers and industrial activities. Reduction in nitrogen in air leads to, among other things, smog, acid rain, polluted drinking water and global warming.
-Provide energy from fusion
-Secure cyberspace (identity thefts, viruses, etc.)
-Develop carbon sequestration methods (methods to capture carbon dioxide produced from vehicles and factories from burning fossil fuels, a major culprit of global warming)
-Enhance virtual reality
-Prevent nuclear terror ( I think this is more political than technological. We already have the technology in place; it's a matter of how we use it only for purposes that benefit humankind.)
-Restore and improve urban infrastructure

There's a good introduction about this in their website.

I personally think the following are especially important (from a technological point of view but not political):
-"Economical" clean energy sources to substitute for fossil fuels (fast diminishing)
-Methods to remove carbon dioxide and cycle nitrogen to control global warming
-Methods to prevent, detect, recover from, cyber attacks. With more and more people/businesses do their financial transactions online, we need effective methods to protect them from malicious attackers.

Saturday, February 16, 2008

Purdue Fulbright Association

With busy academic schedules, I was able to find some time to develop the first cut of the web site for the $subject. It's a combination of HTML+JavaScripts+PHP+MySQL. Purdue provides web space to host web sites for registered student organizations. Here's the URL: http://web.ics.purdue.edu/~pfa/

To prevent spams, I use a simple request-response protocol in this site instead of using CAPTCHA as I don't see strong security requirements for this web site. I also have developed a (stronger) purely server-side approach which uses AJAX to make things efficient (prevent complete page reloading when talking with the server). I will text about it in a future blog when I get some free time so that it might be helpful for those looking for such solutions.

Saturday, February 9, 2008

Secret Sharing

I found this bibliography on secret sharing useful (over 200 references!). It has not been updated after 1998, but you will find many key work done in this area since it was initially introduced in 1979 independently by Adi Shamir and George Blakley.

The basic idea behind Shamir's (t, n) threshold scheme (t <= n) based on Lagrange interpolating polynomials is to split the secret among n people and you need at least t people to construct the key. (Example: 5 people have formed a business and you don't want to allow access to company bank account if majority does not agree. You define ceiling(5/2) <= t <= 5).

How it works: t points in Cartesian coordinate (x1, y1), ..., (xt, yt) uniquely identifies a polynomial of degree <= t-1 in that space. That the Lagrange polynomial. You define a polynomial f(x) = a0 + a_1.x + .. + a_{t-1}x^{t-1} where a0 represent the secret you want to split among n people. You randomly choose n points that satisfies f(x) and give those to each person. If you have at least t points, you can use the Lagrange polynomial to determine the unique polynomial corresponding to those points. The constant gives you the secret value. In practice, we usually take the modulus of f(x) (i.e. f(x) mod p) to bound the points without revealing no more information than it already reveals. There has been numerous extensions to the above idea in the literature some of which are available in the page I mentioned above.

Sunday, February 3, 2008

Diamond for whom?

We, Sri Lankans, mark the 60th independence day tomorrow (Feb. 4th). Or have we actually gained real independence? While corruption and inflation are looming, people find it really hard to keep home fires burning. Party politics has made things worse. It's time we realize that it's only through unity we can achieve the dreams of those shed blood and toiled in 1948 and before, and achieve true independence.

(Update: And the most brutal terrorist group (some information in this wiki page may not be fully consistent as I can see a lot of undoing going on. As a side node, wikipedia should come up with a way to detect suspicious modifications and maintain the authenticity) marked the day with a series of suicide bomb attacks[1, 2, 3] killing innocent civilians)

Saturday, February 2, 2008

Rest in 10 Minutes

Without going into theoretical aspects, I thought it would be helpful for a newcomer to just take a pragmatic approach to get started with REST.

REST stands for REpresentational State Transfer. The key idea behind REST is resources. Everything in the networked world is a resource.
Each resource can be uniquely identified by a URI (E.g: URL's in WWW). WWW is a good example of RESTful design.
These resources can be linked together (E.g: Hyperlinking in WWW).
There's a standardized protocol for client to interact with the resources. (E.g.: Web browsers using HTTP's standard methods such as GET, POST, PUT and DELETE).
It allows you to specify the format in which you want to interact with. (E.g: HTTP Accept headers such text/html, image/jpeg etc.)
It's a stateless protocol. (E.g: HTTP is stateless)

I will now walk you through a simple PHP code snippet to invoke REST services using GET method.

The idea is as follows.
You get the base URL of the resource you want to access. (E.g.: The base URL of Yahoo Traffic REST service is http://local.yahooapis.com/MapsService/V1/trafficData).
You URL encode the parameters expected by the service to indicate your intension. (baseurl?name1=value1&...&namen=valuen)
You get the result back, usually in XML format which you can manipulate easily.

A word about implementations. There are SOAP libraries (e.g.: WSF/PHP) out there which allows you invoke restful services. You can also access such services with those libraries already available. Today, I will take the latter approach and will look into the former approach in a future blog entry.

There are mainly two ways to implement REST clients with built-in PHP libraries.
1. Using cURL
2. Using file_get_contents()

I used the first approach.

Here's how you'd access some the services provided by Yahoo.

Yahoo Locations:

include_once('RESTClient.php');

$base = 'http://local.yahooapis.com/MapsService/V1/geocode';

$params = array( 'appid' => "YahooDemo",
'street' => '271 S River Road',
'city' => 'West Lafayette',
'state' => 'IN',
);

$client = new RESTClient();
$res = $client->request($base, $params);

// Output the XML
echo htmlspecialchars($res, ENT_QUOTES);

$xml = new SimpleXMLElement($res);
echo
"
Latitude : "
.$xml->Result->Latitude."
"
;
echo
"Longitude : ". $xml->Result->Longitude."
"
;
echo
"Address : ". $xml->Result->Address." ".$xml->Result->City." ".$xml->Result->State." ".
$xml->Result->Zip." ".$xml->Result->Country;

?>


Output:
[XML Omitted]
Latitude : 40.419785
Longitude : -86.905912
Address : 271 S River Rd West Lafayette IN 47906-3608 US


Yahoo Traffic:

include_once('RESTClient.php');
$base2 = 'http://local.yahooapis.com/MapsService/V1/trafficData';
$params2 = array( 'appid' => "YahooDemo",
'street' => '701 First Street',
'city' => 'Sunnyvale',
'state' => 'CA',
);

$res2 = $client->request($base2, $params2);

// Output the XML
echo htmlspecialchars($res2, ENT_QUOTES);

?>


Output:
[XML omitted]
Severity[1-5, 5 being the most] : 2
Description : NORTHBOUNDLONGTERM FULL RAMP CLOSURE CONSTRUCTION


Yahoo Maps:

include_once('RESTClient.php');
$base3 = 'http://local.yahooapis.com/MapsService/V1/mapImage';
$params3 = array( 'appid' => "YahooDemo",
'street' => '271 S River Road',
'city' => 'West Lafayette',
'state' => 'IN',
);
$res3 = $client->request($base3, $params3);
$xml3 = new SimpleXMLElement($res3);
echo
".$xml3."'/>
"
;

?>

Output:

As you might have notices I have included 'RESTClient.php' above. Here's the code for the RESTClient class.

//Curl based REST client for GET requests
class RESTClient {
//request takes two parameters
//$baseUrl - base URL of the resource you want to access
//$param - an associative array of parameters you want to pass with the request
public function request($baseUrl, $params) {
$queryString = '';
$responseXml = null;
$response;
$resourceUrl;

foreach (
$params as $key => $value) {
$queryString .= "$key=" . urlencode($value) . "&";
}
$resourceUrl = "$baseUrl?$queryString";



// Initialize the session giving the resource URL
$session = curl_init($resourceUrl);


// Set curl options
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the request
$response = curl_exec($session);

// Close the curl session
curl_close($session);

// Get HTTP Status code from the response
$statusCode = array();
preg_match('/\d\d\d/', $response, $statusCode);

// Check the HTTP Status code
switch( $statusCode[0] ) {
case
200:
break;
//OK
case 503:
echo(
'Failed: 503 : Service Unavailable.');
break;
case
403:
echo(
'Failed: 403 : Access Forbidden.');
break;
case
400:
echo(
'Failed: 400 : Bad request.');
break;
default:
echo(
'Unhandled Status:' . $statusCode[0]);
}

if (
$statusCode[0] == 200) {
$responseXml = strstr($response, '); //stripping off HTTP headers
}
return
$responseXml;
}
}
?>


Friday, February 1, 2008

Is Lighter Better?

The $subject is quite different from what I usually text about. With my busy schedule, I found some time to read certain sections of the book "Is Lighter Better? Skin-tone Discrimination among Asian Americans" by Joanne L. Rondilla and Paul R. Spickard. I was more interested in authors findings abouts Asians themselves about this deep rooted phenomenon. Come to think of it, most of the things we, Asians, experience about colorism are very true in this book. Take movie stars, those in TV commercials, presenters, etc.

It's a good read up on "colorism" and to get to know about people's experiences with skin-tone.

When to/not to Use Web Services

It's not a secret Web Services are getting popular as both P2P integration and consolidation technology. There are limits to what can and cannot be achieved with any technology. Web Services are no exception.

When to use Web Services:
-To integrate heterogeneous systems (different platforms, different languages)
-when you don't know about client environment in advance (For example, Web Services API's provided by amazon.com, numerous mash-up servers, etc.)
-When you want to have the same data in different presentation (This is due to the fact that messaging is purely based on XML and XML can easily be converted to different document formats)
- To make web site content available as a services (Think of as a replacement to RSS feeds)
- To provide different entry points to the same data repository. (For example, data services provide an abstraction for database access)
-To interface legacy systems
- To build B2B electronic procurement systems
- To expose a software as a service
- To reuse existing components; Unlike traditional middle-ware technologies which are essentially using a component-based model of application development, Web services allow almost zero-code deployment.


When not to use Web Services :
-It is not the most efficient (in terms of response time) way to transfer data compared to RPC, CORBA, etc which use native binary messages. Until we find efficient ways to handle XML, web services may not be used for systems where there are stringent real-time timing requirements.
-Message size is lager than that of its predecessors (of course it depends on the encoding used and standardize text added to the message also contributes to this). It may not be suitable for high data volume systems.