CHAPTER REVIEW DRAFT—CISCO CONFIDENTIAL 7-1 Cisco Prime Service Catalog 12.0 Adapter Integration Guide 7 Developing Integration with External Systems Using JSR Portlets The Portal Designer solution within Service Catalog provides a rich platform for integrating with external applications through JSR Portlets. The portal front-end uses Apache Pluto 1.1 libraries as the framework. Portlets developed using APIs which meet the Java Portlet Specification (JSR168, JSR286) standards may be deployed along with Service Catalog. Once deployed, these will appear in Portal Designer as “Third-Party Portlets” and can be added to portal pages. For more information on how to maintain JSR portlets and other content in the Portal Designer solution, see the Cisco Prime Service Catalog Designer Guide. This chapter covers some guidelines on the development and deployment of JSR portlets for the Portal Designer solution. A sample portlet named “MyJSR” is used throughout the chapter as an illustration. The portlet is developed with Spring 3.0 Annotation-based Controller and Sencha’s Ext JS—the JavaScript framework for the portal front-end. Portlet Structure and Packaging The portlet files should be packaged according to the JSR 168 or 286 specifications, in the form of web application (war) files appropriate for the application server used. A typical portlet war file may include servlets, resource bundles, images, html, jsp, css files, and so on. JBoss Application Server Here is the anatomy of a simple portlet named “MyJSR.war”: 1. css MyJSR.css 2. images <Custom Images that the Portlet needs can be placed here> 3. js MyJSRCreatePersonView.js MyJSREdit.js MyJSRHelp.js MyJSRView.js 4. WEB-INF classes com myjsr MyJSRController.class config
24
Embed
Developing Integration with External Systems Using JSR …portlet-el_2_0.tld portlet.xml web.xml jboss-deployment-structure.xml In this sample portlet, the nsAPI java...
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Cisco Prime
C H A P T E R 7
Developing Integration with External Systems Using JSR Portlets
The Portal Designer solution within Service Catalog provides a rich platform for integrating with external applications through JSR Portlets. The portal front-end uses Apache Pluto 1.1 libraries as the framework. Portlets developed using APIs which meet the Java Portlet Specification (JSR168, JSR286) standards may be deployed along with Service Catalog. Once deployed, these will appear in Portal Designer as “Third-Party Portlets” and can be added to portal pages. For more information on how to maintain JSR portlets and other content in the Portal Designer solution, see the Cisco Prime Service Catalog Designer Guide.
This chapter covers some guidelines on the development and deployment of JSR portlets for the Portal Designer solution. A sample portlet named “MyJSR” is used throughout the chapter as an illustration. The portlet is developed with Spring 3.0 Annotation-based Controller and Sencha’s Ext JS—the JavaScript framework for the portal front-end.
Portlet Structure and PackagingThe portlet files should be packaged according to the JSR 168 or 286 specifications, in the form of web application (war) files appropriate for the application server used. A typical portlet war file may include servlets, resource bundles, images, html, jsp, css files, and so on.
JBoss Application Server
Here is the anatomy of a simple portlet named “MyJSR.war”:
1. cssMyJSR.css
2. images<Custom Images that the Portlet needs can be placed here>
In this sample portlet, the nsAPI java client—newscale_appclient.jar—is included in the lib folder as the portlet invokes the REST API to retrieve data from Service Catalog. Pluto libraries and other libraries that the nsAPI java client depends on need to be included in the lib folder. In addition, the jboss-deployment-structure.xml is included to describe the dependencies on the JBoss modules.
An additional descriptor—portlet.xml—must be present to specify the portlet-related configurations.
Dependent Libraries
The set of libraries required for inclusion in the JSR Portlet war file are available in either the deployed RequestCenter application on the application server or the Service Catalog installer image:
-pluto-taglib-2.0.2.jar: under the "preinstall" folder of the product image
-all other files: RequestCenter.war/WEB-INF/lib
7-2Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
Developing PortletsA typical JSR portlet should cover the three rendering modes —View, Edit, and Help. In addition, the portlet would support different window states—Normal, Minimized, and Maximized.
The MyJSR portlet example shown below provides a user interface that supports two functionalities:
1. List Service Catalog users in a grid.
Figure 7-1 Developing Portlets
2. Allow user to be added/updated.
7-3Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
Figure 7-2 Add User
To achieve the above requirements, the sample code that follows includes these high-level operations:
• Retrieval of Service Catalog users using nsAPI java client
• Returning the user details in JSON format to the user interface
• Rendering the list of users in a Ext JS grid on the browser
• Display/entry of user details in a form designed using Ext JS
• Adding/updating user details in the Service Catalog repository using nsAPI java client
MyJSR.css
#Code Custom Styles for the portlet can be designed here.
Now let us examine the content of each of the components within the MyJSR.war.
MyJSRCreatePersonView.js
Example code using Ext JS to display a form for creating a user.
/* Code custom JavaScript for the portlet here */
Ext.onReady(function() {var tab2 = new Ext.FormPanel({id : 'personEditForm',labelAlign : 'top',
7-4Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
7-6Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
text : 'Cancel',handler : function() {window.location=viewPersonUrl; } }] });});
MyJSREdit.js
This JavaScript can be used to add any custom code for portlet edit mode.
/* Code custom JavaScript for the Portlet here */
Ext.onReady(function() {
});
MyJSRHelp.js
This JavaScript can be used to add any custom code for portlet edit mode.
/* Code custom JavaScript for the Portlet here */
Ext.onReady(function() {
});
MyJSRView.js
Example JavaScript to display users in Ext JS grid.
/* Code custom JavaScript for the Portlet here */Ext.onReady(function() {// Demonstrates how to getUser info from Java Script and set it to divvarLogin=document.getElementById('MyJSRLoginNameDiv'); Login.innerHTML=nsAPP_CurrentUserLoginName;varFirstName=document.getElementById('MyJSRFirstNameDiv'); FirstName.innerHTML=nsAPP_CurrentUserFirstName;varLastName=document.getElementById('MyJSRLastNameDiv'); LastName.innerHTML=nsAPP_CurrentUserLastName;varHomeOU=document.getElementById('MyJSRHomeOUDiv'); HomeOU.innerHTML=nsAPP_CurrentUserHomeOuId;var PersonID=document.getElementById('MyJSRPersonIDDiv'); PersonID.innerHTML=nsAPP_CurrentUserId;
7-9Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
}
var grid = new Ext.grid.GridPanel(gridConfig);});
portlet.xml
Example of the portlet specification. The portlet-class needs to be set along with a pair of init-params—contextConfigLocation and nsContentPortlet (nsContentPortlet is always set to “false”).
<?xmlversion="1.0"encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License. You may obtain a copy of the License at
http:www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
See the License for the specific language governing permissions andlimitations under the License.--><portlet-appxmlns="http:java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"version="1.0"xmlns:xsi="http:www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http:java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http:java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"><portlet><description>MyJSR Description</description><portlet-name>nsMyJSR</portlet-name><display-name>My JSR Portlet</display-name><portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class><init-param><name>contextConfigLocation</name><value>/WEB-INF/classes/config/spring/MyJSRApplicationContext.xml</value></init-param><init-param><name>nsContentPortlet</name><value>false</value></init-param><expiration-cache>-1</expiration-cache><supports><mime-type>text/html</mime-type><portlet-mode>VIEW</portlet-mode><portlet-mode>EDIT</portlet-mode><portlet-mode>HELP</portlet-mode></supports><portlet-info><title>My JSR Portlet</title></portlet-info></portlet></portlet-app>
7-10Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
web.xml
Example deployment descriptor with the servlet and servlet mapping is required by the portal server; in this case, Apache Pluto.
<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEweb-appPUBLIC"-Sun Microsystems, Inc. DTD Web Application 2.3EN""http:java.sun.com/dtd/web-app_2_3.dtd"><web-app><display-name>My JSR Portlet Application</display-name><description>My JSR Portlet</description>
<!-- Resources bundle base class --><context-param><param-name>contextConfigLocation</param-name><param-value> /WEB-INF/classes/config/spring/MyJSRApplicationContext.xml</param-value></context-param>
<!- Declare Tag libraries that are used in which are going to use in JSP pages--><taglib><taglib-uri>http://portals.apache.org/pluto</taglib-uri><taglib-location>/WEB-INF/tld/pluto.tld</taglib-location></taglib>
7-12Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsDeveloping Portlets
head.appendChild(script);</script>
<!-- Write your JSP Code for Portlet Edit here --><c:iftest="${portletWindowState == 'NORMAL' or portletWindowState == 'normal'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<c:iftest="${portletWindowState == 'MINIMIZED' or portletWindowState == 'minimized'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<c:iftest="${portletWindowState == 'MAXIMIZED' or portletWindowState == 'maximized'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<!-- Write your JSP Code for Portlet Help here --><c:iftest="${portletWindowState == 'NORMAL' or portletWindowState == 'normal'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<c:iftest="${portletWindowState == 'MINIMIZED' or portletWindowState == 'minimized'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<c:iftest="${portletWindowState == 'MAXIMIZED' or portletWindowState == 'maximized'}">Portlet Mode = <c:outvalue='${portletMode}'/>Portlet Window State = <c:outvalue='${portletWindowState}'/></c:if>
<!-- Write your JSP Code for Portlet Edit here --><c:iftest="${portletWindowState == 'NORMAL' or portletWindowState == 'normal'}"><!--PortletMode = <c:out value='${portletMode}'/>Portlet Window State = <c:out value='${portletWindowState}'/> --></c:if>
<c:iftest="${portletWindowState == 'MINIMIZED' or portletWindowState == 'minimized'}"><!--Portlet Mode = <c:out value='${portletMode}'/>Portlet Window State = <c:out value='${portletWindowState}'/> --></c:if>
<c:iftest="${portletWindowState == 'MAXIMIZED' or portletWindowState == 'maximized'}"><!--Portlet Mode = <c:out value='${portletMode}'/>Portlet Window State = <c:out value='${portletWindowState}'/>--></c:if>
<!-Un-comment this to get User Info from the Portlet Controller that sets user info in modelLogged In User (<c:out value="${userName}" escapeXml="false"/>): <c:out value="${firstName}" escapeXml="false"/> , <c:out value="${lastName}" escapeXml="false"/> , <c:out value="${PersonId}" escapeXml="false"/> , <c:out value="${HomeOUId}" escapeXml="false"/>-->
<!-Write declare divs to display user info --><div>Logged In User (<div id="MyJSRLoginNameDiv" style="text-align:right;display:inline;width:100%;"><span style="padding-left:20px;"></span></div>) : <div id="MyJSRFirstNameDiv" style="text-align:right;display:inline;width:100%;"><span></span></div> , <divid="MyJSRLastNameDiv" style="text-align:right;display:inline;width:100%;"><span style="padding-left:20px;"></span></div></div><div>HomeOUId : <div id="MyJSRHomeOUDiv" style="text-align:right;display:inline;width:100%;"><span style="padding-left:20px;"></span></div> , PersonId : <div id="MyJSRPortletPersonIDDiv" style="text-align:right;display:inline;width:100%;"><span style="padding-left:20px;"></span></div>
The steps for developing java portlet controllers typically include:
Step 1 Write handler code for the three portlet modes—View, Edit, and Help.
Step 2 Write handler code for the three portlet views—Normal, Minimized, and Maximized.
Step 3 For JSR portlets that process/display Service Catalog entities, the nsAPI client can be used to invoke the related REST APIs in the portlet controller.
a. Get reference to nsAPI client API.
b. Call nsAPI client to get a list of the instances for the required Service Catalog entity.
c. Optionally get the details for the currently logged-in user; for example, Person ID, First Name, Last Name.
Step 4 Render the instances in a grid or other format (this example also demonstrates how to do paging in nsAPI for a Ext JS Grid).
Note In a clustered environment, if the portlet references the Service Catalog application URL, then specify the URL as “http://localhost:<port>/RequestCenter” where <port> is the port number used by each node in the cluster. In other words, do not specify the URL as “http:<host_name>/RequestCenter” where <host_name> is the computer name of the web server or one of the hosts within the cluster.
#(Port number and host has to changed as per the application server).BASE_URL=http:localhost:8088/RequestCenter
7-23Cisco Prime Service Catalog 12.0 Adapter Integration Guide
R E V I E W D R A F T — C I S C O C O N F I D E N T I A L
Chapter 7 Developing Integration with External Systems Using JSR PortletsCompiling JSR Portlet Controller
Compiling JSR Portlet ControllerInclude the dependent libraries in the classpath when compiling the portlet controller. For a complete list of libraries, see Portlet Structure and Packaging.
Deploying PortletsThe deployment procedures vary with the application server used. As a general note, a JSR portlet can be deployed like any typical web application through the application server administrator console.
For detailed instructions on how to deploy the JSR portlet, and how to use the portlet on a portal page after deployment, see the Cisco Prime Service Catalog Designer Guide.
7-24Cisco Prime Service Catalog 12.0 Adapter Integration Guide