Tag: Web Services

 

Web Services Part 1 – Dissect Apache SOAP

Until now anybody who has an eye opening on the technology world should have heard enough about Web Service. Is it hype or the next big one?

It seems the server side is becoming a technology-congested area, which is crowded with Web Servers, Application Servers, Transaction Servers, Message Servers, Directory Servers, and Security Servers and so on. Not mention those traditional players that eager to set feet to the server frontier, such as Database Servers, ERP, CRM or PDM systems. In the battleground, the infrastructure technologies or platform technologies are beating up each other too. The fighters in the ring could be found as J2EE/EJB, CORBA, DCOM and the newcomer .NET. So, what is Web Service to do with all of these?

Web Service is a peacemaker.

Web Service connects the extensively wired but technologically segmented world regardless the technical religion, technology cult or commercial power. It offers the first but slightly tangible hope that mentioned in the beetle song, Imagine, “imagine there will be no religion, imagine there will be no nations… imagine the world is ONE…”

A New Game

Comparing to the technologies that Web Service serves, it is much less complex. Web Service is more a simple agreement on paper than a scientific based technology. We will skip the history part of Web Service, which could be found at first couple of paragraphs in any article about Web Service. To start from the basic, all of the Web Service is defined as a XML Document Type Definition (DTD) file. It defines the messaging protocol in XML format that enabling remote procedure call (RPC).

How New?

The buzzword RPC has been around for many years. Under the RPC cloud, blowing with the distributed computing wind, there are several technologies hovering for attention. They are:

OSF DCE – Seems nobody mentions it anymore.

CORBA – Still around but never becomes a reality. Too elite to survive.

DCOM – Microsoft always wants to eat a piece of everyone’s lunch. It will be always in sight.

IIOP/RMI – Here comes Java. Don’t know about Sun, seems people start passing it. It becomes a deep infrastructure technology.

EJB – Can’t call it an infant anymore. May be this is the one finally everyone loves.

Now the Web Service. Is it a competing new thing? At the surface, the answer tends to be yes. But if look further, the role Web Service plays is different. It opens a door toward a room that nobody is in there. It’s a new thing by itself. That is because:

o It uses XML, which is a thing that nobody has problem with.

o It brings no new technology. It could be on top of everything. To be more generic and plausible, HTTP is the de facto Web Service message carrier, which is owned by nobody and belonging to everyone.

o Start from the very beginning, there is no slit of intension from Web Service to compete or replace any establishing technology.

o It just wants to have a simple and less expansive way to allow everyone talk to each other.

Architecture

Now, let’s take look what the world would be with the Web Service in it.

Four static elements compose the Web Services:

XML
There is XML, then Web Service. All Web Service definition and message are in XML.

Universal Description, Discovery and Integration (UDDI)
UDDI provides the protocol to register and find a Web Service in a public UDDI directory. At the time Business-to-Business application integration is still in the early stage, UDDI is far from reality. A directory such as a LDAP based service is more tangible for sharing Web Service.

Web Service Definition Language (WSDL)
WSDL is again a XML DTD that defines standard way of describe a Web Service. It certainly could document a Web Service in any format such Word document or an Excel file. Then the developer should have no problem start develop an application to access the Web Service based on the documents. However, documenting a Web Service in WSDL provides a big room for future automatic client site Web Service stub generation or using GUI application to configure/plug-in Web Service.

Simple Object Access Protocol (SOAP)
Until now, SOAP = Web Service. SOAP is a XML DTD that defines how message will be sent cross the wire. As long as you sent a service request in SOAP, it does not matter how the Web Service is constructed. It will serve you.

Put them all Together

As a developer, you are not expected to implement the SOAP from scratch. Two pieces of the puzzle will finish the whole picture: SOAP API and Server Side SOAP Module.

SOAP API

For Web Service client developer, you don’t have to know XML and the detail of the SOAP DTD. The SOAP API provides you functions that can be easily used to call a remote Web Service.

For the service side of Web Service, the SOAP API allow the developer expose the service to public without deal with the details of SOAP.

Server Side SOAP Module

SOAP module is becoming a must-have component of the modern application servers. It listens the SOAP request, parses it, passes it over the request services and returns the results back to clients.

The benefits and impacts the Web Service brings to the IT world are enormous. It certainly adds an ingredient to the complexity of the enterprise computing architecture. But the techniques of constructing a Web Service and accessing a Web Service are easy and simple. We will look at how the major application server players handling SOAP. Let’s start from the free world, Apache.

The Apache SOAP Project

Before developing a J2EE based application system, a developer should always stop by the Apache Open Source Foundation ‘s web site. Despite the religion aspect of Open Source movement, it does provide high performance and reliable software system and application development tools.

Apache SOAP is just such an open-source implementation of the SOAP v1.1 and SOAP Messages with Attachments specifications in Java. It is the most simple and powerful SOAP API on the market. To Web Service application developers that don’t want themselves to be nailed to a specific application server platform, Apache SOAP API is a safe choice.

Apache SOAP has all the necessary bolt and nuts to construct either client application accessing a SOAP Web Service or to enable a server side function to be a Web Service.

Apache SOAP Client for RPC Service

In the distributed computing arena, RPC is the most serious word and is everything behind the concept ‘distributed”. At programming level, RPC is just way of calling a procedure, which happens to exist remotely. For Apache SOAP, since the SOAP message is as de facto carried through HTTP, a stateless TCP/IP based protocol, the PRC here is really a reminder of requesting a Web Service in a synchronized fashion. It means that a SOAP RPC client program is waiting and expecting the return result immediately for every request sent to a Web Service.

Writing an Apache SOAP RPC client is a very simple task, provides all the information regarding the Web Service are available, such as the URI of the Web Service, method name to call and parameters for the remote method.

The steps and Apache API involved are showing in the sequence diagram early in this section.

Apache SOAP Client for Messaging Service
Message oriented computing has been around for a while. Message server such IBM MQ Series and the new message queue servers based on Java Message Service Framework from Sun are becoming one type of backbone services in enterprise computing environment. Web Service defiantly should be able to expose the messaging service to remote client via SOAP.

To have access to messaging service, a developer could use Apache SOAP API with more detail granularity. There is a set of lower level classes are provided with Apache SOAP to construct a message sent to server.

Apache SOAP RPC Server

The beauty of Web Service is its simplicity. Apache SOAP brings most of the beauty out of Web Service. There is no programming needed for exposing application functions as a Web Service. It is just the matter of configuration.

Once finished installation of Apache SOAP for application server such as Apache Tomcat, a SOAP Servlet is plugged into the application server, which will filter and parse SOAP message from outside world. To enable a application to be a Web Service, the developer just need create a SOAP deployment descriptor file, witch is a XML file just like the standard Servlet deployment descriptor file, web.xml. Once the descriptor file is deployed, the job is done. Currently Apache SOAP surpport three types of exposition, for Java Application (classes), EJB, server side BSF Script.

The last two steps, Create WSDL file and Register to UDDI Service, are really options.

Apache SOAP Messaging Server

Developing a SOAP messaging server with Apache SOAP is a bit involved comparing to expose a RPC based Web Service. The application function can only be exposed as Web Service by implement Apache SOAP API with predefined function signature. The Web Service should take the responsibilities to parse the SOAP request and return information. After done development, the deployment is no difference from the RPC server. A deployment descriptor file should be created and deployed to Apache SOAP application server module.

The Road Ahead

Since the emerging of Internet, seems everyone has been forced to be in caching-up mode. Web based application architecture is quickly evolved from CGI, Server Side process caching, Server Side Scripting, ASP/DCOM to Application Server, JSP, Servlet and EJB. Building enterprise web application framework architecture is just like buying a computer, once you paid the bill and bring it home, there are immediately better ones loaded on the shelf.

Now again, Web Service promises everything. We all hope Web Service could finally close application integration loop and offer us a stable and long live architecture. However, I doubt the technology will stop just here, there will be always better way to do the job. Therefore, the best you can do is to keep your eyes wide open.

Wireless LAN@Home, Part I – Wi-Fi is Wining, Bluetooth and HomeRF are Fighting

Starting from year 2000, the installation base of broadband Internet connection at home is escalated. Statistic also shows that more and more family own more than one PC. Home LAN (local area network) is definitely and obviously the next consideration for those PCs.

When talking about connection, communication equipment and PC at home, it always involves wires, sockets, connectors, technical jargons and the works to put them together. Not mention the frustrations encountered to the non-computer-savvy people.

Just thinking about how many wires we have at home, there are phone lines, cable TV lines, speaker wires and of cause, power lines. If you did not build the house yourself, certainly once a while you need spend time for some do-it-yourself wiring works.

Another cable for PC?!

Now, let’s put the end of it.

The advancing of technology brings to market a wonderful breed of products that enable computers and even home appliances connection to each other, oh yes, wirelessly with reasonable cost. They are Wi-Fi, Bluetooth and HomeRF, weird names though.

In this article, I will focus on Wi-Fi because this technology is relatively mature and it is wining the competition. It also has a long list of products available from varieties of well-known vendors. Bluetooth, as a hot technology baby, is making the first set of steps all by itself and soon to be a hyper noise young adult. But seems it’s walking into a different area than Wi-Fi’s and claim as an owner: consumer electronics and home appliances. As for HomeRF, I announce it’s a loser.

Technical Background

The term “Wi-Fi” is used in place of IEEE 802.11b HR, as “Ethernet” is used instead of IEEE 802.3. So, if you are familiar with Ethernet already, it’s time to know Wi-Fi only because it will rule the LAN world in the near future.

Wi-Fi products are based on the IEEE 802.11b WLAN standard, which operates in the worldwide 2.4 GHz Industry, Science, and Medicine (ISM) band. The WECA (Wireless Ethernet Compatibility Alliance) is the nonprofit organization to certify interoperability of Wi-Fi products and to promote Wi-Fi as the global, wireless LAN standard across all market segments. It was formed in 1999, initially by 3Com, Cisco Systems, Intersil, and Lucent Technologies. Now there are more than 60 major network companies become member of WECA and the member base is growing.

Wi-Fi is aiming at both business and consumer market. It could be the replacement or extension of existing Ethernet based LAN.

If you a bit about modern network technology, you must know the seven (7) ISO layers. IEEE 802.11b, as Wi-Fi standard, is defined at the Physical (PHY) layer and Medium Access Control (MAC) sub-layer.

There are two major technology differences between wired and wireless Wi-Fi LAN. They are Network Topology and Radio Technology.

Network Topology

In wired LAN, topology is an essential architecture consideration. Ring (Token-Ring) or Bus (Ethernet), it was used to be a big question. Alone with Ethernet dominating the LAN world, there are more questions because topology also determine the connecting media. We have 1Base5 (UTP star topology), 10Base5 (tick coaxial bus topology), 10Base2 (thin coaxial bus topology), 10BaseT (UTP star topology), fiber (FDDI) and couple of others. There are different types of category for UTP, which replaced coaxial in most of local LANs.

In Wi-Fi wireless LAN (WLAN), I would say the topology concept is not significant any more. The only reason we still mention topology with WLAN is because it’s a big deal with Wi-Fi’s ancestor, Ethernet. When the air is the connection media, how would we talking about topology?

There are and will be many writings talking about the benefits of using wireless LAN in business or at home. But I think it’s saying all when you compare one breathes through a pipe that inserted into his noise and one breathes in the open air.

Radio Technology

We can eliminate the jargon Topology, but the core part of Wi-Fi is something not exists with Ethernet, the Radio Technology.

IEEE 802.11 defines two (2) radio technologies namely Direct Sequence Spread Spectrum (DSSS), and Frequency Hopped Spread Spectrum (FHSS). The details of these technologies are beyond this paper and my interests. It just always amazes me that there are such complex technologies that deal with invisible things in the air.

The Connection

As I mentioned above, there are no such thing called topology in Wi-Fi WLAN, but still, there are couple of unique equipments that you need to build a WLAN. It will be more involved and complicate when extending existing wired LANs in business area. But that can be taken care of by money. At home, with limited resource, things might be different. Fortunately, Wi-Fi is also a simple and flexible technology when apply it to a relatively isolate small area, home. That’s the beauty of Wi-Fi.

In WLAN, a group of connected computers is called Basic Service Set (BSS). In an isolate area such as home, a WLAN is sometimes called an Ad Hoc network. That is because there is not physical connecting between two computers. When one party of the connection is removed from home, the network is gone too. As always, there is a term for such network, Independent Basic Service Set (IBSS).

As illustrate in above diagram, there are three (3) components to form a computer WLAN. They are Access Point (AP), Station and Wireless Net Card.

Access Point (AP)

It is also called Internet/Network Gateway by some vendors. You only need it when you want to connect all you computer to outside network, say Internet. A BSS does not have to have an AP. When there is no AP in the WLAN, the IBSS is formed as peer-to-peer based connection. A BSS has a AP is said to be operating in the infrastructure mode.

Station

It’s a computer for a simple computer network. It could be any equipment connects to the WLAN wirelessly.

Wireless Net Card

To enable you computer join the wireless network, just like in wired LAN, you need a card plug into your computer. In this case, it’s card sending wireless signal.

That’s it. It’s hardly to say that you have a network set up since there is no wire, but you are definitely connected with just the above components.

The Concerns: Reliability, Security and Money

Everybody is worried about the cutting-edge technology would turning into bleeding-edge. Wi-Fi, as very young technology, is reliable enough for purchase consideration? I think it’s a yes.

WECA had setup a vigorous certification program to certify Wi-Fi products. They says that any product designated with a Wi-Fi logo has been qualified to assure interoperability between PC wireless LAN cards, devices and access points from different vendors. Such PC products include PCMCIA cards for notebooks, ISA and PCI cards for desktops, and Universal Serial Bus (USB) modules that can be used with either platform.

Companies whose products have received Wi-Fi-certification include 3Com, Cisco Systems, Compaq, Intel, Nokia, and Samsung.

Another issue, since your data will be send into the open air, is it secure? Well, security is always a double blade sword. One side, no matter what you do, you just can’t have enough it. On another side, there is cost.

IEEE 802.11 provides two security methods: authentication and encryption.

Authentication is the means by which one station is verified to have authorization to communicate with a second station in a BSS. In the infrastructure mode, authentication is established between an AP and each station. The encryption of Wi-Fi uses the RC4 PRNG algorithm from RSA Data Security, Inc.

For home usage, I think all above are secure enough for most of home network. If you truly believe resources and money will be spent to break into your WLAN and decrypt your data, and your data worth it, more money will help.

Now, the last issue, money. Currently, the cost of wireless card and AP is in the $150 – $400 range. Quite expensive comparing to Ethernet card. But the price will be decrease rapidly towards year-end while more Wi-Fi products brought to market every day.

Very soon, there will be no wire.

Extend Swing by Example – A Custom Searchable JComboBox

INTRODUCTION

When developing an application using object-oriented (OO) language such as C++ and Java, the developers frequently encounter one task, which is to extend the existing classes to provide more or customized functionalities to meet users’ requirements. From pure OO perspective, creating a subclass from an existing one (or interface), adding more functions or overriding existing functions in parent classes would achieve this goal. This task is with the big word in OO world, Inheritance. Object composition is another way of extending existing classes. But in real world things tend to be more complex, hence theory should be applied differently. That’s what developers will experience in Java world.

One of the well-know design patterns that is heavily applied in Java Swing is Model-View-Controller (MVC). To customize a Swing component, a developer must understand how MVC architect works. This article will demonstrate MVC in action by customizing JComboBox to change the default searching capability.

MVC

Java Swing is a collection of GUI components that are totally redesigned apart from Java AWT. The architecture of Swing is based on so called modified-MVC. The MVC is a design pattern originated from the pure object-oriented language small-talk. Basically it’s the separation of a GUI component’s data, appearance and function (action). In Java Swing architecture, the View and Controller of MVC are collapsed to be one GUI Manager of a component. That’s where the word ‘modified’ comes from. This concept can be well represented by one of business practice, outsourcing. That is whenever you instantiate a Swing component, you actually got a shell package. The life of the component is supported by a group of objects handling different organs of the component. The benefits of such design pattern are enormous, which is not the focus of this article.

For developers, to extend and customize the behavior of Swing component, obviously will not be as simple as extend the component itself. The developers will deal with the outsourcing parties of the component.

To allow developers communicating with the Swing component and providing extra functionalities, usually a set of interfaces are defined within the component. By implementing the interface, the developers can customize the component by plug the implementation. In this case, the inheritance of OO is more a mechanical tools than a methodology.

Encounter JComboBox

A Swing Combo Box is consisting of two parts. One part is a text field and another one is a drop down list. The text field can be set editable or non-editable.

By default, when the text field is set non-editable, the combo box can be searched by typing the first letter of the item in the list. If there are more than one item shares the same initial, the first one is always the selected one. In certain situation this default search is becoming useless. For example, when all the items in the list have the same prefix, the search becomes handicapped.

When a custom behavior is in demand, the touching of Swing MVC is inedible. Now, let’s take a look what JComboBox offers to extend the functionality.

javax.swing
Class JComboBox

java.lang.Object
+–java.awt.Component
+–java.awt.Container
+–javax.swing.Jcomponent
+–javax.swing.JComboBox

Here are some methods in of JComboBox interesting us.

public void setEditor(ComboBoxEditor anEditor)

public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)

public void setModel(ComboBoxModel aModel)

public void setRenderer(ListCellRenderer aRenderer)

public void setUI(ComboBoxUI ui)

By looking at these function, we would notice that the JComboBox delegates certain functions and internal data to different objects that have certain Swing type(interface). These setters can be used to provide JComboBox with custom data and behaviors. The OO Inherence is out of picture here. The JComboBox, like almost all of other Swing components, is a composition classes. Using MVC terminology, the above methods can be categorized as:

Model: setModel() to custom the data that the combo box represent.

View: setUI() and setRenderer() to custom the combo box look and feel.

Control: setEditor(), setKeySelectionManager() to custom editing and keyboard related functions.

A good design pattern book would explain all the benefit of such architect, if you catch an empty feeling when lost the powerful OO inherence. A recommendation is Design Pattern, by Erich Gamma …, and published by Addison Wesley.

Retool the Search

This demo application has two combo boxes on it.

As stated in previous section, the searching in JComboBox is not sufficient enough for some application. In this section, we will customize the searching. Two approaches will be demonstrated:

Searching while typing

While typing, the combo box trying to locate the item the mach the typed string (not just the initial letter) from the first letter. Hit any non-character key will start a new search. For example, when you type ‘thi’, the selected item will be ‘this’, which is the first one matches the ‘thi’.

This type of searching is achived by providing the JComboBox a custom JComboBox.KeySelectionManager object.

Searching after typing

The text field of JComboBox is set to be editable. After type a string, hit Enter key, the matched item will be selected and shown in the text field. The matching is same as the first type of search.

An Action Listener is added to the JComboBox to conduct the searching by response the Enter key.

Let’s work through the code to see how they are done.

public class SearchableComboBox extends JPanel {

static JFrame frame;
/**

* the drop down box for Searching while Typing.

*/

JComboBox jcb1 = null;
/**

* The drop down box for Search after Typing.

*/

JComboBox jcb2 = null;

/**

* If the Frame is visible. The combombox poppup

* Can only be set to

* visible after the main frame is visible.

*/

public boolean bVisible = false;

Notice the plain Swing JComboBox is used to define the two combo box members. We are not customizing it by extending it.

public SearchableComboBox() {

String[] listExamples = {

“This”,

“is”,

“just”,

“a”,

“test”,

“case”,

“hello”,

“the”,

“world”

};

This is the list of string we put into the combo box to do the test.

jcb1 = new JComboBox(listExamples);

jcb1.setEditable(false);

jcb1.setAlignmentX(Component.LEFT_ALIGNMENT);

jcb1.setKeySelectionManager( new myKeyManager() );

The first combo box, search while typing, has set to have a new JComboBox.KeySelectionManager instance. Be aware that KeySelectionManager is an interface defined as inner interface of JComboBox. MyKeyManager is an inner class defined in SearchableComboBox by implementing the interface.

Implementing Interfaces are the most important way of customizing Swing components.

class myKeyManager implements JComboBox.KeySelectionManager {

String keys = null;

int curSelected = 0;

myKeyManager ()

{ }

/**

* Searchs the data model based on the letter typed in.

*

* @param aKey the current typed in letter.

* @param aModel

* @return the index of item selected.

*/

public int selectionForKey(char aKey, ComboBoxModel aModel)

{

int iCount = aModel.getSize();

int iPatternLen = 0;

int iSelected = 0;

String sItem = null;

if ( Character.getNumericValue(aKey) == -1)

{

keys = null;

}

else

{

if (keys != null)

keys = keys + (new Character(aKey)).toString();

else

keys = (new Character(aKey)).toString();

if (keys != null )

iPatternLen = keys.length();

for (int pos = 0; pos < iCount; pos ++ )

{

sItem = (String)aModel.getElementAt(pos);

if (sItem.length() >= iPatternLen )

{

if( sItem.substring(0,iPatternLen).equals(keys) )

{

iSelected = pos;

curSelected = iSelected;

break;

}

}

else

iSelected = curSelected;

}

}

if( bVisible )

jcb1.setPopupVisible(true);

return curSelected;

}

}

In the method selectionForKey, any custom searching mechanism can be created and the JComboBox will take it use it. JComboBox only knows the interface, means it only deals with a type of object. The concrete function is delegated to the object that implements the interface.

The same approach has footprints all over Swing. To customize Swing, you basically replace some bolts and nuts. You won’t touch or rebuild the whole frame.

The second combo box is event driven searching.

void searchJCB(JComboBox jcb) {

String newSelection = (String)jcb.getSelectedItem();

int iCount = jcb.getItemCount();

int iSelectionLen = newSelection.length();

//save the selection index from last search.

int iSelected = 0;

//the current selection index.

int iSelecting = 0;

String sItem = null;

for (int pos = 0; pos < iCount; pos ++ )

{

sItem = (String)jcb.getItemAt(pos);

A method searchJCM is defined to conduct the search based on the string in the text field of the JComboBox object.

As you may see or feel, the first the approach is more flexible. Different searching algorisms can be easily plug-and-play. It’s the recommended method of customizing Swing components.