Anshuk Pal Chaudhari

Subscribe to Anshuk Pal Chaudhari: eMailAlertsEmail Alerts
Get Anshuk Pal Chaudhari: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Related Topics: Java EE Journal, Apache Web Server Journal, Open Web Magazine

J2EE Journal: Article

Web Service Invocation Framework

Adding wheels to Web services

The following descriptions pertain to Figure 1:

  • WSIF Service: The WSIFService interface is used for creating an instance of the WSIFOperation interface to use for a specific invocation of a service operation
  • WSIF Operation: The run-time illustration of an operation, called WSIFOperation, is used for invoking a service based on a particular binding
  • WSIF Provider: A WSIF provider is an implementation of a WSDL binding that can run a WSDL operation through a binding-specific protocol. WSIF includes SOAP providers, JMS providers, Java providers, and EJB providers - and it can include all of those concurrently, if required.
WSIF Binding Examples
General Prerequisites
www.apache.org/dyn/closer.cgi/ws/wsif/
  • wsif.jar
  • wsif-j2c.jar
We need to just add them in the classpath and we are ready to use WSIF.

Java Binding
Description
We will now demonstrate invoking a simple Java Class as a Service using the WSIF APIs.

  • We have a Java Class called as CalculatorImpl, which has a method of simple addition.
  • Now since we are calling the Java class as a service, we also need to change the WSDL accordingly. All elements of the WSDL remain the same, only the binding tag is changed to indicate that we are using JAVA Binding.
  • A mapping from the abstract types used in WSDL message parts to Java types that represent the same information is achieved by the "format: typemapping" element.
  • To represent Java method in a WSDL in an abstract way the "java: operation" element is used
  • To represent a Java object as an endpoint for a service available through a Java binding we use the "java: address." The className attribute is used to give a fully qualified class name to be used for service invocation. Please refer the binding element of "Addition.wsdl."
  • Now we take a look into the changes in the client for invoking the simple addition service. We call the method executeRequestResponseOperation, which is method from class WSIFOperation_Java, This class implements the WSIFOperation interface. The method contains three parameters (input, output, and fault), which are objects of the WSIFMessage interface. Please refer the "getAdditionResult" method of Run.java.
Enterprise Java Beans (EJB) Binding
Description
We will now try to demonstrate the invocation of an EJB as a service.
  • The EJB that we have developed is used to insert values in an Oracle database
  • We have deployed the EJB on the WebLogic Server 8.1
  • The binding element in the WSDL indicates that it is EJB binding. The format:typeMapping and ejb:operation elements remain the same as in the case of Java binding
  • To specify an EJB object as an endpoint we modify the ejb:address as shown below. The className (optional) attribute gives the fully qualified name of the home interface class of the EJB, while the jndiName attribute specifies the name under which this EJB can be looked up in a JNDI context. Please refer "EJBSample.wsdl"
  • As we can see even in this case, it is the WSDL that is changed; the binding name has changed and we have different attributes for the EJB address, which is the endpoint for the service
  • For the client, refer to the Run.java of the EJB binding source code
Multiple Bindings
Description
The following service invocation aims to showcase the most important concept of WSIF - multiple binding and protocol with the same WSDL file. Let's look at an example:
  • We have a service, for instance, a Calculator. Now it is quite possible to have multiple clients who need to access the service, for instance, a "Dot Net Client" and a "Java Client."
  • The Calculator application has been developed in Java.
  • Now the only way for the Dot Net Client to access that service Calculator is only when the functionality is exposed via SOAP binding. SOAP binding is fine for the Dot Net Client, but why would a client in Java access the service via SOAP binding and not via simple Java binding?
  • For the Java Client it is always better to access a Java Class than to access a Web service through a SOAP binding.
  • WSIF provides the option of exposing the functionality of a service through multiple bindings, and that too in single WSDL file. Let's see how.
  • We have a simple Java Class, which we expose as Web service on WebLogic Server 8.1.
  • Now we will describe the same class in a WSDL as SOAP binding (Web service) as well as a Java binding (simple Java Class). Please refer the binding element of MultiBinding.wsdl.
  • Now it is up to the client what port to use at what time. If we notice the service element of the WSDL carefully, it shows one service whose functionality with multiple bindings, for instance the Dot Net Client, will be using the SimpleSumServiceSOAPPort, and the Java Client will be using the SimpleSumServiceJavaPort. Let us see the client for the invocation of multiple bindings. Please refer the Dot Net Client "Form1.cs" (source code is available by viewing this article - see zip.html file.
Here WebReference is a Dot Net Skeleton that contains the method of the Web service. In case of the Java Client, we have to use the executeRequestResponseOperation specific to the WSIF Framework.

Advantages
The advantage here lies in the fact that we can have multiple bindings for a single service. The client finds a suitable binding for them and then invokes the service. It is also convenient for building the client on any platform and to access the service.

JMS Bindings
Description
The following service invocation aims at using the message-oriented middleware using Java Messaging Service (JMS) through WSIF Apis. We only want to demonstrate that it is possible to bind JMS using WSIF.

  • We have developed a Message Driven Bean (MDB) as a service that has a method that just appends "Hi" to whatever the user enters.
  • The MDB is being deployed on WebLogic Server 8.1.
  • The main focus of the service is the JMS binding.
  • The JMS binding in this case uses JMS text messages for communication
  • The WSIF API provides the translation of the invocation to the sending of JMS text message to the particular queue. The specific part of WSDL that deals with the JMS binding is shown below. Please refer the binding element of "JMS.wsdl."
  • The service in the WSDL also describes the different parameters that need to be given in order to look up the Queue. The Client for calling the MDB is also a very simple one. Please refer the client "Run.java" of JMS binding.

More Stories By Anshuk Pal Chaudhari

The authors are interning and/or working as part of the Web Services COE (Center of Excellence) for Infosys Technologies, a global IT consulting firm, and have substantial experience in publishing papers, presenting papers at conferences, and defining standards for SOA and Web services. The Web Services COE specializes in SOA, Web services, and other related technologies.

More Stories By Sandeep Gaikwad

The authors are interning and/or working as part of the Web Services COE (Center of Excellence) for Infosys Technologies, a global IT consulting firm, and have substantial experience in publishing papers, presenting papers at conferences, and defining standards for SOA and Web services. The Web Services COE specializes in SOA, Web services, and other related technologies.

More Stories By Ambar Verma

The authors are interning and/or working as part of the Web Services COE (Center of Excellence) for Infosys Technologies, a global IT consulting firm, and have substantial experience in publishing papers, presenting papers at conferences, and defining standards for SOA and Web services. The Web Services COE specializes in SOA, Web services, and other related technologies.

More Stories By V. Niranjan

The authors are interning and/or working as part of the Web Services COE (Center of Excellence) for Infosys Technologies, a global IT consulting firm, and have substantial experience in publishing papers, presenting papers at conferences, and defining standards for SOA and Web services. The Web Services COE specializes in SOA, Web services, and other related technologies.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.