Building Portals with the Java Portlet API (Expert's Voice).pdf

This preview shows page 1 out of 418 pages.

You've reached the end of your free preview.

Want to read all 418 pages?

Unformatted text preview: CYAN MAGENTA YELLOW BLACK PANTONE 123 CV EMPOWERING PRODUCTIVITY FOR THE JAVA DEVELOPER Dear Reader, Pro Struts Applications Jeff Linwood and Dave Minter Dave Minter APRESS JAVA ROADMAP Beginning J2EE 1.4 Beginning Java Objects Enterprise Java Development on a Budget Beginning JSP 2 Building Portals with the Java Portlet API with the Jeff Linwood, co-author of How do you bring your existing applications into the portal? How do you integrate your content management system and search engine with the portal? How do you get started with the portlet API? We show you how to solve real problems, like the ones we have seen as consultants and software developers. We cover the portlet API in depth, explaining the concepts and classes with example scenarios and code. When you are comfortable with the portlet API, we examine portal integration techniques, Single Sign-On, content management, charting, personalization, application and content syndication, and searching. We believe that with the remarkable cooperation in unifying the portlet API across many different vendors, using standards for portals is now the best choice. Our examples will therefore run on any portal that supports the portlet API. We avoid proprietary tools, instead showing how to incorporate several open source software projects into your portlets, including XDoclet, Apache Jakarta Lucene, and JFreeChart. Our backgrounds as developers and consultants lead us to look for books that concentrate on solving real problems with new technologies, not just explaining their details. We hope that this book will help you to solve problems using the portlet API. Building Portals Java Portlet API Building Portals with the Java Portlet API THE EXPERT’S VOICE ® IN JAVA Includes Includes Pluto, Lucene, and and XDoclet Building Portals with the Java Portlet API Learn how to create portlet applications, integrate existing web applications, and incorporate XDoclet, Apache Jakarta Lucene, JFreeChart, and other open source projects Join online discussions: forums.apress.com SOURCE CODE ONLINE FOR PROFESSIONALS BY PROFESSIONALS ™ ISBN 1-59059-284-0 54999 US $49.99 Linwood and Minter Jeff Linwood and Dave Minter Foreword by Ian Griffiths Shelve in Java User level: Intermediate–Advanced 6 89253 15840 1 9 781590 592847 this print for content only—size & color not accurate spine = 0.790" 416 page count Praise for Building Portals with the Java Portlet API : “The book gives a solid introduction to developing a portal . . . Clearly the authors understand portal development and know how to pass that information on to their readers.” —Thomas Paul, JavaRanch ( ) “The text is well written and easy to read; graphics and illustrations are used sparingly and to great effect.” — Jack Herrington, Code Generation Network ( ) 2840chFM.qxd 7/13/04 12:43 PM Page i Building Portals with the Java Portlet API JEFF LINWOOD, DAVE MINTER 2840chFM.qxd 7/13/04 12:43 PM Page ii Building Portals with the Java Portlet API Copyright © 2004 by Jeff Linwood, Dave Minter All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN (pbk): 1-59059-284-0 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Steve Anglin Technical Reviewer: Carsten Ziegeler Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, John Franklin, Jason Gilmore, Chris Mills, Steve Rycroft, Dominic Shakeshaft, Jim Sumser, Karen Watterson, Gavin Wray, John Zukowski Project Manager: Kylie Johnston Copy Edit Manager: Nicole LeClerc Copy Editor: Liz Welch Production Manager: Kari Brooks Production Editor: Ellie Fountain Compositor: Kinetic Publishing Services, LLC Proofreader: Nancy Sixsmith Indexer: James Minkin Artist: Kinetic Publishing Services, LLC Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY 10010 and outside the United States by Springer-Verlag GmbH & Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany. In the United States: phone 1-800-SPRINGER, e-mail [email protected], or visit . Outside the United States: fax +49 6221 345229, e-mail [email protected], or visit . For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit . The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at in the Downloads section. 2840chFM.qxd 7/13/04 12:43 PM Page iii Contents at a Glance Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii Chapter 1 Introduction to Portals and Portlets . . . . . . . . . . . . . . 1 Chapter 2 Portlet Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Chapter 3 The Portlet Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Chapter 4 Portlet Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Chapter 5 Using Servlets and JavaServer Pages with Portlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Chapter 6 Packaging and Deployment Descriptors . . . . . . . . . . . . 159 Chapter 7 Portal and Portlet Configuration . . . . . . . . . . . . . . . . 185 Chapter 8 Security and Single Sign-On . . . . . . . . . . . . . . . . . . . . . . 209 Chapter 9 RSS and Syndication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Chapter 10 Integrating the Lucene Search Engine . . . . . . . . . . . 255 Chapter 11 Personalization and User Attributes . . . . . . . . . . . . . 281 Chapter 12 Web Services for Remote Portlets (WSRP) and Application Syndication . . . . . . . . . . . . . . . . . . . . . . 295 Chapter 13 Exposing an Existing Application As a Portlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Chapter 14 Charting with JFreeChart . . . . . . . . . . . . . . . . . . . . . . . . . 339 Chapter 15 Content Management Systems . . . . . . . . . . . . . . . . . . . . . . . 359 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 iii 2840chFM.qxd 7/13/04 12:43 PM Page iv 2840chFM.qxd 7/13/04 12:43 PM Page v Contents Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiii About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xiv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xv Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii Chapter 1 Introduction to Portals and Portlets .....1 Providing a Solution with Portals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Designing the Portal’s Information Architecture . . . . . . . . . . . . . . . . 2 Portal Application Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Building Portlets with the Portlet API . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Providing Technical Solutions with Portals . . . . . . . . . . . . . . . . . . . . . . 7 Security and Single Sign-On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Content Syndication and RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Searching Content from the Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Portals and Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Integrating Existing Applications into the Portal . . . . . . . . . . . . . . 9 Using Charts in the Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Content Management and Portlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Chapter 2 Portlet Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 First Portlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Building the Portlet Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Packaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Deploying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Portlet Programming 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 GenericPortlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Portlet Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Portlet Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Enhancing the Portlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Web.xml Deployment Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 v 2840chFM.qxd 7/13/04 12:43 PM Page vi Contents Packaging and Deploying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Chapter 3 The Portlet Life Cycle . . . . . . . . . . . . . . . . . . . . . . . 41 The Portlet Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Creation of the Portlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Request Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Destroying the Portlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Threading Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Chapter 4 Portlet Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Portlet Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Render Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Action Request and File Uploading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Portlet Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Render Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Action Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Portlet Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Sessions and Interportlet Communication . . . . . . . . . . . . . . . . . . . . . . . 102 Content Markup Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Portlet Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Window States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Style Sheets and the User Experience . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Chapter 5 Using Servlets and JavaServer Pages with Portlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Portlets, Servlets, and JSP Design Goals . . . . . . . . . . . . . . . . . . . . . . 119 Portlet Request Dispatcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Request and Response Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Session Management Between a Portlet and a Servlet or JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Creating a Form in JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Using the Portlet JSP Tag Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 To-Do List Portlet Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 vi 2840chFM.qxd 7/13/04 12:43 PM Page vii Contents The web.xml Deployment Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Directory Structure of the Application . . . . . . . . . . . . . . . . . . . . . . . . 153 Complete Code Listing for the To-Do List Portlet . . . . . . . . . . . . 154 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Chapter 6 Packaging and Deployment Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Portlet Application Packaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Portlet Application Deployment Descriptor Structure . . . . . . . . . 160 Web Application Deployment Descriptor . . . . . . . . . . . . . . . . . . . . . . . . . 170 XDoclet Portlet Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Chapter 7 Portal and Portlet Configuration . . . . . . . . . 185 Using the PortalContext to Retrieve Information About the Portal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Using the PortletConfig Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Using Portlet Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Chapter 8 Security and Single Sign-On . . . . . . . . . . . . . . . 209 Portlet Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Chapter 9 RSS and Syndication . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Overview of RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Walking Through an Example RSS File . . . . . . . . . . . . . . . . . . . . . . . . . . 240 RSS Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 Displaying Syndicated Information in Portlets . . . . . . . . . . . . . . . . 247 Syndicating Out . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 Chapter 10 Integrating the Lucene Search Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Overview of Lucene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 Downloading and Installing Lucene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 vii 2840chFM.qxd 7/13/04 12:43 PM Page viii Contents Lucene Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 Building an Index with Lucene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Designing a Portlet to Search the Index . . . . . . . . . . . . . . . . . . . . . . . 270 Developing a Portlet for Lucene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Indexing Other Types of Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Lucene and Different Types of Content . . . . . . . . . . . . . . . . . . . . . . . . . 279 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Chapter 11 Personalization and User Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Making a Good Impression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Making Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Chapter 12 Web Services for Remote Portlets (WSRP) and Application Syndication . . . . . . 295 WSRP Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 WSRP and the Java Portlet API . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture