By Binildas C.A. | |
In this article, Binildas C.A. sheds light on this important, yet sparsely documented, area of interoperability considerations. He also discusess about some of the solutions available to work hassle-free with .NET and J2EE. The article converges at a point, and rightly so, to propose web services as a technology for attaining client side interoperability, and in that attempt, addresses two important approaches: top-down and bottom-up. As proof of the proposed technology, practical demonstration of the two approaches, and the successful implementation of a solution, the writer showcases a sample architecture based on BEA WebLogic Server and .NET C# client. | |
Java 2 Platform, Enterprise Edition (J2EE) is a mature middle tier technology that has become the norm for building production quality enterprise applications. Scalability, reliability, extensibility, security, etc. are few main operating qualities which give J2EE its edge over competing platforms. Though it is comparatively easier to develop, deploy and maintain applications in the J2EE stack, many a times the J2EE components need to interoperate with other technologies. Recent trends in development have witnessed Java/J2EE’s rising popularity in enterprise class server side application development from its historical stronghold in client side applets and applications. In assessing different solutions like C and C++, and other object-based programming languages like Delphi, Java/J2EE have been found the most stable and proven. Microsoft’s Integrated Development Suite (IDS), composing its IDE, Visual Studio, along with a tight integration of programming languages like Visual Basic and Visual C++, has made this development environment the best for fast-paced application development. ATLs and MFCs add to this suite. When evaluating for use in native applications that require speed and richness, these technologies are still preferred. Microsoft’s .NET offerings that work across Windows 3.1 through Windows XP offer enhanced power to the developer desiring to implement an interoperable solution. In this article, we will combine the richness and performance of .NET with the stability and maturity of J2EE, shedding special focus on client side interoperability with examples deployed in BEA WebLogic Server 8.1 and .NET platform respectively. Requirements to Deploy and Run Examples • Windows XP Interoperability in the Presentation Tier Interoperability Considerations • Data formats: When evaluating a data format, take note of the differences across various platforms. For example, an int in Java occupies 32 bits, and 16 bits in C++. Unicode representation is a blessing when it comes to representing characters, since it is possible to represent all character sets using its 2 byte representation of char. Hence, if the same value is represented differently by different platforms, how can we integrate applications in different technologies? Apart from those aspects mentioned, there is the next level of considerations: • Performance and standards compliance Interoperability Solutions • COM/DCOM: Microsoft Transaction Server (MTS) with its COM/DCOM protocols is a solution for distribution and interoperability. However, MTS is proprietary and rests on inelegant Microsoft extensions to C++ and other languages with COM/DCOM bindings. Using Web Service for Presentation Tier Interoperability Steps for Interoperability • XML Schema for describing data The primary specifications upon which web services are based are too open and broad. That opens up the scope for a lot of ambiguities once it gets implemented as a web service solution. To reduce these ambiguities and achieve interoperability, web service vendors formed a consortium called Web Service Interoperability Organisation. This standards body drafted their first specification called the Basic Profile 1.0 (BP 1.0). This profile aims to bring about a set of conformance rules that clear up ambiguities in the above standards. Even though no one is required to adhere to BP, doing so will make interoperability less painful. There are primarily two approaches in integrating a .NET client and a J2EE server – top-down and bottom-up approach. Let us briefly explain the difference between these two: • Top-down Approach In the top-down approach, similar to CORBA where we start from an IDL, we start from the WSDL in web services. The service description is fully described in the WSDL. Any client can use this WSDL file and follow any of the different binding options available. By binding options, we mean either statically generating client side stubs and binding at compile time, or generating dynamic proxies at run-time by introspecting the WSDL file on the fly. The main problem with top-down approach is data compatibility. Standards are evolving, and it takes some time before the latest standard is reflected in implementations. Even then, it will not happen exactly at the same point in time. This gives the notion of the common denominator, which is generally the super set of all data types supported by “all the implementations in consideration”. It is highly important that we stick to this super set whenever we design interoperability solutions. With this design approach in mind, we need to architect for either of these approaches. To solve this problem, we should look at exchanging only primitive data types, such as strings, integers and so on. All web service stacks support these data types, providing the greatest levels of flexibility and client access. In this approach, the service definition exposes what it mandates, and it is up to the client run-time to agree to the service format. • Bottom-up Approach One scenario is when we need to send a very complex data structure, which we suspect will be supported by all client run-times. In such case, we package the data as a string. The best solution here is to populate a string with an XML representation of the data. This XML encoding should follow an agreed schema. This again implies we start from an “agreed schema”, set up the service implementation, and then expose the service description. The client may have some or full idea about the “service types” involved. Most of the times, such approach will result in a kind of document-oriented web service. Vendor tools can again help in automating this process. Most relevant steps to follow include: • Create schema that represents the XML form of the data Client applications that consume the web service need to understand the formats and valid values so as to process the service return types. Architecture for Presentation Tier Interoperability We will have three methods in our service interface, as shown below: public interface Trader extends EJBObject{ TradeResult buy (String stockSymbol, int shares) throws RemoteException; TradeResult sell (String stockSymbol, int shares) throws RemoteException; String getAllProducts() throws RemoteException; The notable point in this interface is that TradeResult is a complex type. When such complex type is visible in the service interface, it eventually means that the client needs to understand this complex type when it binds to avail the service. Web service standards are mature to the extent that this level of interoperability is possible in many cases. The third method does not have any visible complex type. In fact, the return type which is a simple string is going to be a flattened representation of a more complex type. The former two methods (buy and sell) are examples for the top-down approach, and we will build the third method (getAllProducts) in the bottom-up approach. The service will be implemented as a stateless session bean in the WebLogic J2EE platform. The client will be built in .NET using the C# programming language.
While the first two methods are simple, let us explore the rationale behind the third method. In fact, the third method is intended to return a collection of Product complex type. Perhaps, this type too is not that complex that we can return them similar to TradeResult as with the other two methods. To demonstrate the concept, let us assume that the collection of Product complex type is not simple, and we have taken an architectural decision to flatten this collection as an XML string. For this, let us quickly list down the steps to perform: • Agree on a schema for the complex collection type Implementing the Demonstration As usual, the data for Product types might be streamed from a database. Once the data and XSD are available, we normally need to use any available automatic methods to convert data to XML format. Many Java XML products can map a field in the class to an element or attribute in the XML Schema. Sometimes, existing classes map to the correct schema without requiring an intermediary. If this is the case, we can create mapping files for existing classes, as this removes the step of taking data from existing Java classes into Schema-based Java classes. Since this article has intended to show the architectural building blocks for attaining interoperability and not demonstrate various implementation mechanisms, this part is intentionally omitted by hard coding the XML structure with data in the server side implementation. In the client side, we have two components – EJBClient and DataClient, both implemented in .NET. The EJBClient will avail the buy and sell services while DataClient will access the getAllProducts service. To build these clients, we first need to generate client side stubs for the web service. The commands used are displayed in Fig. 2.
These commands will generate TraderService.cs (C#.NET files). Now, coding the EJBClient is simple. By executing EjbClient.exe, we can invoke Buy and Sell.
The DataClient is designed to show the XML data retrieved from the server in a DataGrid control. This is done with only two lines of code: products1.ReadXml(memStream); where products1 is a typed DataSet in .NET, and memStream is a MemoryStream type, which is an in-memory representation of the XML data. Even without generating a typed DataSet, it is possible to bind the XML data using the two lines of codes and display it in the format shown in Fig. 4.
A Typed DataSet is easily generated from the XSD, which helps especially when working with the DataSet to do type-safe coding, using the command in Fig. 5.
Before building the server, do make necessary changes in the build.xml file, corresponding to the line: Summary |
Thursday, August 23, 2007
J2EE and .NET: Presentation Tier Interoperability
Subscribe to:
Post Comments (Atom)
0 komentar:
Post a Comment