100% found this document useful (1 vote)
21 views

Pro Jakarta EE 10: Open Source Enterprise Java-based Cloud-native Applications Development Peter Späth - Download the ebook and start exploring right away

The document promotes the book 'Pro Jakarta EE 10: Open Source Enterprise Java-based Cloud-native Applications Development' by Peter Späth, available for download at ebookmass.com. It also lists several other recommended titles related to cloud-native development and Java applications, providing links for each. The document includes details about the book's content, authors, and publishing information.

Uploaded by

liexhuiyi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
21 views

Pro Jakarta EE 10: Open Source Enterprise Java-based Cloud-native Applications Development Peter Späth - Download the ebook and start exploring right away

The document promotes the book 'Pro Jakarta EE 10: Open Source Enterprise Java-based Cloud-native Applications Development' by Peter Späth, available for download at ebookmass.com. It also lists several other recommended titles related to cloud-native development and Java applications, providing links for each. The document includes details about the book's content, authors, and publishing information.

Uploaded by

liexhuiyi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Visit ebookmass.

com to download the full version and


explore more ebook or textbook

Pro Jakarta EE 10: Open Source Enterprise Java-


based Cloud-native Applications Development Peter
Späth

_____ Click the link below to download _____


https://ebookmass.com/product/pro-jakarta-ee-10-open-source-
enterprise-java-based-cloud-native-applications-development-
peter-spath/

Explore and download more ebook or textbook at ebookmass.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Beginning Cloud Native Development with MicroProfile,


Jakarta EE, and Kubernetes: Java DevOps for Building and
Deploying Microservices-based Applications 1st Edition
Tarun Telang
https://ebookmass.com/product/beginning-cloud-native-development-with-
microprofile-jakarta-ee-and-kubernetes-java-devops-for-building-and-
deploying-microservices-based-applications-1st-edition-tarun-telang/

Beginning Cloud Native Development with MicroProfile,


Jakarta EE, and Kubernetes 1st Edition Tarun Telang

https://ebookmass.com/product/beginning-cloud-native-development-with-
microprofile-jakarta-ee-and-kubernetes-1st-edition-tarun-telang/

Beginning Spring Boot 3: Build Dynamic Cloud-Native Java


Applications and Microservices - Second Edition K. Siva
Prasad Reddy
https://ebookmass.com/product/beginning-spring-boot-3-build-dynamic-
cloud-native-java-applications-and-microservices-second-edition-k-
siva-prasad-reddy/

Building Modern Business Applications: Reactive Cloud


Architecture for Java, Spring, and PostgreSQL 1st Edition
Peter Royal
https://ebookmass.com/product/building-modern-business-applications-
reactive-cloud-architecture-for-java-spring-and-postgresql-1st-
edition-peter-royal-2/
Building Modern Business Applications: Reactive Cloud
Architecture for Java, Spring, and PostgreSQL 1st Edition
Peter Royal
https://ebookmass.com/product/building-modern-business-applications-
reactive-cloud-architecture-for-java-spring-and-postgresql-1st-
edition-peter-royal/

Pro Spring Security: Securing Spring Framework 6 and Boot


3–based Java Applications, Third Edition Massimo Nardone

https://ebookmass.com/product/pro-spring-security-securing-spring-
framework-6-and-boot-3-based-java-applications-third-edition-massimo-
nardone/

Modern Enterprise Architecture: Using DevSecOps and Cloud-


Native in Large Enterprises 1st Edition Jeroen Mulder

https://ebookmass.com/product/modern-enterprise-architecture-using-
devsecops-and-cloud-native-in-large-enterprises-1st-edition-jeroen-
mulder/

Beginning EJB 3: Java EE 7 Edition Jonathan Wetherbee

https://ebookmass.com/product/beginning-ejb-3-java-ee-7-edition-
jonathan-wetherbee/

Cloud-native Computing Pethuru Raj

https://ebookmass.com/product/cloud-native-computing-pethuru-raj/
Pro
Jakarta EE 10
Open Source Enterprise Java-based
Cloud-native Applications Development

Peter Späth
Pro Jakarta EE 10
Open Source Enterprise
Java-based Cloud-native
Applications Development

Peter Späth
Pro Jakarta EE 10: Open Source Enterprise Java-based Cloud-native Applications
Development

Peter Späth
Leipzig, Sachsen, Germany

ISBN-13 (pbk): 978-1-4842-8213-7 ISBN-13 (electronic): 978-1-4842-8214-4


https://doi.org/10.1007/978-1-4842-8214-4
Copyright © 2023 by Peter Späth
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Laura Berendson
Coordinating Editor: Mark Powers
Copy Editor: Kezia Endsley
Cover designed by eStudioCalamar
Cover image by Dapiki Moto on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub (https://github.com/Apress). For more detailed information, please visit
http://www.apress.com/source-code.
Printed on acid-free paper
To Nicole.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Part I: Development Workflow Proposal��������������������������������������������������������� 1


Chapter 1: Installing a Development Server������������������������������������������������������������� 3
Installing and Running Under Linux���������������������������������������������������������������������������������������������� 4
Installing and Running Under Windows���������������������������������������������������������������������������������������� 5
GlassFish Application Debugging�������������������������������������������������������������������������������������������������� 6
Elaborated GlassFish Operation Instructions�������������������������������������������������������������������������������� 6

Chapter 2: Creating and Building Projects with Eclipse������������������������������������������� 7


Installing Eclipse��������������������������������������������������������������������������������������������������������������������������� 7
Configuring Eclipse����������������������������������������������������������������������������������������������������������������������� 9
Adding Java Runtimes���������������������������������������������������������������������������������������������������������������� 10
Adding Plugins���������������������������������������������������������������������������������������������������������������������������� 10
Using Eclipse to Administer a Jakarta EE Server������������������������������������������������������������������������ 11
Eclipse Everyday Usage�������������������������������������������������������������������������������������������������������������� 19
Changing the Project Layout������������������������������������������������������������������������������������������������������� 20

Chapter 3: Development with NetBeans as an IDE������������������������������������������������� 23


Installing NetBeans��������������������������������������������������������������������������������������������������������������������� 23
Starting a NetBeans Project�������������������������������������������������������������������������������������������������������� 24
Multi-IDE Projects����������������������������������������������������������������������������������������������������������������������� 25

v
Table of Contents

Chapter 4: Git and Subversion�������������������������������������������������������������������������������� 27


The Subversion Version Control System������������������������������������������������������������������������������������� 27
Subversion Clients���������������������������������������������������������������������������������������������������������������������� 32
The Git Version Control System��������������������������������������������������������������������������������������������������� 36
Git Clients������������������������������������������������������������������������������������������������������������������������������������ 39

Chapter 5: Continuous Integration�������������������������������������������������������������������������� 43


The Jenkins CI Server����������������������������������������������������������������������������������������������������������������� 43
Starting a Jenkins Project����������������������������������������������������������������������������������������������������������� 44
Build Triggers������������������������������������������������������������������������������������������������������������������������������ 46
Creating Real-World Builds��������������������������������������������������������������������������������������������������������� 49
Triggering Builds from Git����������������������������������������������������������������������������������������������������������� 53
Triggering Builds from Subversion���������������������������������������������������������������������������������������������� 55
Analyzing Jenkins Builds via REST��������������������������������������������������������������������������������������������� 56

Chapter 6: Corporate Maven Repositories�������������������������������������������������������������� 61


The Maven Repository Layout����������������������������������������������������������������������������������������������������� 63
A Simple Server to Provide Mavenized Artifacts������������������������������������������������������������������������� 64
The Marvin EAR Root Project������������������������������������������������������������������������������������������������� 65
The Marvin Web Project��������������������������������������������������������������������������������������������������������� 69
The Marvin EJB Project��������������������������������������������������������������������������������������������������������� 70
Laying Out the Projects Again������������������������������������������������������������������������������������������������ 71
The Web Project Code������������������������������������������������������������������������������������������������������������ 72
The EJB Project Code������������������������������������������������������������������������������������������������������������ 75
Building and Deploying the EAR�������������������������������������������������������������������������������������������� 79
Using the Corporate Repository��������������������������������������������������������������������������������������������� 79
A Sample Java Library����������������������������������������������������������������������������������������������������������� 80
Building and Uploading Company Libraries�������������������������������������������������������������������������������� 82

Part II: Advanced Web Tier Topics���������������������������������������������������������������� 87


Chapter 7: Facelets������������������������������������������������������������������������������������������������� 89
Faces Templating via Facelets���������������������������������������������������������������������������������������������������� 89
Installing Facelets����������������������������������������������������������������������������������������������������������������������� 90
vi
Table of Contents

Facelets Tags Overview�������������������������������������������������������������������������������������������������������������� 91


The <ui:include> Tag������������������������������������������������������������������������������������������������������������� 91
First Variation of the <ui:composition> Tag�������������������������������������������������������������������������� 91
Second Variation of the <ui:composition> Tag���������������������������������������������������������������������� 91
The <ui:insert> Tag��������������������������������������������������������������������������������������������������������������� 92
The <ui:define> Tag�������������������������������������������������������������������������������������������������������������� 93
The <ui:param> Tag�������������������������������������������������������������������������������������������������������������� 93
The <ui:component> Tag������������������������������������������������������������������������������������������������������ 93
The <ui:decorate> Tag���������������������������������������������������������������������������������������������������������� 94
The <ui:fragment> Tag���������������������������������������������������������������������������������������������������������� 95
The <ui:repeat> Tag�������������������������������������������������������������������������������������������������������������� 96
The <ui:debug> Tag�������������������������������������������������������������������������������������������������������������� 97
An Example Facelets Project������������������������������������������������������������������������������������������������������ 98

Chapter 8: Faces Custom Components����������������������������������������������������������������� 111


Custom Tag Libraries���������������������������������������������������������������������������������������������������������������� 111
Composite Components������������������������������������������������������������������������������������������������������������ 114
Custom Components in Java���������������������������������������������������������������������������������������������������� 117

Chapter 9: Flows��������������������������������������������������������������������������������������������������� 119


The Flow Process���������������������������������������������������������������������������������������������������������������������� 119
Basic Flow Setup���������������������������������������������������������������������������������������������������������������������� 120
Overriding Conventions������������������������������������������������������������������������������������������������������������� 123
Specifying a Different Flow Start Page�������������������������������������������������������������������������������� 124
Specifying a Different Return Page������������������������������������������������������������������������������������� 124
Programmatic Configuration����������������������������������������������������������������������������������������������������� 125
Handling Flow Outcome������������������������������������������������������������������������������������������������������������ 127
Passing Data Between Flows���������������������������������������������������������������������������������������������������� 127

Chapter 10: Websockets��������������������������������������������������������������������������������������� 131


Websockets on the Server Side������������������������������������������������������������������������������������������������ 131
Websockets on the Client Side�������������������������������������������������������������������������������������������������� 135

vii
Table of Contents

Chapter 11: Frontend Technologies���������������������������������������������������������������������� 137


No Third-Party Frontend Technology����������������������������������������������������������������������������������������� 138
Play 2���������������������������������������������������������������������������������������������������������������������������������������� 139
React����������������������������������������������������������������������������������������������������������������������������������������� 139
Angular 2����������������������������������������������������������������������������������������������������������������������������������� 141
Spring Boot������������������������������������������������������������������������������������������������������������������������������� 142
Vue�������������������������������������������������������������������������������������������������������������������������������������������� 142
Spring MVC������������������������������������������������������������������������������������������������������������������������������� 143
Ember���������������������������������������������������������������������������������������������������������������������������������������� 144
Act.Framework�������������������������������������������������������������������������������������������������������������������������� 145
Apache Struts 2������������������������������������������������������������������������������������������������������������������������ 145
GWT������������������������������������������������������������������������������������������������������������������������������������������� 146
Vaadin��������������������������������������������������������������������������������������������������������������������������������������� 147
DataTables�������������������������������������������������������������������������������������������������������������������������������� 147
D3js������������������������������������������������������������������������������������������������������������������������������������������� 148

Chapter 12: Form-Based Authentication�������������������������������������������������������������� 149


Enabling Security on the Sever������������������������������������������������������������������������������������������������� 149
Form-Based Authentication for Faces�������������������������������������������������������������������������������������� 151
Security Role Mapping�������������������������������������������������������������������������������������������������������������� 154
Form-Based Authentication XHTML Code��������������������������������������������������������������������������������� 155

Chapter 13: Client Certificates������������������������������������������������������������������������������ 159


Preparing Scripting������������������������������������������������������������������������������������������������������������������� 159
Generating Client Certificates��������������������������������������������������������������������������������������������������� 160
Storing the Client Certificate in the Browser���������������������������������������������������������������������������� 163
Storing the Client Certificate on the Server������������������������������������������������������������������������������ 164
Client Certificate Web Applications������������������������������������������������������������������������������������������� 166
Additional GlassFish Configuration������������������������������������������������������������������������������������������� 168
Client Certificate Example��������������������������������������������������������������������������������������������������������� 169

viii
Table of Contents

Chapter 14: REST Security������������������������������������������������������������������������������������ 175


Security Constraints for REST URLs������������������������������������������������������������������������������������������ 176
About JSON Web Tokens����������������������������������������������������������������������������������������������������������� 176
Preparing GlassFish������������������������������������������������������������������������������������������������������������������ 178
The JWT Login Process, Client Code����������������������������������������������������������������������������������������� 178
Server Code������������������������������������������������������������������������������������������������������������������������������ 184
The JWT Login Process, Server Code��������������������������������������������������������������������������������������� 185
Sending JWTs Back to the Server��������������������������������������������������������������������������������������������� 190
Handling JWTs in REST Endpoints�������������������������������������������������������������������������������������������� 191

Chapter 15: JAVA MVC������������������������������������������������������������������������������������������ 195


About MVC�������������������������������������������������������������������������������������������������������������������������������� 195
Installing Java MVC������������������������������������������������������������������������������������������������������������������� 196
Configuration Files�������������������������������������������������������������������������������������������������������������������� 198
Static Files�������������������������������������������������������������������������������������������������������������������������������� 203
Model Classes��������������������������������������������������������������������������������������������������������������������������� 203
Controller Classes��������������������������������������������������������������������������������������������������������������������� 206
Messages���������������������������������������������������������������������������������������������������������������������������������� 212
View Pages������������������������������������������������������������������������������������������������������������������������������� 214
Running the Pet Shop Application��������������������������������������������������������������������������������������������� 223

Part III: Advanced Architecture Related Topics������������������������������������������ 225


Chapter 16: Microprofiles������������������������������������������������������������������������������������� 227
Starting a MicroProfile Sample Project������������������������������������������������������������������������������������� 229
Installing a MicroProfile Server������������������������������������������������������������������������������������������������� 231
Changing the Application to a Microservice����������������������������������������������������������������������������� 231
Deploying and Running the Microservice��������������������������������������������������������������������������������� 234

Chapter 17: Custom CDI���������������������������������������������������������������������������������������� 241


CDI Specification����������������������������������������������������������������������������������������������������������������������� 241
Building Object Graphs������������������������������������������������������������������������������������������������������������� 242
Qualifiers����������������������������������������������������������������������������������������������������������������������������������� 246

ix
Table of Contents

Alternatives������������������������������������������������������������������������������������������������������������������������������� 249
Producers���������������������������������������������������������������������������������������������������������������������������������� 251
Scope���������������������������������������������������������������������������������������������������������������������������������������� 253
Interceptors������������������������������������������������������������������������������������������������������������������������������� 255
Decorators�������������������������������������������������������������������������������������������������������������������������������� 255

Chapter 18: Interceptors�������������������������������������������������������������������������������������� 257


CDI Interceptors������������������������������������������������������������������������������������������������������������������������ 257
JPA Lifecycle Listeners������������������������������������������������������������������������������������������������������������� 261
Servlet Listeners����������������������������������������������������������������������������������������������������������������������� 263
Faces Phase Listeners�������������������������������������������������������������������������������������������������������������� 264

Chapter 19: Bean Validation��������������������������������������������������������������������������������� 267


Where to Use Bean Validation��������������������������������������������������������������������������������������������������� 268
How to Add Constraints������������������������������������������������������������������������������������������������������������� 269
Built-in Constraints������������������������������������������������������������������������������������������������������������������� 269
Custom Constraints������������������������������������������������������������������������������������������������������������������� 272
Bean Validation Exceptions������������������������������������������������������������������������������������������������������� 274

Chapter 20: Jakarta EE Concurrency�������������������������������������������������������������������� 277


Preparing the Jakarta EE Server����������������������������������������������������������������������������������������������� 277
Using a ManagedExecutorService�������������������������������������������������������������������������������������������� 278
Using a ManagedScheduledExecutorService���������������������������������������������������������������������������� 280
Using the ManagedThreadFactory�������������������������������������������������������������������������������������������� 283
Enterprise Concurrency and Transactions��������������������������������������������������������������������������������� 284

Chapter 21: Batch Processing������������������������������������������������������������������������������ 285


Batch Processing Concepts������������������������������������������������������������������������������������������������������ 285
Preparing the Server for Batch Processing������������������������������������������������������������������������������� 286
An Employee Attendance Example Batch Processing��������������������������������������������������������������� 287
Starting a Batch Processing EAR Project���������������������������������������������������������������������������������� 288
Example Data Preparation�������������������������������������������������������������������������������������������������������� 293
Job Definition File��������������������������������������������������������������������������������������������������������������������� 293

x
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Table of Contents

Batch Processing Scheduling��������������������������������������������������������������������������������������������������� 295


Batch Processing Java Artifacts����������������������������������������������������������������������������������������������� 296
Building and Deploying the Application������������������������������������������������������������������������������������ 303

Part IV: Useful Supporting Technologies����������������������������������������������������� 305


Chapter 22: XML Binding�������������������������������������������������������������������������������������� 307
Why JAXB Is So Complicated���������������������������������������������������������������������������������������������������� 307
Writing a Java Object Tree as XML�������������������������������������������������������������������������������������������� 309
Adding a Schema���������������������������������������������������������������������������������������������������������������������� 313
Transforming from XML to Java������������������������������������������������������������������������������������������������ 316
Generating Java Classes from Schemas����������������������������������������������������������������������������������� 317

Chapter 23: JSON Handling���������������������������������������������������������������������������������� 319


JSON Documents���������������������������������������������������������������������������������������������������������������������� 319
JSON with REST Services��������������������������������������������������������������������������������������������������������� 320
Generating JSON����������������������������������������������������������������������������������������������������������������������� 323
Parsing JSON���������������������������������������������������������������������������������������������������������������������������� 324
Binding JSON to Java Objects��������������������������������������������������������������������������������������������������� 325

Chapter 24: Jakarta Mail�������������������������������������������������������������������������������������� 331


Installing Jakarta Mail��������������������������������������������������������������������������������������������������������������� 331
Generating and Sending Emails������������������������������������������������������������������������������������������������ 331

Chapter 25: Application Client (Groovy)��������������������������������������������������������������� 335


Providing an Enterprise Application������������������������������������������������������������������������������������������ 335
Building an Application Client��������������������������������������������������������������������������������������������������� 337
Running a GroovyConsole Application Client���������������������������������������������������������������������������� 338

Chapter 26: Adding Scripting Languages������������������������������������������������������������� 341


Installing Scripting Engines������������������������������������������������������������������������������������������������������ 341
Using Scripting in Java������������������������������������������������������������������������������������������������������������� 342

xi
Table of Contents

Part V: Advanced Resource Related Topics������������������������������������������������ 345


Chapter 27: Hibernate as ORM����������������������������������������������������������������������������� 347
Installing Hibernate������������������������������������������������������������������������������������������������������������������� 347
Adapting the Persistence Configuration������������������������������������������������������������������������������������ 348
Fetching the Hibernate Session������������������������������������������������������������������������������������������������ 349

Chapter 28: Connectors���������������������������������������������������������������������������������������� 351


Coding a Resource Adapter������������������������������������������������������������������������������������������������������� 351
Packaging and Deploying a Resource Adapter������������������������������������������������������������������������� 366
Deployment Descriptors������������������������������������������������������������������������������������������������������������ 369
Resource Adapter Deployment�������������������������������������������������������������������������������������������������� 369
Defining a Resource Adapter on the Server������������������������������������������������������������������������������ 370
Resource Adapter Clients���������������������������������������������������������������������������������������������������������� 371

Chapter 29: Caching��������������������������������������������������������������������������������������������� 373


Installing Ehcache��������������������������������������������������������������������������������������������������������������������� 373
Configuring Hibernate for Ehcache������������������������������������������������������������������������������������������� 374
Defining Cached Objects in the Code���������������������������������������������������������������������������������������� 377
Monitoring Caching Activities��������������������������������������������������������������������������������������������������� 378

Chapter 30: NoSQL������������������������������������������������������������������������������������������������ 381


Using CouchDB from Jakarta EE Applications��������������������������������������������������������������������������� 381
Using MongoDB from Jakarta EE Applications�������������������������������������������������������������������������� 385

Part VI: Security Enhancements����������������������������������������������������������������� 389


Chapter 31: Secured JMX������������������������������������������������������������������������������������� 391
Using SSL for Remote JMX Connections���������������������������������������������������������������������������������� 391
Generating the SSL Keys����������������������������������������������������������������������������������������������������������� 391
Configuring the Server�������������������������������������������������������������������������������������������������������������� 395
Configuring the Client��������������������������������������������������������������������������������������������������������������� 395
Disabling Random JMX Ports���������������������������������������������������������������������������������������������������� 397

xii
Table of Contents

Chapter 32: Java Web Tokens with Encryption���������������������������������������������������� 399


Installing Jose4j������������������������������������������������������������������������������������������������������������������������ 400
Encrypting Claims��������������������������������������������������������������������������������������������������������������������� 400
Decrypting Claims��������������������������������������������������������������������������������������������������������������������� 403
Further Reading������������������������������������������������������������������������������������������������������������������������ 405

Chapter 33: Java Enterprise Security������������������������������������������������������������������� 407


Form-Based Authentication������������������������������������������������������������������������������������������������������ 407
The Security API������������������������������������������������������������������������������������������������������������������������ 408
Authentication Data: IdentityStore�������������������������������������������������������������������������������������������� 408
Authentication Methods: HttpAuthenticationMechanism���������������������������������������������������������� 410

Part VII: Advanced Monitoring and Logging����������������������������������������������� 413


Chapter 34: Monitoring Workflow������������������������������������������������������������������������ 415
Using JMX as a Monitoring Technology������������������������������������������������������������������������������������ 415
Enabling Remote JMX��������������������������������������������������������������������������������������������������������������� 417
MBeans in Jakarta EE Applications������������������������������������������������������������������������������������������� 418
Aggregating Values������������������������������������������������������������������������������������������������������������������� 420
JMX Clients������������������������������������������������������������������������������������������������������������������������������� 423
Monitoring Frameworks������������������������������������������������������������������������������������������������������������ 425

Chapter 35: Logging Pipeline with Fluentd����������������������������������������������������������� 427


Installing Fluentd���������������������������������������������������������������������������������������������������������������������� 428
Running Fluentd������������������������������������������������������������������������������������������������������������������������ 429
Using Logfiles as Input�������������������������������������������������������������������������������������������������������������� 430
Filtering������������������������������������������������������������������������������������������������������������������������������������� 432
Using Multiple Routes��������������������������������������������������������������������������������������������������������������� 433
Fluentd Output�������������������������������������������������������������������������������������������������������������������������� 435
Further Reading������������������������������������������������������������������������������������������������������������������������ 436

xiii
Table of Contents

Chapter 36: Performance Troubleshooting����������������������������������������������������������� 437


Load and Performance Tests����������������������������������������������������������������������������������������������������� 437
NFR Testing Methodology���������������������������������������������������������������������������������������������������� 438
Where to Run NFR Tests������������������������������������������������������������������������������������������������������ 440
NFR Test Duration���������������������������������������������������������������������������������������������������������������� 441
NFR Tests with JMeter��������������������������������������������������������������������������������������������������������� 441
Frontend Tests with Selenium��������������������������������������������������������������������������������������������� 445
Analyzing Performance Figures������������������������������������������������������������������������������������������������ 446
Reducing the File Size��������������������������������������������������������������������������������������������������������� 446
Plotting a Performance Chart���������������������������������������������������������������������������������������������� 447
No Min or Max, Please��������������������������������������������������������������������������������������������������������� 449
Code-Level Monitoring with VisualVM�������������������������������������������������������������������������������������� 450
Code Optimization��������������������������������������������������������������������������������������������������������������������� 452

Chapter 37: Garbage Collection���������������������������������������������������������������������������� 455


The Importance of Garbage Collectors�������������������������������������������������������������������������������������� 455
G1 Garbage Collector���������������������������������������������������������������������������������������������������������������� 456
Shenandoah GC������������������������������������������������������������������������������������������������������������������������� 456
Zero Garbage Collector������������������������������������������������������������������������������������������������������������� 456
Garbage Collector Logs������������������������������������������������������������������������������������������������������������� 457

Chapter 38: Memory Troubleshooting������������������������������������������������������������������ 459


Identifying Memory Leaks��������������������������������������������������������������������������������������������������������� 459
More Evidence: Heap Dumps���������������������������������������������������������������������������������������������������� 463
Analyzing Heap Dumps������������������������������������������������������������������������������������������������������������� 466

Chapter 39: Custom Log4j Appender�������������������������������������������������������������������� 473


Including Log4j�������������������������������������������������������������������������������������������������������������������������� 475
A Statistics Appender���������������������������������������������������������������������������������������������������������������� 475

Index��������������������������������������������������������������������������������������������������������������������� 481

xiv
About the Author
Peter Späth graduated in 2002 as a physicist and became an IT consultant, mainly for
Java-related projects. In 2016, he decided to concentrate on writing books on various
technology-related topics, with his main focus on software development. With two
books about graphics and sound processing, two books about Android app
development, and several books about Java, Späth continues his efforts in writing
software development-related literature.

xv
About the Technical Reviewer
Massimo Nardone has more than 25 years of experience
in security, web/mobile development, cloud, and IT
architecture. His true IT passions are security and Android.
He has been programming and teaching others how to
program with Android, Perl, PHP, Java, VB, Python, C/C++,
and MySQL for more than 20 years. He holds a Master of
Science degree in computing science from the University
of Salerno, Italy. He has worked as a CISO, CSO, security
executive, IoT executive, project manager, software engineer,
research engineer, chief security architect, PCI/SCADA
auditor, and senior lead IT security/cloud/SCADA architect for many years. His technical
skills include security, Android, cloud, Java, MySQL, Drupal, Cobol, Perl, web and
mobile development, MongoDB, D3, Joomla, Couchbase, C/C++, WebGL, Python, Pro
Rails, Django CMS, Jekyll, Scratch, and more. He was a visiting lecturer and supervisor
for exercises at the Networking Laboratory of the Helsinki University of Technology
(Aalto University). He also holds four international patents (in the PKI, SIP, SAML,
and Proxy areas). He is currently working for Cognizant as the head of cybersecurity
and CISO to help clients in areas of information and cybersecurity, including strategy,
planning, processes, policies, procedures, governance, awareness, and so forth. In
June, 2017, he became a permanent member of the ISACA Finland Board. Massimo has
reviewed more than 45 IT books for different publishing companies and is the co-author
of Pro Spring Security: Securing Spring Framework 5 and Boot 2-based Java Applications
(Apress, 2019), Beginning EJB in Java EE 8 (Apress, 2018), Pro JPA 2 in Java EE 8 (Apress,
2018), and Pro Android Games (Apress, 2015).

xvii
Introduction
Java is not just a programming language, it’s also a platform used to host software. As
far as enterprise environments go, Java Enterprise Edition Jakarta EE (formerly JEE) has
an extensive collection of APIs that are particularly useful for addressing corporate IT
requirements.
This book covers advanced topics of Jakarta EE development. This includes pro-­
level web tier development, architecture-related matters, advanced XML and JSON
processing, application clients and scripting languages, resource handling, high-level
security enhancements, and advanced monitoring and logging techniques.
The target version of Jakarta EE is version 10. Unless otherwise noted, server scripts
have been tested on Ubuntu 22.04. Switching to Debian, Fedora, or OpenSUSE Leap
should not impose any problems.
The book is for advanced enterprise software developers with knowledge of
Java Standard Edition version 8 or later and some experience in Jakarta EE (or JEE)
development. Having read the book titled Beginning Jakarta EE from the same author
and publisher (ISBN: 978-1-4842-5078-5) will surely help, but it’s not a strict prerequisite.
I keep references to the beginner book at a bare minimum. I also assume that you can
use the online API references, so this book is not a complete reference in the sense that
not all API classes and methods are listed. Instead, the book includes techniques and
technologies that will help professional Java enterprise-level developers deal with topics
and master problems that arise in a corporate environment.
The book uses the Linux operating system as its development platform, although
the code can run on other platforms without requiring complex changes. The server
installations—like version control, continuous integration systems, and operating
instructions—all target the Linux operating system. This book also does not cover
hardware issues, except for some cases where hardware performance has a noticeable
impact on the software.
After finishing this book, you will be able to develop and run Jakarta EE 10 programs
of mid- to high-level complexity.

xix
Introduction

How to Read This Book


You can read this book sequentially from the beginning to the end, or you can
read chapters on an ad hoc basis if your work demands special attention to one or
another topic.

Source Code
All the source code in this book can be found at github.com/Apress/pro-jakarta-ee10.

xx
PART I

Development Workflow
Proposal
CHAPTER 1

Installing a Development
Server
This book uses GlassFish version 7.0.1 as a Jakarta EE server, although I try to avoid
vendor lock-in, so that, unless otherwise noted, you can test all the examples on different
Jakarta EE servers.
For the Eclipse IDE, there is a GlassFish plugin called GlassFish Tools, which you can
use if you want to. I don’t use it in this book for several reasons. First of all, the plugin
can have issues with your Eclipse installation. Second, if you don’t use the plugin and
instead use a terminal to start and stop the server and then use a build tool like Gradle to
install and uninstall Enterprise applications, you are already close to what you need for
integration testing and production setups. Third, it is easier to switch between different
Jakarta EE servers and different IDEs. Fourth, you don’t have to learn how to use that
plugin, including any peculiarities that might arise.
So for now, simply download and install the GlassFish server, version 7.0.1, from this
location:

  https://glassfish.org/download.html

Select the Full Platform variant.

Note GlassFish 7.0.1 runs on JDK 11 through 19. You can try higher JDK
versions for GlassFish 7.0.1, but they might not work.

3
© Peter Späth 2023
P. Späth, Pro Jakarta EE 10, https://doi.org/10.1007/978-1-4842-8214-4_1
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
There was quite a mediæval-looking heavy steel mace, and
many sabres, and sword sticks, some made with crutch handles
terminating in horses’ heads. There were also a number of steel
cuirasses. I believe this armoury was arranged by Mr Kipling, the
father of Mr Rudyard Kipling, who was head of the art school of
Lahore for many years, and to whom is due the extremely
interesting museum.
There were relics of elaborate decoration on the walls and vaults
of what remained of the palace, and some of the glass (convex-
mirror-mosaic) work united with gesso-relief ornament, which we
saw at Udaipur, Amber, Delhi, and other places: but the British
occupation had tried its best, by introducing hideous chunks of
barrack buildings, to take the romance and beauty out of the place.
Close to the Fort outside its gate is the Samadh, or burning-
place of Ranjit Singh. A carved lotus flower, surrounded by eleven
smaller ones, on a raised platform inside the pavilion-like building,
mark the place where his body was burned with eleven ladies of his
Zenana. Not far off rises the dome of the Jama Musjid and its noble
minarets of red sandstone.
There is a fine park-like country beyond the walls on this side of
the city with groups of old trees. The minarets and domes of Lahore
have a striking effect seen from outside the gate. We returned
through the bazaars a different way, passing the golden domed
mosque and also the Wazar Khan mosque, the latter a very fine one
fronting a small square in the middle of the city, and having two
large minarets faced with enamelled tiles in blue and green and
other colours, cobalt predominating. The spandrils of the main
entrance, and in fact the whole of the front, being decorated with
tiles in large arabesques and borderings, a large Arabic text in blue
written boldly over the arch, and panels down each flank of smaller
scale work. It was the first tiled mosque we had seen, and quite
characteristic of the art of a district which culminates in the
renowned tombs at Multan.
At the English club house on the Mall, the pipers of a Highland
regiment were playing on the lawn in front. The club had well laid
out and ample lawn tennis courts, large blue durries being hung at
each end of the courts to stop the balls, and the players had native
caddies to pick them up. There were zoological gardens near by
where we saw nylghaus and antelopes and birds of various sorts.
A Victoria memorial on a large scale was in progress at a place
where branching roads met. The work of the British sculptor in India
cannot be said to be much more exhilarating than the work of the
British architect, as a rule, to judge from the specimens we saw,
chiefly of statues of the late Queen Victoria.
The courts of Justice at Lahore are more successful than most of
the modern examples in India, perhaps because designed in what
might be called the local style—the Mogul. Near by in a little garden
enclosed by clipped hedges was a bronze statue of Lord Laurence
offering the choice of government by pen or sword to the passer by.
It had some dramatic expression, though the choice of a momentary
attitude in a portrait statue is perhaps open to criticism.
We visited the museum, where Mr Percy Brown has succeeded
Mr Kipling as director. Here is a most interesting collection of typical
native textiles, including the raised wax designs gilded, silvered, and
lacquered on grounds of different coloured cloths, an art which is
still practised in the district with success, traditional designs of
flowers and birds being repeated in a very skilful and effective way,
and applied to the adornment of portières, covers, etc. There were
also good collections of native jewellery and enamels. Champlévé
enamel, such as is done at Lucknow, was illustrated by specimens in
different stages from the commencement to the finish, side by side
with cloissoné (Japanese) illustrated in the same complete way, as
well as complete models showing native industries and handicrafts in
operation; interesting old Hindu herbals and manuscripts on vellum
with characteristic miniatures; drawings of local palaces and gardens
in plan, elevation and bird’s-eye perspective.
There was a very notable collection of Greco-Buddhist
sculptures, which were extremely interesting and unusual.
Very little wood-carving, curiously enough, except modern
examples in screens and furniture, the work of the Art School,
exhibited in a separate room. The city of Lahore being so rich in
carved wood-work it was less necessary to have it in the museum,
and, of course, much better to see it in situ. The modern way of
selling the spoils of old buildings to private collections or to
museums is carried on in Europe to an alarming extent, so that one
begins to fear, in view of the rapid destruction of ancient houses now
going on, whether there will soon be left any genuine bits of
antiquity in this commercial world. It is better of course that relics of
ancient art should find a haven in a public museum than that it
should perish altogether, but any destruction or removal for the
express purpose of transportation to a museum should be
deprecated.
On the whole the Lahore museum was a well-chosen and
arranged museum, judiciously limited to Indian art, and it was
interesting to see the groups of natives—men, women, and children
—apparently scanning the different objects with the greatest interest
and with much animated conversation among themselves. One
afternoon we drove to the Waza Khan Mosque, and I made the
sketch reproduced here of the entrance to the mosque from the
carriage. The crowd was curious, but not nearly so troublesome as
elsewhere, and our conductor, or running footman, kept them off
pretty well. The square had large pools of mud in it here and there
after recent rains. Zebus were straying about, or lying down. Fruit
and good stalls occupied other parts of the ground, and ox-carts
deposited loads of wood. Men sat in groups in the porch of the
mosque, or on the steps, from which boys flew their little diamond-
shaped paper kites. The mysterious-looking white figures of the
Mohammedan women wandered about like substantial ghosts. We
saw a pretty little gazelle at one of the stalls, perfectly tame, and a
great pet of the native who owned it.
The Cashmere travelling merchants, who display their tempting
wares at all the hotels, spread out their stuffs in profusion—Bokhara
embroideries, Persian covers, kincobs, turbans, and portières of
black, red, or green grounds, effectively decorated with designs in
the raised wax, such as we saw in the museum—and used all their
persuasive arts to effect sales.
We did not stay long enough in Lahore to see much of the
Society there, but before leaving we had a visit from the Princess
Duleep Singh and her sister, who, hearing from friends at Amritzar
that we were there, came to see us at the hotel. The princess was
dressed as a Parsee lady in beautiful classical draperies, white with
embroidered borders, and she drove herself in a dog-cart, but the
sister was in European dress. The princess recalled the circumstance
of my having made a little sketch in her brother the prince’s cottage
on the Norfolk coast, which had been designed for him by Mr
Detmar Blow, which we visited when staying in the neighbourhood.
THE MERCHANTS OF KASHMIR

We left Lahore the mid-day Lucknow Mail, after a long wait, the
platform covered with picturesque groups of squatting natives. We
eventually shared a compartment, as far as Umballa, with an English
official, his German wife and a little girl. As far as Umballa on this
line, coming north, we had already journeyed. The chief incident
after leaving Lahore was the catching fire of one of the boxes of one
of the carriages of our train, which caused the passengers hastily to
leave it, and crowd into other parts of the train, when it was stopped
and the burning carriage taken off at a small station just before
Amritzar.
LAHORE—THE MOSQUE OF WAZA KHAN

At Umballa, the dining station, which we reached when it was


dark, some said we had to change, others said not. This was
puzzling. One official with more authority than the others said
emphatically “no,” at last. So, having just time, we scurried across
the bridge to the refreshment room with light hearts and sharp
appetites, snatched a hasty meal and hurried back to find
Moonsawmy, who acted as courier and took charge of the tickets, in
some difficulty with the officials about the tickets. One official (the
stationmaster) came up, and then said we ought to have changed
into the train which was just at that moment steaming out of the
station, excusing his mistake by saying that he had not till then seen
our tickets, fussily ordering a humble Hindu clerk to take the
numbers.
After this we got into our compartment again and settled
ourselves for a sleep, as we were not due at Lucknow until next
morning. During the night we were constantly disturbed by people
opening the carriage door and peering in—no doubt in search of
lower berths, which we occupied. At one place a Eurasian got in with
a quantity of baggage, and got out again only a few stations off. On
leaving, perceiving he had disturbed us he said he was “sorry for the
trouble.”
At Barielly another man (English) got in with his traps and rugs
and settled himself to sleep on the middle berth—which in some
carriages economises space between the two side ones—though he
was at first a little taken aback at seeing that one of us was a lady.
However, he turned out to be a very agreeable companion
afterwards, and we got quite friendly as the train the next morning
approached Lucknow, we having previously decided not to stop at
Cawnpore.
CHAPTER XI

LUCKNOW

A rriving at Lucknow in due course we parted with our fellow


traveller, who was met by the military chaplain, and we did
not see him again. The chaplain kindly gave us some information,
and said that the hotel we were bound for was reputed to be “the
best in India.” This was good hearing, and we found it quite borne
out by our experience of Wurtzler’s, where we presently found
ourselves in comfortable rooms, bungalow-like, opening on to a
verandah. The hotel had formerly been a palace, and was rather a
handsome building in its way, with a round-arched arcaded front,
long and low, with a pleasant enclosure of trees and flower garden.
IN HOSPITAL, LUCKNOW. THE OPERATING TABLE (PATIENT HAD A BIT
OF GRIT IN HER EYE AFTER A TRAIN JOURNEY)—SIXTEEN RUPEES
WERE EXTRACTED!

There was “a little rift within the lute,” however, which rather
marred the first moments of our arrival at Lucknow, my wife having
unfortunately got a little bit of grit in her eye from the engine while
in the train. There was nothing for it but to drive to the hospital the
first thing after breakfast. Luckily we caught the chief surgeon (Col.
Anderson) just as he was attending to some native cases in waiting.
He at once took us to the “operating room,” which sounded rather
fearsome, and was indeed a severe place with a polished marble
floor, a case of surgical instruments and an operating table being the
only furniture visible. The poor eye-patient had to extend herself on
the table, while the Colonel very deftly found and quickly removed a
tiny black speck which had caused all the trouble—working up right
under the upper lid of the eye. He put some cocaine into the eye
first of all, and afterwards applied a little lint and lotion. The relief
must have been worth anything—it might have been described as a
lesser Relief of Lucknow!

JUGGLERS AT LUCKNOW—THE MANGO TREE TRICK

The next example of human skill or sleight of hand we witnessed


was in the juggling, not the surgical, profession. It was a native
conjurer who, under the arcade of the hotel, showed us the famous
mango tree trick. As additional attractions, or a sort of side-show, he
had a large cobra in a round box, which, when the lid was off, reared
its head all alive and hissing, and ready for a performance with a
well-to-do mongoose, which was held in readiness by a cord tied
tightly round its neck, which is apparently the only way in which to
secure a mongoose.
The man commenced his performance by placing a monkey’s
skull on the pavement, and sticking a little china doll up in front of it.
Then he produced a very dry-looking mango seed about the size of a
small potato, and this he planted carefully in an ordinary earthen
flower-pot, covering the seed with soil, and then watering it,
muttering some unknown words over it. He then put it under a cloth
raised tentwise by a stick, to let it grow, as he said, while he went
on with a number of small but very skilful conjuring tricks with cards,
coins, marbles, ring and handkerchief, etc., any of which he offered
to teach. Presently he lifted the cloth and showed the mango tree
sending up a shoot of fresh green, and apparently growing
vigorously. Then he covered it up again and performed some more
tricks, after which he again uncovered the mango, which now
showed a stem and bunch of leaves at the top like a miniature tree.
Finally, after another interval of a few minutes juggling and
conjuring, he lifted the cloth again, and, holding the pot in one
hand, he pulled up the little mango tree with the other, showing it
had stem, roots, and all. The man had an assistant, but he only
played a very subordinate part, handing the conjurer the various
things he wanted from time to time, holding the mongoose, but not
performing in any way. These wonders were to be seen for the fee
of three rupees. The conjurer was very proud of his “chits” which he
showed, and among the signatures were those of “Castlereagh” and
“Wenlock”; and he asked for a written testimonial in his book.
At Lucknow we had an introduction to the Chief Commissioner,
Mr Ross Scott, who received us very cordially at his charming house,
and offered to do anything for us. Among other kindnesses he sent
my wife (whose health had suffered from the climate everywhere in
India) a supply of excellent milk from his own cows during her stay,
which proved of immense benefit. At his house we met Mrs Dowden
and her daughter, who kindly undertook to show us over the ruins of
the Residency which were quite close by. The building stands, or
what remains of it after the bombardment it sustained during the
terrible days of “the Mutiny,” amid pleasant lawns and fine trees, and
creepers cover the ruins. In one of the rooms is a good model of the
Residency as it was in 1857 in the midst of the native city on a rising
ground, but thickly surrounded by the houses and mosques, from
which guns and mortars were trained on to it. These were shown
planted on flat roofs or in courtyards, wherever there was vantage
ground. Nothing but a few shapeless ruins remain hereabouts now
of the old native city, which has since been curtailed and cut in two
by a broad road for the rapid movement of troops. However savage
and cruel the sepoys may have been, the British reprisals were
certainly severe. They seemed to have practically “wiped out” old
Lucknow afterwards. We were shown a building—the Sikander Bagh
—a high-walled enclosure, once a fair rose garden, which was taken
by Colin Campbell, and where 2000 rebels were bayoneted without
mercy by the British troops. A young English officer, speaking
professionally, perhaps, we met at a friend’s house, said that
Sikander Bagh gave him more satisfaction than any other memorial
of the mutiny. He positively “gloated over it,” and intended to go
there again and “gloat.” It is said even that British soldiers
bayoneted even the sick and wounded Hindu soldiers in the hospitals
who begged to be shot instead!
The whole place is overshadowed by memories of that awful
period. Nothing can impair the courage and endurance of the heroic
defenders of the Residency; but it is now, I believe, generally
admitted that the outbreak was not without its causes, and that the
government of the day did not act judiciously, to say the least. It is
commonly called “The Mutiny,” but it was really an insurrection,
which must from various causes have been smouldering for some
time before it burst into flame. The “greased cartridges” were only
the last straw. There seems to have been much discontent. Many
sepoys, too, had been disbanded. The British annexation, the
deposition and deportation of the reigning King of Oudh and the
confiscation of his revenues, must all be considered as provocative
causes; and it is a question whether at any time British rule has
made itself loved in India, or the British residents have ever really
understood the Indian people. Native feeling must have been
generally ignored.
It was a formidable revolt, accompanied, no doubt, by
explosions of race hatred and by terrible cruelties, but there was
savagery on both sides—a desperate attempt to regain possession of
their own country and its government on the part of the princes and
people.
The question remains, with all the official solicitude of the British
government for the welfare of the natives, all the railways,
engineering, and irrigation works, are they really better off than they
were under native rule?
Are they not, though under British administration, more heavily
taxed than they were under the native kings? Mr William Digby,
C.I.E., who had long personal and official experience in India, brings
a formidable array of facts and statistics (from official sources, too),
in his “Prosperous British India,” in support of the view that they are,
and, moreover, that the ryot—the tiller of the soil—is gradually
becoming poorer under our rule.
To a passing observer, the Hindus—nay, the people of India,
either Hindus or Mohammedans—can never be Europeanised. There
is a great gulf between the East and the West. After all these years
of British occupation and administration, the two races live entirely
apart and separate. In religion, manners, and customs, and
sentiment, they are fundamentally different, opposed, one might
say.
The British remain a transitory garrison of military and civil
administrative aliens, in the midst of vast populations, rooted in the
traditions, religious beliefs and observances of untold centuries,
during which they have carried on the same mode of life, and who
seem neither to seek or to desire change.
The mere struggle to live must occupy the energies of the vast
majority, but among the more educated and leisured classes of
natives there is a growing feeling of what we should call nationalism
in Europe, though it may be more strictly racial than national. It is
difficult, however, to see how anything like a universal movement
over the whole peninsula could arise, considering the differences of
caste, race and religion, or the wide differences which separate
Hindus and Mohammedans. Some, however, rather think that
political change may be forced by bankruptcy, considering the
poverty of the people and the limits of taxation being reached.
We were shown, at the Residency, the room where Sir Henry
Laurence was struck with the shell, the holes its explosion made in
the wall, his grave also, and many other memorials which have a
profound interest for the English visitors. Old rust-eaten, muzzle-
loading muskets, sabres, and shot and shell, with which the
Residency was peppered, were collected in a group in one of the
rooms, and the place, as far as possible, has been made an historical
museum of the period of the siege.
Our friends introduced us at the Chatter Manzel, formerly a
palace of the kings of Oudh, but now used as an English club. The
rooms were of spacious and good proportions—long in comparison
with their width. Proportion, in fact, is the principal notable quality of
the local architecture at Lucknow, the details being comparatively
common-place after the beautiful inventive detail and decoration of
the Mogul architects at Delhi and Agra, the ornamentation being
mostly mere repetitions. After the marble inlay of the Taj Mahal and
the Diwan-ud-Daulat, and Sikandra, or the rich arabesques of the
Zenana rooms at Amber, the white and yellow wash and the rather
coarse plaster work of the palaces and pavilions of Lucknow look,
comparatively speaking, cheap. The stuccoed domes of the mosques
miss the splendour of the gold and ivory-like marble seen elsewhere.
Even the Jama Musjid, fine in scale as it is, lacks the charm of
colour. There was a smaller mosque near the old stone bridge,
however, which stood out against the deep-blue sky in dazzling
whiteness, but this only showed how beautiful plain whitewash
appears illuminated by the Indian sun—pearly with delicate
reflections and warm shadows.
The Iambara had a beautifully-proportioned court, with steps up
to the pavilion, the symmetry of the spacing being rather pleasantly
broken by the mosque on one side being placed at a different angle
in order to point to the direction of Mecca, as all Mohammedan
mosques must do.
Inside the pavilion, under canopies of heavy embroidery in gold
and silver, supported by chased silver poles, were the tombs of one
of the kings and his zenana. On the walls were mirrors which
reminded us of our English empire-period framed mantle-glasses.
Some of these had curious tempera paintings inserted in their
frames of native birds and trees, and there were other Indian
paintings, one showing General or Captain Martin—the French
adventurer who founded the Martinière at Lucknow in the early
nineteenth century—in a blue coat and gold lace and white nankeen
trousers, like a naval officer of that period, conferring with the King
of Oudh and his court. An image of a winged horse (a Buddhist
symbol) strikingly resembled the Assyrian type of winged man-
headed creatures, the treatment being remarkably similar. The
crowned head, with long, black, curled locks, and formal, rather
small, wings, with each feather expressed. There was an umbrella
attached, which moved to and fro over the head of the figure by
clock-work.
We were interested to see in the Daulat Khan—a sort of gallery
up a steep flight of steps—a series of full-length portraits of the
kings of Oudh in their robes, painted by English artists. Most of
these were signed by my friend T. Erat Harrison, 1882–4, and I
recalled the fact of having seen him at work on one of them about
that time.
An English lady, Mrs Dowden (wife of Colonel Dowden), was kind
enough to conduct us through Lucknow and its wonders, and she
proved an excellent cicerone, and waved off all unnecessary
attentions from caretakers and their hangers-on with the decisive air
of a resident.
We passed a hideous clock tower—one of many in India—put up
by some modern architect (as a Jubilee memorial, I think). It is
astonishing what monstrosities in clock towers have been
perpetrated by modern architects in India.
Finally, we got to the gate of the old city of Lucknow, by which
we entered the principal street of the bazaar. There were many
interesting native shops. At one I noticed some blocks of patterns for
printing by hand on cotton. They were cut in some hard wood. The
handicraft, too, was still carried on here. There were many pretty
bead necklaces, tassels, and quaint toys. We visited, up a steep
narrow staircase, a muslin and jewel merchant’s store. He showed
some charming Indian muslins spangled with silver spots and
patterns. He also had one or two pieces of old Lucknow enamel not
ordinarily seen in the bazaars now.
BETTER LUCK AT LUCKNOW—THROUGH THE CHOWK ON AN ELEPHANT

We visited another friend who had been spending the winter at


Lucknow—Mrs Jopling-Rowe, the well-known artist, whose son is a
Magistrate here, dining with them at their charming bungalow one
evening. Mr Commissioner Jopling very courteously placed elephants
at our disposal on which to ride through the chowk.
An irrigation well near the hotel interested me, and I made a
sketch of it in a chequered shade. The yoke of oxen and two natives
at work hauling up the water for the garden in a leather bucket.
While thus engaged another friend travelling in the East came up, so
that as regards friends we were quite in luck’s way at Lucknow.
After this it was time to go and meet the elephants our friends
had ordered at the chowk. Mrs Jopling-Rowe took us in her carriage
through Wentworth Park, and past the palaces to the gate of the
city, where we found two fine elephants in waiting. My wife and I
mounted one of them by the usual ladder, the animal kneeling. A
young officer who was of the party, however, showed us another
way. He got a leg up by means of the trunk, and so over the
elephant’s head on to his back. We then processed through the
bazaar (the chowk), preceded by a native policeman, in khaki with a
scarlet turban, to clear the way, and two more behind. The
elephants seemed to quite fill up the narrow street, so that there
was danger of a block when we met an ox-cart. A very
comprehensive view is to be had from an elephant’s back, as one
can see not only a long way ahead, but well into the shops where
the people are at work, and also command the balconies and roofs,
where there were often interesting groups.
IRRIGATION WELL, LUCKNOW

We threaded our way through the chowk, passing at its end


under one of the old arched gateways and along a narrower street,
which led us out into the broad military road, which the British, after
the revolt, ruthlessly cut right through the old city, uglifying it, of
course. There is a wonderful variety and richness, again, here, in the
old house fronts with arcaded balconies and doorways of carved
wood. The patterns, chiefly running borders, treated very fancifully
and delicately. The native houses were not so high as in Lahore, but
the carving might compare with the same sort of work there in
detail.
We lunched at the charming abode of another English official
and his wife (Mr and Mrs Saunders), who were very pleasant and
hospitable. The lady had considerable taste in furniture and
decoration, and her rooms showed the influence of white and green,
and looked cool and agreeable in a light key.
Afterwards we drove to see the celebrated Martinière, the young
officer accompanying us. The Martinière is the fantastic palace built
by the French General or Captain Martin, before mentioned, and is a
curious conglomerate sort of scenic design of late Italo-French
Renaissance character, reminding one rather of Isola Bella, semi-
classical figures being perched on every pinnacle and balustrade,
and there were two grotesque lions, doing duty as supporters or
consoles, with mouths so open that the sky could be seen through
them. The building towered high in several stories in the centre, and
spread out wide into two curved long and low wings of one story,
opening on to broad terraces and steps leading to a small lake, from
the middle of which rose a fluted column. The general’s heart is said
to be buried beneath this. The Martinière was intended by him to be
a college for boys. He founded another at Calcutta, and another in
his native town—Lyons—in France. Martin seems to have had a
curious, eventful history, beginning as a French prisoner, under the
British, afterwards entering the British army and becoming a captain,
when he took service under the Nawab of Oudh and became general
of his army, finally accumulating by some means a large fortune,
which he spent on this building and in founding the schools which
bear his name.
We passed another house ruined at the time of “the Mutiny,”
whence the women and children were removed to from the
Residency, and where Lieutenant Paul is buried.
Mr Ross Scott entertained us with a distinguished company to
dinner at his hospitable house before we left Lucknow. One English
colonel of the party with whom I had a conversation had recently
returned from Burmah, and had brought back some fine silk
embroidered robes, some china bowls, and caps. The latter were of
soft felt, and could be worn either with the edge turned down or up,
forming a brim.
The colonel had lived some time in Burmah and had seen service
there, having been through the British campaign against the
“Dacoits.” He said that the Dacoits were largely composed of men of
the disbanded native army (for which I suppose our Government
were responsible), and they roamed about the country preying on
the people, plundering and sometimes murdering them. The
Burmese people, he said, only wanted to be left alone in peace (like
most people). He had made many friends among them, as he knew
the language and had lived amongst them at that time. On revisiting
the country and finding things under British control and
administration, he found most of his Burmese native friends in
prison. They were there, he said, merely for breaking some official
regulation which probably they did not in the least understand. The
natives complained to him that the English officials lived aloof from
them, and were not friendly and sympathetic as he (the Colonel) had
been, and they never got any forwarder.
CHAPTER XII

BENARES

O ur next destination was Benares. I had for long had the


feeling, from the descriptions one had read and the
photographs one had seen of this wonderful place, that it would sum
up and centralise, as it were, to the eye the whole life of the Indian
people, while it would also be a symbol of their faith to the mind.

It was, therefore, with unusual anticipations that we turned our


faces thither, and on the 21st of January took the early morning train
from Lucknow to the great focus of Hindu worship on the sacred
Ganges. The kind commissioner’s native servant, in scarlet, awaited
us at the station with a parting gift and a note of introduction to the
Maharajah of Benares.
The train passed through a richer and more fruitful country than
usual, but level, plain all the way, reaching Benares Cantonment
about two o’clock. We drove to Clark’s hotel, which has a pretty
portico full of palms, and a splendid orange creeper, then in full
flower, hung over the usual bungalow annexe. The house was quiet,
and had a semi-private aspect, more like a country bungalow.
Finding the Maharajah’s palace was some five or six miles off
and on the other side of the river, we were advised to leave our
letter at the Guest House with our cards. The Guest House was quite
near by. Continuing our drive through the bazaar we thought the
main street wider than most of the native cities, but the bazaars did
not look so busy, and many shops were vacant. Balconies, the roofs
of which were supported on arcades of slender columns with Hindu
caps, were of a different type to those hitherto seen. In the
European quarter there were poorly-designed, would-be Gothic
British buildings, and mission churches of the usual bald type. There
was a Queen’s Park with the commonplace iron railing and low stone
parapet enclosing it, these innovations, as usual, quite spoiling the
surroundings of a native city.
The next morning we had a visit from the Maharajah’s private
secretary, who invited us to drive in the afternoon to visit the
Buddhist topes and sculptures at Sarnath about five miles from
Benares. An American lady we had previously met was to be of the
party, and she was staying at the Guest House, and at the appointed
hour the Maharajah’s carriage, with a coachman in a green and gold
turban and scarlet tunic, and two active young Hindus, similarly
dressed, acted as running footmen to clear the way, when not at
their posts standing at the back of the carriage. We called at the
Guest House for our American friend. It was a more palatial building
than the one at Gwalior, standing in a small park with outer gates
and a drive. The house was in the classic style—a white building
with flat roof and columned portico. In the large hall on the ground
floor there was a small coloured statuette of the Maharajah on
horseback, photographs and portraits upon the walls, including
English miniatures of an English officer and his ladies of the early
nineteenth century, and some engravings of portraits of Queen
Caroline. A stuffed lioness was lying on a side-board.
THE MAHARAJAH PLACES HIS CARRIAGE AT OUR DISPOSAL

The road to Sarnath lay through avenues of fine trees a great


part of the way, chiefly mangoes, banyans, acacias, and tamarinds.
The young trees planted to fill the gaps were protected by circular
fences, sometimes topped by prickly pears. Sometimes the circular
fence was made of bricks, an aperture being left between every
alternate brick.
At Sarnath we saw the results of recent excavations. There was
a wonderful pillar made out of a single piece of marble, but fractured
in digging it out. One part stood upright in the earth, the other lay
horizontally. The top or cap was placed under an awning near by. It
was formed of four lions facing outwards, their heads, chests, and
fore limbs being alone visible, their claws resting on the rim of a
circular fillet, on which was sculptured in low relief a horse, an
elephant, a lion, and a bull, each animal being placed between a
wheel of a solar character, each wheel having twenty-four spokes.
Below this fillet was a curved drooping fringe of leaves such as are
characteristic in Persian columns as well as Hindu. The marble of
which the column and the sculptures were made was of a peculiar
greyish almost of a flesh colour, with small spots. Both the column
and the sculptures were very highly polished, and the treatment of
the lions was remarkably Greek in character with perhaps a touch of
Persian or even Assyrian formalism in the treatment of the heads
and manes of the lions. The animals in relief, between the wheels,
too, were remarkably free, spirited, and well modelled.
There were the remains of an ancient Buddhist temple near. In
what was probably the inner shrine was a sculptured standing figure
of Buddha, about two-thirds life size, in alto relievo. The figure was
represented in a long robe, the limbs being boldly expressed through
the drapery, which hung broadly and smoothly over them, without
folds, except at the sides, which were treated in the rather formal
spiral manner of early Greek work.
The American lady remarked on seeing this figure that “The
gentleman seems to have put his legs through his clothes.”
The figure was framed in a border of astralagus, cut in low relief,
having a running escalloped border outside it and stepped
mouldings. The doorway to this shrine, too, had a richly carved
bordering.
There were many most interesting fragments collected together
in and around a building near. In the court was a large circular
carved stone. This was called Buddha’s umbrella, and its original
position was over the head of a large figure of the saint, sculptured
in the round, close by. The design of the umbrella, a lotus flower, the
flower of life, the petals radiating from the centre, and enclosing this
were a series of concentric rings of pattern; the first consisted of
rosettes, or smaller lotus flowers, alternating with grotesque lions,
winged horses, elephants, camels, and bulls; the next showed the
anthemion, doubled or reversed, alternating with the fylfot or
gammadion 卍, and another form frequent in early Greek pattern (as
well as Chinese) the geometric four-petalled flower. There were
numerous small figures of Buddha here, treated in a similar way to
the one first mentioned, as well as other sculptures of a Hindu type,
resembling those at Ellora.
There we saw the great Tope (called the Dhamek). This stood on
rather higher ground, and was apparently built of rubble, which was
exposed at the top, but the sides were covered with fine bands of
carved ornament in stone, carried to a considerable height, and
consisting of a frieze of bold scroll work of a Greek character,
alternating with bands of a kind of Chinese-like diagonal diaper,
divided by plain belts of stone. At intervals these bands were
intersected by flat dome-shaped forms slightly projecting beyond the
bands, and in these were recesses intended, no doubt, originally to
contain seated figures of Buddha. These flat dome-shaped forms,
connected by bands, suggested a palisade, which may have been
the original way of enclosing and protecting these topes or tombs;
and they may also have been the early form or prototype of the
curious clustered dome-shaped pinnacles which are multiplied to
form the spires of Jain temples so often seen in India.
Sarnath is the place where Buddha began to preach, and the
great tope is supposed to mark the spot where his first sermon was
delivered. The excavations of General Cunningham here disclose the
fragments of a great city which probably stood here about 2000
years ago.
Returning to Benares from this intensely interesting spot, we
dined at the Guest House with our American friend. The rooms were
luxuriously upholstered and furnished from Europe, and were
occupied by the Prince and Princess of Wales when they were here
in 1905. The dinner was excellently cooked and served by native
attendants, with the choicest wines and liquors.
There were some lovely old Indian miniatures on vellum framed
and hanging on the wall of one of the salons, representing various
scenes in the life of a Maharajah—a cock-fight, polo, reception of a
foreign embassy (in Dutch seventeenth century costume), and other
subjects, each full of charming details of architecture, dress and
decoration. Besides these there were the usual official photographic
groups, showing English officers, princes, and governor-generals
grouped around the Maharajah—in one the Czar of Russia appeared.
Indian carpets were on the floor, and English sporting prints on the
walls of the dining-room.
The next day, January 23rd, His Highness’s secretary had
arranged to send a carriage for us quite early (about 7 A.M.), to take
us to see the ghats. When we reached the river side, which is a
considerable drive from the Guest House, we found a beautiful state
barge awaiting us. It was shaped and painted like a peacock, and
had a little pavilion in the centre. In this lovely vessel we embarked,
and glided slowly down the river with the stream, guided by the
scarlet-jacketed oarsmen, with their long bamboo handled oars, and
a broad steering paddle at the stern.
BENARES: VIEWING THE GHATS FROM THE MAHARAJAH’S PEACOCK BOAT

The spectacle of Benares from a boat on the Ganges is perhaps


the most extraordinary sight in all India. At every ghat or opening to
the river, down the great flights of steps, a throng of natives in all
the colours of the rainbow press to the water’s edge. Some plunge
in, some approach timidly, and very gradually submerge themselves.
Their brown skins shining in the water. The men always have some
sort of waist cloth on, but the women go in in their garments, or, at
least, clad to their waists. All ages are there—it recalled the
mediæval allegories of the Fountain of Youth. One does not often
see infants dipped, though they are, occasionally, by their parents,
and object to the water in the same natural and vigorous manner as
European babies are apt to do at their baptism.
Old tottering women and men may be seen, as well as the
young, strong and vigorous, all earnestly washing, or performing
strange genuflexions with the most determined devotion.
Characteristic features of this wonderful scene are the large matting
umbrellas of the priests, who sit on small platforms of bamboo
raised on the steps. These expect fees to be paid them by those who
come to bathe at the ghats. Rows of snake charmers greet the
traveller on landing at the ghats, who turn hissing cobras out of
circular boxes and hold them aloft or twine them round their necks,
or perhaps, as an extra attraction, empty out a swarm of scorpions
to catch the eye of the stranger, all eager to perform the marvels of
their art on the slightest encouragement—and a few rupees. Sacred
zebu bulls wander about and often lie on the steps.
It seems strange that people should lave and drink of the water,
which is fouled one would suppose by all sorts of impurities at the
margin. Washing of clothes goes on everywhere, decayed flowers
float along, even bodies of drowned dogs are seen occasionally. It
must have been at Benares that Æsop’s fable of the two pots was
born, for there the earthen and brazen vessels might quite possibly
float down the stream together. Pots are scoured on the steps, and
at the Burning Ghat they pour the ashes of the dead into the river.
WE SEE SNAKES AT BENARES

At the Burning Ghat they pile up logs of wood to form the pyre,
and the white turbaned dark figures, with nothing on but waist
cloths, are kept busy at their ghastly work. Some of the bodies are
brought down with flowers and chanting: others lie there with no
following or ceremony: some are swathed in red or white cloth like
mummies, others as they were born are lifted on to the piles of logs,
which being set alight, soon reduce all to the same condition. Some
of the bodies are carefully dipped in the Ganges before being
burned, and are often left at the water’s edge while the pyre is being
prepared. Wood was placed over as well as under the bodies, and a
torch was put to the mouth. Other bodies, again, are taken out in
boats unburned and apparently dressed and seated in chairs, and
suddenly in mid-stream are toppled over into the water. We saw an
old man disposed of in this way. Our boatman pointed him out as a
specially holy person, and we did not realise he was a corpse. The
bodies of infants, swathed in white, are also treated in this way.
The Maharajah’s secretary explained that the Ganges water had
been analysed by European experts and pronounced to be the best
water in the world, having a peculiar property of destroying the
germs of disease. It was difficult, however, to see how even “the
best water” could avoid getting fouled with such operations
constantly going on; but of course there is a strong stream all the
time, so that everything must eventually be carried down to the sea.
A continuous many-coloured stream of pilgrims, bearing huge
bundles of bedding, were constantly moving along behind this busy
life of the bathing ghats, ascending or descending the great flights
of steps leading up through the various gates to the city. It seemed
to be part of that universal exodus we had witnessed at every
railway station in India. It is said that representatives from every
village in the peninsula may be found at Benares.
Then, as a no less striking background to these extraordinary
human groups, rise the domes of temples and minarets of palaces,
their golden vanes and finials glittering against the deep blue sky.
Windows, balconies and terraces placed high up, with vast walls
below them. These great walls, which give so much distinction and
breadth to the river front of Benares, have a practical reason,
inasmuch as it is a necessity thus to raise the temple and palace
floors, owing to the sudden rising of the Ganges in the rainy season,
when these walls are sometimes hidden in the waters.
The musical accompaniments of the spectacle consist in the
weird and wandering notes which issue from the temples, produced
by a sort of hautboy, and the subdued thud of the tom-toms. I saw a
dusky long-haired fakir stand on the steps at the Mahikarunika ghat
and sound a long straight brass trumpet.
After voyaging in the peacock boat the whole length of the
ghats, we returned to our carriage-in-waiting at a convenient point
from which to approach the Golden Temple. From the main street of
the Bazaar we were conducted by the secretary down a very narrow
passage crowded with worshippers, and then up a dark staircase to
a terrace from which we could see the cluster of gilded copper
domes. Afterwards in the sacred precincts we saw the “well of
knowledge,” but did not drink of it, having too much foreknowledge
of the condition of its water.
Our next excursion was to pay a visit to the Maharajah at his
palace. We were conducted by his secretary in the carriage as
before, driving to the river side opposite the palace some six miles
off. On the road we stopped to see the famous Monkey Temple—a
Hindu Temple in an arcaded court of the usual type. This court was
full of monkeys—a sandy-brown coloured sort with pink faces,
probably Macaques—not so handsome as the wild silver grey ones
we had seen at Ahmedabad. They accepted offerings, but not so
greedily, as they were evidently well fed, and dried peas lay about
untouched. They gambolled about the temple at their sweet will.
These monkeys are sacred to Vishnu, and represent Hunuman the
monkey god.
There was a fine tank with steps to the water’s edge, close by
the temple. Just before this we passed the Hindu College which Mrs
Annie Besant has established for the higher education of native
children of both sexes—but not a mixed school. This work has been
liberally endowed by the Maharajah of Benares, who also granted
the site. Mrs Besant is the principal, but owing to the illness of
Colonel Alcott, she was not then there, being at Madras nursing the
Colonel in what proved to be his last illness.
Reaching the river side, a boat was in waiting to take us across
to the palace, rowed by two Hindu boys—at least they started
rowing, but soon we got into shallows, where they took to poling,
and finally had to get out and push the boat along, until getting into
deeper water again they rowed us to the palace steps.
It was quite a high steep flight, no doubt existing for the same
river reason as the high walls of Benares—to be out of the reach of
the floods. There were numbers of natives ascending and
descending or grouped on the steps.
We climbed up, and entered the palace up more stairs, and were
shown into a large reception salon, where much of the furniture was
“under canvas,” but there was one handsome couch displayed, inlaid
with ivory. Presently H.H. the Maharajah entered, accompanied by
his two chief officers, who spoke English well, his painter in ordinary,
and several attendants. Chairs were placed in the centre of the
room, around a small marble table. The Maharajah seated himself,
and we with the private secretary grouped ourselves about him. The
Maharajah was dressed in a small-patterned long tunic of pink
brocaded with gold, a small round cap on his head, close fitting
white trousers and patent leather shoes. He seemed quite merry and
pleased to see us. I showed him my book of sketches, which
interested him, as he said he had never seen drawings of the kind
before. His painter in ordinary, to whom I was introduced, was also
interested, and asked some questions through the secretary, not
himself speaking English. He had painted the full length portraits of
the Maharajahs which hung aloft in this salon. The Prince presently
rose and invited us to the terrace, to which we passed after him,
through an arcade, an attendant holding a large silk umbrella over
him. There was a very fine view from this terrace up and down the
river. The city of Benares, with its domes and minarets, seen far
down on the left, and the open plain country opposite. The secretary
said that when the Ganges rose the city looked as if it was floating
on the surface of the water.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like