Monday, February 23, 2009

SOA Live Demo - Web Services

Download the source codes from here.

Requirements - Java Development Kit, NetBeans 6.5, GlassFish v2, Visual Studio 2008, Internet Information Services.

Follow the below steps to get the projects running in Java and .NET Environments. There are four projects in the download archive - Palindrome_WebService, Palindrome_Java, Palindrome_JSP and Palindrome_J2ME.

Open the downloaded projects (Palindrome_WebService, Palindrome_Java, Palindrome_JSP and Palindrome_J2ME) in NetBeans 6.5.

The Palindrome_WebService project has the source code for the web service. Deploy it in GlassFish.

The Web Service can be tested by a built-in Web Service tester of NetBeans/GlassFish. The tester gives the method parameters and return values, along with the request and response SOAP messages.

This Web Service can be hooked to a Java client with a GUI. Open the Palindrome_Java project and run it.

Similarly, the Web Service can be also used in a JSP page. Open the Palindrome_JSP project and run it.

The Web Service can also be used in a J2ME mobile device. Open the Palindrome_J2ME project and run it.

All these projects are primarily implementations of Java. However this Java Web Service can also be connected to an entirely new language (if it has XML support). Open the remaining projects from the downloaded archive (Palindrome_CSharp and Palindrome_ASP.NET) in Visual Studio.

Consider a C# client which accesses the Java Web Service. Open the Palindrome_CSharp project in Visual Studio and run it. Remember GlassFish needs to be up and running with the Web Service deployed, for this to work.

Finally consider an ASP.NET page, using C# hosted on IIS, accessing the Java Web Service hosted on GlassFish. Open the Palindrome_ASP.NET project in Visual Studio and run it to achieve this.

Well, that's it. So we have used a Java Web Service in a Java client, JSP page, J2ME mobile device, C# console application and in an ASP.NET page.

SOA Live Demo - JNI

Download the source codes from here.

Requirements - Java Development Kit and Visual Studio.

This article focuses on how to connect a C++ Dynamic Link Library to a Java program using the Java Native Interface. To run a C++ function in a Java program, we would require the C++ function to be in a DLL and this DLL to be loaded at run-time into the memory by the Java program.

Load the library from the Java program using the full path with the load function or let the JVM load the DLL using the system path with the loadLibrary function.

The C++ function is declared native in the Java program. Compile the file to generate the class file using the javac command.

Create a C++ header for the native function using the javah command on the generated class file. A declaration for the function is generated following the syntax java_<class>_<function>.

Create a new project to generate the DLL in Visual C++. The project consists of the header generated from the previous step, a C++ file using the function declaration generated in the header and a header consisting of the required function that is to be used in the Java program. A DLL is generated from this project.

Any C++ application can be created normally which uses the existing function.

Copy the DLL generated from Visual Studio to the path specified in the Java application and run the Java program using the java command.

As a result, the same function was used in a C++ program as well as in a Java program.

SOA - Adapters, Benefits And The Future

SOA Adapters

Adapters are interfaces to connect to heterogeneous systems. Several vendors provide adapter solutions for creating web services around existing applications. Typical adapter solutions cover Database adapters, File (Local, FTP) adapters, ERP Application adapters, Polling adapters, etc.

Benefits Of SOA

  1. SOA offers business solutions across platforms
  2. It is location independent
  3. Search and connectivity to other services is dynamic
  4. Enhances reliability
  5. Leverages existing development skills
  6. Enhances ability to quickly meet customer demands
  7. Lower costs associated with acquisition of technology
  8. Leverages existing investments

What's Next?

  1. SOA and BPEL
  2. SOA Implementation using JBI and OpenESB
  3. SOA Integration Scenarios
  4. SOA and Integration Patterns/Frameworks
  5. Security, Scalability and Reliability of SOA Solutions
  6. Sun, IBM and Microsoft, etc., specific SOA offerings

Organizational Approach To SOA

SOA plays an important role in organizations. If an organization is starting fresh in terms of IT solutions, it can implement the concept of SOA directly.

The challenge comes up in those organizations that have existing applications and these applications being heterogeneous in nature. A typical organization can have ERP applications (SAP, Oracle), Java applications, .NET applications and LAMP applications. To avoid complex maintenance activities and address future requirements, organizations are taking the following steps -

  • Detailed study of applications
  • Creating services of common nature around these applications
  • Implementing new applications around these services as a SOA model

One of the key aspects on which organizations focus in terms of services is the Governance. Primary objective of SOA governance is tracking all the available services and ensuring controlled creation and avoiding duplicates. Typical organizations classify their services into -

  • Intranet (for internal usage)
  • Extranet (for the outside world, like Suppliers, Consumers, Banks, etc.)

Composite Services Using SOA

Services are generally created from scratch or are formed from existing services. One of the key concepts of SOA is the creation of composite services.

SOA facilitates reuse of existing services to provide complex services, thereby avoiding redundancy of a particular service.

Case Study

Consider an educational institute with these existing services -

  • Given a minimum aggregate score, a list of all student IDs is generated
  • Given a student ID, the students name is generated
  • Given a department name, a set of all Student IDs belonging to that department is returned

Now consider the demand for two additional services -

  • Given a minimum aggregate score, a list of all student names is needed
  • Given a particular department, a list of all student names is to be generated

The required services can be obtained from existing services as follows -

  • From the first service, a list of student IDs is generated and each ID is fed to the second service to obtain the composite service

  • Similarly, the next composite service is obtained by obtaining the student list from the third service and feeding them to the second service

SOA - The Web Services Model

The latest trends of SOA follow the Web Services model for implementing the Service Providers. However, the first question which arises here is - "What's a Web Service?"

According to W3C, A Web Service is a software system designed to support inter-operable machine-to-machine interaction over a network.

A Web Service has an interface described in machine-processable format, specifically WSDL (Web Service Description Language).

The services provided by the Service Providers are maintained as a list by a Service Broker which interacts with Service Providers and Service Consumers using UDDI (Universal Description Discovery and Integration) Inquiry and Publish.

Other systems interact with the Web Service as prescribed by its description using SOAP (Simple Object Access Protocol), typically conveyed using HTTP requests with XML serialization.

A typical Web Service is implemented as -

The Service Providers are generally Java Web Services or .NET Web Services.

The Service Consumers can be implemented in -

  • Java, JSP and J2ME (using NetBeans)
  • C# and ASP.NET (using Visual Studio)

The Service Consumers can actually be written in any language which can understand XML and interact through SOAP messages.

SOA - The Simplified Model

For several college students and graduates, the concept of SOA can be well comprehended with traditionally taught languages in several of the educational institutes - C++ and Java. A C++ function can be created to provide a service, and this function (service) can be used in a C++ program as well as in a Java program.

In terms of SOA, a C++ service is being utilized by a C++ consumer as well as a Java consumer.

The C++ function can be used in a Java function using the Java Native Interface (JNI). The JNI is a programming framework that allows Java code running in the Java virtual machine to call libraries written in other languages, such as C, C++ and Assembly.

JNI allows Java developers to add functionality to their Java applications that the Java API can't provide. It is used in time critical calculations or operations where the native code is faster than the JVM code.

The SOA model using JNI can be represented as follows -

The Philosophy Of SOA

SOA is not a product; instead it is an architectural approach for building solutions. SOA is primarily a concept of Service Providers and Service Consumers. SOA refers to the architectural style in which Service Consumers use the services offered by Service Providers. The essence of SOA lies in consumer centric behavior, and in ensuring that services can be located dynamically on need basis.

In any application, there are three parts - Front End, Business Logic and Persistence. In SOA they are mapped as below -

While SOA concepts are reasonably simple to understand and apply, they require a phased roadmap which takes some time. The vital starting phase of SOA is not technology but identifying the business-specific services in an organization.

Services are generally provided using concepts like -

  • Functions
  • APIs
  • Components
  • Web Services

The first three concepts, stated above are language dependent to a very large extent. However Web Services provide a language independent approach, and are one of the most popular approaches for SOA in today’s world.

Sunday, February 22, 2009

Service Oriented Architecture - Bringing Versatility To Business

According to a survey, a search made in Google for SOA would yield about 8 million entries. This clearly emphasizes the popularity and demand for SOA in today’s IT market.

Judging this huge demand for SOA, I decided to take up a short series of blog articles about SOA and how SOA can be implemented as a programmer.

Here are a few topics the subsequent blog-posts are going to cover -

  • The Philosophy of SOA
  • SOA - The Simplified Model
  • SOA - The Web Services Model
  • Composite services using SOA
  • Organizational approach to SOA
  • SOA Adapters

Finally, these are the live models that will be implemented -

  • JNI
  • Web Services

The presentation has been uploaded here and abstract has been uploaded here. The Web Services source codes are available here and the JNI source codes are available here.