New Features in JBuilder 2005 Part IV

Web Services

Web services continue to be an important technology for developers regardless of platform. JBuilder 2005 includes excellent support for both building and consuming web services.

Web Services Designer

The Web Services designer resembles most of the other non-UI designers in JBuilder 2005 (for example, the EJB designer). It allows you to import a Web Service definition either from a WSDL URL or from UDDI. When you import a WSDL, it creates entries for each exposed object. For example, here is the imported Eliza Chat Bot web service.

 

The Web Service Designer allows you to import a WSDL.

Consuming a Web Service

To consume a web service, you use the Web Services Designer to import a WSDL for the service you want to call. The Web Services designer creates a project node (much like the other external configuration items, like web modules or EJBs). When you right click on the designer and issue a Make command, it builds all the necessary sources files to make a call to the web service. In fact, it even builds a JUnit test case that shows you how to call the web service! Once you have built the web service, you can make method calls on it just like any other method. Here is the IDE view for the Eliza web service, which is incorporated into a Swing application.

 

The ClientModule acts as a project node like other designers.

To make the web service method call (after building the web service stub files), you use the Locator as a factory class to create an instance of an object that implements the web service interface. In this example, the ChatLocator acts as a factory to create a chat object. The application allows you to post questions to the chat bot, which she answers.

 

Chatting with the Eliza Bot.

The code underneath the Ask button makes a call to the web service, passing the question text in the textarea on the top.

Web Service Call to Eliza


public void jButton2_actionPerformed(ActionEvent e) {
    SoapInterop.ChatBindingStub binding;
    try {
        binding = (SoapInterop.ChatBindingStub)
                  new SoapInterop.ChatLocator().getIBaseDataTypes();
    } catch (javax.xml.rpc.ServiceException jre) {
        if(jre.getLinkedCause()!=null)
            jre.getLinkedCause().printStackTrace();
        throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
    }
    try {
        txtA.setText(binding.eliza(txtQ.getText()));
    } catch (RemoteException ex) {
        ex.printStackTrace();
    }
}
Creating Web Services

JBuilder 2005 also makes it easy to create your own web services. To create a Web Service, you first create a project. Then, if you select the option to build a new Web Service (and you don’t yet have a Web Module), JBuilder 2005 will prompt you to create a Web Module. This is the web application that will host your web service.One of the options available allows you to copy the Axis toolkit’s welcome page to your web application (Axis is the open source Web Services toolkit JBuilder 2005 uses).

The next step is to build a Java class whose methods you want to expose as web services. This is a Plain Old Java Object (POJO), which doesn’t implement any special interfaces or extend a certain base class. In this case, it is a very simple Math class.

Simple Math Web Service Class


package borcon_mathws;
public class MathServer {
    public MathServer() {
    }
    
    public int sum(int op1, int op2) {
        return op1 + op2;
    }
}

Once you have your class, you associate it with the web service using the designer.

 

Create a web service based on a simple Java class.

Now, just build the web service node. This generates all the necessary source files to publish your web service. When you run the web application, JBuilder 2005 by default takes you to the Axis Admin page.

 

The Axis welcome page.

This page allows you to browse web services and administer Axis. If you choose to view web services, it presents a list of the published web services (which includes the MathServer). Clicking on the link for the web service issues an HTTP GET on the web service, to which Axis responds with the WSDL for that web service.

 

Axis allows you to query the WSDL of your web service.

This web service is now callable from Java, .NET, Ruby, or any other language/platform that supports calling web services. JBuilder 2005 combined with Axis makes building a web service trivial.

Debugging Web Services

The web application built by Axis and JBuilder 2005 is a standard web application, meaning that you can run it in debug mode, using all the debugging features of JBuilder. However, a need still exists to "snoop" on the web traffic between the web application and the client making the web service call. This allows you to debug the SOAP information traveling on the wire. Axis includes a tool called TCP Monitor that allows you to monitor the traffic along TCP. It is included with JBuilder 2005, and shown here.

 

The TCP Monitor tool lets you watch network activity.

Java Server Faces

One of the most significant new API’s to come from Sun in years is Java Server Faces. It is a new framework for building web applications that allows features that previously was only available in desktop applications. JBuilder 2005 has state-of-the-art support for building JSF applications. When you create a new web application, one of the frameworks available is JSF. When you select JSF, you should also choose JSTL (some of the JSF functionality relies on JSTL features). Once you have created the application, create a new JSP and select the JSF tags. JBuilder 2005 presents you with the JSF designer, which is the updated designer for all user interfaces.

 

The component drop area is highlighted.

As you can see, when you select a component from the palette on the left, JBuilder 2005 shows you what markup is going to be added in the JSP. Because this is the first JSF component placed on the page, JBuilder 2005 also realizes that the JSF form and view tags are also required, so it adds them as well. For subsequent components, it will only drop the required markup. When you drop a component on the page, ErrorInsight shows the required property values highlighted.

 

JBuilder 2005 ErrorInsight highlights required components.

Note that JBuilder 2005 uses the JSF tag syntax ("#{…}"), which is close to JSP Expression language syntax ("${…}"). The value property required for the inputTextArea component can either be entered in the JSP source or via the property editor on the right. There are advantages to using the property editor — it will prompt you to create managed components if they don’t yet exist.

 

The property editor prompts you to create binding components.

When you invoke the dialog from the property editor, it allows you to create managed components, reference existing ones, and create managed properties on the components.

 

The Value Binding dialog

JBuilder 2005 makes JSF development as easy as building desktop applications. And that is one of the advantages of JSF — creating a RAD framework to make it easier to develop web applications. JSF combined with a tool like JBuilder 2005 takes web development to a new level of productivity.

Summary

For whatever reason, developers don’t seem to update JBuilder in every iteration. One of the reasons must be the speed in which new versions appear. However, in every version, new compelling reasons and added functionality keeps it one the cutting edge. JBuilder 2005 has a huge list of updated and added features, and should become a part of every Java developers toolkit.

No comments yet

Leave a Reply

You must be logged in to post a comment.