Web Service Caching Using Command Cache



Similar documents
CONFIGURATION AND APPLICATIONS DEPLOYMENT IN WEBSPHERE 6.1

WIRIS quizzes web services Getting started with PHP and Java

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

: Test 217, WebSphere Commerce V6.0. Application Development

Overview of Web Services API

Listeners. Formats. Free Form. Formatted

IBM. Implementing SMTP and POP3 Scenarios with WebSphere Business Integration Connect. Author: Ronan Dalton

CREATE A CUSTOM THEME WEBSPHERE PORTAL

IBM Tivoli Workload Scheduler Integration Workbench V8.6.: How to customize your automation environment by creating a custom Job Type plug-in

RoomWizard Synchronization Software Manual Installation Instructions

IBM WebSphere Portal Integrator for SAP

DEPLOYMENT GUIDE Version 1.1. Deploying the BIG-IP LTM v10 with Citrix Presentation Server 4.5

bbc Developing Service Providers Adobe Flash Media Rights Management Server November 2008 Version 1.5

BPM Scheduling with Job Scheduler

Deploying Intellicus Portal on IBM WebSphere

Prestashop Ship2MyId Module. Configuration Process

How to utilize Administration and Monitoring Console (AMC) in your TDI solution

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

Deploying the BIG-IP System v10 with Oracle Application Server 10g R2

Approved SCOM Health Check Report Installation Guide

User Replicator USER S GUIDE

Developing WCM based WebSphere Portal application using IBM Rational Application Developer

DEPLOYMENT GUIDE DEPLOYING THE BIG-IP LTM SYSTEM WITH CITRIX PRESENTATION SERVER 3.0 AND 4.5

Create a Web Service from a Java Bean Test a Web Service using a generated test client and the Web Services Explorer

Policy Guide Access Manager 3.1 SP5 January 2013

CA Spectrum and CA Service Desk

Application Interface Services Server for Mobile Enterprise Applications Configuration Guide Tools Release 9.2

Using Internet or Windows Explorer to Upload Your Site

SSO Plugin. J System Solutions. Upgrading SSO Plugin 3x to 4x - BMC AR System & Mid Tier.

Struts Tools Tutorial. Version: M5

IBM WEBSPHERE LOAD BALANCING SUPPORT FOR EMC DOCUMENTUM WDK/WEBTOP IN A CLUSTERED ENVIRONMENT

Eucalyptus User Console Guide

Developing an EJB3 Application. on WebSphere 6.1. using RAD 7.5

Developing Physical Solutions for InfoSphere Master Data Management Server Advanced Edition v11. MDM Workbench Development Tutorial

Manage Workflows. Workflows and Workflow Actions

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

TIBCO BusinessEvents Business Process Orchestration Release Notes

Handle Tool. User Manual

CS506 Web Design and Development Solved Online Quiz No. 01

DEPLOYMENT GUIDE Version 1.1. Deploying F5 with Oracle Application Server 10g

Note: With v3.2, the DocuSign Fetch application was renamed DocuSign Retrieve.

Sophos Mobile Control Web service guide

TSM for Windows Installation Instructions: Download the latest TSM Client Using the following link:

OUTLOOK ANYWHERE CONNECTION GUIDE FOR USERS OF OUTLOOK 2010

Developing Web Views for VMware vcenter Orchestrator

FlexSim LAN License Server

OTN Developer Day Enterprise Java. Hands on Lab Manual JPA 2.0 and Object Relational Mapping Basics

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

Documentum Content Distribution Services TM Administration Guide

McAfee One Time Password

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

Catalog Web service and catalog commerce management center customization

WA2087 Programming Java SOAP and REST Web Services - WebSphere 8.0 / RAD 8.0. Student Labs. Web Age Solutions Inc.

WA2102 Web Application Programming with Java EE 6 - WebSphere RAD 8.5. Classroom Setup Guide. Web Age Solutions Inc. Web Age Solutions Inc.

How to Back Up and Restore an ACT! Database Answer ID 19211

Crystal Reports Integration Plugin for JIRA

Customizing the SSOSessionTimeout.jsp page for Kofax Front Office Server 3.5.2

Deploying the BIG-IP LTM system and Microsoft Windows Server 2003 Terminal Services

IP Phone Services Configuration

Tool Tip. SyAM Management Utilities and Non-Admin Domain Users

Configure Single Sign on Between Domino and WPS

Developer Guide: Unwired Server Management API. Sybase Unwired Platform 2.1

Web Services API Developer Guide

How to test and debug an ASP.NET application

Configuring Secure Socket Layer (SSL) for use with BPM 7.5.x

WA1791 Designing and Developing Secure Web Services. Classroom Setup Guide. Web Age Solutions Inc. Web Age Solutions Inc. 1

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

TIBCO ActiveMatrix BusinessWorks Plug-in for Big Data User s Guide

MAGEJAM PLUGIN INSTALLATION GUIDE

Introducing the BIG-IP and SharePoint Portal Server 2003 configuration

Creating Java EE Applications and Servlets with IntelliJ IDEA

Building and Using Web Services With JDeveloper 11g

Adeptia Suite LDAP Integration Guide

This presentation explains how to integrate Microsoft Active Directory to enable LDAP authentication in the IBM InfoSphere Master Data Management

Practice Fusion API Client Installation Guide for Windows

Active Directory Integration for Greentree

BMC Remedy Integration Guide

Introduction to Business Reporting Using IBM Cognos

System Area Manager. Remote Management

User's Guide - Beta 1 Draft

Printer Connection Manager

Silect Software s MP Author

LogLogic General Database Collector for Microsoft SQL Server Log Configuration Guide

SQL Server Setup for Assistant/Pro applications Compliance Information Systems

System Administration and Log Management

Nintex Workflow 2010 Installation Guide. Installation Guide Nintex USA LLC, All rights reserved. Errors and omissions excepted.

Installing and Configuring DB2 10, WebSphere Application Server v8 & Maximo Asset Management

Fax and SMS Quickguide

Java Access to Oracle CRM On Demand. By: Joerg Wallmueller Melbourne, Australia

Windows 7 Hula POS Server Installation Guide

JobScheduler Web Services Executing JobScheduler commands

Configuring IBM WebSphere Application Server 7.0 for Web Authentication with SAS 9.3 Web Applications

Fax User Guide 07/31/2014 USER GUIDE

The software shall provide the necessary tools to allow a user to create a Dashboard based on the queries created.

Use Enterprise SSO as the Credential Server for Protected Sites

Virtual Office Remote Installation Guide

Integrating WebSphere Portal V8.0 with Business Process Manager V8.0

Managing Software and Configurations

Transcription:

Web Service Caching Using Command Cache Introduction Caching can be done at Server Side or Client Side. This article focuses on server side caching of web services using command cache. This article will explain the same using an example. This article assumes some basic level of web services knowledge The example was built and tested using the following software: RAD (Rational Application Developer 8) WAS (Web Sphere Application Server 7) Requirement Scenario 1) We need to create a web service called FindDoctor. 2) FindDoctor web service should have a following method ArrayList<Doctor> fetchdoctorlist(string zipcode, String name, long ttlsec){ //return list of Doctor whose first name is name and location zip code is zipcode 3) FindDoctorDAO class is used to retrieve required rows from database. 4) We need to cache the output of the FindDoctor web service at WAS (Websphere Application Server) using Zip Code and Doctor Name as cache IDs. 5) We need to allow client to dynamically specify the TTL (Time to Live) value for each cache entry. 6) Use Cache Monitor to view cache entries. Implementation 1) Creating FindDoctor Web service Create a dynamic web project. Now Create a java Class say FindDoctor which has our web service method.

The following is the stub of the class public class FindDoctor { //public constructor public FindDoctor(){ //web service method public ArrayList<Doctor> fetchdoctorlist(string zipcode, String name, long ttlsec){ return null; Note: Doctor is a java bean which our DAO (FindDoctorDAO) is returning. 2) Creating a class that extends CacheableCommandImpl CacheableCommandImpl class provides methods to cache data. The CacheableCommandImpl is an abstract class. In order to use caching make a concrete sub-class of it (FindDoctorCacheCmd) and override the isreadytocallexecute() and performexecute() methods. The CacheableCommandImpl class provides life cycle for the cache-able object, it will call the isreadytocallexecute() method of the extending class(finddoctorcachecmd) to check if the class is ready to execute. You can use this method to check if your data access part is ready. For eg, if you are accessing database you can check in this method whether your database connection is null and if you are talking to a web service then use this method to check if you can get a connection to the web service. Only when the isreadytocallexecute() method returns true, the flow will move forward. If it returns false, exception will be thrown. The performexecute() method of the extending class is where we write our data access code(service logic). In our case we want to query the database for a list of doctors having the given name and residing in the given zip code.

public class FindDocCacheCmd extends CacheableCommandImpl{ //list of doctors from database private ArrayList<Doctor> doclist=null; //zip code where the doctor lives private String zipcode; //name of the doctor private String name; public FindDocCacheCmd(){ public FindDocCacheCmd(String zipcode,string name){ this.zipcode=zipcode; this.name=name; @Override public boolean isreadytocallexecute() { return (zipcode!= null) && (name!= null); @Override public void performexecute() throws Exception { System.out.println("Not in Cache"); FindDoctorDAO docdao=new FindDoctorDAO(); try { setdoclist((arraylist<doctor>) docdao.fetchdoctors(zipcode,name)); catch (SQLException e) { e.printstacktrace(); public void setdoclist(arraylist<doctor> doclist) { this.doclist = doclist; public ArrayList<Doctor> getdoclist() { return doclist; public String getzipcode(){ return zipcode; public String getname() { return name; public void setname(string name) { this.name = name; Note: We have called the DAO (service logic) in the performexecute() method.

3) Creating cachespec.xml <?xml version="1.0"?> <!DOCTYPE cache SYSTEM "cachespec.dtd"> <cache> <cache-entry> <class>command</class> <sharing-policy>not-shared</sharing-policy> <name>com.atech.training.cachecmd.finddoccachecmd</name> <cache-id> <component type="method" id="getzipcode"> <required>true</required> </component> <component type="method" id="getname"> <required>true</required> </component> <timeout>150</timeout> <inactivity>100</inactivity> </cache-id> </cache-entry> </cache> Place the cachespec.xml file within the WEB-INF folder. You can also place a global cachespec.xml file in the application server properties directory. The cachespec.dtd and a sample cachespec.xml file are available in the application server s properties directory (<APP-SERVER HOME>\properties). In the cachespec.xml first we are setting value of class to command, to let DynaCache know that we want to cache a custom java object. The value of name attribute is fully qualified name of the Java object. The cache-id element is used to define how to generate unique cache key for the cache-able object. In our case we wanted to use the zipcode and name (Doctor Name) as the caching id. Since the DynaCache can use getzipcode() and getname() methods to get the caching id, we configure it inside the component tag with type= method and id= <METHOD NAME> The value of timeout element equal to 150. What this means is that the cache entry is valid only for 150 seconds. The value of inactivity is 100. This means that the cache entry will be removed if it is not accessed within 100s. The maximum period for which the cache entry exists in the cache is determined by the timeout and inactivity. The following explains this

Case 1: Timeout > Inactivity Timeout=60s Inactivity=40s Case 2: Timeout < Inactivity Timeout=30s Inactivity=50s Cache entry accessed within 40s will make it stay till 60s. After 60s (timeout) it will be removed. If it is not accessed within 40s (inactivity), it will be removed from the cache after 40s, even before the timeout. This means that inactivity takes precedence over timeout in this case. Cache entry will stay till 30s only, whether it is accessed or not. This means that timeout takes precedence over inactivity in this case. 4) Calling execute() method in web service. Update the fetchdoctorlist() method of our FindDoctor web service as follows //service method public ArrayList<Doctor> fetchdoctorlist(string zipcode, String name, long ttlsec){ FindDocCacheCmd finddoc=new FindDocCacheCmd (zipcode, name); try { System.out.println("Calling Execute"); finddoc.execute(); catch (CommandException e) { e.printstacktrace(); return finddoc.getdoclist(); The client of this web service on calling the fetchdoctorlist() method will supply the zipcode, doctor name and time to live (timeout of the cache) value as input parameters. Out of these parameters, zipcode and name are used to create a new object of the FindDocCacheCmd class. FindDocCacheCmd finddoc=new FindDocCacheCmd (zipcode, name); Call the execute() method of the created object. Have a look at FindDocCacheCmd class code. You will notice that we are not overriding the execute() method. The execute() method is provided by the super class and it is the place where the life cycle of cache is provided.

The execute() method checks if there is object in cache for the current zipcode and name pair (zipcode and name together are the cache-id that we configured in the cachespec.xml). If yes, it will return the FindDocCacheCmd object from the cache. Otherwise it will call performexecute() method of FindDocCacheCmd object and once the result is returned it will store the instance of FindDocCacheCmd in DynaCache for the zipcode and name pair. After execute() method has been called, the FindDocCacheCmd object gets ready and we can call its getter methods to read the doctor list. i.e. getdoclist(); 5) Enabling dynamic caching You will have to enable the dynamic caching on your server if it is not already enabled. You can use the WebSphere Application Server Administrative Console to do that. Follow these steps Log into WebSphere Application Server Admininstrative Console Go to Servers -> WebSphere_Portal. If you are using a different server (say Websphere Application Server), select it. On the server details page expand Container Services and click on Dynamic Cache Service. On the Dynamic Cache Service page make sure that "Enable Service at server startup" check box is checked. To enable servlet caching, click Web Container Settings and check Enable Servlet Caching. To enable portlet caching, click Portlet Container Settings and check Enable Portlet Fragment Cache Save your changes and restart the server Note: The web service is now ready for caching. You can test it using cache monitor. Remember that the TTL for the cache entries is taken from the cashespec.xml file because we have not changed it programmatically in our implementation. If cache monitor is already installed (which will not be the default) follow these steps to view the cache entries: Open http://<server URL>/cachemonitor/ (eg. http://locahost:10000/cachemonitor).

Login

Click Cache Contents in the left menu Call the FindDoctor webservice from some client or use Generic Service Client. Open Cache Monitor and Click Refresh Instances button under Cache Monitor Note: The response is cached. If you call the web service with same zipcode and name arguments again (before cache entry s TTL), the response will be taken from the cache. The timeout (seconds) field value is 150 which we configured in cachespec.xml. If you want to install the cache monitor see the appendix at the end.

6) Allowing the Client to customize the TTL values for each cache entry For this to happen we need to first update our FindDocCacheCmd class and FindDoctor class as follows. Updating FindDocCacheCmd class Add a private class variable private long cachetimeout; Generate setter and getter for cachetimeout public void setcachetimeout(long cachetimeout) { this.cachetimeout = cachetimeout; public long getcachetimeout() { return cachetimeout; Add the following method public void setexptime(long ttlsec){ this.getentryinfo().settimelimit((int) ttlsec); this.getentryinfo().setinactivity((int) ttlsec); Update the performexecute() method. public void performexecute() throws Exception { System.out.println("Not in Cache"); setexptime(getcachetimeout()); FindDoctorDAO docdao=new FindDoctorDAO(); try { setdoclist((arraylist<doctor>) docdao.fetchdoctors(zipcode)); catch (SQLException e) { e.printstacktrace();

Updating FindDoctor class Update fetchdoctorlist() method so it look as follows public ArrayList<Doctor> fetchdoctorlist(string zipcode, String name, long ttlsec){ FindDocCacheCmd finddoc=new FindDocCacheCmd(zipCode, name); try { System.out.println("Calling Execute"); finddoc.setcachetimeout(ttlsec); finddoc.execute(); catch (CommandException e) { e.printstacktrace(); return finddoc.getdoclist(); Save and Generate the Web Service Again. Open Cache Monitor. Call the FindDoctor webservice from a client or use Generic Service Client. Give ttlsec value this time, say 60. In Cache Monitor click Refresh Instances button under Cache Monitor Note: The value of Timeout(seconds) field is 60, the one we passed as ttlsec parameter instead of 150 which we initially specified in cachespec.xml.

APPENDIX: HOW TO INSTALL DYNAMIC CACHE MONITOR IN WEBSPHERE? Go to the websphere adminstrative console.

Click continue.

Click Finish. Click save.

To see the dynamic cache monitor, make sure that the websphere server is running and go to the url http://<server url>/cachemonitor/ Authors: Yawar Khan Ascendant Technology India. (Chennai) Sankar Krishnan.S Ascendant Technology India. (Chennai)