mastering resin - download.e-bookshelf.de€¦ · wiley publishing, inc. mastering resin richard...

30
Wiley Publishing, Inc. Mastering Resin Richard Hightower Joseph D. Gradecki

Upload: others

Post on 04-Oct-2020

6 views

Category:

Documents


1 download

TRANSCRIPT

  • Wiley Publishing, Inc.

    Mastering Resin

    Richard HightowerJoseph D. Gradecki

    C1.jpg

  • Wiley Publishing, Inc.

    Mastering Resin

    Richard HightowerJoseph D. Gradecki

  • Vice President & Executive Group Publisher: Richard SwadleyVice President & Executive Publisher: Robert Ipsen Vice President & Publisher: Joseph B. Wikert Executive Editor: Robert Elliot Executive Editorial Director: Mary Bednarek Editorial Manager: Kathryn A. Malm Production Editor: Vincent KunkemuellerBook Producer: Ryan Publishing Group, Inc.Copyeditors: Elizabeth Welch and Tiffany TaylorCompositor: Gina Rexrode

    Copyright © 2003 by Wiley Publishing, Inc. All rights reserved.

    Published by Wiley Publishing, Inc., Indianapolis, Indiana

    Published simultaneously in Canada.

    No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or byany means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permittedunder Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permissionof the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright ClearanceCenter, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Cross-point Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-mail: [email protected].

    Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in prepar-ing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a par-ticular purpose. No warranty may be created or extended by sales representatives or written sales materials.The advice and strategies contained herein may not be suitable for your situation. You should consult with aprofessional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or anyother commercial damages, including but not limited to special, incidental, consequential, or other damages.

    For general information on our other products and services please contact our Customer Care Departmentwithin the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

    Trademarks: Wiley, the Wiley Publishing logo, and related trade dress are trademarks or registered trade-marks of John Wiley & Sons, Inc. and/or its affiliates in the United States and other countries, and may not beused without written permission. All other trademarks are the property of their respective owners. Wiley Pub-lishing, Inc. is not associated with any product or vendor mentioned in this book.

    Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not beavailable in electronic books.

    Library of Congress Cataloging-in-Publication Data:

    ISBN 0-471-43103-6

    Printed in the United States of America

    10 9 8 7 6 5 4 3 2 1

  • Acknowledgments xi

    About the Authors xiii

    Introduction xv

    Part I Introduction to Resin

    Chapter 1 An Overview of Resin 1What Is Resin? 4

    Resin/Resin Enterprise Features 4Resin Enterprise 8

    What’s Next 9

    Chapter 2 Setting Up the Resin Server 11Requirements for Installation 11

    Support Software 11Integrating Resin 12

    Ports 13Obtaining Java 14

    IBM 14Installing Resin on Windows 14

    Windows Service Startup 16Installing Resin on Unix/Linux 19

    Executing Resin under Unix 19Testing the Installation 21Command-Line Options 22Documentation 24The Basic Configuration 24

    The HTTP Port 26Logging in Resin 3.x 26The Java Compiler 27The Error Page 29The Server Restart Ping 30

    What’s Next 30

    Part II Application Development with Resin

    Chapter 3 Using JSP and Resin 31Beginning JSP Usage 31An Overview of JSP Technology 32Resin Support for JSP 34

    Page Placement 34

    iii

    C O N T E N TS

  • The JSP Hello World 34Combining Java and HTML 37

    JSP Variables 38Using the Request Variable 38Using the Response Variable 41Response Redirection 41Response Encoding 42Using the Application Variable 42Using the Session Variable 43

    Directives 44Imports 45Sessions 45Error Pages 46Includes 46

    Using Beans 46Accessing Databases 49JSTL and JSP-EL Support 50What’s Next 51

    Chapter 4 Using Servlets and Resin 53The Servlet Life Cycle 53Configuring Resin 55

    Web Defaults in Resin 3.x 55Resin web.xml Elements 56 57A Shortcut 59

    Hello World Servlet 59Using init Parameters 61

    Servlet and Forms 62Accessing the Database 64Development 66JSP Templates 67

    Templates and Objects 68What’s Next 71

    Chapter 5 Using XTP and StyleScript 73The Hello World XTP 73XML, XPath, XSL, and StyleScript 76

    XML 76XPath 77XSL 82

    Matching Tags with Attributes 89Using XTP for Style Changes 92Returning XTP from a Servlet 92The Account History Example 93StyleScript and XSL 94What’s Next 105

    C o n t e n t siv

  • Chapter 6 Object-Relational Mapping with CMP 107Resin-EE Features 108Setting Up Your Database 108Basic Database Access 109

    The login Table Entity Bean 109The EJB Descriptor 113Configuring the web.xml File 116Using the Entity Bean 116Deploying the Code 118Running the Code 118

    Using EJB-QL and ejbSelect() 119Adding Finder Methods 119Using ejbSelect() 124

    Changing Entity Values 126Updating the Table 131

    Removing a Bean 134Using Multiple Entity Beans 134

    Adding a Groups Bean 136Relationships 137

    Relationship Types 138Building a Relationship between login and groups 139

    Transactions 145Using Stateless Session Beans 146What’s Next 149

    Chapter 7 Using XDoclet with Resin 151Installing XDoclet 151Adding a New Entitlements Bean 152The Ant Build File 155The Files Ant Produces 157Expanding a Bean 157Resin XDoclet Tags 159What’s Next 161

    Chapter 8 The Burlap Web Service Protocol 163Downloading the Code 164The Specification 164

    Serialization 164The Tag 169The Tag 169

    Using BasicAPI 170Writing a Basic Client 171

    Executing the Code 172Writing a Basic Service 173

    Creating the Interface 173The Build Interface JAR 174

    Contents v

  • C o n t e n t svi

    Writing the Authentication Service 174The Server Structure 175

    Creating a Client for the New Service 176What’s Next 177

    Chapter 9 Hessian Binary Web Service Protocol 179Downloading the Code 180Using BasicAPI 180Writing a Basic Client 181

    Downloading the Interface Class 182Writing a Basic Service 183

    Creating the Interface 183Building the Interface JAR 184Writing the Authentication Service 184Server Structure 186Changing Resin.conf 187Changing web.xml 187Starting the Server 188

    Client for the New Service 188Mobile Hessian 190

    What’s in the Code 193Serialization Classes 194Python Hessian 196Hessian Mux 196Hessian Specification 196

    Serialization 197Calls 198Reply 198

    What’s Next 198

    Chapter 10 Parsing 199XML Parsing 199

    DOM XML Parsing 200SAX XML Parsing 203Changing Parsers 204

    HTML Parsing 205What’s Next 206

    Chapter 11 Database Connectivity 207Traditional JDBC Connectivity 207Using Resin's JNDI Configuration 209

    Basic Configuration Parameters 210Library Placement 210Using the Configuration 210

    Connecting to MySQL 211

  • Connecting to Other Databases 213Database Pooling 214Database Reliability 216Connecting through JSP 217What’s Next 219

    Chapter 12 Debugging and Logging 221Error Types 221

    Compiler Parse Errors 221Run-time Errors 222Logic Errors 223

    Just-In-Time Compilers 224Tracing Your Code 224

    Resin Logging 225RootCause Exception 227Thread Dumps 227Resin and Debuggers 228What’s Next 229

    Chapter 13 Security 231Authentication 231

    Providing Basic Authentication with XmlAuthenticator 231Specifying a Password File 235Session Timeouts 236Storing Passwords in a Database with JdbcAuthenticator 236

    Authentication API 239Authorization 239Logging Out 240Using OpenSSL with Resin 240Using JSSE with Resin 242What’s Next 243

    Chapter 14 Page Caching 245Overview of Page Caching 245

    How Web Caches Work 246HTML Metatags and HTTP Headers 246

    Resin and Caching 248Using Expires 249Using If-Modified 250Using Cache-Mapping 250Setting Cache-Control 251

    What’s Next 251

    Contents vii

  • Part III Resin Administration

    Chapter 15 Resin Server Configuration 253Details of resin.conf 253

    XML Elements 254Environments 254High-Level Configuration Format 254Using #include and app-default.xml 255Default Path Values 255

    Tag Definitions 256Common Environment Tags 256Web-App Tags 267Application and Server Tags 276 Configuration Elements 287

    What’s Next 288

    Chapter 16 Configuring Your Web Server 289URL-Dispatching 289Apache 291

    Installing and Configuring Apache on Unix 291Installing and Configuring Apache on Windows 292Configuring resin.conf 295Testing Apache and Resin 295Troubleshooting 296Virtual Hosts 297Error Pages 298

    Using IIS with Resin 298Testing IIS and Resin 300

    Using Netscape iPlanet with Resin 300Running Netscape iPlanet and Windows 301

    Hosting a CGI without Apache 301CGIServlet 301FastCGIServlet 302

    Resin and WebDav 303Configuring for WebDav 303Configuring Windows' My Network Places 304

    What’s Next 305

    Chapter 17 Exploring Virtual Hosting 307Basic Virtual Hosting 307Virtual Hosting Using External Web Servers 309IP Virtual Hosting 310Providing JVMs per Host 310What’s Next 311

    C o n t e n t sviii

  • Chapter 18 Using Resin HardCore 313Building the Module 313Installing the Module 314Running the Module 314What’s Next 314

    Chapter 19 Load Balancing and Reliability 315Sessions 315

    srun Indexing 316Distributed Sessions 316File-Distributed Sessions 319

    Load-Balancing Options 319Hardware Load Balancing 319Using Resin as a Balancer 321Using srun-backup 323

    Reliability Options 323Conclusion 324

    Part IV Appendixes

    Appendix A Resin Sources 325

    Appendix B Resin Status 329

    Appendix C Resin and Eclipse 335Installing the Eclipse Plugin 335Using ResinProjectWizard 336Using ResinLauncher 338

    Debugging 340

    Appendix D Burlap and Hessian APIs 343Package com.caucho.burlap 343Package com.caucho.burlap.io 353Package com.caucho.hessian 353Package com.caucho.hessian.io 361

    Index 363

    Contents ix

  • xixi

    Dedication

    This book is dedicated to Christ, my wife and our sons.

    Acknowledgments

    I’d like to thank Scott Ferguson, Resin Architect, and Sam Heisz, Resin Soft-ware Engineer, for their excellent and thorough technical review of this book.

    I’d like to thank Tim Ryan, Tiffany Taylor, and Liz Welch for their guidanceand editing; also, thanks to everyone at Caucho for creating excellent products.

    A C K N O W L E D G M E N TS

  • xiii

    C O N T E N TS

    Richard Hightower is CTO of Trivera Technologies, a leading Java educa-tion company that offers online and classroom training, as well as consultingon enterprise Java application development. Rick is a software engineer bytraining who specializes in software development tools and processes, anddeveloping enterprise applications using J2EE, XML, UML, JDBC, SQL, andopen source technologies. Formerly he was the Senior Software Engineer forJava Architecture at Intel’s Enterprise Architecture Lab. Rick is the co-authorof the popular Java Tools for Extreme Programming. Rick has extensiveexperience in both developing with Resin and teaching classes about it.

    Joseph D. Gradecki is a software engineer at Comprehensive Software Solutions, where he works on their SABIL product, a enterprise-level securi-ties processing system. He has built numerous dynamic, enterprise applica-tions using Java, AspectJ, servlets, JSPs, Resin, MySQL, BroadVision, XML,and more. He is the author of Mastering JXTA and the coauthor of MySQLand Java Developer’s Guide (with Mark Matthews and Jim Cole). Mr.Gradecki holds Bachelor’s and Master’s degrees in Computer Science and iscurrently pursuing a Ph.D. in Computer Science.

    xiii

    A B O U T T H E A U T H O R S

  • When the page layout function of HTML was combined with thepower of Java, JavaServer Pages were born. To enhance the powerand performance of JSPs, servlets were introduced, which removedJava code from the HTML page and placed it on the server itself. The Resin 3.x family of servers, including Resin Core and Resin-EE, all providethe ability to accurately and quickly process JSP and servlets, as well asdeliver enterprise-level server functionality. Features of the Resin serversinclude:

    ■■ Full specification support for JSP and servlets

    ■■ Load balancing

    ■■ Built-in Web server with high-performance HTML processing

    ■■ Resin XTP templates for dynamic web page creation

    ■■ Virtual hosting

    ■■ Model-View-Controller support with JSP Templates

    ■■ Web services using Burlap and Hussein

    ■■ Resin Hardcore—incorporation of Resin into a Linux kernel

    ■■ J2EE and EJB support

    All of these features and more await you with Resin servers.

    Introduction

    xv

  • Who Should Read This Book

    This book is designed to be a comprehensive handbook for installing, adminis-tering, and developing Java Web applications with the Resin 3.x family ofservers. All developers and administrators currently using Resin, or evaluatingany application server (including Resin, Tomcat, and JRun) should use thisbook as a guide to Resin and its features. Developers using this book shouldhave an understanding of Java and basic Internet programming concepts.

    Book Organization

    This book is organized into three parts. The first part is an introduction toResin, including installation, setup, and explanations of how Resin workswith various Java-based technologies. The second part covers applicationdevelopment with JSP, EJBs, templates, and other Java technologies. Thethird part covers advanced configuration of the Resin family of products,including enterprise-level features such as load-balancing.

    Part I: Introduction to Resin

    Chapter 1: Resin Setup

    In this chapter we cover the requirements for installing the Resin server. Thechapter provides detailed instructions for installing Resin Core on LinuxMandrake 8.2, as well as in a Windows environment using both Windows 2000Server and Windows XP Professional. Each of the installations will be fol-lowed by a full test to insure the installation was completely successful. Afterthe installation steps, the directory structure for Resin Core will be discussed,along with common errors encountered during installation.

    Chapter 2: Resin and Java Technologies

    This chapter examines the underlying architecture of the Resin server inorder to provide an overall picture of its functionality. Following the archi-tecture is a discussion of each of the primary Java technologies relevant tothe Resin family of products: servlets, JavaServer Pages, JavaBeans, andEJBs.

    I n t r o d u c t i o nxvi

  • Part II: Application Developmentwith Resin

    Chapter 3: JSP and Resin

    The part of the book devoted to developing Web application developmentbegins with a discussion of using JSP with Resin. We create a sample appli-cation to obtain information from a client, access a database, and display out-put using Resin. A discussion and example of using JavaBeans with JSP isalso included.

    Chapter 4: Servlets and Resin

    JavaServer Pages is a great improvement over the static HTML page. Servletspull the processing to the server with all the power of Java. This chapter willstep through how to write servlets to be executed on the Resin server. Thischapter also demonstrates how to access the database through a servlet andJSP support.

    Chapter 5: Using XTP with XSL and StyleScript

    Resin doesn’t just rely on HTML, JSP, and servlets for content transformationand delivery; it includes a Native format called XTP or XML Template Pages.This chapter includes detailed coverage of XPath expressions, format of XTP,and using XTP for output translation. We will cover how to write stylesheetsusing both XSL and StyleScript syntax.

    Chapter 6: Object-Relational Mapping with CMP

    This chapter takes an in-depth look at the Resin-EE product which isdesigned to support CMP. Detailed steps for installing Resin-EE on both Windows and Unix/Linux machines are included. The focus of the chapter isbuilding a comprehensive distributed application that demonstrates thepower and functionality of Resin-EE.

    Chapter 7: Using XDoclet with Resin

    Now that we’ve just spent an entire chapter discussing how to write anddeploy EJBs using Resin, we introduce Resin’s support for XDoclet. UsingJavadoc notation, EJBs can be written in a small percentage of the time nor-mally required. This chapter includes installation instructions and describesthe process of writing EJBs with XDoclet.

    B o o k O r g a n i z a t i o n xvii

  • Chapter 8: Burlap Web Service Protocol

    The Resin servers support two different kinds of Web services: Burlap andHussein. In this chapter on Burlap, the discussion begins with a comparisonbetween Burlap and SOAP. Next, an overview of the Burlap specification willtake place and provide a complete understanding of how Burlap applies toWeb services. The theoretical discussion will be followed by writing a Burlapservice and a client to use the new service in Java. Next, the issue of how toserialize data through Burlap will be covered. The chapter will continue withthe steps necessary to write Burlap clients in Python, Perl, and C#. Finally, adiscussion of how Burlap and EJB interact.

    Chapter 9: Hessian Binary Web Service Protocol

    The second Web services protocol supported by the Resin servers is Hessian.This chapter begins with a detailed discussion of the Hessian Binary Web Ser-vice Protocol. The discussion will be followed with the steps necessary towrite both a service and client using the Java language. This chapter includesdetails for writing clients in Python and C#. Finally, a discussion on the inter-action between Hessian and EJB.

    Chapter 10: Parsing

    In this chapter, the Resin server includes a complete HTML parser. Thisparser can be used to pull HTML tags from HTML documents from an HTMLeditor or even from web pages pulled from the Internet. The parsing can be toa document or even a DOM object for further processing.

    Chapter 11: Database Connectivity

    The real power of a Web site was realized when it was married to a database.This chapter demonstrates how Resin allows access to several different data-bases including MySQL, Microsoft SQL Server, and Oracle. This chapter cov-ers a wide range of database-related information, including using connectionpools for efficient connections and a comprehensive look at database config-uration.

    Chapter 12: Debugging and Logging

    This chapter explains the configuration settings for all logging; it alsoincludes code that demonstrates how to log application activity.

    Introductionxviii

  • Chapter 13: Security

    This chapter explains how to use Resin with OpenSSL. Topics and code willinclude login configuration, authenticator support, and authorization setup.

    Chapter 14: Page Caching

    Caching is fundamental to any good Internet server. Resin includes full caching,and this chapter provides an overview of the Resin Cache, cache configurationoperations, and demonstrates the effectiveness of the cache.

    Part III: Resin Administration

    Chapter 15: Resin Server Configuration

    This chapter provides a comprehensive review of all Resin configurationoptions (except those for the internal Web server which are covered in the nextchapter). The discussion begins with a full explanation of the resin.conf file.The configuration options covered are: general, servlet, database, Web applica-tion, and http. Other topics include threading, Linux boot start, and keepalives.

    Chapter 16: Web Server Configuration

    Resin can be configured to use either its own internal Web server or externalWeb servers such as Apache, IIS, and Netscape. This chapter will include acomplete review of all configuration options for the internal Web server forboth Windows and Linux platforms; it also explains how to configure Resin towork with external Web servers. Other topics include hosting CGI’s written inPHP, Perl, and Python without using Apache; CGIServlet; FastCGIServet; andfull coverage of Resin’s WebDav.

    Chapter 17: Virtual Hosting

    This chapter includes complete instructions for installing and configuringResin’s built-in virtual hosting capabilities. The chapter also explains how touse Resin with external Web servers in a virtual hosting configuration.

    Chapter 18: Resin Hardcore

    An experimental but powerful feature of the Resin Core product is its ability tobe incorporated directly into the kernel of the Linux OS. This chapter explains

    Book Organization xix

  • why incorporating Resin into the latest Linux kernel is a good performanceoption, and it provides detailed steps for performing the incorporation. Thepotential problems associated with the Resin-Linux kernel mix will be dis-cussed as well as example code for testing the incorporation.

    Chapter 19: Reliability and Load Balancing

    This chapter provides an overview of Resin’s approach to reliability and loadbalancing, as well as configuration details. Additional topics include handlingsessions and persistence, as well as building multiple Web servers. Finally,the topic of server failure is discussed.

    Part IV: Appendixes

    Appendix A: Working with Resin Source Code

    This appendix provides information on the Resin Source Code.

    Appendix B: Resin Status

    This appendix explains how to use Resin’s built-in status servlet to obtain awide range of information about the server. Related security issues are alsodiscussed.

    Appendix C: Resin and Eclipse

    This appendix provides details of using Resin as your Web development plat-form from within the Eclipse IDE.

    Appendix D: Burlap and Hessian APIs

    This appendix is a concise, quick reference to Resin’s Burlap and HessianAPIs.

    I n t r o d u c t i o nxx

  • During the early years of the Web, developers used a fairly small set ofHTML document tags to manipulate the style and layout of each Webpage. These static Web pages were usually stored on the same com-puter that was executing a Web server. When a user launched a Web browseron his or her local machine and pointed that browser to a Web server, a pro-tocol-based exchange of information began. The page sent to the user wasreally just a text file with information and HTML tags embedded in it topresent the information in a clear manner.

    As time went on, it became clear that providing up-to-date and personalizedinformation was going to be a developer’s nightmare if using static pages wasthe only option. Keeping the static pages up-to-date was feasible, but person-alizing that information manually was next to impossible. This meant that thepages had to be created on the fly in response to an action or request by theuser. One early solution to this problem was called Common Gateway Inter-face (CGI). Figure 1.1 shows an example of how requests are made using CGIand a Web server.

    Unfortunately, there were some problems with using CGI for dynamic Webpage generation. First, the CGI protocol was designed to allow a Web server tocommunicate with an external program and not specifically for the generationof dynamic Web pages. The creation of the Web pages is actually a side effect ofthe CGI protocol. As shown in Figure 1.1, the protocol is written so that theWeb server will create new process spaces in which the CGI application willexecute. All information passed from the user’s Web browser to the Web server

    An Overview of Resin

    C H A P T E R 1

    1

  • is passed as environment variables to the waiting CGI application. All of theseoperations are expensive in terms of processor time as well as memory utiliza-tion.

    An Overview of Resin2

    Web Server

    CGI Process

    CGI ProcessCGI Request

    CGI Request

    Figure 1.1 CGI request flow.

    The second problem is the fact that most CGI applications were written inPerl, with C and C++ coming in second. Depending on your programmingcapability, Perl could be a stumbling block to Web development.

    After the success of CGI became apparent, an alternative implementation ofCGI was created called FastCGI. Figure 1.2 shows the request flow inFastCGI.

    CGI Processpersistent

    CGI Request

    CGI Request

    Web Server

    Figure 1.2 FastCGI request flow.

    The primary difference between CGI and FastCGI is the creation of persis-tent processes in which the CGI application executes. By using persistentprocesses, the Web server doesn’t have to expend processor time and mem-ory constantly creating and destroying processes. The success of FastCGI ledto the development of other products, like mod_perl and PerlEx, to addressperformance and interface issues.

    The overall success of CGI was dependent on the fact that most Web serverson the market supported its use. This included open-source servers, such asApache; Internet Information Services (IIS) from Microsoft; and iPlanet fromNetscape. However, at the same time these Web servers started experiment-ing with newer technologies like Active Server Pages (ASP) and Server-SideJavaScript (SSJS).

    Both ASP and SSJS solutions to the problem of dynamic Web pages employthe concept of embedding code into the HTML page where dynamic contentis needed. ASP, for example, uses JScript or VBScript. Figure 1.3 shows theprocess flow for ASP and SSJS.

    As Figure 1.3 shows, a user requests an ASP page from a Web server that sup-ports ASP, usually IIS. The page is pulled into the Web server and processed.

  • The processing involves executing the ASP or SSJS code within the serverand replacing the code with HTML tags and content. The resulting static pageis sent to the browser.

    An Overview of Resin 3

    Web Server ASP

    HTML

    ASPProcessing

    Page Request

    Figure 1.3 ASP/SSJS process flow.

    One of my core beliefs is that all programming languages—both conventionaland Internet based—should be compared with each other only when we’rediscussing a specific solution. Is Java better than Cobol? Well, for some appli-cations clearly it is, but in some business situations, fancy GUIs and RMI justaren’t needed. The same is true for things like ASP and servlets. Therefore, atthis point, let’s move to a discussion of JSP, servlets, and beans, whichentered the scene after ASP and SSJS.

    In the hierarchy of power, the JavaServer Pages (JSP) technology probablycomes next. JSP pages are similar to both ASP and SSJS in that code is embed-ded in the HTML of a Web page. However, JSP isn’t designed to be specific toone Web server. As long as a Web server can interpret the Java code embeddedin the Web page, it will be able to handle JSP pages. Some of the real power inJSP comes from its ability to interact with JavaBeans. Beans are modularpieces of Java code designed to perform a specific job. Beans can be referencedfrom JSP pages and automatically instantiated on the server machine.

    Finally, we have servlets. A servlet is an extension to a Web server written asa class that will be instantiated to provide additional functionality to theserver. Figure 1.4 shows the process flow for a Web page that utilizes servlets.

    Web Server

    JavaExtension

    JavaExtension

    Page

    Figure 1.4 Servlet processing.

    When a Web page that includes calls to a servlet is requested by a browser, theHTML is processed by the Web server and the servlet calls are farmed to aservlet engine. The servlet engine will instantiate the servlet code, processthe request, and return any results to the Web server. Servlets are powerfulbecause they:

  • ■■ Remain in memory after the first instantiation.■■ Are portable to any platform that can execute Java.■■ Have access to the full power of the Java language and its supporting

    classes.

    You can use servlets for database access, distributed access using RemoteManagement Interface (RMI) or Common Object Request Broker Architec-ture (CORBA), and a host of other operations.

    In the remainder of this chapter, we cover the Resin server product familyand take a more in-depth look at the features provided by the servers.

    What Is Resin?

    Resin is a high-performance XML application server for use with JSPs,servlets, JavaBeans, XML, and a host of other technologies. The 2.1.x line ofservers is fully Servlet 2.3 and JSP 1.2 compliant and beats all of the competi-tion in number of operations per second, as shown in the data obtained fromwww.caucho.com/articles/benchmark.xtp. Released in August 2003, Resin3.x is JSP 2.0 and Servlet 2.4 draft compliant. As the drafts become standard,Resin 3.x will be updated to reflect any changes.

    Over the past few years, the Resin family of servers has evolved with theneeds of its users. As of this writing, two Resin application servers are avail-able. Resin is the core product, and it supports all of the basic featuresdefined in this chapter. Resin Enterprise enhances the core product withEnterprise JavaBeans (EJB) container-managed persistence (CMP) and data-base caching. Distributed objects are included using the Burlap protocol aswell as full support for the EJB 2.0 specification. In the remainder of thischapter, we outline the major features of the Resin application server.

    Resin/Resin Enterprise FeaturesThe following features are available in both Resin and Resin Enterprise:

    ■■ JSP/servlet support

    ■■ Serif/XTP

    ■■ XML/XSL

    ■■ Internal and external Web servers

    ■■ Load balancing

    ■■ Distributed sessions

    ■■ Security

    ■■ Virtual hosting

    An Overview of Resin4

  • ■■ Web services

    ■■ JSP-EL

    ■■ JDK 1.4 Logging

    Let’s take a look at each of these features.

    JSP

    As mentioned earlier, the Resin application server fully supports the Java JSP2.0 specification. JSP pages can use Java as well as JavaScript to embed codewithin the HTML tags and text on the page. However, beginning with Resin3.x, JavaScript is not supported; therefore you will only want to use Java inyour JSP pages. The server can handle XML-based JSP notation like the following:

    Hello

    What's your name?


    The Resin server allows you to create custom tag libraries to add better inter-nal documentation to Web pages. Full support is provided for Web applica-tions pulling together JSP pages, scripts, and beans.

    XSLJSP, servlets, and XML Template Pages can take advantage of Resin’s abilityto process Extensible Stylesheet Language (XSL) or Extensible Markup Lan-guage (XML) style sheets. By using XSL, basic XML can be transformed toHTML or another output, such as Wireless Application Protocol (WAP).Depending on the needs of the user, different style sheets can be created andused against XML to produce the desired output. In the following example, aJSP page instructs the Resin server to use the new.xsl style sheet against theprovided XML:

    What Is Resin? 5

  • Output Just For You

    data

    Web Server SupportOut of the box, Resin is a fully self-contained application server as well as aWeb server. There is no need for any additional server software. The internalWeb server is very fast and, in most cases, outperforms the competition.Resin also supports these external Web servers: Apache, Netscape, IIS, andO’Reilly WebSite.

    Load BalancingThere’s no need to worry about losing customers or visitors to your site whenit’s powered with a Resin server. Resin supports the use of a hardware loadbalancer for higher cost situations and a low-cost solution using Resin itself.The LoadBalanceServlet servlet is executed on one front-end machine, and itdistributes user requests to numerous back-end servers. The Resin serveralso includes an HTTP proxy cache to make the entire system more efficient.

    Distributed SessionsFor sites that must use sessions, Resin supports sticky and distributed ses-sions. Through file-based and in-memory hashtables, customer won’t haveproblems with shopping carts when requesting transfers to different serversin a server farm or when a server crashes. There is support for database per-sistent sessions as well as TCP-based distribution.

    SecurityThe Resin server includes four security mechanisms for use in applications:

    Authentication through XmlAuthenticator—This allowsusername/password combinations to be placed in configuration files.

    Authorization for protecting areas of a Web site—The areas of thesite can be protected using various constraints: pattern-based for specificpages, roles-based for specific users, IP-based for keeping pages specificto specific machines, and transport-based for limiting pages to SSL. Fur-ther authorization can be constrained using custom controls.

    Encryption of data—Resin supports OpenSSL for encrypting data. Fullsupport is provided for certificates.

    An Overview of Resin6

  • Security Manager for separating virtual uses in an ISP situation—The manager will put each Web application in its own separate securityenvironment.

    Virtual Hosting

    If you are in a situation where numerous users or departments will be usingResin, it’s a good idea to configure virtual hosting. In this mode, each host hasits own directory structure. Advanced configuration allows each host to haveits own Java Virtual Machine (JVM) for complete separation.

    Web Services

    The developers of Resin have incorporated two different Web service proto-cols to support this new Internet technology. The protocols are called BurlapWeb Service Protocol and Hessian Binary Web Service Protocol.

    Burlap

    Burlap Web Service Protocol is designed to be a lightweight protocol forallowing EJB services to communicate with non-Java servers and clients. Theunderlying protocol is all XML-based for maximum interoperability. The pro-tocol is simple, and using a Burlap service results in behavior similar toinstantiating an object and calling a method. A basic client would look likethis:

    public class Client {

    public static void main(String[] args)

    throws Exception {

    BurlapProxyFactory factory = new BurlapProxyFactory();

    TestService test = (TestService) factory.create(

    TestService.class, "http://www.gradecki.com/burlap/testSer-

    vice");

    System.out.println("Call doIt(): " + TestService.doIt());

    }

    }

    Building a Burlap service is just like creating a standard Java class, with thepublic methods exposed or made available to remote clients. Here’s the codefor the service called by our client:

    public class TestService extends BurlapServlet implements Basic {

    public String doIt()

    {

    return "called doIt()";

    }

    }

    What Is Resin? 7

  • You can use the protocol in Java 2 Micro Edition (J2ME) devices, and it alsosupports object serialization.

    Hessian

    The Hessian Binary Web Service Protocol is designed to be a simple protocoljust like Burlap but is optimized for sending binary data between servers andclients. The API for Hessian is just as simple as Burlap, and it supports seri-alization as well.

    Resin EnterpriseThe remaining features are specific to Resin Enterprise:

    ■■ CMP

    ■■ XDoclet

    ■■ EJB-QL

    CMP

    For those of you who have written servlets—or just about any type of Webapplication that uses a database—the acronyms ODBC and JDBC may makeyou tremble. When writing servlets that connect with a database, JDBC is thecommon interface used. The developer is responsible for creating the con-nection to the database, building the SQL, and executing the calls. With EJBcontainer-managed persistence (see http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/EJBConcepts4.html#62950), most of the work is done for you. Resinhelps even further by intelligently caching the database data. Full relationscan be created between CMP beans like 1-n, 1-1, and others using a series of XML-based configurations.

    XDoclet

    Resin Enterprise supports XDoclet, which is an extension to JavaDoc avail-able at http://xdoclet.sourceforge.net/. The custom Javadoc @tags created byResin are: resin-ejb:entit-bean, resin-ejb:cmp-field, resin-ejb:entity-method,and resin-ejb:relation.

    EJB-QL

    The Enterprise server supports Enterprise JavaBeans Query Language (EJB-QL) in its use of container-managed persistence. EJB-QL (which is defined by

    An Overview of Resin8