corner imagecorner image
FeaturesPluginsDocs & SupportCommunityPartners

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.

Contents

Content on this page applies to NetBeans IDE 6.0 and 6.1

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE Web & Java EE pack 6.0 or 6.1 or
Java pack 6.5
Java Development Kit (JDK) version 6 or
version 5
Java EE-compliant web or application server Tomcat web server 6.0 and/or
GlassFish application server v2

Both Tomcat and GlassFish can be installed, optionally, with the Web and Java EE distribution of NetBeans IDE. Alternatively, you can visit the GlassFish downloads page or the Apache Tomcat downloads page.

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):

Available web services in Services tab

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.

    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.

  4. Check Visual Web JavaServer Faces under Frameworks, as shown below:
    Selecting Visual Web Java Server Faces (JSF) Framework in New Web Application Project
  5. 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: Completed Page 1 jsp file in Visual Designer

Here is how to design the page shown above:

  1. 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.
  2. Drag and drop a Text Field component next to each Label component. Create 4 text fields in total.
  3. 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.
  4. Right-click all 4 text fields and select Add Binding Attribute from each context menu.
  5. Drag and drop the Button component to the desired location and change the text to Validate and the id to validateButton.
  6. 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.
  7. 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.

  1. 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().
  2. Type or paste the following code. Replace the parameter values for bean.setUserID and bean.setPassword with your StrikeIron credentials.
    public String validateButton_action() {
        USAddressVerificationSoapVerifyAddressUSA bean =
                this.getUSAddressVerificationSoapVerifyAddressUSA1();
        //bean.setUnregisteredUserEmail("your_email_address_here");
        bean.setUserID("your_strikeiron_userid_here");
        bean.setPassword("your_strikeiron_password_here");
        bean.setAddressLine1((String) getAddressLine1TF().getText());
        bean.setAddressLine2((String) getAddressLine2TF().getText());
        bean.setCityStateZip((String) getCityStateZipTF().getText());
    
        getResultTF().setText(bean.invokeMethod().getAddressStatus());
    
        return null;
    }

    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:

  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:
    Web Service test client in browser

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.

Finding more Strike Iron services in IDE

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.



See Also

For more information about using NetBeans IDE 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.

Bookmark this page

del.icio.us furl simpy slashdot technorati digg