gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Desktop Computers
Boat Donations
Promos and Premiums
Find Software
Auto Insurance Quote
Computer Deals
Domain registration
Promotional Gifts
Online Universities
Compare Prices
Baby Photo Contest
Memory Upgrades
Calling Cards
Career Education

 


  Generate Revenue Through IT Using Business Service Management
Sponsored by HP
Making sure that your business applications are available to their end users is an important part of running your business smoothly. Business operations have evolved to where IT must now broaden its focus to help the company attract, retain and grow customer relationships and increase customer satisfaction. Business service management (BSM) helps lay the foundation by managing services in dynamic support of business requirements. »
 
  Managing the Modern Network
Sponsored by HP
Networks are more than vehicles to transport e-mail and Web pages. In a global economy where information crosses the globe in an instant, and where Web-based applications power business, it's more important than ever to ensure your network is safe from threats and optimized to deliver the data your business needs. »
 
  Storage Networking 2, Configuration and Planning
Sponsored by HP
In Part 1, we discussed storage area networks (SANs) and fibre channel. In Part 2, delve into best practices and cover the general concepts you must know before configuring SAN-attached storage. The most critical, sometimes tedious, part of setting up a SAN is configuring each individual disk array. This guide examines configurations for SAN-attached servers and disk arrays, and also includes a look at the future of IP storage. »
 
  Is Your Disaster Recovery Plan Good Enough? Get Disaster Recovery Right
Sponsored by HP
Preparing for a disaster is more often than not part of the storage planning process, and without question it is one of the most difficult task, since it includes local hardware and software, networking equipment, and a test plan to ensure that you can recover from the disaster. Learn how to put your organization on the proper disaster recovery plan, now. »
 
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Implementing Contextual Web Services
By Ayyappan Gandhirajan

Go to page: 1  2  3  Next  

Overview

Web Services are a true interoperable technology that enables disparate systems to talk to each other using a common language. The Web Service consumers communicate to Web Services using SOAP messages transported over standard HTTP protocol. HTTP is a stateless protocol in nature, meaning that subsequent Web Service requests (for example, SOAP over HTTP) from the same user are considered as independent requests. The stateless behavior simplifies the design of HTTP protocol but this forces developers to use alternate methods such as cookies to maintain the user state. As the Web Services technology and the standards around it evolve more and more, the kind of application that the large enterprises implement using Web Services also tends to evolve. In the recent past, the use of Web Services has moved beyond simple laboratory services to highly advanced domain services. It will slowly become mandatory that Web Services understand the context under which the user operates to provide more sophisticated, user-centric personalized services.

A classic example where the context will play a major role is Business Activity Monitoring, one of the critical requirements of the complex business process manager. When the business transaction spans multiple Web Services and multiple machines, the application will require common information something like correlation id (in other words, typically a transaction id) that will be passed to all participating activities so that a real time summary is generated for operational purposes.

This article will discuss more about the need for context in Web Service end points and also give a glimpse on how Web Services can be enabled to gain access to Web Service context using vendor-specific API and standard JAX-RPC API.

The Need for Context Access in Service Endpoints

The Web Services technology already has something called handlers (also known as interceptors) that can gain access to context information. Handlers act as pre and post processors that intercept incoming Web Services requests, extract the context information, and implement the behaviors as per project requirements. For example, they implement non-functional requirements such as security. The handlers are really useful mechanisms because they are loosely coupled, non intrusive, and highly transparent.

However, in some scenarios, apart from handlers, the service end point objects (also known as back end components) also might want to access the context information such as message context, HTTP session objects, and so on. For example, consider this restaurant application that behaves differently for different user types. This restaurant application returns the list of a maximum of the three nearest restaurants in the given vicinity for the classic user type. Meanwhile, for the premium user type, the application returns, hypothetically, the unlimited list of nearest restaurants in the given vicinity. In this case, the end point object must know who the user is and the user type that it belongs to. Otherwise, it will not know whether to serve the limited list of restaurants or unlimited list of restaurants. Figure 1 depicts this scenario.

Figure 1: Contextual Services

One way to implementing this functionality could be that the user id and user type information may be passed as method arguments to Web Services. However, as you might notice, there are some quite obvious disadvantages with this approach:

  • The user will be expected to pass on the values for these arguments from the client side. In most cases, the user may not know what the values are. For example, the client application may not know what the user id is. (In most applications, the user will know only the alphanumeric username and it is the application's responsibility to fetch the corresponding user id and other necessary context information from the user store to respond to the clients as expected).
  • Some fields may be system generated and they are not relevant to users. For example, a transaction id would need to be generated.
  • When the application needs more and more information, the method signature will have to be modified accordingly. This will displease all stakeholders in the Web Services realm.

A Solution Explored

When there are several issues with passing the information as method arguments, there must be a way for the service end points to gain access to context information. JAX-RPC provides a mechanism for Web Service end point objects to access the context and HTTP session information. This feature will be available to developers who use the Servlets-based implementation of JAX-RPC runtime. For example, they can use Apache Axis. Non-Servlets-based runtimes, such as WebLogic 8.1, do not support this feature. As a workaround, WebLogic offers developers its vendor specific Application Programming Interfaces (API) to access the context information. However, from version 9.x onwards, WebLogic has changed its Web Services development model and hence it deprecated the use of all these APIs. The new development model (in 9.x onwards) is based on Servlets; therefore, it supports standard APIs provided by JAX-RPC. In the following sections, you will see how context can be accessed using standard and WebLogic APIs.

Accessing Context Using the WebLogic API

As mentioned earlier, the JAX-RPC runtime provided by WebLogic 8.1 was not based on Servlets; therfore, it implements the feature in slightly a different way. It provides an API called weblogic.webservice.context.WebServiceContext to access the Web Service context. The Web Service developer will have to invoke the static method, currentContext, on weblogic.webservice.context.WebServiceContext to obtain the reference to weblogic.webservice.context.WebServiceContext. For more information on Java documentation, please visit this URL http://edocs.bea.com/wls/docs81/javadocs/ weblogic/webservice/context/WebServiceContext.html.

The following code sample will provide a glimpse on how developers can use this API. This example program assumes (but code details of handlers are not mentioned here) the typical design, the Web Service will have handlers that collect the user credentials, perform security operations if required, fetch the user id from the database corresponding to the given username, and places the user id in the message context so that the user id information can be used in the service end point to decide the fate of the results to the user.

package service;

import javax.xml.rpc.handler.soap.SOAPMessageContext;

import weblogic.webservice.context.WebServiceContext;

public class RestaurantServiceBEA81{

   public String getRestaurants( int latitude, int longitude ) {
      try {
         WebServiceContext wsc =
            WebServiceContext.currentContext();

         SOAPMessageContext mcontext = wsc.getLastMessageContext();

      //Play with message context

         if( mcontext.containsProperty( "userId" ) ) {
         String userId = (String) mcontext.getProperty( "userId" );

         String userType = "Classic";

         //String userType = UserDAO.getUserType( userId );

         if( userType.equals( "Premium" ) ) {
            return "<Restaurants>" +
               "<Restaurant>Italiano</Restaurant>"     +
               "<Restaurant>Pizza Hut</Restaurant>"    +
               "<Restaurant>Mona Lisa</Restaurant>"    +
               "<Restaurant>Chili's</Restaurant>"      +
               "<Restaurant>Sushi Bistro</Restaurant>" +
               "<Restaurant>Naan-N-Curry</Restaurant>" +
               "</Restaurants>";
            }
         }

      }
      catch ( Exception ex ) {
         ex.printStackTrace();
      }


      return "<Restaurants>" +
             "<Restaurant>Italiano</Restaurant>"  +
             "<Restaurant>Pizza Hut</Restaurant>" +
             "<Restaurant>Mona Lisa</Restaurant>" +
             "</Restaurants>";
   }

}

Go to page: 1  2  3  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Enterprise Java Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Whitepaper: XML Processing in Applications--Take the Next Step
Five Trends for Application Development & Program Management. Download Complimentary Report Now.
Guide to Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.
Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES