Automated Billing and Faxing for the Web - Getting a Transaction Notification
(Page 3 of 5 )
When an order is processed, PayPal generates a notification that is then posted to the URL specified in the form as the hidden field notify_url. This is an example of a web service that relies on ordinary HTTP—no fancy SOAP or other RPC underpinnings.
Using a simple HTTP request/response is perhaps the most basic, universal real world web service. It works with virtually every programming language and requires no special configuration to use. It’s a classic case of the simple solution being the best solution.
Example 6-2 shows the JSP used to receive notifications from the PayPal server.
Example 6-2. Notification JSP
<%@ page contentType="text/html; charset=iso-8859-1"
language="java" import="com.cascadetg.ch06.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/ xhtml1/DTD/xhtml1-transitional.dtd">
<%
new PayPalReciept().handleRequest(request, response);
response.setStatus(200);
%>
The lineresponse.setStatus(200)notifies PayPal that the notification has successfully been handled. By default, PayPal resends the notification until it gets a status code of200back, indicating that the transmission was successful. Disabling this line or substituting a different response code is an easy way to generate additional test load for your server without having to manually enter a lot of transactions.
The bulk of the work for this application is handled by supporting Java classes, as shown in Figure 6-5.
The first class, shown in Example 6-3, exposes one main method,handleRequest(), to the JSP page. In thehandleRequest()method, the first thing to be done is verify that the data sent by PayPal is correct with theverifyRequest()method. TheverifyRequest() method retrieves the parameters sent by PayPal and then posts

Figure 6-5. PayPal and Fax classes
them back to PayPal via an HTTPS connection, with an additional parameter added (cmd=_notify-validate).
Next: Getting a Transaction Notification continued >>
More Web Services Articles
More By O'Reilly Media
|
This article is excerpted from chapter six of the book Real World Web Services, written by Will Iverson (O'Reilly; ISBN: 059600642X). Check it out today at your favorite bookstore. Buy this book now.
|
|