Building multi-tenant mashups with widgets for RESTful services IBM Developer Skills
Building multi-tenant mashups with widgets for RESTful services Using Lotus Widget Factory, Lotus Mashups and WebSphere sMash IBM Developer Skills Welcome to the IBM Software-as-a-Service demonstration series. In this series, we will demonstrate some architectural patterns exploiting features in IBM middleware for building software-as-a-service solutions. In this demo, we will show how Lotus Widget Factory and Lotus Mashups can be used to build and deploy tenant specific customizable widgets in mashup pages in a sample multi-tenant banking application. We will also show how these widgets can be used to invoke RESTful web services running in tenant specific instances of WebSphere sMash in the sample application. This sample application has been used to illustrate multiple SaaS architectural patterns in earlier demos in this series and it’s relevant parts are available for download from the websites associated with each demo. Building multi-tenant widgets and mashups for RESTful services Using Lotus Widget Factory, Lotus Mashups and WebSphere sMash Customers and Employees of Web Bank Customers and Employees of First Bank N.A Mashups for Web Bank Mashups for First Bank N.A Shared widgets with dynamic profiles and customizable themes and skins . User registry entries for First Bank User registry entries for Web Bank Security Layer using Tivoli Directory Server Machine 2 Presentation Layer using Lotus Mashups Develop iWidgets using Lotus Widget Factory RESTful services implemented in Groovy for First Bank N.A. RESTful services implemented in Groovy for Web Bank Services Layer using WebSphere sMash Shared tables in a Data Layer using DB2 V9 Machine 1 As shown in this diagram, the user interface layer of the sample application is built with Lotus Mashups. Lotus Widget Factory is used to create the iWidgets that will be deployed in the Lotus mashup pages. The services, data and security layers are built with Websphere sMash, DB2 Express-C and Tivoli Directory Server respectively. Lotus Widget Factory provides an easy-to-use development environment enabling users to rapidly create dynamic iWidgets without writing code. An iWidget is a standard way of defining simple and extensible browser-based widgets. Lotus Mashups is a graphical environment for rapidly assembling enterprise and web-based content into simple, flexible and dynamic web applications that present the content as widgets. Websphere sMash is a development and execution environment which can be used to create, assemble and deploy applications written in dynamic scripting languages such as Groovy, quickly and easily. DB2 Express is IBM’s entry-level database server for transaction processing. Tivoli Directory Server is IBM's implementation of the Lightweight Directory Access Protocol, or LDAP commonly used for accessing user information from a registry. We show how the sample multi-tenant banking application can share its user interface layer and data layer components between customers and employees of two fictitious tenant banks: First Bank N.A and Web Bank. Next we show the functional layers of the application. <<Video>> First we show how Lotus Widget Factory is used to create multi-tenant widgets exploiting the dynamic profile feature. First, we create a Lotus Widget Factory Project named BankApps. We select a Lotus Mashup server for deploying the widgets. Next, we create a Lotus Widget Factory model named ManageCustomer under the BankApps project. Lotus Widget Factory contains various builders that are snapped together using a wizard-based interface to create models. These models generate the code and configuration that comprise the widgets. Here we use the REST Service Call Builder for the getCustomerProfileByCustomerId RESTful service. This RESTful service runs in WebSphere sMash and returns data in the Java Script Object Notation (JSON) format. For this data to be used by Widget Factory, we need to use a restructure handler (JSON handler) that converts the JSON data to XML. We used an open source JSON library in Java from json.org to create this restructure handler. In the REST Service Call builder, we made the following changes to make use of the restructure handler: 1) specified the new JSON handler in the “Restructure Type” input field 2) set the content type to “text/plain” using the “Forced Content-Type” input field in the Advanced section 3) Added a call to the ServiceCallMethods “setAddHtmlDocumentWrapper()” method to force a XML element to be wrapped around the results. In order to show or hide tenant specific fields in the widgets for a tenant bank, we use the Dynamic Profile feature in Lotus Widget Factory. We create a Profile Set called J2BWPFPortletsConfigPS. We add a profile entry “product_subtype” Next, we add two profiles “bank1” and “bank2” and configure the value for “product_subtype” to “Show” and “Hide” respectively. In a similar way, we add other profile entries and configure their values. Next, we add profiling to the “bankId” variable. The bankId variable identifies the tenant bank for the user invoking this widget. The value of this variable is programmatically determined at runtime by parsing the fully qualified distinguished name returned by the LDAP server for the user invoking this widget as shown here Finally, we deploy the project and publish the widgets to Lotus Mashups as shown here. We login as the administrator for Lotus Mashups. We create a New Page for the tenant “First Bank N.A”. Different themes can be applied to mashup pages and different skins can be applied to the widgets. We create themes and skins using different CSS files and logos for each tenant bank, package these as a single WAR file and deploy to Lotus Mashups. For the First Bank N.A mashup page, we go to “Edit Properties”, select the theme firstBankEmptheme. Next, we set the background color to white and we set the page border as shown. We add the widgets Manage Customer and Manage Loan Portfolio for the employee role to this Mashups page. Then, we share the page with the group “bank1employee”. Users in different roles such as customers, employees etc. see different pages at runtime. This is enabled by the facility in Mashups to share different pages with different groups. Next we login as the employee for First Bank N.A with user id b1e1 and see the mashup page for employees of First Bank N.A. Similarly, we create another mashup up page for the customer role for First Bank N.A. Next we login as a customer for First Bank N.A with user id b1u1 and we see three different widgets – Customer Accounts, Interest Rates and Loan Requests Next we login as a customer for Web Bank with user id b2u1. Note that a different theme provides a different look and feel from First Bank N.A. Also note that the product “subtype” field in the Interest Rates widget which was visible for First Bank N.A, is not visible for Web Bank. Also access to each bank’s mashup pages is restricted to only employees and customers of that bank. Here we show that a First Bank N.A. user b1u1 can not login to Web Bank mashup page. Here we show the view All Customers service being invoked from the ManageCustomer widget. The script implementing the service in turn invokes the sMash data api to access a shared DB2 Express-C database. Now we can see the get Customer Profile service being invoked from the widget. The Security layer includes a Tivoli Directory Server instance configured in a multi-tenant configuration. A single LDAP database is shared between First Bank N.A. and Web Bank. Here we can see the LDAP hierarchy in a Lightweight Data Interchange Format file with entries for users belonging to both the banks. The Data Layer includes shared tables with DB2 V9 XML columns for storing customizable tenant specific data. Here we can see the XML schema for the <CUSTINFOXML> table. Conclusion Rapidly create shared widgets with tenant specific customizations using Lotus Widget Factory Deploy widgets into tenant-specific access controlled mashup pages using Lotus Mashups Invoke RESTful services implemented in dynamic scripting languages using WebSphere sMash In conclusion, we have demonstrated, How to rapidly create shared widgets with tenant specific customizations using Lotus Widget Factory How to deploy widgets into tenant specific access controlled mashup pages using Lotus Mashups How to invoke RESTful services implemented in dynamic scripting languages using WebSphere sMash.