Products Docs & Support Community

Consuming StrikeIron Web Services in Web Applications

This tutorial outlines the steps to consume StrikeIron web services prepackaged with NetBeans IDE 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.

Software Needed for the Tutorial

Before you begin, you need to install the following software on your computer:

  • NetBeans IDE 6.0 Web & Java EE
  • Java Standard Development Kit (JDK) version 5.0 or above (download)
  • An application server that supports web services and JSF, such as Glassfish V2 or the Tomcat Web Server, both of which you can select from the installer that you use to install NetBeans IDE 6.0.

NetBeans IDE 6.0 comes 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:

Note: In order to access the StrikeIron web services, you need to have a StrikeIron userid and password. You can obtain them from StrikeIron. Alternatively, you can simply provide your unregistered e-mail address. However, in this case you will only be able to access the services a very limited number of times.

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.

  1. Choose File > New Project. Under Categories, select Web. Under Projects, select Web Application and click Next.
  2. Under Project Name, enter USAddressVerificationDemo.
  3. Under Server, select the server and click Next.
  4. Check Visual Web JavaServer Faces under Frameworks, as shown below:

  5. Click Finish.

Designing the Web Page

After you create the USAddressVerificationDemo project, the IDE automatically opens the default Page1.jsp in the visual designer. On the right-hand side of the canvas, you will also 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:

  1. Drag and drop the Label component from the palette to the desired location. After the label is created on the canvas, you can modify the text of the label. Repeat the same step to create each label.
  2. Drag and drop the Text Field component to the desired location. Change the id property for the text field in the Properties window. Repeat the same step to create each text field. For this demo, from top to bottom, change the id for each text field to the following: addressLine1TF, addressLine2TF, cityStateZipTF, and resultTF.
  3. Drag and drop the Button component to the desired location and change the text to Validate and the id to validateButton.
  4. Switch to the Services window. In the Services window, expand the Web Services node, then the Strike Iron Services node, then the USAddressVerification node, and finally the USAddressVerificationSoap node.
  5. 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 walks your through implementing the code to invoke the US Address Verification service using data collected and display the result.

  1. Double-click the Validate button. The IDE switches to the Java source view and places the cursor on validateButton_action().
  2. Type in the code as shown below:
    public String validateButton_action() {
        USAddressVerificationSoapVerifyAddressUSA bean =
                this.getUSAddressVerificationSoapVerifyAddressUSA1();
        //bean.setUnregisteredUserEmail("your_email_address_here");
        bean.setUserID("your_userid_here");
        bean.setPassword("your_password_here");
        bean.setAddressLine1((String) getAddressLine1TF().getText());
        bean.setAddressLine2((String) getAddressLine2TF().getText());
        bean.setCityStateZip((String) getCityStateZipTF().getText());
        getResultTF().setText(bean.invokeMethod().getAddressStatus());
        return null;
    }

    Note: In order to access the US Address Verification service, you need to enter your StrikeIron userid and password. You can obtain them from StrikeIron. Alternatively, you can specify your e-mail address by uncommenting the statement calling setUnregisteredUserEmail() and commenting out the calls to setUserID() and setPassword(). However, you will only be able to access the service a very limited number of times. When using the unregistered approach, you will first receive an error when you invoke the web service, at the end of the next step, if you invoke it before the unregistered e-mail address has been processed by StrikeIron. An e-mail should arrive at the specified e-mail address, to indicate that you can make use of the web services. At that point, you can make use of them.

Testing the Web Page

To test the application, do the following:

  1. In the Projects window, right click the project and choose Run. The server starts and the browser opens.
  2. 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:



Next Steps

For more information about using NetBeans IDE 6.0 to develop Java EE applications, see the following resources:

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.