In early April 2002,
the Google search engine we all know and love opened its doors
to web services by introducing the Google Web APIs service. Developers
can now tap the seemingly limitless amount of information available
in Google's database, which consists of over two billion documents.
Because of the support for web services in Macromedia ColdFusion
MX, the Google Web APIs service is now available not only to ColdFusion
developers but also to Macromedia Flash MX developers.
In fact, there are several potential audiences that can use the
Google web APIs as a web service in ColdFusion MX:
- A Java developer, familiar with web services, produces a
CFX tag that allows ColdFusion developers to use Java functionality
without understanding Java code.
- A ColdFusion developer with some Java experience leverages
the Google web APIs service and Java interoperability newly
available in ColdFusion MX.
- A beginning ColdFusion developer invokes the Google Web APIs
service directly.
- An advanced ColdFusion developer promotes encapsulation by
building a ColdFusion component that wraps the Google Web APIs
service.
- A Macromedia Flash MX developer uses ActionScript to connect
to a ColdFusion component for the Google Web APIs service connectivity.
- A Macromedia Flash developer leverages the Google Web APIs
service directly using the Macromedia Flash Remoting feature
in ColdFusion MX.
This article is the first in a series that explores the above
possibilities in ColdFusion MX. Instead of focusing on architecture,
it teaches you different ways to invoke a web service in ColdFusion
MX—using Java, ColdFusion code, ColdFusion components, Macromedia
Flash MX, and Macromedia Flash Remoting. I will first start with
a short overview and list of prerequisites and then I’ll
explain how a Java developer can implement server-side code with
Java and make it available to ColdFusion.
Note: The easiest way for ColdFusion MX developers
to implement web services is through ColdFusion components and
the cfinvoke tag, which will be explained in future installments
of this article series, and is currently explained in other web
services articles in the Macromedia Designer and Developer Center.
For those of you using ColdFusion versions prior to ColdFusion
MX, however, this article gives the Java developer options for
exposing web services to ColdFusion developers through a Java
CFX tag. This article assumes you understand Java basics to create
the Java CFX tag.
Before you get started
Download
the sample files for this tutorial.
You need the following Macromedia software for this tutorial:
- Macromedia ColdFusion
MX. You can download a trial or purchase a full version.
- Macromedia
Dreamweaver MX. If you haven't explored the features of
Dreamweaver MX, this will be a great opportunity to find out
more. You can download a trial or purchase a full version.
You also need the Google Web APIs (Application Programming Interface)
service. Download the developer's kit from Google at http://www.google.com/apis/.
This file is small (less than 1 MB) and is essential for this
tutorial. It's free and you don't even have to enter your e-mail
address to download it. It includes the WSDL file (don't worry,
I'll explain the acronym later), a Java library, and documentation
for access to the Google Web APIs service, among other items.
Once you've downloaded the Zip file, unzip it into an easily accessible
directory.
Once you download and extract the Google Web APIs service (Step
1 at: http://www.google.com/apis/),
configure ColdFusion so it has access to the Google Web APIs service
with the following procedure:
- In the ColdFusion Administrator, select the "Java and
JVM" menu option. Look at the entry for a classpath setting.
A classpath tells the underlying Java implementation where to
look to find additional libraries that are used by application
components. In this case, that component is the Google Web APIs
library.
- In the classpath field enter the full path to the googleapi.jar
file (including the filename) that you downloaded and installed
with the Google Web APIs (in the prerequisites). The googleapi.jar
file is typically located in the directory where you extracted
the Google Web APIs ZIP file (such as, c:\googleapi\googleapi.jar).
- In order for this change to take effect, click the Submit
Changes button and restart the ColdFusion services, as prompted
by the ColdFusion Administrator.
Next, create a Google account (Step 2 at: http://www.google.com/apis/).
Although doing so is free, you must supply your e-mail address
in order for you to receive a license key that allows your programs
to access the Google Web APIs service. The key is a short string
that you must include whenever your code calls the Google Web
APIs service. The key limits how many times per day you can query
Google from your applications. The default limit imposed by Google
is 1,000 queries per day. You will need to insert the key into
the CFML file included with the sample files for this tutorial.
This article is not intended to teach you Java. Nonetheless,
ColdFusion MX has excellent Java interoperability and some of
the examples use Java objects. In this part of the series, invoking
a web service with a Java CFX, you must have the appropriate JDK
installed. The examples in this article were built using JDK 1.4.
Any JDK of version 1.2 or greater will work. Upcoming articles
in this series do not use a CFX tag and therefore do not require
an additional JDK installation.
|