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

Spring 5 Recipes: A Problem-Solution Approach 4th Edition Marten Deinum 2024 scribd download

Deinum

Uploaded by

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

Spring 5 Recipes: A Problem-Solution Approach 4th Edition Marten Deinum 2024 scribd download

Deinum

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Spring 5 Recipes: A Problem-Solution Approach 4th


Edition Marten Deinum

https://textbookfull.com/product/spring-5-recipes-a-problem-
solution-approach-4th-edition-marten-deinum/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Pro Spring MVC with WebFlux: Web Development in Spring


Framework 5 and Spring Boot 2 2nd Edition Marten Deinum

https://textbookfull.com/product/pro-spring-mvc-with-webflux-web-
development-in-spring-framework-5-and-spring-boot-2-2nd-edition-
marten-deinum/
textboxfull.com

Pro Spring MVC with WebFlux: Web Development in Spring


Framework 5 and Spring Boot 2 2nd Edition Marten Deinum

https://textbookfull.com/product/pro-spring-mvc-with-webflux-web-
development-in-spring-framework-5-and-spring-boot-2-2nd-edition-
marten-deinum-2/
textboxfull.com

Android Recipes A Problem-Solution Approach Dave Smith

https://textbookfull.com/product/android-recipes-a-problem-solution-
approach-dave-smith/

textboxfull.com

Raku Recipes: A Problem-Solution Approach J.J. Merelo

https://textbookfull.com/product/raku-recipes-a-problem-solution-
approach-j-j-merelo/

textboxfull.com
Pro Spring MVC with WebFlux Web Development in Spring
Framework 5 and Spring Boot 2 Second Edition Marten Deinum
Iuliana Cosmina
https://textbookfull.com/product/pro-spring-mvc-with-webflux-web-
development-in-spring-framework-5-and-spring-boot-2-second-edition-
marten-deinum-iuliana-cosmina/
textboxfull.com

C Recipes - A Problem-Solution Approach 1st Edition


Shirish Chavan

https://textbookfull.com/product/c-recipes-a-problem-solution-
approach-1st-edition-shirish-chavan/

textboxfull.com

JavaScript Recipes: A Problem-Solution Approach 1st


Edition Russ Ferguson

https://textbookfull.com/product/javascript-recipes-a-problem-
solution-approach-1st-edition-russ-ferguson/

textboxfull.com

wxPython Recipes: A Problem - Solution Approach 1st


Edition Mike Driscoll

https://textbookfull.com/product/wxpython-recipes-a-problem-solution-
approach-1st-edition-mike-driscoll/

textboxfull.com

MATLAB Recipes: a problem-solution approach 2nd Edition


Michael Paluszek

https://textbookfull.com/product/matlab-recipes-a-problem-solution-
approach-2nd-edition-michael-paluszek/

textboxfull.com
Spring 5 Recipes
A Problem-Solution Approach

Fourth Edition

Marten Deinum
Daniel Rubio
Josh Long
Spring 5 Recipes
A Problem-Solution Approach

Fourth Edition

Marten Deinum
Daniel Rubio
Josh Long
Spring 5 Recipes: A Problem-Solution Approach
Marten Deinum Daniel Rubio
Meppel, Drenthe, The Netherlands Ensenada, Baja California, Mexico
Josh Long
Canyon Country, California, USA
ISBN-13 (pbk): 978-1-4842-2789-3 ISBN-13 (electronic): 978-1-4842-2790-9
DOI 10.1007/978-1-4842-2790-9
Library of Congress Control Number: 2017954984
Copyright © 2017 by Marten Deinum, Daniel Rubio, and Josh Long
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.
Cover image by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Massimo Nardone
Coordinating Editor: Mark Powers
Copy Editor: Kim Wimpsett
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. 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 rights@apress.com, or visit www.apress.com/
rights-permissions.
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 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 via the book’s product page, located at www.apress.com/9781484227893. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
Contents at a Glance

About the Authors�������������������������������������������������������������������������������������������������xxxi


About the Technical Reviewer����������������������������������������������������������������������������xxxiii
Acknowledgments�����������������������������������������������������������������������������������������������xxxv
Introduction�������������������������������������������������������������������������������������������������������xxxvii


■Chapter 1: Spring Development Tools�������������������������������������������������������������������� 1

■Chapter 2: Spring Core Tasks������������������������������������������������������������������������������ 27

■Chapter 3: Spring MVC�������������������������������������������������������������������������������������� 117

■Chapter 4: Spring REST������������������������������������������������������������������������������������� 183

■Chapter 5: Spring MVC: Async Processing�������������������������������������������������������� 209

■Chapter 6: Spring Social������������������������������������������������������������������������������������ 267

■Chapter 7: Spring Security�������������������������������������������������������������������������������� 297

■Chapter 8: Spring Mobile����������������������������������������������������������������������������������� 345

■Chapter 9: Data Access������������������������������������������������������������������������������������� 361

■Chapter 10: Spring Transaction Management��������������������������������������������������� 415

■Chapter 11: Spring Batch���������������������������������������������������������������������������������� 447

■Chapter 12: Spring with NoSQL������������������������������������������������������������������������� 483

■Chapter 13: Spring Java Enterprise Services and Remoting Technologies������� 541

■Chapter 14: Spring Messaging�������������������������������������������������������������������������� 615

■Chapter 15: Spring Integration�������������������������������������������������������������������������� 655

iii
■ Contents at a Glance


■Chapter 16: Spring Testing�������������������������������������������������������������������������������� 691

■Chapter 17: Grails���������������������������������������������������������������������������������������������� 731

■Appendix A: Deploying to the Cloud������������������������������������������������������������������ 775

■Appendix B: Caching����������������������������������������������������������������������������������������� 795

Index��������������������������������������������������������������������������������������������������������������������� 821

iv
Contents

About the Authors�������������������������������������������������������������������������������������������������xxxi


About the Technical Reviewer����������������������������������������������������������������������������xxxiii
Acknowledgments�����������������������������������������������������������������������������������������������xxxv
Introduction�������������������������������������������������������������������������������������������������������xxxvii


■Chapter 1: Spring Development Tools�������������������������������������������������������������������� 1
1-1. Build a Spring Application with the Spring Tool Suite����������������������������������������������� 1
Problem�������������������������������������������������������������������������������������������������������������������������������������������������� 1
Solution�������������������������������������������������������������������������������������������������������������������������������������������������� 1
How It Works������������������������������������������������������������������������������������������������������������������������������������������� 2

1-2. Build a Spring Application with the IntelliJ IDE������������������������������������������������������� 10


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 10
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 10
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 10

1-3. Build a Spring Application with the Maven Command-Line Interface�������������������� 20


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 20
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 21
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 21

1-4. Build a Spring Application with the Gradle Wrapper����������������������������������������������� 22


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 22
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 22
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 22

v
■ Contents

1-5. Build a Spring Application with the Gradle Command-Line Interface��������������������� 23


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 23
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 23
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 24

1-6. Build a Spring Application with the Gradle Wrapper����������������������������������������������� 25


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 25
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 25
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 25

Summary������������������������������������������������������������������������������������������������������������������������ 26

■Chapter 2: Spring Core Tasks������������������������������������������������������������������������������ 27
2-1. Use a Java Config to Configure POJOs������������������������������������������������������������������� 28
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 28
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 28
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 28

2-2. Create POJOs by Invoking a Constructor���������������������������������������������������������������� 34


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 34
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 34
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 34

2-3. Use POJO References and Autowiring to Interact with Other POJOs���������������������� 37
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 37
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 37
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 37

2-4. Autowire POJOs with the @Resource and @Inject Annotations����������������������������� 44


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 44
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 44
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 44

2-5. Set a POJO’s Scope with the @Scope Annotation�������������������������������������������������� 46


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 46
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 46
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 47

vi
■ Contents

2-6. Use Data from External Resources (Text Files, XML Files,
Properties Files, or Image Files)������������������������������������������������������������������������������������� 49
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 49
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 50
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 50

2-7. Resolve I18N Text Messages for Different Locales in Properties Files������������������� 54
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 54
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 54
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 54

2-8. Customize POJO Initialization and Destruction with Annotations��������������������������� 56


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 56
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 57
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 57

2-9. Create Post-Processors to Validate and Modify POJOs������������������������������������������� 61


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 61
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 61
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 61

2-10. Create POJOs with a Factory (Static Method, Instance Method,


Spring’s FactoryBean)���������������������������������������������������������������������������������������������������� 64
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 64
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 64
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 64

2-11. Use Spring Environments and Profiles to Load Different Sets of POJOs�������������� 69
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 69
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 69
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 69

2-12. Make POJOs Aware of Spring’s IoC Container Resources������������������������������������� 71


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 71
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 71
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 73

vii
■ Contents

2-13. Use Aspect-Oriented Programming with Annotations������������������������������������������� 73


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 73
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 73
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 74

2-14. Access the Join Point Information������������������������������������������������������������������������ 81


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 81
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 81
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 82

2-15. Specify Aspect Precedence with the @Order Annotation������������������������������������� 83


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 83
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 83
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 83

2-16. Reuse Aspect Pointcut Definitions������������������������������������������������������������������������ 85


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 85
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 85
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 85

2-17. Write AspectJ Pointcut Expressions���������������������������������������������������������������������� 87


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 87
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 87
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 87

2-18. Use AOP for introductions for POJOs�������������������������������������������������������������������� 92


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 92
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 92
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 92

2-19. Introduce States to Your POJOs with AOP������������������������������������������������������������� 94


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 94
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 94
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 95

viii
■ Contents

2-20. Use Load-Time Weaving AspectJ Aspects in Spring��������������������������������������������� 97


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 97
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 97
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 97

2-21. Configure AspectJ Aspects in Spring������������������������������������������������������������������ 101


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 101
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 101
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 102

2-22. Inject POJOs into Domain Objects with AOP������������������������������������������������������� 103


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 103
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 103
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 104

2-23. Applying Concurrency with Spring and TaskExecutors��������������������������������������� 105


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 105
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 105
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 106

2-24. Communicate Application Events Between POJOs��������������������������������������������� 112


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 112
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 112
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 112

Summary���������������������������������������������������������������������������������������������������������������������� 115

■Chapter 3: Spring MVC�������������������������������������������������������������������������������������� 117
3-1. Develop a Simple Web Application with Spring MVC�������������������������������������������� 117
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 117
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 117
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 119

3-2. Map Requests with @RequestMapping���������������������������������������������������������������� 129


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 129
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 129
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 129

ix
■ Contents

3-3. Intercept Requests with Handler Interceptors������������������������������������������������������ 133


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 133
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 133
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 134

3-4. Resolve User Locales�������������������������������������������������������������������������������������������� 136


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 136
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 137
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 137
Changing a User’s Locale������������������������������������������������������������������������������������������������������������������� 138

3-5. Externalize Locale-Sensitive Text Messages�������������������������������������������������������� 139


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 139
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 139
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 140

3-6. Resolve Views by Name���������������������������������������������������������������������������������������� 141


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 141
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 141
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 141

3-7. Use Views and Content Negotiation���������������������������������������������������������������������� 144


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 144
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 144
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 144

3-8. Map Exceptions to Views�������������������������������������������������������������������������������������� 146


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 146
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 146
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 147

3-9. Handle Forms with Controllers����������������������������������������������������������������������������� 149


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 149
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 149
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 149

x
■ Contents

3-10. Handle Multipage Forms with Wizard Form Controllers������������������������������������� 162


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 162
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 162
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 163

3-11. Use Bean Validation with Annotations (JSR-303)������������������������������������������������ 173


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 173
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 173
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 174

3-12. Create Excel and PDF Views������������������������������������������������������������������������������� 175


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 175
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 175
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 176

Summary���������������������������������������������������������������������������������������������������������������������� 181

■Chapter 4: Spring REST������������������������������������������������������������������������������������� 183
4-1. Publish XML with REST Services�������������������������������������������������������������������������� 183
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 183
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 183
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 184

4-2. Publish JSON with REST Services������������������������������������������������������������������������ 191


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 191
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 191
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 192

4-3. Access a REST Service with Spring���������������������������������������������������������������������� 196


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 196
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 196
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 196

4-4. Publish RSS and Atom Feeds�������������������������������������������������������������������������������� 200


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 200
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 200
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 200

Summary���������������������������������������������������������������������������������������������������������������������� 208
xi
■ Contents


■Chapter 5: Spring MVC: Async Processing�������������������������������������������������������� 209
5-1. Handle Requests Asynchronously with Controllers and TaskExecutor����������������� 209
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 209
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 209
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 210

5-2. Use Response Writers������������������������������������������������������������������������������������������� 217


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 217
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 217
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 217

5-3. Use Asynchronous Interceptors���������������������������������������������������������������������������� 222


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 222
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 222
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 222

5-4. Use WebSockets��������������������������������������������������������������������������������������������������� 224


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 224
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 224
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 225

5-5. Develop a Reactive Application with Spring WebFlux������������������������������������������� 233


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 233
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 233
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 235

5-6. Handle Forms with Reactive Controllers��������������������������������������������������������������� 244


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 244
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 244
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 244

5-7. Publish and Consume JSON with Reactive REST Services����������������������������������� 257
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 257
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 257
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 257

xii
■ Contents

5-8. Use an Asynchronous Web Client�������������������������������������������������������������������������� 259


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 259
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 259
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 260

5-9. Write a Reactive Handler Function������������������������������������������������������������������������ 264


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 264
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 264
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 264

Summary���������������������������������������������������������������������������������������������������������������������� 266

■Chapter 6: Spring Social������������������������������������������������������������������������������������ 267
6-1. Set Up Spring Social��������������������������������������������������������������������������������������������� 267
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 267
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 267
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 267

6-2. Connect to Twitter������������������������������������������������������������������������������������������������� 269


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 269
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 269
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 269

6-3. Connect to Facebook�������������������������������������������������������������������������������������������� 274


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 274
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 274
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 274

6-4. Show the Service Provider’s Connection Status��������������������������������������������������� 277


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 277
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 277
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 277

6-5. Use the Twitter API������������������������������������������������������������������������������������������������ 282


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 282
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 282
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 283

xiii
■ Contents

6-6. Use a Persistent UsersConnectionRepository������������������������������������������������������� 284


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 284
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 284
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 284

6-7. Integrate Spring Social and Spring Security��������������������������������������������������������� 286


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 286
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 286
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 286

Summary���������������������������������������������������������������������������������������������������������������������� 295

■Chapter 7: Spring Security�������������������������������������������������������������������������������� 297
7-1. Secure URL Access����������������������������������������������������������������������������������������������� 298
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 298
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 298
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 299

7-2. Log In to Web Applications������������������������������������������������������������������������������������ 303


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 303
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 303
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 303

7-3. Authenticate Users������������������������������������������������������������������������������������������������ 310


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 310
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 310
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 310

7-4. Make Access Control Decisions���������������������������������������������������������������������������� 319


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 319
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 319
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 320

7-5. Secure Method Invocations���������������������������������������������������������������������������������� 327


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 327
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 327
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 327

xiv
■ Contents

7-6. Handle Security in Views�������������������������������������������������������������������������������������� 330


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 330
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 330
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 330

7-7. Handle Domain Object Security���������������������������������������������������������������������������� 332


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 332
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 332
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 332

7-8. Add Security to a WebFlux Application����������������������������������������������������������������� 340


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 340
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 340
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 340

Summary���������������������������������������������������������������������������������������������������������������������� 344

■Chapter 8: Spring Mobile����������������������������������������������������������������������������������� 345
8-1. Detect Devices Without Spring Mobile������������������������������������������������������������������ 345
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 345
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 345
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 345

8-2. Detect Devices with Spring Mobile����������������������������������������������������������������������� 350


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 350
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 350
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 350

8-3. Use Site Preferences�������������������������������������������������������������������������������������������� 352


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 352
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 352
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 352

8-4. Use the Device Information to Render Views�������������������������������������������������������� 354


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 354
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 354
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 354

xv
■ Contents

8-5. Implement Site Switching������������������������������������������������������������������������������������� 358


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 358
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 358
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 358

Summary���������������������������������������������������������������������������������������������������������������������� 360

■Chapter 9: Data Access������������������������������������������������������������������������������������� 361
Problems with Direct JDBC������������������������������������������������������������������������������������������ 362
Setting Up the Application Database���������������������������������������������������������������������������� 362
Understanding the Data Access Object Design Pattern���������������������������������������������������������������������� 363

Implementing the DAO with JDBC�������������������������������������������������������������������������������� 364


Configuring a Data Source in Spring���������������������������������������������������������������������������� 366
Running the DAO���������������������������������������������������������������������������������������������������������� 368
Taking It a Step Further������������������������������������������������������������������������������������������������ 368
9-1. Use a JDBC Template to Update a Database��������������������������������������������������������� 368
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 368
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 369
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 369

9-2. Use a JDBC Template to Query a Database���������������������������������������������������������� 373


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 373
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 374
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 374

9-3. Simplify JDBC Template Creation������������������������������������������������������������������������� 379


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 379
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 379
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 379

xvi
■ Contents

9-4. Use Named Parameters in a JDBC Template�������������������������������������������������������� 382


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 382
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 382
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 382

9-5. Handle Exceptions in the Spring JDBC Framework���������������������������������������������� 384


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 384
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 384
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 385

9-6. Avoid Problems by Using ORM Frameworks Directly�������������������������������������������� 389


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 389
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 389
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 389

9-7. Configure ORM Resource Factories in Spring������������������������������������������������������� 398


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 398
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 399
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 399

9-8. Persist Objects with Hibernate’s Contextual Sessions����������������������������������������� 406


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 406
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 406
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 407

9-9. Persist Objects with JPA’s Context Injection��������������������������������������������������������� 409


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 409
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 409
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 409

9-10. Simplify JPA with Spring Data JPA��������������������������������������������������������������������� 412


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 412
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 412
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 413

Summary���������������������������������������������������������������������������������������������������������������������� 414

xvii
■ Contents


■Chapter 10: Spring Transaction Management��������������������������������������������������� 415
10-1. Avoid Problems with Transaction Management�������������������������������������������������� 416
Manage Transactions with JDBC Commit and Rollback��������������������������������������������������������������������� 422

10-2. Choose a Transaction Manager Implementation������������������������������������������������� 423


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 423
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 423
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 423
10-3. Manage Transactions Programmatically with the Transaction Manager API������ 424
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 424
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 425
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 425

10-4. Manage Transactions Programmatically with a Transaction Template��������������� 427


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 427
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 427
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 427

10-5. Manage Transactions Declaratively with the @Transactional Annotation����������� 430


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 430
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 430
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 430

10-6. Set the Propagation Transaction Attribute���������������������������������������������������������� 431


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 431
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 431
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 432

10-7. Set the Isolation Transaction Attribute���������������������������������������������������������������� 436


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 436
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 436
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 437

10-8. Set the Rollback Transaction Attribute���������������������������������������������������������������� 444


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 444
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 444
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 444

xviii
■ Contents

10-9. Set the Timeout and Read-Only Transaction Attributes�������������������������������������� 444


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 444
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 445
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 445

10-10. Manage Transactions with Load-Time Weaving������������������������������������������������ 445


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 445
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 445
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 446

Summary���������������������������������������������������������������������������������������������������������������������� 446

■Chapter 11: Spring Batch���������������������������������������������������������������������������������� 447
Runtime Metadata Model��������������������������������������������������������������������������������������������� 448
11-1. Set Up Spring Batch’s Infrastructure������������������������������������������������������������������ 449
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 449
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 449
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 449

11-2. Read and Write Data������������������������������������������������������������������������������������������� 453


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 453
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 453
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 453

11-3. Write a Custom ItemWriter and ItemReader������������������������������������������������������� 460


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 460
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 460
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 460

11-4. Process Input Before Writing������������������������������������������������������������������������������ 463


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 463
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 463
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 463

xix
■ Contents

11-5. Achieve Better Living Through Transactions������������������������������������������������������� 465


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 465
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 465
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 465

11-6. Retry������������������������������������������������������������������������������������������������������������������� 467


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 467
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 467
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 467

11-7. Control Step Execution��������������������������������������������������������������������������������������� 470


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 470
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 470
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 471

11-8. Launch a Job������������������������������������������������������������������������������������������������������ 474


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 474
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 475
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 475

11-9. Parameterize a Job��������������������������������������������������������������������������������������������� 479


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 479
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 479
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 479

Summary���������������������������������������������������������������������������������������������������������������������� 481

■Chapter 12: Spring with NoSQL������������������������������������������������������������������������� 483
12-1. Use MongoDB����������������������������������������������������������������������������������������������������� 483
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 483
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 483
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 484

12-2. Use Redis������������������������������������������������������������������������������������������������������������ 497


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 497
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 497
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 497

xx
■ Contents

12-3. Use Neo4j������������������������������������������������������������������������������������������������������������ 503


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 503
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 503
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 503

12-4. Use Couchbase��������������������������������������������������������������������������������������������������� 521


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 521
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 521
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 521

Summary���������������������������������������������������������������������������������������������������������������������� 540

■Chapter 13: Spring Java Enterprise Services and Remoting Technologies������� 541
13-1. Register Spring POJOs as JMX MBeans������������������������������������������������������������� 541
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 541
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 542
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 542

13-2. Publish and Listen to JMX Notifications������������������������������������������������������������� 557


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 557
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 557
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 557

13-3. Access Remote JMX MBeans in Spring�������������������������������������������������������������� 559


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 559
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 559
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 560

13-4. Send E-mail with Spring’s E-mail Support��������������������������������������������������������� 564


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 564
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 564
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 564

13-5. Schedule Tasks with Spring’s Quartz Support���������������������������������������������������� 572


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 572
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 572
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 572

xxi
■ Contents

13-6. Schedule Tasks with Spring’s Scheduling���������������������������������������������������������� 577


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 577
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 577
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 577

13-7. Expose and Invoke Services Through RMI���������������������������������������������������������� 580


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 580
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 580
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 581

13-8. Expose and Invoke Services Through HTTP�������������������������������������������������������� 584


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 584
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 585
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 585

13-9. Expose and Invoke SOAP Web Services with JAX-WS���������������������������������������� 588
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 588
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 588
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 588

13-10. Use Contract-First SOAP Web Services������������������������������������������������������������� 594


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 594
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 594
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 594

13-11. Expose and Invoke SOAP Web Services with Spring-WS���������������������������������� 599
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 599
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 599

13-12. Develop SOAP Web Services with Spring-WS and XML Marshalling���������������� 606
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 606
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 607
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 607

Summary���������������������������������������������������������������������������������������������������������������������� 613

xxii
■ Contents


■Chapter 14: Spring Messaging�������������������������������������������������������������������������� 615
14-1. Send and Receive JMS Messages with Spring��������������������������������������������������� 615
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 615
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 616
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 616

14-2. Convert JMS Messages�������������������������������������������������������������������������������������� 627


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 627
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 627
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 627

14-3. Manage JMS Transactions���������������������������������������������������������������������������������� 630


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 630
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 630
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 630

14-4. Create Message-Driven POJOs in Spring������������������������������������������������������������ 631


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 631
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 631
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 632

14-5. Cache and Pool JMS Connections���������������������������������������������������������������������� 638


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 638
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 638
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 638

14-6. Send and Receive AMQP Messages with Spring������������������������������������������������ 639


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 639
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 639
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 639

14-7. Send and Receive Messages with Spring Kafka������������������������������������������������� 646


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 646
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 646
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 646

Summary���������������������������������������������������������������������������������������������������������������������� 654

xxiii
■ Contents


■Chapter 15: Spring Integration�������������������������������������������������������������������������� 655
15-1. Integrate One System with Another Using EAI���������������������������������������������������� 655
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 655
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 655
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 655

15-2. Integrate Two Systems Using JMS���������������������������������������������������������������������� 658


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 658
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 658
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 658

15-3. Interrogate Spring Integration Messages for Context Information��������������������� 662


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 662
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 662
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 662

15-4. Integrate Two Systems Using a File System������������������������������������������������������� 665


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 665
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 665
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 666

15-5. Transform a Message from One Type to Another������������������������������������������������ 667


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 667
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 668
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 668

15-6. Handle Errors Using Spring Integration�������������������������������������������������������������� 671


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 671
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 671
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 671

15-7. Fork Integration Control: Splitters and Aggregators������������������������������������������� 674


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 674
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 674
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 674

xxiv
■ Contents

15-8. Implement Conditional Routing with Routers����������������������������������������������������� 678


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 678
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 678
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 678

15-9. Stage Events Using Spring Batch����������������������������������������������������������������������� 679


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 679
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 679
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 679

15-10. Use Gateways��������������������������������������������������������������������������������������������������� 682


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 682
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 682
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 682

Summary���������������������������������������������������������������������������������������������������������������������� 689

■Chapter 16: Spring Testing�������������������������������������������������������������������������������� 691
16-1. Create Tests with JUnit and TestNG�������������������������������������������������������������������� 692
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 692
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 692
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 692

16-2. Create Unit Tests and Integration Tests��������������������������������������������������������������� 696


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 696
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 696
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 697

16-3. Implement Unit Testing for Spring MVC Controllers�������������������������������������������� 705


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 705
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 705
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 706

16-4. Manage Application Contexts in Integration Tests���������������������������������������������� 707


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 707
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 707
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 708

xxv
■ Contents

16-5. Inject Test Fixtures into Integration Tests����������������������������������������������������������� 712


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 712
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 712
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 712

16-6. Manage Transactions in Integration Tests����������������������������������������������������������� 714


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 714
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 714
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 715

16-7. Access a Database in Integration Tests�������������������������������������������������������������� 719


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 719
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 719
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 719

16-8. Use Spring’s Common Testing Annotations�������������������������������������������������������� 721


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 721
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 722
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 722

16-9. Implement Integration Tests for Spring MVC Controllers������������������������������������ 723


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 723
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 723
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 723

16-10. Write Integration Tests for REST Clients����������������������������������������������������������� 726


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 726
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 726
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 726

Summary���������������������������������������������������������������������������������������������������������������������� 730

■Chapter 17: Grails���������������������������������������������������������������������������������������������� 731
17-1. Get and Install Grails������������������������������������������������������������������������������������������� 731
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 731
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 731
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 731

xxvi
■ Contents

17-2. Create a Grails Application���������������������������������������������������������������������������������� 732


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 732
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 732
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 732

17-3. Get Grails Plug-Ins���������������������������������������������������������������������������������������������� 737


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 737
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 737
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 738

17-4. Develop, Produce, and Test in Grails Environments�������������������������������������������� 738


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 738
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 738
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 739

17-5. Create an Application’s Domain Classes������������������������������������������������������������� 740


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 740
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 740
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 741

17-6. Generate CRUD Controllers and Views for an Application’s Domain Classes������ 743
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 743
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 743
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 743

17-7. Implement Internationalization (I18n) for Message Properties��������������������������� 747


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 747
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 747
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 747

17-8. Change Permanent Storage Systems����������������������������������������������������������������� 750


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 750
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 750
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 750

xxvii
■ Contents

17-9. Customize Log Output����������������������������������������������������������������������������������������� 753


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 753
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 753
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 753

17-10. Run Unit and Integration Tests�������������������������������������������������������������������������� 755


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 755
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 755
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 755

17-11. Use Custom Layouts and Templates����������������������������������������������������������������� 761


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 761
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 761
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 761

17-12. Use GORM Queries�������������������������������������������������������������������������������������������� 764


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 764
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 764
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 764

17-13. Create Custom Tags������������������������������������������������������������������������������������������ 766


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 766
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 766
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 766

17-14. Add Security������������������������������������������������������������������������������������������������������ 768


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 768
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 768
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 768

Summary���������������������������������������������������������������������������������������������������������������������� 772

■Appendix A: Deploying to the Cloud������������������������������������������������������������������ 775
A-1. Sign Up for CloudFoundry������������������������������������������������������������������������������������� 775
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 775
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 775
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 776

xxviii
Exploring the Variety of Random
Documents with Different Content
saw, that it is no other than the isles of St. Ambrose and St. Felix,
which are two hundred leagues from the coast of Chili.
Meteorological From the 23d of February, to the 3d of March, we
Observations. had westerly winds, constantly varying between S.
W.. and N. W. with calms and rain: every day, either a little before
noon, or soon after, we had sudden gusts of rain, accompanied with
thunder. It was strange to us to meet with this extraordinary wind,
under the tropic, and in that ocean, so much renowned above all
other seas, for the uniformity and the freshness of the E. and S. E.
trade-winds; which are said to reign in it all the year round. We shall
find more than one opportunity to make the same observation.
Astronomical During the month of February, M. Verron
observations, communicated to me the result of four observations,
compared with
towards determining our longitude. The first, which
the ship’s
reckoning. was made on the 6th at noon, differed from my
reckoning only 31′; which I was more to the
westward than his observation. The second, taken at noon on the
11th, differed from my estimated longitude 37′ 45″, which I was to
the eastward of him. By the third observation, made on the 22d,
reduced to noon, I was more westward than he, by 42′ 30″; and I
had 1° 25′ of difference west, from the longitude determined by the
observations of the 27th. Then we met with calms and contrary
winds. The thermometer, till we came into 45° lat. always kept
between 5° and 8° above the freezing-point: it then rose
successively; and when we ran between 27° and 24° of lat. it varied
from 17° to 19°.
There was an almost epidemical sore-throat among the crew of
my frigate, as soon as we had left the straits. As it was attributed to
the snow-waters of the straits, I ordered every day, that a pint of
vinegar, and red hot bullets should be put into the scuttled cask,
containing the water for the crew to drink, on the upper deck.
Happily these sore throats yielded to the simplest remedies; and, at
the end of March, we had no-body upon the sick-list. Only four
sailors were attacked by the scurvy. About this time we got plenty of
Bonitos and Great-ears (Grandes-Oreilles); and, during eight or ten
days, sufficient were taken to afford one meal a-day for the crews of
both ships.
Chart
of the Discoveries
in the
South Pacifick Ocean,
made by
M. de Bougainville.
in 1768.

Continuation
of the
Track
of the
French Ships.
Meeting with During March, we ran on the parallel of the first
the first isles. lands and isles marked on the chart of M. Bellin, by
the name of Quiros’s Isles. On the 21st we caught a 1768. March.
tunny, in whose belly we found same little fish, not yet digested, of
such species as never go to any distance from the shore. This was a
sign of the vicinity of land. Indeed, the 22d, at six in the morning,
we saw at once four little isles, bearing S. S. E. ½E. and a little isle
about four leagues west. The four isles I called les Observations
quatre Facardins; and as they were too far to on one of these
windward, I stood for the little isle a-head of us. As isles.
we approached it, we discovered that it is surrounded with a very
level sand, and that all the interior parts of it are covered with thick
woods, above which the cocoa-trees raise their fertile heads. The
sea broke much to the N. and S. and a great swell beating all along
the eastern side, prevented our access to this isle in that part.
However, the verdure charmed our eyes, and the cocoa-trees every
where exposed their fruits to our sight, and over-shadowed a grass-
plot adorned with flowers; thousands of birds were hovering about
the shore, and seemed to announce a coast abounding in fish, and
we all longed for a descent. We thought this would be easy on the
western-side; and we ran along the coast at the distance of about
two miles. We saw the sea break on every side with equal force,
without a single harbour or creek, which might serve for shelter, or
stem the force of the sea. Thus losing all hopes of landing there,
unless at the evident risk of having our boats staved to pieces, we
resumed our course again, when some of our people cried out, that
they saw three men running to the sea-shore. We It is inhabited,
should never have thought that so small an isle notwithstandin
could be inhabited; and my first conjectures were, gsize. its small

that some Europeans must certainly have been


shipwrecked upon it. I presently gave orders to lay-to; as I was
determined to do all I could to save them. These men were returned
into the woods; but soon after they came out again, fifteen or
twenty in number, and advanced very fast; they were naked, and
bore very long pikes, which they brandished against the ships, with
signs of threatening; after this bravado, they retired to the woods,
where we could distinguish their huts, by means of our glasses.
These men seemed very tall, and of a bronze colour—Who can give
an account of the manner in which they were conveyed hither, what
communications they have with other beings, and what becomes of
them when they multiply on an isle, which has no more than a
league in diameter? I called it Isle des Lanciers[93]. Being less than a
league to the N. E. of this isle, I made the signal to the Etoile to
sound; she did so with a line of two hundred fathom, without finding
any bottom.
Farther From that day we always shortened sail at night,
meeting with fearing to meet all at once some of these low-lands,
islands.
to which it is so dangerous to come near. We were
obliged to bring-to[94], during a part of the night, between the 22d
and 23d; as we had a storm, with very high wind, rain, and thunder.
At day-break we saw land, bearing from us, from N. E. b. N. to N. N.
W. We stood for it, and at eight o’clock were about three leagues
from its eastermost point. Then, though it was somewhat hazy, we
perceived breakers along this coast, which appeared very low, and
covered with trees: therefore, we stood out to sea again, waiting for
the fair weather to allow us to come nearer the coast at a less risk;
this we were able to do towards ten o’clock. Being only one league
off the island, we ran along it, endeavouring to find a proper
landing-place; we could not find bottom with 120 fathom. A bar, over
which the sea broke with great violence, lay along the whole coast;
and we soon discovered, that this island is formed by two very
narrow slips of land, which join at the N. W. end, and leave an
opening to the S. E. between their extremities. The Description of
middle of this isle is therefore occupied by the sea, the largest of
these isles.
in all its length, which is about ten or twelve leagues
S. E. and N. W. so that it appears like a very oblong horse-shoe,
whereof the opening or entrance is at S. E.
The two necks of land are so very narrow, that we could perceive
the sea beyond the most northerly one. They seem composed of
nothing but sandy downs, interspersed with low grounds, without
either trees or verdure. The higher downs are covered with cocoa-
nut and other lesser trees, which were very shady. After noon we
saw periaguas in the kind of lake which this island forms; some
sailing, others paddling. The savages in them were naked. In the
evening we saw a great number of these islanders along the coast.
They likewise seemed to have such long lances as the inhabitants of
the first island threatened us with. We had not yet found any place
where our canoes could land. The sea foamed every where with
equal violence. Night interrupted our researches; we passed it plying
under our top-sails; and not discovering any landing-place, on the
24th in the morning, we continued our course, and left this
inaccessible island; which, on account of its figure, I called Harp
Island. I question whether this extraordinary land is rising and
encreasing, or whether it is decaying? How was it peopled? Its
inhabitants appeared to us tall and well proportioned. I admire their
courage, if they live unconcerned on these little slips of sand, which
are exposed to be buried in the sea every moment by a hurricane.
First division: The same day, at five in the afternoon, we saw
Dangerous another land, about seven or eight leagues distant;
Archipelago.
the uncertainty of its position, the inconstant squally
and tempestuous weather, and the obscurity of the night obliged us
to stand off and on. The 25th, in the morning, we came near the
land, which we found to be another very low island, extending S. E.
and N. W. about twenty-four leagues. We continued till the 27th to
sail between low and partly overflowed islands, four of which we
examined, all of the same nature, and all inaccessible, and not
deserving that we should lose our time in visiting them. I gave the
name of Dangerous Archipelago to this cluster of islands; of which
we saw eleven, and which are probably more numerous. It is very
dangerous sailing amidst these low isles, surrounded with breakers
and shoals; where it is necessary, especially at night, to use the
utmost precaution.
Error in the I determined to stand more southerly, in order to
chart of this get clear of these dangerous parts. Indeed, on the
part of the
Pacific Ocean.
28th, we ceased to see the land. Quiros, discovered
first, in 1606, the south end of this chain of islands,
which extend W. N. W. and among which admiral Roggewein found
himself engaged in 1722, in about 15° lat. he called them the
Labyrinth. Upon the whole, I know not on what grounds our
geographers lay down after these isles, a beginning of land seen, as
they say, by Quiros; and to which they give seventy leagues of
extent. All that can be inferred from the Journal of this navigator is,
that the first place he landed at, after his departure from Peru, was
eight leagues in extent. But far from considering it as a considerable
coast, he says, that the savages who inhabit it, gave him to
understand, that he should find great countries in his way[95]. If any
considerable land existed hereabouts, we could not fail meeting with
it; as the least latitude we were hitherto arrived at, was 17° 40′ S.
which is the same that Quiros observed on this very coast, whereof
the geographers have been pleased to make a great continent.
I agree, that it is difficult to conceive such a number of low
islands, and almost drowned lands, without supposing a continent
near it. But Geography is a science of facts; in studying it, authors
must by no means give way to any system, formed in their studies,
unless they would run the risk of being subject to very great errors,
which can be rectified only at the expence of navigators.
Astronomical Mr. Verron, in March, gave me three observations
observations, of longitude. The first, taken by Hadley’s octant, on
compared with
my reckoning.
the 3d in the afternoon, was only 21′ 30″ different
from my reckoning, I being so much to the
westward of the observed longitude. The second, made by the
megameter, and reduced to noon of the 10th, differed considerably
from my reckoning, as my computed longitude was 3° 6′ more
westward than that taken by observation. On the contrary, from the
result of the third observation, taken with the octant on the 27th, my
reckoning agreed within 39′ 15″, which he found I was more
eastward than his longitude. It must be observed, that since my
leaving the straits of Magalhaens, I have always followed the
longitude of my departure, without correcting it in the least, or
making use of the observations.
Meteorological The thermometer[96] constantly kept between 19°
observations. and 20°, during this month, and even near the land.
Towards the end of the month, we had five days west winds, with
squalls and storms, which succeeded each other almost without
interruption. It rained continually; and the scurvy made its
appearance on eight or ten persons of the crew. Moistness is one of
the most powerful causes of this disease. Each Advantageous
sailor got daily a pint of lemonade, prepared with a use of
kind of powder, called powder of faciot; which we lemonade-
powder at sea.
made great use of, during the course of this voyage.
On the third of March I had likewise begun to make Water deprived
use of the distilling apparatus of M. Poissonier; and of its salt.
we continued till we arrived at New Britain to make use of the sea-
water, which was by this means deprived of its salt; employing it in
broth, and in boiling meat and legumes. The supply of water it
procured us, during this long run, was a very great resource. We
lighted our fire at five in the evening, and put it out 1768. April.
by five or six in the morning, making above a barrel of water every
night. By way of sparing our fresh water, we always kneaded our
bread with salt water.
Second division The second of April, at ten in the morning, we
of lands; perceived, to the N. N. E. a high and very sleep
Archipelago of
Bourbon.
mountain, seemingly surrounded by the sea. I called
it the Boudoir, or the Peak of the Boudeuse. We
stood to the northward, in order to make it plain, Sight of Taiti.
when we saw another land, bearing W. by N. the coast of which was
not so high, but afforded an indeterminate extent to our eyes. We
had a very urgent necessity for touching at some place where we
might get refreshments and wood, and we flattered ourselves to find
them on this land. It was a calm almost the whole day. In the
evening a breeze sprung up, and we stood towards the land till two
in the morning, when we stood off shore again, for three hours
together. The sun rose obscured by clouds and haze; and it was nine
o’clock in the morning before we could see the land again, its
southermost point then bearing W. by N. We could no longer see the
peak of the Boudeuse, but from the mast-head. The wind blew N.
and N. N. E. and we stood as close upon it as we could, in order to
fall into windward of the island. As we came nearer we saw, beyond
its northermost point, a distant land, still further to northward,
without our being able at that time to distinguish whether it joined
to the first isle, or whether it formed a second.
Manœuvres in During the night, between the third and fourth,
order to land we turned to windward, in order to get more to the
there.
northward. With joy we saw fires burning on every
part of the coast, and from thence concluded that it was inhabited.
The 4th, at day-break, we discovered that the two lands, which
before appeared separate, were united together by a low land,
which was bent like a bow, and formed a bay open to the N. E. We
run with all sails set towards the land, standing to windward of this
bay, when we perceived a periagua coming from the offing, and
standing for the land, and making use of her sail and paddles. She
passed athwart us, and joined a number of others, which sailed a-
head of us, from all parts of the island. One of them went before all
the rest; it was manned by twelve naked men, who presented us
with branches of bananas; and their demonstrations signified that
this was their olive-branch. We answered them with First traffic
all the signs of friendship we could imagine; they with these
islanders.
then came along side of our ship; and one of them,
remarkable for his prodigious growth of hair, which stood like bristles
divergent on his head, offered us, together with his branch of peace,
a little pig, and a cluster of bananas. We accepted his present, which
he fastened to a rope that was thrown over to him; we gave him
caps and handkerchiefs; and these first presents were the pledges of
our alliance with these people.
The two ships were soon surrounded with more than an hundred
periaguas of different sizes, all which had outriggers. They were
laden with cocoa-nuts, bananas, and other fruits of the country. The
exchange of these fruits, which were delicious to us, was made very
honestly for all sorts of trifles; but without any of the islanders
venturing to come aboard. We were obliged either to come into their
periaguas, or shew them at a distance what we offered in exchange;
when both parties were agreed, a basket or a net was let down by a
rope; they put their goods in it, and so we did ours; giving before
they had received, or receiving before they gave indifferently, with a
kind of confidence, which made us conceive a good opinion of their
character. We further saw no kind of arms in their periaguas, in
which there were no women at this first interview. The periaguas
kept along-side of the ships, till the approach of night obliged us to
stand off shore, when they all retired.
We endeavoured, during night, to go to the northward, never
standing further than three leagues from the land. All the shore was,
till near midnight, covered as the night before, with little fires at a
short distance from each other: it seemed as if it was an illumination
made on purpose, and we accompanied it with several sky-rockets
from both our ships.
Description of The 5th we spent in plying, in order to work to
the coast as windward of the island, and in letting the boats
seen from the
offing.
sound for an anchoring-place. The aspect of this
coast, elevated like an amphitheatre, offered us the
most enchanting prospect. Notwithstanding the great height of the
mountains, none of the rocks has the appearance of barrenness;
every part is covered with woods. We hardly believed our eyes,
when we saw a peak covered with trees, up to its solitary summit,
which rises above the level of the mountains, in the interior parts of
the southermost quarter of the island. Its apparent size seemed to
be no more than of thirty toises in diameter, and grew less in
breadth as it rose higher. At a distance it might have been taken for
a pyramid of immense height, which the hand of an able sculptor
had adorned with garlands and foliage. The less elevated lands are
interspersed with meadows and little woods; and all along the coast
there runs a piece of low and level land, covered with plantations,
touching on one side the sea, and on the other bordering the
mountainous parts of the country. Here we saw the houses of the
islanders amidst bananas, cocoa-nut, and other trees loaded with
fruit.
As we ran along the coast, our eyes were struck with the sight of
a beautiful cascade, which came from the tops of the mountains,
and poured its foaming waters into the sea. A village was situated at
the foot of this cascade, and there appeared to be no breakers in
this part of the coast. We all wished to be able to anchor within
reach of this beautiful spot; we were constantly sounding aboard the
ships, and our boats took soundings close under the shore; but we
found a bottom of nothing but rocks in this port, and were forced to
go in search of another anchorage.
Continuation of The periaguas returned to the ship at sun-rising,
the traffic with and continued to make exchanges all the day. We
the islanders.
likewise opened new branches of commerce; for,
besides the fruits, which they brought the day before, and other
refreshments, such as fowls and pigeons, the islanders brought with
them several instruments for fishing; stone chisels, (herminettes de
pierre) strange kinds of cloth, shells, &c. They wanted iron and ear-
rings in exchange. This bartering trade was carried on very honestly,
as the day before: this time some pretty and almost naked women
came in the periaguas. One of the islanders went on board the
Etoile, and stayed there all night, without being in the least uneasy.
This night was likewise spent in plying; and on the 6th in the
morning we were got to the most northerly extremity of the island.
Another isle now came within sight: but seeing several breakers that
seemed to obstruct the passage between the two isles, I determined
to return in search of anchorage in the first bay, which we saw on
the day of our land-fall. Our boats which sounded a-head of us
towards shore, found the north side of the bay every where
surrounded, at a quarter of a league’s distance, by a reef which
appears at low water. However, about a league from the north point,
they discovered a gap in the reef, of the width of twice a cable’s
length at most, where there was 30 and 35 fathom of water, and
within it a pretty extensive road, where the bottom varied from nine
to thirty fathom. This road was bounded to the south by a reef,
which, proceeding from the land, joined that which surrounded the
shore. Our boats had constantly found a sandy bottom, and
discovered several little rivers fit for watering at. Upon the reef, on
the north side, there are three little islands.
Anchorage at This account determined me to come to an
Taiti. anchor in the road, and we immediately made sail
to enter into it. We ranged the point of the starboard reef in
entering; and as soon as we were got within it, we let go our best
bower in 34 fathom, bottom of grey sand, shells, and gravel; and we
immediately carried out the stream-anchor to the north-west, in
order to let go our small bower there. The Etoile went to windward,
and came to an anchor a cable’s length to the northward of us. As
soon as we were moored, we struck yards and top-masts.
Difficulty of As we came nearer the shore, the number of
mooring the islanders surrounding our ships encreased. The
ships.
periaguas were so numerous all about the ships,
that we had much to do to warp in amidst the croud of boats and
the noise. All these people came crying out tayo, which means
friend, and gave a thousand signs of friendship; they all asked nails
and ear-rings of us. The periaguas were full of females; who, for
agreeable features, are not inferior to most European women; and
who in point of beauty of the body might, with much reason, vie
with them all. Most of these fair females were naked; for the men
and the old women that accompanied them, had stripped them of
the garments which they generally dress themselves in. The glances
which they gave us from their periaguas, seemed to discover some
degree of uneasiness, notwithstanding the innocent manner in which
they were given; perhaps, because nature has every where
embellished their sex with a natural timidity; or because even in
those countries, where the ease of the golden age is still in use,
women seem least to desire what they most wish for. The men, who
were more plain, or rather more free, soon explained their meaning
very clearly. They pressed us to choose a woman, and to come on
shore with her; and their gestures, which were nothing less than
equivocal, denoted in what manner we should form an acquaintance
with her. It was very difficult, amidst such a sight, to keep at their
work four hundred young French sailors, who had seen no women
for six months. In spite of all our precautions, a young girl came on
board, and placed herself upon the quarter-deck, near one of the
hatchways, which was open, in order to give air to those who were
heaving at the capstern below it. The girl carelessly dropt a cloth,
which covered her, and appeared to the eyes of all beholders, such
as Venus shewed herself to the Phrygian shepherd, having, indeed,
the celestial form of that goddess. Both sailors and soldiers
endeavoured to come to the hatch-way; and the capstern was never
hove with more alacrity than on this occasion.
At last our cares succeeded in keeping these bewitched fellows in
order, though it was no less difficult to keep the command of
ourselves. One single Frenchman, who was my cook, having found
means to escape against my orders, soon returned more dead than
alive. He had hardly set his feet on shore, with the fair whom he had
chosen, when he was immediately surrounded by a croud of Indians,
who undressed him from head to feet. He thought he was utterly
lost, not knowing where the exclamations of those people would
end, who were tumultuously examining every part of his body. After
having considered him well, they returned him his clothes, put into
his pockets whatever they had taken out of them, and brought the
girl to him, desiring him to content those desires which had brought
him on shore with her. All their persuasive arguments had no effect;
they were obliged to bring the poor cook on board, who told me,
that I might reprimand him as much as I pleased, but that I could
never frighten him so much, as he had just now been frightened on
shore.
CHAP. II.
Stay at Taiti; account of the good and evil which befel us there.
Landing. I have pointed out the obstacles which we met with
in coming to an anchor. When we were moored, I went on shore
with several officers, to survey the watering-place. An immense
croud of men and women received us there, and could not be tired
with looking at us; the boldest among them came to touch us; they
even pushed aside our clothes with their hands, in order to see
whether we were made exactly like them: none of them wore any
arms, not so much as a stick. They sufficiently expressed their joy at
our arrival. The chief of this district conducted and Visit paid to
introduced us into his house, in which we found five the chief of the
or six women, and a venerable old man. The women district.
saluted us, by laying their hands on their breasts, and saying several
times tayo. The old man was the father of our host. He had no other
character of old age, than that respectable one which is imprinted on
a fine figure. His head adorned with white hair, and a long beard; all
his body, nervous and fleshy, had neither wrinkles, nor shewed any
marks of decrepitude. This venerable man seemed to be rather
displeased with our arrival; he even retired without answering our
civilities, without giving any signs of fear, astonishment, or curiosity;
very far from taking part in the raptures all this people was in at our
sight, his thoughtful and suspicious air seemed to shew that he
feared the arrival of a new race of men would trouble those happy
days which he had spent in peace.
Description of We were at liberty to examine the interior parts of
his house. the house. It had no furniture, no ornament to
distinguish it from the common huts, except its extent. It was about
eighty feet long and twenty feet wide. In it we observed a cylinder
of ozier, three or four feet long, set with black feathers, which was
suspended from the thatch; and besides it, there were two wooden
figures which we took for idols. One, which was their god[97], stood
upright against one of the pillars; the goddess was opposite, leaned
against the wall, which she surpassed in height, and was fattened to
the reeds, of which their walls are made. These figures, which were
ill made, and without any proportion, were about three feet high,
but stood on a cylindrical pedestal, hollow within, and carved quite
through. This pedestal was made in the shape of a tower, was six or
seven feet high, and about a foot in diameter. The whole was made
of a black and very hard wood.
The chief then proposed that we should sit down upon the grass
before his house, where he ordered some fruit, broiled fish and
water to be set before us: during the meal he sent for some pieces
of cloth, and for two great collars or gorgets of oziers, covered with
black feathers and shark’s teeth. They are pretty like in form to the
immense ruffs, worn in the time of Francis the first. One of these he
put upon the neck of the Chevalier d’Oraison, another upon mine,
and distributed the cloths. We were just going to return on board
when the Chevalier de Suzannet missed a pistol, which had been
very dexterously stolen out of his pocket. We informed the chief of
it, who immediately was for searching all the people who surrounded
us, and even treated some of them very harshly. We stopt his
researches, endeavouring only to make him understand, that the
thief would fall a victim to his own crime, and that what he had
stolen could kill him.
The chief and all his people accompanied us to our boats. We
were almost come to them when we were stopped by an islander, of
a fine figure, who lying under a tree, invited us to sit down by him
on the grass. We accepted his offer: he then leaned towards us, and
with a tender air he slowly sung a song, without doubt of the
Anacreontic kind, to the tune of a flute, which another Indian blew
with his nose: this was a charming scene, and worthy the pencil of a
Boucher. Four islanders came with great confidence to sup and lye
on board. We let them hear the music of our flutes, base-viols, and
violins, and we entertained them with a fire-work of sky-rockets and
fire-snakes. This sight caused a mixture of surprize and of horror in
them.
Project of a On the 7th in the morning, the chief, whose name
camp for our was Ereti, came on board. He brought us a hog,
sick on shore.
some fowls, and the pistol which had been stolen at
his house the day before. This act of justice gave us a good opinion
of him. However, we made every thing ready in the morning, for
landing our sick people, and our water casks, and leaving a guard
for their defence. In the afternoon I went on shore with arms and
implements, and we began to make a camp on the banks of a little
brook, where we were to fill our water. Ereti saw the men under
arms, and the preparations for the encampment, without appearing
at first surprised or discontented. However, some Opposition on
hours after he came to me, accompanied by his the part of the
father and the principal people of the district, who islanders.
had made remonstrances to him on this occasion, and gave me to
understand that our stay on shore displeased them, that we might
stay there during day-time as long as we pleased, but that we
should ly on board our ships at night. I insisted upon establishing
the camp, making him comprehend that it was necessary to us, in
order to get wood and water, and to facilitate the exchanges
between both nations. They then held a second council, the remit of
which, was, that Ereti came to ask me whether we intended to stay
here for ever, or whether we intended to go away again, and how
soon that would be. I told him that we should set sail in eighteen
days, in sign of which, I gave him eighteen little stones. Upon this
they held a new conference, at which they desired I would be
present. A grave man, who seemed to have much They consent
weight with the members of the council, wanted to to it on some
conditions.
reduce the number of days of our encamping to
nine; but as I insisted on the number I had at first required, they at
last gave their consent.
From that moment their joy returned; Ereti himself offered us an
extensive building like a shed, close to the river, under which were
some periaguas, which he immediately got taken away. Under this
shed we raised the tents for those who were ill of the scurvy, being
thirty-four in number, twelve from the Boudeuse, Establishment
and twenty-two from the Etoile, and for some of a camp for
necessary hands. The guard consisted of thirty our sick and
artificers.
soldiers, and I likewise landed muskets enough to
arm the workmen and the sick. I staid on shore the first night, which
Ereti likewise chose to pass under our tents. He ordered his supper
to be brought, and joined it to ours, driving away the crowd which
surrounded the camp, and retaining only five or six of his friends.
After supper he desired to see some sky-rockets played off, and they
frightened him at least as much as they gave him pleasure. Towards
the end of night he sent for one of his wives, whom he sent to sleep
in prince Nassau’s tent. She was old and ugly.
Precautions The next day was spent in completing our camp.
taken. Conduct The shed was well made, and entirely covered over
of the natives.
by a kind of mats. We left only one entrance to it,
which we provided with a barrier, and placed a guard there. Ereti, his
wives and his friends alone were allowed to come in; the croud kept
on the outside of the shed, and only a single man of our people with
a switch in his hand was sufficient to clear the way. Hither the
natives from all sides brought fruits, fowls, hogs, fish, and pieces of
cloth, which they exchanged for nails, tools, beads, buttons, and
numberless other trifles, which were treasures to them. They were,
upon the whole, very attentive to learn what would give us pleasure;
they saw us gathering antiscorbutic plants, and searching for shells:
their women and children soon vied with each other in bringing us
bundles of the same plants, which they had seen us collecting, and
baskets full of shells of all sorts. Their trouble was paid at a small
expence.
Assistance they This same day I desired the chief to shew me
give us. where I might cut wood. The low country where we
were, was covered only with fruit trees, and a kind of wood full of
gum, and of little consistence; the hard wood grows upon the
mountains. Ereti pointed out to me the trees which I might cut
down, and even shewed towards which side I should fell them. The
natives assisted us greatly in our works; our workmen cut down the
trees and made them into faggots, which the islanders brought to
the boats; they likewise gave us their assistance in making our
provision of water, filling the casks, and bringing them to the boats.
Their labour was paid in nails, of which, the number was
proportionate to the work they had done. The only constraint which
their presence put upon us, was, that they obliged us to have our
eyes upon every thing that was brought on shore, and even to look
to our pockets; for even in Europe itself, one cannot see more expert
filchers than the people of this country.
Precautions However, it does not appear that stealing is usual
taken against among themselves. Nothing is shut up in their
thieves.
houses, every piece of furniture lies on the ground,
or is hung up, without being under locks, or under any person’s care.
Doubtless their curiosity for new objects excited violent desires in
them; and besides that, there are always base-minded people every
where. During the two first nights we had some things stolen from
us, notwithstanding our guards and patroles, at whom the thieves
had even thrown stones. These thieves hid themselves in a marsh
full of grass and reeds, extending behind our camp. This marsh was
partly cleared by my orders, and I commanded the officer upon duty
to fire upon any thieves who should come for the future. Ereti
himself told me to do it, but took great care to shew me several
times the spot where his house was situated, earnestly
recommending it to me, to fire towards the opposite quarter. I
likewise sent every evening three of our boats, armed with
pedereroes and swivel guns, to ly at anchor before the camp.
All our transactions were carried on in as friendly a manner as
possible, if we except thieving. Our people were daily walking in the
isle without arms, either quite alone, or in little companies. They
were invited to enter the houses, where the people gave them to
eat; nor did the civility of their landlords stop at a slight collation,
they offered them young girls; the hut was immediately filled with a
curious croud of men and women, who made a circle round the
guest, and the young victim of hospitality. The ground was spread
with leaves and flowers, and their musicians sung an hymeneal song
to the tune of their flutes. Here Venus is the goddess of hospitality,
her worship does not admit of any mysteries, and every tribute paid
to her is a feast for the whole nation. They were surprised at the
confusion which our people appeared to be in, as our customs do
not admit of these public proceedings. However, I would not answer
for it, that every one of our men had found it impossible to conquer
his repugnance, and conform to the customs of the country.
Beauty of the I have often, in company with only one or two of
interior parts of our people, been out walking in the interior parts of
the country.
the isle. I thought I was transported into the garden
of Eden; we crossed a turf, covered with fine fruit-trees, and
interfered by little rivulets, which keep up a pleasant coolness in the
air, without any of those inconveniences which humidity occasions. A
numerous people there enjoy the blessings which nature showers
liberally down upon them. We found companies of men and women
sitting under the shade of their fruit-trees: they all greeted us with
signs of friendship: those who met us upon the road stood aside to
let us pass by; every where we found hospitality, ease, innocent joy,
and every appearance of happiness amongst them.
Presents of I presented the chief of the district in which we
European fowls were with a couple of turkies, and some ducks and
and seeds
made to the
drakes; they were to be considered as the mites of
chief. the widow. I likewise desired him to make a garden
in our way, and to sow various sorts of feeds in
them, and this proposal was received with joy. In a short time, Ereti
prepared a piece of ground, which had been chosen by our
gardeners, and got it inclosed. I ordered it to be dug; they admired
our gardening instruments. They have likewise around their houses
a kind of kitchen gardens, in which they plant an eatable hibiscus or
okra, potatoes, yams, and other roots. We sowed for their use some
wheat, barley, oats, rice, maize, onions, and pot herbs of all kinds.
We have reason to believe that these plantations will be taken care
of; for this nation appeared to love agriculture, and would I believe
be easily accustomed to make advantage of their soil, which is the
most fertile in the universe.
Visit of the During the first days of our arrival, I had a visit
chief of a from the chief of a neighbouring district, who came
on board with a present of fruits, hogs, fowls, and
neighbouring cloth. This lord, named Toutaa, has a fine shape,
district. and is prodigiously tall. He was accompanied by
some of his relations, who were almost all of them six feet (French
measure) high: I made them presents of nails, some tools, beads,
and silk stuffs. We were obliged to repay this visit at his house,
where we were very well received, and where the good-natured
Toutaa offered me one of his wives, who was very young and pretty
handsome. The assembly was very numerous, and the musicians
had already began the hymenean. Such is their manner of receiving
visits of ceremony.
On the 10th, an islander was killed, and the natives came to
complain of this murder. I sent some people to the house, whither
they had brought the dead body; it appeared very plain that the
man had been killed by a fire-arm. However, none of our people had
been suffered to go out of the camp, or to come from the ships with
fire-arms. The most exact enquiries which I made to find out the
author of this villainous action proved unsuccessful. The natives
doubtless believed that their countryman had been in the wrong; for
they continued to come to our quarters with their usual confidence.
However, I received intelligence that many of the people had been
seen carrying off their effects to the mountains, and that even Ereti’s
house was quite unfurnished. I made him some more presents, and
this good chief continued to testify the sincerest friendship for us.
Loss of our I hastened in the mean while the completing of
anchors, our works of all kinds; for though this was an
dangers which
we meet with.
excellent place to supply our wants at, yet I knew
that we were very ill moored. Indeed, though we
under-run the cables almost every day with the long boat, and had
not yet found them chafed[98], yet we had found the bottom was
strewed with large coral; and besides, in case of a high wind from
the offing, we had no room to drive. Necessity had obliged us to
take this anchorage, without leaving us the liberty of choosing, and
we soon found that our fears were but too well grounded.
Account of the The 12th, at five in the morning, the wind being
manoeuvres south, our S. E. cable, and the hawser of the
stream-anchor, which by way of precaution we had
which saved extended to the E. S. E. parted at the bottom. We
us. immediately let go our sheet-anchor, but before it
had reached the bottom, the frigate swung off to her N. W. anchor,
and we fell aboard the Etoile on the larboard side. We hove upon
our anchor, and the Etoile veered out cable as fast as possible, so
that we were separated before any damage was done. The store
ship then sent us the end of a hawser, which she had extended to
the eastward, and upon which we hove, in order to get farther from
her. We then weighed our sheet-anchor, and hove in our hawser and
cable, which parted at the bottom. The latter had been cut about
thirty fathom from the clinch; we shifted it end for end, and bent it
to a spare anchor of two thousand seven hundred weight, which the
Etoile had stowed in her hold, and which we sent for. Our S. E.
anchor, which we had let go without any buoy-rope, on account of
the great depth, was entirely lost; and we endeavoured, without
success, to save the stream-anchor, whose buoy was sunk, and for
which it was impossible to sweep the bottom. We presently swayed
up our fore-top-mast and fore-yard, in order to be ready for sailing
as soon as the wind should permit.
In the afternoon the wind abated and shifted to the eastward. We
then carried out to the S. E. a stream-anchor, and the anchor we
had got from the Etoile, and I sent a boat to sound to the
northward, in order to know whether there was a passage that way,
by which means we might have got out almost with any wind. One
misfortune never comes alone; as we were occupied with a piece of
work on which our safety depended, I was informed Another
that three of the natives had been killed or wounded murder of
with bayonets in their huts, that the alarm was some islanders.
spread in the country, that the old men, the women
and the children fled towards the mountains with their goods, and
even the bodies of the dead, and that we should perhaps be
attacked by an army of these enraged men. Thus our situation gave
us room to fear a war on shore, at the very moment when both
ships were upon the point of being stranded. I went ashore, and
came into the camp, where, in presence of the chief, I put four
soldiers in irons, who were suspected to be the authors of this
crime: these proceedings seemed to content the natives.
Precautions I passed a part of the night on shore, and
against the reinforced the watches, fearing that the inhabitants
consequences
which it might
might revenge their countrymen. We occupied a
have had. most excellent post, between two rivers, distant
from each other at most only a quarter of a league;
the front of the camp was covered by a marsh, and on the remaining
side was the sea, of which we certainly were the masters. We had a
fair chance to defend this post against the united forces of the whole
island; but happily the night passed very quietly in the camp,
excepting some alarms occasioned by thieves.
Continuation of It was not from this part that I dreaded the worst
the dangers that could happen; the fear of seeing the ships lost
which the ships
run.
upon the coast, gave me infinitely more concern.
From ten o’clock in the evening, the wind freshened
very much from the east; and was attended with a great swell; rain,
tempest, and all the sad appearances which augment the horror of
these dreadful situations.
Towards two o’clock in the morning, a squall drove the ships
towards the coast: I came on board; the squall happily was not of
long duration; and as soon as it was blown over, the wind blew off
more. At day-break we encountered new misfortunes; our N. W.
cable parted; the hawser, which the Etoile had given us, and which
held us by her stream-anchor, had the same fate a few minutes
after. The frigate then swinging off to her S. E. anchor and hawser,
was no more than a cable’s length off shore, upon which the sea
broke with great violence. In proportion, as the danger became
more pressing, our resources failed us; the two anchors of which the
cable’s had just parted, were entirely lost to us; their buoys
disappeared, being either sunk, or taken away, during the night, by
the Indians. Thus we had lost already four anchors, in four and
twenty-hours, and had yet several losses to sustain.
At ten o’clock in the morning, the new cable we had bent to the
anchor of two thousand seven hundred weight from the Etoile,
which held us to the S. E. parted, and the frigate, riding by a single
hawser, began to drive upon the coast. We immediately let go our
sheet-anchor under foot; it being the only one which we had
remaining at our bow: but of what use could it be to us? We were so
close to the breakers, that we must have been upon them before we
had veered out cable sufficient to make the anchor catch hold in the
ground. We expected every moment the sad conclusion of this
adventure, when a S. W. breeze gave us some hopes of setting sail.
Our jib and stay-sails were soon hoisted; the ship began to shoot a-
head, and we were endeavouring to make sail, in order to veer away
cable and hawser, and get out; but the wind almost immediately
shifted to the eastward again. This interval had, however, given us
time to take on board the end of a hawser, from a second stream-
anchor of the Etoile, which she had just carried out to the eastward,
and which saved us for this time. We hove in upon both hawsers,
and got somewhat further from the shore. We then sent our long-
boat aboard the Etoile, to help her in mooring her securely; her
anchors happily lay in a bottom less covered with coral than that
where we had let ours go. This being done, our long-boat went to
weigh the anchor of 2700 weight by its buoy-rope; we bent another
cable to it, and carried it out to the N. E. We then weighed the
stream-anchor belonging to the Etoile, and returned it to her. During
these two days M. de la Giraudais, captain of that store-ship, had a
very great share in the preservation of the frigate, by the assistance
which he gave me: it is with pleasure that I pay this tribute of
gratitude to an officer, who has already been my companion on
former voyages, and whose zeal equals his talents.
Peace made However, when the day appeared, no Indian was
with the come near the camp, not a single periagua was
islanders.
seen sailing, all the neighbouring houses were
abandoned, and the whole country appeared as a desert. The prince
of Nassau, who with only four or five men was gone out a little
further, in order to search for some of the natives, and to inspire
them with confidence again, found a great number of them with
Ereti, about a league from the camp. As soon as that chief knew the
prince again, he came up to him with an air of consternation.
The women, who were all in tears, fell at his feet, kissed his
hands, weeping and repeating several times, Tayo, maté, you are
our friends, and you kill us. By his caresses and demonstrations of
friendship, he at last succeeded in regaining their confidence. I saw
from on board a croud of people running to our quarters: fowls,
cocoa-nuts, and branches full of bananas, embellished this
procession, and promised a peace. I immediately went ashore with
an assortment of silk stuffs, and tools of all sorts; I distributed them
among the chiefs, expressing my concern to them on account of the
disaster which had happened the day before, and assuring them,
that I would punish the perpetrators. The good islanders loaded me
with caresses; the people applauded the reunion, and, in a short
time, the usual croud and the thieves returned to our quarters,
which looked like a fair. This day, and the following, they brought
more refreshments than ever. They likewise desired to have several
muskets fired in their presence, which frightened them very much,
as all the creatures which we shot at were killed immediately.
The Etoile sets The boat, which I had sent to sound to the
sail. northward, was returned with the good news of
having found a very fine passage. It was then too late to profit of it
the same day; for night was coming on. Happily it passed quietly,
both on shore and at sea. The 14th in the morning, wind at east, I
ordered the Etoile, who had got her water and all her men on board,
to weigh and go out by the new north passage. We could not go out
by that passage before the store-ship, she being moored to the
northward of us. At eleven she came to sail, from a hawser, which
she had carried on board of us. I kept her long-boat and two small
anchors; I likewise took on board, as soon as she was got under sail,
the end of the cable of her S. E. anchor, which lay in a good bottom.
We now weighed our sheet-anchor, carried the two stream-anchors
further out; and were by this means moored by two great, and three
small anchors. At two o’clock in the afternoon, we had the
satisfaction of seeing the Etoile without the reefs. Our situation by
this means became less terrifying; we had at least secured to
ourselves the means of returning to our country, by putting one of
the ships out of danger. When M. de la Giraudais was got out into
the offing, he sent back his boat to me, with Mr. Lavari Leroi, who
had been employed to survey the passage.
We laboured all day, and a part of the night, to complete our
water, and to remove the hospital and the camp. I Inscription
buried near the shed, an act of taking possession, buried.
inscribed on an oak plank, and a bottle well corked and glued,
containing the names of the officers of both ships. I have followed
the same method in regard to all the lands discovered during the
course of this voyage. It was two o’clock in the morning, before
every one of our people were on board: the night was still stormy
enough to give us some disturbance, notwithstanding the number of
anchors we had moored.
The Boudeuse On the 15th, at six o’clock in the morning, the
sets sail; runs wind blowing off shore, and the sky looking stormy,
new dangers.
we weighed our anchor, veered away the cable of
that which belonged to the Etoile, cut one of the hawsers, and
veered out the other two, setting sail under our fore-sail and top-
sails, in order to go out by the eastern passage. We left the two
long-boats to weigh the anchors; and as soon as we were got out of
the reefs, I sent the two barges armed, under the command of
ensign the chevalier de Suzannet, to protect the work of the long-
boats. We were about a quarter of a league off shore, and began to
give ourselves joy of having so happily left an anchorage, that had
given us such terrible alarms, when the wind ceasing all at once, the
tide and a great swell from the eastward, began to drive us towards
the reefs to leeward of the passage. The worst consequences of the
shipwreck, with which we had hitherto been threatened, would have
been to pass the remainder of our days on an isle adorned with all
the gifts of nature, and to exchange the sweets of the mother-
country, for a peaceable life, exempted from cares. But now
shipwreck appeared with a more cruel aspect; the ship being rapidly
carried upon the rocks, could not have resisted the violence of the
sea two minutes, and hardly some of the best swimmers could have
saved their lives. At the beginning of the danger, I had made signal
for the long boats and barges to return and tow us. They came at
the very moment, when we being only 35 or 36 fathom (50 toises)
from the reef, our situation was become quite desperate; the more
so as we could not let go an anchor. A westerly breeze, springing up
that instant, brought hope along with it; it actually freshened by
degrees; and at nine o’clock in the morning, we were quite clear of
all dangers.
Departure from I immediately sent the boats back in quest of the
Taiti; losses anchors, and I remained plying to wait for them. In
which we
sustained
the afternoon we joined the Etoile. At five in the
there. evening our long-boat came on board with the best
bower, and the cable of the Etoile, which she carried
to her: our barge, that of the Etoile, and her long-boat returned
soon after; the latter bringing us our stream-anchor and a hawser.
As to the other two stream-anchors, the night coming on, and the
sailors being extremely fatigued, they could not weigh them that
day. I at first intended to keep plying off and on during night, and to
send them out for them the next morning; but, at mid-night a strong
gale sprung at E. N. E. obliging me to hoist in the boats, and make
sail, in order to get clear of the coast.
Thus an anchorage of nine days cost us six anchors; which we
should not have lost, had we been provided with some iron chains.
This is a precaution which no navigator ought to forget, if he is
going upon such a voyage as this.
Regret of the Now that the ships are in safety, let us stop a
islanders at our moment to receive the farewel of the islanders. At
departing.
daybreak, when they perceived us setting sail, Ereti
leaped alone into the first periagua he could find on shore, and
came on board. There he embraced all of us, held us some moments
in his arms, shedding tears, and appearing much affected at our
departure. Soon after, his great periagua came on board, laden with
refreshments of all kinds; his wives were in the periagua; and with
them the same islander, who, on the first day of our land-fall, had,
lodged on board the Etoile. Ereti took him by the One of them
hand, and, presenting him to me, gave me to embarks with
understand, that this man, whose name was us, at his own
and his nation’s
Aotourou, desired to go with us, and begged that I request.
would consent to it. He then presented him to each
of the officers in particular; telling them that it was one of his
friends, whom he entrusted with those who were likewise his
friends, and recommending him to us with the greatest signs of
concern. We made Ereti more presents of all sorts; after which he
took leave of us, and returned to his wives, who did not cease to
weep all the time of the periagua’s being along-side of us. In it there
was likewise a young and handsome girl, whom the islander that
stayed along with us went to embrace. He gave her three pearls
which he had in his ears, kissed her once more; and,
notwithstanding the tears of this young wife or mistress, he tore
himself from her, and came aboard the ship. Thus we quitted this
good people; and I was no less surprised at the sorrow they certified
on our departure, than at their affectionate confidence on our
arrival.
CHAP. III.
Description of the new island; manners and character of its
inhabitants.

Lucis habitamus opacis,


Riparumque toros & prata recentia rivis
Incolimus.
Virg. Æneid. Lib. VI.

The isle which at first was called New Cythera, is known by the
name of Taiti amongst its inhabitants. Its latitude Geographical
has been determined in our camp, from several position of
meridian altitudes of the sun, observed on shore Taiti.
with a quadrant. Its longitude has been ascertained by eleven
observations of the moon, according to the method of the horary
angles. M. Verron had made many others on shore, during four days
and four nights, to determine the same longitude; but the paper on
which he wrote them having been stolen, he has only kept the last
observations, made the day before our departure. He believes their
result exact enough, though their extremes differ among themselves
7° or 8°. The loss of our anchors, and all the accidents I have
mentioned before, obliged us to leave this place much sooner than
we intended, and have made it impossible for us to survey its coasts.
The southern part of it is entirely unknown to us; that which we
have observed from the S. E. to the N. W. point, seems to be fifteen
or twenty leagues in extent, and the position of its principal points,
is between N. W. and W. N. W.
Better Between the S. E. point and another great cape
anchorage than advancing to the northward, about seven or eight
that where we
were.
leagues from the former, you see a bay open to the
N. E. which has three or four leagues depth. Its shores gradually
descend towards the bottom of the bay, where they have but little
height, and seem to form the finest and best peopled district of the
whole island. It seems it would be easy to find several good
anchoring-places in this bay. We were very ill served by fortune in
meeting with our anchorage. In entering into it by the passage
where the Etoile came out at, M. de la Giraudais assured me, that
between the two most northerly isles, there was a very safe
anchorage for at least thirty ships; that there was from twenty-three
to between twelve and ten fathom of water, grey sand and ooze;
that there was a birth of a league in extent, and never any sea. The
rest of the shore is high, and seems in general to be quite
surrounded by a reef, unequally covered by the sea, and forming
little isles in some parts, on which the islanders keep up fires at
night on account of their fishery, and for the safety of their
navigation; some gaps from space to space form entrances to the
part within the reefs, but the bottom must not be too much relied
upon. The lead never brings up any thing but a grey sand; this sand
covers great masses of hard and sharp coral, which can cut through
a cable in one night, as fatal experience taught us.
Beyond the north point of this bay, the coast forms no creek, nor
no remarkable cape. The most westerly point is terminated by a low
ground, from which to the N. W. and at about a league’s distance,
you see a low isle, extending two or three leagues to the N. W.
Aspect of the The height of the mountains in the interior parts
country. of Taiti, is surprising in respect to the extent of the
island. Far from making its aspect gloomy and wild, they serve only
to embellish it, offering to the eye many prospects and beautiful
landscapes, covered with the richest productions of nature, in that
beautiful disorder which it was never in the power of art to imitate.
From thence spring a vast number of little rivulets, which greatly
contribute to the fertility of the country, and serve no less to supply
the wants of the inhabitants than to adorn and heighten the charms
of the plains. All the flat country, from the sea-shore to the foot of
the mountains, is destined for the fruit-trees, under which, as I have
already observed before, the houses of the people of Taiti are built,
without order, and without forming any villages. One would think
himself in the Elysian fields: Public paths, very judiciously laid out,
and carefully kept in a good condition form the most easy
communication with every part of the country.
Its productions. The chief productions of the isle are [99]cocoa-
nuts, plantains or bananas, the bread-fruit, yams, curassol, okras,
and several other roots and fruits peculiar to the country: plenty of
sugar-canes which are not cultivated, a species of wild indigo, a very
fine red and a yellow substance for dying, of which I cannot say
from whence they get them. In general, M. de Commerçon has
found the same kinds of vegetables there as are common in India.
Aotourou, whilst he was amongst us, knew and named several of
our fruits and legumes, and a considerable number of plants,
cultivated by the curious, in hot-houses. The wood which is fit for
carpenters work grew on the mountains, and the islanders make
little use of it; they only employ it for their great periaguas, which
they make of cedar wood. We have likewise seen pikes of a black,
hard and heavy wood among them, very like iron-wood. For building
their common periaguas, they make use of the tree which bears the
bread-fruit. This is a wood which will not split, but is so soft and full
of gum, that it is only as it were bruised when worked with a tool.
It does not This isle, though abounding with very high
appear that mountains, does not seem to contain any minerals,
there are any
mines.
since the hills are every where covered with trees
and other plants[100]. At least it is certain that the
islanders do not know any metals. They give the same name of
aouri, by which they asked us for iron, to all the kinds of metals we
could shew them. But in what manner they became acquainted with
iron, is not easily understood; however, I shall soon mention what I
think on this subject. I know of only a single rich There are fine
article of commerce, viz. very fine pearls. The wives pearls.
and children of the chief people wear them at their ears; but they
hid them during our stay amongst them. They make a kind of
castanets of the shells of the pearl-oyster, and this is one of the
instruments employed by their dancers.
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!

textbookfull.com

You might also like