Consuming StrikeIron Web Services in Web Applications
This tutorial outlines the steps to consume StrikeIron web services prepackaged
with NetBeans IDE 6.1 or 6.0, using the Visual Web designer. Specifically,
it will demonstrate how to build a web application that invokes the US Address Verification
service to verify the address entered by the user.
You also need a StrikeIron account in order to
access StrikeIron web services. As a NetBeans user, you obtain free
StrikeIron hits when you register for a StrikeIron account. For more
details, visit http://developer.strikeiron.com/netbeans/freetrial/.
NetBeans IDE 6.0 and 6.1 come prepackaged with a set of popular StrikeIron web services. You can access them by
switching to the Services window, expanding the Web Services node, and opening the StrikeIron Services node.
There, after a moment while the services load, you should see the following services (in 6.0—6.1 has many more):
Later in the tutorial, we will demonstrate how to consume these web services
by dragging and dropping them onto the Visual Web designer.
Creating a Web Project
First, you need to create a web project that is supported by the Visual Web designer.
Choose File > New Project. Under Categories, select Web. Under Projects, select Web Application and click Next.
Under Project Name, enter USAddressVerificationDemo.
Under Server, select the server and click Next.
Creating a project in NetBeans 6.1 includes new options which can be left at the default. For example, the Use Dedicated Folder for Storing Libraries checkbox may be left unselected.
Check Visual Web JavaServer Faces under Frameworks, as shown below:
Click Finish.
Designing the Web Page
After you create the USAddressVerificationDemo project, the IDE
automatically opens the default Page1.jsp in the Design tab,
which contains an empty canvas. On the right-hand side of
the canvas, you will see the Palette (available under the Window
menu). We will implement the page as shown below:
Here is how to design the page shown above:
Drag and drop the Label component from the palette to the
canvas. After the label is created on the canvas, you can
modify the text of the label. Repeat the same step to create 4 labels
in total. You can drag the labels with the mouse to arrange them as
you want.
Drag and drop a Text Field component next to each Label component.
Create 4 text fields in total.
Change the id property of each text field, by selecting the text field
with the mouse and changing the id in the text field's Properties window.
From top to bottom, set the text fields' id properties to the
following: addressLine1TF, addressLine2TF,
cityStateZipTF, and resultTF.
Right-click all 4 text fields and select Add Binding Attribute from each
context menu.
Drag and drop the Button component to the desired location and change
the text to Validate and the id to validateButton.
Switch to the Services window. In the Services window, expand the Web Services node, then the StrikeIron
Services node, then the USAddressVerification node, and finally the
USAddressVerificationSoap node.
Drag
and drop the verifyAddressUSA operation node onto the canvas. As shown in the
screenshot above, you should now see
two new nodes, USAddressVerificationSOAPVerifyAddressUSA1 and USAddressVerificationSoapClient1,
appear under the Page1 node in the Navigator.
Implementing the Web Page
This section shows you code to invoke the US
Address Verification service. This code uses the web page you made in
Designing the Web Page to collect data and display the result.
On the Page1.jsp canvas, double-click the Validate button.
The IDE switches to the Java source view
and places the cursor on the validateButton_action().
Type or paste the following code. Replace the parameter values for
bean.setUserID and bean.setPassword with your
StrikeIron credentials.
In order to access StrikeIron web services, you need a StrikeIron
userid and password. You can obtain free StrikeIron hits by registering for a
StrikeIron account. For more details, visit
http://developer.strikeiron.com/netbeans/freetrial/.
Testing the Web Page
To test the application, do the following:
In the Projects window, right click the project and choose Run. The server starts and the browser opens.
In the browser, type in an address in the Address Line 1, Address Line 2 and City State & Zip text f
ields and click Validate. You should see the result in the Result field as shown below:
Looking for More StrikeIron Services
In the Services window, right-click on the StrikeIron Services node and choose Find StrikeIron
Services. Type a search word, such as "stock", and press Enter. When the search returns,
the results are displayed in a list on the left of the dialog.
Select a row to see the service description details.
To use a service, select it and click Add. The new service is added to the StrikeIron folder and
is then immediately ready for trying out.
To send comments and suggestions, get support, and keep informed on the latest
developments on the NetBeans IDE Java EE development features, join
the mailing list.