Step 7: Use the Control from the Web Service

In this section, you will insert a method in the web service to call a method on the custom control.

Insert a Control

  1. In the Project Explorer, double-click the web service file ServicesWeb/Java Resources/src/services/MailingListService.java.
  2. Right-click in the Design View editor, then select New Control Reference.

    New control reference

    In the Select Control dialog, note that you can choose from various existing controls, including MailingListControl, the one you created earlier in the controls package.

  3. Select MailingListControl - controls, then click OK.

  4. Press Ctrl+Shift+S to save your work.

In Design View, the web service should look like this:

The web service code in Source View should be as follows:

package services;

import javax.jws.*;
import org.apache.beehive.controls.api.bean.Control;
import controls.MailingListControl;

@WebService
public class MailingListService {

    @Control
    private MailingListControl mailingListControl;

    @WebMethod
    public String getCustomers() {
        return "John Smith";
    }
}

Note that Workshop added the required imports for MailingListControl. It also added a variable declaration for a control of type MailingListControl named mailingListControl. Workshop declared mailingListControl to be a control by adding the @Control annotation.

Call a Method on the Control

You will now add a method to the service that will call a method on mailingListControl, the instance of MailingListControl you just created.

  1. In Design View, right-click the control method getLocalCustomers and select Generate Delegate Method.

    A corresponding method is added to the web service client interface.

  2. Press Ctrl+Shift+S to save your work.

The source code for the web service class should now be as follows:

package services;

import javax.jws.*;
import org.apache.beehive.controls.api.bean.Control;
import controls.MailingListControl;
 
@WebService
public class MailingListService {
 
    @Control
    private MailingListControl mailingListControl;
 
    @WebMethod()
    public String getCustomers() {
        return "John Smith";
    }

    @WebMethod
    public model.Customer[] getLocalCustomers() {
        return mailingListControl.getLocalCustomers();
    }
}

The new method calls the control method getLocalCustomers, which will return an array of Customer objects for all customers in California in the sample database.

In the next step, we will test the new method.

Click one of the following arrows to navigate through the tutorial:


Still need help? Post a question on the Workshop newsgroup.