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

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

The document is about 'Spring 5 Recipes: A Problem-Solution Approach', 4th Edition by Marten Deinum and others, providing solutions to common problems in Spring development. It includes chapters on various Spring topics such as MVC, REST, security, and data access, along with practical examples. Additionally, it offers links to other related resources and books for further learning.

Uploaded by

lemoiragnove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
10 views

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

The document is about 'Spring 5 Recipes: A Problem-Solution Approach', 4th Edition by Marten Deinum and others, providing solutions to common problems in Spring development. It includes chapters on various Spring topics such as MVC, REST, security, and data access, along with practical examples. Additionally, it offers links to other related resources and books for further learning.

Uploaded by

lemoiragnove
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Spring 5 Recipes: A Problem-Solution Approach

4th Edition Marten Deinum download

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

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

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/

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/

Android Recipes A Problem-Solution Approach Dave Smith

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

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

https://textbookfull.com/product/raku-recipes-a-problem-solution-
approach-j-j-merelo/
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/

C Recipes - A Problem-Solution Approach 1st Edition


Shirish Chavan

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

JavaScript Recipes: A Problem-Solution Approach 1st


Edition Russ Ferguson

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

wxPython Recipes: A Problem - Solution Approach 1st


Edition Mike Driscoll

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

MATLAB Recipes: a problem-solution approach 2nd Edition


Michael Paluszek

https://textbookfull.com/product/matlab-recipes-a-problem-
solution-approach-2nd-edition-michael-paluszek/
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
Later, when I could sleep no more, and had made my desert toilet, I
stood in the doorway, and saw the two Indians coming back as in
the morning: the woman with a bundle of fire-wood on her
shoulders, the man walking empty-handed and burdenless before
her. I turned to the station-keeper, and pointing to the bundle she
had brought in the morning, and which lay untouched by the wall, I
said, indignantly:
"It seems to me you need not have sent the poor woman out in the
blazing sun to gather fire-wood, when you had not even used this.
You might have waited till now."
"She—she would have been somewhere else in the blazing sun; she
was just going—" And he stopped—as he had spoken—in haste, yet
with some confusion.
I cast a pitying look on the woman, which, however, she heeded no
more than the rose-pink and pale-gold sunset-clouds floating above
her, and then wandered slowly forth toward the hill, which I meant
to climb while the day was going down.
When I reached the top, the light, flying clouds had grown heavy
and sad, and their rose hue had turned into a dark, sullen red, with
tongues of burning gold shooting through it—the history of Arizona,
pictured fittingly in pools of blood and garbs of fire. But the fire died
out, and a dim gray crept over the angry clouds; and then, slowly,
slowly, the clouds weaved and worked together till they formed a
single heavy bank—black, dark, and impenetrable.
Just as I turned to retrace my steps, my eyes fell on a group of low
bushes, which would have taken the palm in any collection of those
horribly dead-looking things that ladies call phantom-flowers. So
pitilessly had the sun bleached and whitened the tiny branches, that
not a drop of life or substance seemed left; yet they were perfect,
and phantom-bushes, if ever I saw any. How well they would look on
those graves below, I thought, as I approached to break a twig in
remembrance of the strange sight. But how came the red berries on
this one? I stooped, and picked up—a rosary; the beads of red-
stained wood, the links and crucifix of some white metal, and
inscribed on the cross the words, "Souvenir de la Mission." How had
it come there? Had ever the foot of devout Catholic pressed this
rocky, thorny ground? Of what mission was it a gift of love and
remembrance? Surely it had not lain here a hundred years—the gift
of love from one of the Spanish padres of the Arizona Missions to an
Indian child of the church! Or had it come from one of those
California Missions, where the priests to this day read masses to the
descendants of the Mission Indians? Yonder, in the west, with the
purplish mists deepening into darkness in its cleft sides, was the
mountain which to-morrow would show us "Montezuma's face," and
here lay the emblem of peace, of devotion to the one living God.
Perhaps the station-keeper could solve the mystery; so I hastened
back through the gloom that was settling on the earth, unbroken by
any sound save the distant yelping of a coyote, who had spied me
out, and followed me, as though to see if I were the only one of my
kind who had come to invade his dominion.
"See what I have found!" I cried exultingly, when barely within
speaking distance of the station-keeper, who stood within the
doorway.
In a moment he was beside me, calling out something in his Indian-
Spanish, which seemed to electrify the woman, who still sat by the
adobe wall. Springing up with the agility of a panther, she was by my
side, pointing eagerly to my hand holding the rosary.
"What does she want?" I asked, in utter consternation.
"The rosary; give her the rosary"—the barefooted man was speaking
almost imperiously—"it's hers; she has the best right to it."
"Gladly," I said; but she had already clutched it, and turned tottering
back to the mud-wall, against which she crouched, as though afraid
of being robbed of her new-found treasure.
The man turned to me in evident excitement: "And you found it!
Where? She has been hunting for it these years—day after day—in
the blazing sun and streaming rain; and you found it. Well, old
Screetah's eyes are getting blind—she's old—old."
"But her son might have found it, if he had looked; for I found it just
up on the hill there," I suggested.
"He's not her son; only an Indian I kept to look after her, kinder; for
she's been brooding and moping till she don't seem to notice
nothing no more. But now she's found it, maybe she'll come round
again, or go on to Sonora, where, she says, her people are."
"How came she to lose it, then, if it was so precious?"
"She didn't lose it—but, I forget everything; supper's been waiting
on; if you'll eat hearty, I'll tell you about those beads after a while.
The moon won't rise till after ten, and you've good three hours yet."
I was so anxious to hear about the beads, that I would not give the
man time to wash dishes; though he insisted on putting away the
china cup and plate, which he kept for State occasions, when he saw
my disposition to let Bose make free with what was on the table—
table being a complimentary term for one of the ambulance-seats.
In the days when this had been a military post, garrisoned by but
one company of the —— Infantry, the station-keeper had been an
enlisted man, and the servant of Captain Castleton, commanding the
camp and company. Young, handsome, and generous, the men were
devoted to their captain, though as strict a disciplinarian as ever left
the military school. The little settlement springing up around the
camp was chiefly peopled by Indians and Mexicans, and only two or
three Americans. When Captain Castleton had been here just long
enough to get desperately tired of the wearisome solitude and
monotony of camp, and had put in motion whatever influence his
friends had with the authorities at head-quarters to relieve him of
the command of the post and the inactive life he was leading, an
Indian woman and her daughter came into the settlement one
evening, and found ready shelter with the hospitable Mexicans. That
she was an Indian was readily believed; but that the girl with her
belonged to the same people, was not received with any degree of
faith by those who saw her. She was on her way back to Sonora, she
said, to her own people, from whence she had come with her
husband, years ago, along with a pack-train of merchandise, for
some point in Lower California. From there she had gradually drifted,
by way of San Diego, into California, up to Los Angeles, and on to
some Mission near there, where she had lived among the Mission
Indians, after her husband's death, and where Juanita had been
taught to read, write, and sing by the Mission priests.
At last Screetah had concluded to go back to Sonora, and had
drifted downward again from Los Angeles, to Temescal, to Temacula,
to Fort Yuma, and through the desert, till, finally, some
compassionate Mexicans had carried her and the girl with them
through the last waterless stretch to this place. The girl, with her
velvety eyes and delicately turned limbs, soon became the favorite
and the adored of every one in camp and settlement; and, though
that branch of her education to which her mother pointed with the
greatest pride—reading and writing—had never taken very deep root
in the girl's mind, she sang like an angel, and looked "like one of
them pictures where a woman's kneeling down, with a crown around
her head," while she was singing. Indeed, the religious teachings of
the good priests seemed to have sunk deeply into the gentle heart
of Juanita, and her greatest treasure—an object itself almost of
devotion—was a rosary the priest had given her on leaving the
Mission. It had been impressed on her, that "so long as these beads
glided through her fingers, while her lips murmured Aves and Pater-
nosters, night and morning, so long were the angels with her. Did
the angels take the rosary from her—which would happen if Juanita
forgot the teachings of the priests, and no longer laid her heart's
inmost thoughts before the Blessed Mother—then would she lose her
soul's peace and her hopes of heaven; and she must guard the
sacred beads as she would her own life."
There was no point of resemblance between Juanita and the old
Indian woman; and the girl, though warmly attached to her, declared
that she was not her mother, only her nurse or servant. Her mother,
she said, had been a Spanish Doña, and her father a mighty chief of
his tribe, whose head had been displayed on the gate of some
Mexican fortress for weeks after it had been delivered to the
Government by some treacherous Indian of his band. Juanita's
personal appearance, the fluency with which she spoke Spanish, her
very name even, seemed to confirm her accounts, dim and confused
as the recollections of her earliest childhood were; nevertheless, she
had "Indian in her," as the man said, for she proved it before she
died.
But to return to the time of their arrival in camp. Screetah seemed in
no hurry to resume her journey through the burning desert; and, as
Captain Castleton said, he would no doubt have retained her by
force rather than let her drag the poor child through the waterless
wastes into sure destruction. He had given them an old tent after
they had been with their Mexican friends for nearly a week; and
when these same Mexicans left the camp, the two women were
given possession of their house. Here it became a source of never-
ending delight to the old Indian that all the choice things by which
she set such store, and which among her "civilized" Indian friends
had been so scarce, as coffee, sugar, and bacon, were served out to
her as though they rained down from the sky. But to do Screetah
justice, the sweetest side of bacon and the biggest bagful of sugar
never gave her half the pleasure that she felt when one of the
soldiers gave to Juanita a lank, ragged pony, which, on a scout, he
had bought, borrowed, or stolen from an Indian at the Maricopa
Wells. Her time was now pretty equally divided between the rosary
and the pony, which, in time, lost its ragged, starved appearance,
under her treatment, and retained only its untamable wildness, and
the unconquerable disposition to throw up its hindlegs when running
at full tilt, as though under apprehension that the simple act of
running did not give an adequate idea of its abilities. At first, Captain
Castleton, highly amused, would call for his horse when he saw
Juanita battling with her vicious steed on the plain near camp, in
order to witness the struggles of "the wild little Indian" near by. But,
after awhile, they would ride forth together, and dash over the level
ground or climb up to the highest point of the hill—Juanita's voice
ringing back to the camp almost as long as she was in sight,
chanting some wild anthem, in which seemed blended the joyous
strains of the heavenly band and the wild song of the savage when
he flies like an arrow through his native plains.
Old Screetah's low-roofed adobe had assumed quite an air of
comfort through the exertions of some good-natured soldiers, and
more particularly through the manifestations of Captain Castleton's
favor. From a passing pack-train, laden with Sonora merchandise, he
had bought the matting that covered the mud-floor; the sun-baked
pottery-ware was Screetah's greatest boast, as it came from the
same province—her birthplace; and the bright-colored Navajo
blanket had been bought with many a pound of bacon and of coffee
—articles more precious far in this country than the shining metal
which men risk their lives to find here. No wonder that the captain
passed more of his time in Screetah's hut than in his white wall-tent,
where the sun, he said, blinded him, beating on the fly all day long;
and where the slightest breeze brought drifts of sand with it. That
Juanita seemed to live and breathe only for him had come to be a
matter of course. Among the Mexicans it was accepted that at a
certain phase or change of the moon there had been some words
spoken, or some rite performed, by old Screetah, which, according
to their belief, constituted Indian marriage; and both seemed happy
as the day is long.
Like a thunderbolt from the clear sky it struck him one day, when the
mail-rider brought official letters advising him of the change that had
been made in his favor. He was directed to proceed at once to Drum
Barracks, there to await further orders! It was, perhaps, the first
time that he experienced the curse of having his most ardent wishes
gratified. For days he wandered about like the shadow of an evil
deed—restless from the certainty of approaching judgment, and
fainting with the knowledge that he was powerless to ward off the
coming blow. It was hard to make Juanita understand the situation,
and the necessity of parting; but when she had once comprehended
that she was to be abandoned—a fate which, to her, meant simply to
be thrust out on the desert and left to die—the Indian blood flowed
faster in her veins, and rose tumultuously against the fair-faced
image that her heart had worshipped. What was life to her with the
light and warmth gone out of it? He was leaving her to die; and die
she would.
When the little cavalcade, ready and equipped for the march, was
about to leave the camp, Juanita was nowhere to be found. For
hours the captain sought her in every nook they had explored
together, and called her by every endearing name his fancy had
created for her. Juanita's pony was gone from his accustomed place,
and he knew it would be useless to await her return. Captain
Castleton was not a coward; the searching glances he sent into
every cañon they passed, and among the sparse trees on their road,
were directed by the burning desire to meet the dearly loved form
once more; but they would not have quaked had the arrow Juanita
knew so well to speed, sank into his heart instead.
Days passed ere Juanita returned; and, though Screetah grovelled at
her feet with entreaties not to leave her again, and the soldiers
showed every possible kindness and attention to the girl, she was
seldom seen among them. Sometimes, at the close of day, she was
seen suddenly rising from some crevice in the hill, where she had
clambered and climbed all day; but oftener she was discovered
mounted on her pony, her long, black hair streaming, her horse in
full gallop, as though riding in pursuit of the setting sun. No word of
complaint passed her lips; no one heard her draw a sigh, or saw her
shed a tear; and none dared to speak a word of comfort. But when
Screetah tried to cheer her, one day, she held out her empty hands,
saying, simply, "I have the rosary no more!" Then Screetah knew
that all hope was lost, and she pleaded no more, but broke the
beautiful, sun-baked pottery, tore the matting from the floor, and
crouched by the threshold from noon to night, and night till morning,
waiting quietly for the silent guest that she knew would some day,
soon, enter there with Juanita.
One day, she came slowly down from the hill and entered the dark
adobe, where Screetah sat silent by the door.
"A little cloud of dust is rising on the horizon," she said to the old
Indian, "and I must prepare;" and Screetah only wailed the death-
song of her race.
Though Juanita had returned on foot, she had ridden away on the
pony the day before, and the soldiers started out to look for the
animal, thinking it had escaped from her, or had been stolen by
some marauding Indian. But they found the carcass not far from
camp—with Juanita's dagger in the animal's heart. The next day she
went to the top of the hill again, and when night came, she said,
"The cloud grows bigger." On the third day, when Juanita lay
stretched on the hard, uncomfortable bed, denuded of all its gay
robes and blankets, a sudden excitement arose outside, such as the
signs of anything approaching camp always create. A hundred
different opinions were expressed as to what and who it could be.
Nearer and nearer came the cloud of dust, and a cry of surprise
went up, as the horse fell from fatigue on the edge of the camp, and
the rider took his way to old Screetah's hut.
What passed within those dark, low walls—what passionate appeals
for forgiveness, what frantic remorse and bitter self-accusations they
echoed—only Screetah and the dying girl knew. The old Indian was
touched, and tried to plead for him; but Juanita seemed to heed
neither the man's presence nor the woman's entreaties. She died
"with her face to the wall," and the words of forgiveness, which he
had staked life and honor to hear, were never uttered by those
firmly-closed lips.
With the day of Juanita's death commenced the old Indian woman's
search for the rosary, and she tore her hair in desperation when they
laid the girl in her narrow cell before she had found it. Day after day,
the search was continued. Was it not the peace of Juanita's soul she
was seeking to restore? After awhile the camp was broken up, by
orders from district head-quarters, and a forage-station established.
Our friend, whose term of service had expired, was made station-
keeper, and, one by one, the people from the settlement followed
the military, till, at last, only he and old Screetah were left of all the
little band that once had filled the dreary spot with the busy hum of
life.
HETTY'S HEROISM.
"But, father, you don't really mean to watch the old year out, do
you? It's only a waste of candles, and the boys won't want to get up
in the morning."
"Mebbee so, mother; but New Year's Eve don't come every day; so
let's have it out." And old man Sutton tipped back his chair, after
filling his pipe, and looked contentedly up at the white ceiling of the
"best room."
Johnny, the younger son of the family, whistled gleefully, threw more
wood on the blazing pile in the fire-place, and then, resuming his
oft-forbidden occupation of cracking walnuts in the best room, said:
"Don't the wind howl, though? Just drives the rain. Golly, ain't it nice
here?"
"You're not to say bad words," broke out his mother, sharply. "Father,
why don't you correct the boy? Such a night as this, too, when—"
"What's that?" interrupted the oldest son, springing from his seat,
and showing a straight, manly form and clear, deep eyes, as he
stood by the door in a listening attitude.
"Coyotes, brother Frank; the ghosts don't come round this early, do
they?" laughed the younger.
"Hush, Johnny! It's some one crying for help—a woman's voice!"
"Tut, tut! where would a woman come from this time o' night, and
not a house within miles of us?"
"A woman's voice, I'll stake my head," insisted Frank, after a
moment's silence in the room.
The mother had laid down her glasses. "Wonder if the boy thinks
Lolita is coming through the storm to watch the old year out with
him?" She laughed as at something that gave her much pleasure,
though the rest did not share her merriment.
They were all three listening at door and window now, and when
Frank threw the one nearest him quickly open, there came a sound
through the din and fury of the rain-storm that was neither the
howling of the wind nor the yelp of the coyote.
"Now what do you say?" asked Frank; and he had already passed
through an inner apartment, and in a moment stood on the porch
again, swinging a lantern and peering out into the dark and rain,
listening for that cry of distress. It came in a moment—nearer than
they had expected it.
"Help! help! oh, please come and help!"
"The d—l!" was old man Sutton's exclamation; not that he really
thought the slender little figure perched on the back of the tall horse
was the personage mentioned—it was only a habit he had of
apostrophizing.
The horse had stopped short and was breathing hard, and the
prayer for help was frantically repeated by the rider. "Come quick,
and help the poor fellow; I've been gone so long from him—oh! do
come!"
"What poor fellow—and where is he?" asked the old man, in
bewilderment.
"The stage-driver—and he's lying near the old Mission, with his leg
broken. The horses shied in the storm and overturned the stage, and
I was the only passenger, and I crept out of it, and the driver
couldn't move any more, and told me to unhitch the horses and
come this way for help, and—oh! do come now!" She ended her
harangue, delivered with flying breath and little attention to rhetoric
or inter-punctuation.
"And you came those nine miles all alone, gal?" asked the old man.
"Oh, I think I must have come a hundred miles," she replied, with a
wild look at the faces on the porch and in the open doorway; "and it
is so cold!" She drew the dripping garments closer about her, while
father and son consulted together, with their eyes only, for a brief
moment. Then the old man said she must be taken in, and they
must get the wagon ready, and waken Pedro and Martin.
Without a word Frank gave a lantern to Johnny, lifted the girl from
the horse and carried her into the room, brushing the drenched hair
back from her face, when he sat her down, as he would have done a
child's. But she pleaded excitedly, "Indeed I cannot stay—let me go
back, and you can follow."
"So you shall go back, my gal," said Mr. Sutton, "as soon as the
wagon is ready. See how she's shivering, mother; get her some hot
tea, and give her your fur sack—for she'll go back with us or die."
"My fur sack?" repeated the old lady, incredulously; "my best sack—
out in this rain!"
"Best sack be ——," he shouted, angrily; "I'll throw it in the fire in a
minute!" And the best sack quickly made its appearance, in spite of
the threat of speedy cremation.
The tea was brought by Johnny, hastily drank, and then the girl
repeated her wish to move on. Frank's own cloak was thrown over
"the best fur sack"—not, I fear, so much from a desire to save this
garment as from the wish to keep the shrinking form in it from
shivering so painfully.
It was New-Year's day—though the light had not yet dawned before
the sufferer was comfortably lodged at the Yedral Ranch, and Hetty,
as well as the Sutton family, slept later into the morning than usual.
The sun had risen as serenely cloudless as though no storm had
passed through the land but yesternight; and Father Sutton, thinking
he was the first one up, was surprised to encounter Hetty with
Johnny, her new-found cavalier. He hailed her in his unceremonious
fashion: "I'm glad to see you up bright and early, gal—make a good
farmer's wife some day. Did you come down this way to live on a
ranch?"
"No, sir; I came to teach school. Your name is among those of the
gentlemen who engaged me."
"The ——! Are you the new school-marm? Then you're Miss——"
"Hetty Dunlap is my name."
He held out both hands. "A happy New-Year to ye, Hetty Dunlap—
and happy it'll be for all of us, I'm thinking; for a gal that's got so
much pluck as you is sure to know something about teachin' school.
Here, Johnny, how d'ye like your teacher?"
Now, Johnny had drawn back with some slight manifestation of
disfavor when Hetty's true character came to light. But she laid her
hand on his shoulder in her shy yet frank manner, and said quickly:
"I had already selected Johnny as a sort of assistant disciplinarian. I
am so little that I shall want some one who is tall and strong to give
me countenance;" which at once restored the harmony between
them. They went in to breakfast together, during which meal it was
decided by Father Sutton that Hetty was to live in his family, though
"the Price's" was the place where, until now, the teachers had made
their home, being nearest to the school.
"But then," said the old man, "if the Rancho Yedral can't afford a
mustang for such a brave little rider every day of the year, then I'll
give it up;" and he slapped his hat on and left the house.
"Yes," Frank commented rather timidly, "you are brave—a perfect
heroine. And yet you are so very small." She was standing in just the
spot where he had brushed the hair out of her face last night, and
perhaps his words were an apology.
"True," she assented, "I am small; not much taller than my sister's
oldest girl, and she is only twelve."
"You have a sister?"
"Yes, in the city; and she has six children." Her voice was raised a
little, her nut-brown eyes looked into his with an unconscious appeal
for sympathy, and her delicate nostrils quivered as in terror—which
the bare recollection of the little heathens seemed to inspire her
with.
"And did you live at her house?—have you neither father nor mother
living?"
"Neither. How happy you must be—you have so kind a father and so
good a mother—"
The "good mother" came in just then, shaking her best sack
vigorously, and lamenting, in pointed words, the "ruination" of this
expensive fur robe—calling a painful blush to Hetty's cheek as well
as Frank's. The young man tried vainly to make it appear a pleasant
joke. "Indeed, mother, you ought to look upon that piece of fur as a
handsome New-Year's gift—you have my promise of a new fur sack
as soon as I go to the city. And isn't my word good for a fur sack?"
he asked, laughingly.
"Yes," said the good mother. "I know your extravagance well
enough; but, to my notion, you can afford such things better after
you've married Lolita, than before."
Frank bit his lips angrily, and turned away—but not before Hetty had
seen the hot red that flushed his cheek.
Toward noon there was loud rejoicing on the porch, and Hetty,
looking from her window, saw Mrs. Sutton welcoming a tall, dark-
eyed girl of about twenty, whose companion—her brother, to all
appearance—seemed several years her senior.
This girl, Lolita Selden, the daughter of an American father and a
wealthy Spanish mother, was a fair specimen of the large class
represented by her in California. Generous and impulsive, as all her
Spanish half-sisters are, neither her piecemeal education, nor the
foolish indulgence of the mother, had succeeded in making anything
of her but an impetuous, though really kind-hearted woman. In the
brother's darker, heavier face, there was less of candor and
sympathy, and his figure—though he had all the grace and dignity of
the Spaniard—was lacking in height and the breadth of shoulder that
made Frank Sutton look a giant beside him.
It was some time before our heroine was introduced to the pair; not,
indeed, till dinner was on the table, though Frank had repeatedly
hinted to his mother that Hetty might not feel at liberty to make her
appearance among them without being formally invited—to which he
received the cheering response that "he was always botherin'."
When they met, it was hard to say whether Hetty was more
charmed with Lolita's stately presence and simple kindness, or Lolita
with Hetty's heroism. The brother, too, seemed lost in admiration of
Hetty's heroic conduct or Hetty's pretty face—a fact which escaped
neither Frank nor his mother, for she commented on it days
afterward. "What a chance it would be for a poor girl like this 'ere
one, if she could make a ketch of young Selden, and he married
her!"
"What! that black-faced Spaniard?" but Frank's generous heart
reproached him even while he spoke, and his mother took
advantage of his penitence and charged him with a message to
Lolita, that needed to be delivered the same day. When, therefore,
after school-hours, Frank returned bringing with him both Hetty and
Lolita—the latter was visiting her new friend at the school-house—
the mother was well pleased, and spoke more kindly than she had
yet spoken to the new teacher.
"Old man" Sutton, too, had many a pleasant word for both young
girls; and altogether Hetty soon realized that home could be home
away from her sister's house and the six plagues it held.
Spring came into the land, dressing in glossier green the grayish
limbs of the white-oak in the valley, opening with balmy breath the
blossoms of the buckeye by the stream, and covering with gayest
flowers the plain and the hillside; while in some shady nook the
laurel stood, shaking its evergreen leaves in daily wonderment at the
dress changes and the youthful air all nature had put on. The wild
rose creeping over the veranda of the Yedral Ranch shed its perfume
through the house, and cast its bright sheen upon the very roof-tree,
a passion-vine, in sombre contrast, rearing its symbolic blossom
cheek to cheek with the rosy flower-face of the gay child of Castile.
Long since had the stage-driver left the Yedral Ranch, grateful for
kind treatment received, his head and heart full of a firm conviction
on two points: The first, that there was just one man good enough
to be Hetty Dunlap's husband, and that that man was Frank Sutton:
the second, that there was only one woman good enough to be
Frank's wife, and she Hetty Dunlap.
He had resumed his old post, and many a pleasant word and
startling bit of news did he call out to Hetty and her friends when
they were down by the "big gate," as he drove by very slowly, so as
to enjoy conversation as long as possible. George was a deal
pleasanter when Hetty was there by herself, or at least without
Lolita; and once, when, by chance, Hetty and Frank were there
alone together, he called down, regardless of the staring passengers
in the coach, "That's the way I like to see things; two's good
company, and three's none. Don't see what you want to be luggin'
that Spanish gal round with you for, Frank; she ain't none o' your'n
nohow, and never will be, nuther."
Before the flush had died on her face, Hetty found her arm drawn
through Frank's, and as they slowly bent their steps homeward, the
mind of each seemed absorbed in the contemplation of some
intricate puzzle, on the solving of which depended their whole future
welfare. Then Frank raised his merry, twinkling eyes and charged her
with being hopelessly enamored of George, the stage-driver, defying
her to say that she had not just then been thinking of him, as he
knew by her absent looks.
"I—I was only looking down that way, and thinking there is no
lovelier spot on earth than Yedral Ranch." She stopped abruptly;
what she was saying now to cover her confusion, she had said a few
days ago, from the fulness of her heart, to Lolita, strolling along this
same road; and the Spanish girl had answered impulsively, "Yes; and
you shall always make your home here when I—" Then she had
stopped, crimson in the face, and Hetty had not urged her to finish
the sentence.
But Frank, with quickly altered tone, asked softly, "Do you like it so
well, Hetty—really and truly? And have you not wanted often to go
back to the city?"
"To the city?" she repeated, with a little shiver; "no—no!"
The call of a partridge from behind the nearest manzanita bush
warned them that young Johnny was there, and the next moment he
appeared before them—his mother's ambassador to Hetty. "Would
she be kind enough just for once to help with the cake? His mother
had burnt her right hand, and she could not stir the batter with her
left."
"And could not you have done it 'just for once' as well?" asked
Frank, impatiently; at which question Johnny opened his eyes wide.
"She didn't ask me," he said; and then they all went silently to the
house.
To do Mrs. Sutton justice, she was loud in her praises of Hetty's
obliging disposition, and Hetty's proficiency in cake-baking, that
evening at tea; and particularly to Julian Selden, who was there with
his sister, did she untiringly sing Hetty's perfections. This seemed to
have the effect of making the young Spaniard bolder and more
desirous of pushing his suit, for the very next evening they came
home from Hetty's school a partie carrée—Lolita, her brother, Hetty
and Frank.
The facts of the case were that, following a suggestion of Frank's,
Johnny, on Julian's second attempt to escort Hetty home, had kept
close by her side during the whole ride, much more to Hetty's
delight than Julian's. In consequence, Julian had been wise enough
to bring Lolita with him; and Frank, though chagrined, was better
pleased to find them both at Hetty's school than one alone.
Through the spring and far into the summer they met almost daily in
this way; and sometimes, though Mother Sutton's invitations to
Lolita and her brother to "come every day—every day," were loud
and vociferous, the brother and sister would return to their own
home after a protracted ride, leaving Hetty and Frank to find their
way back to Yedral Ranch alone. Hetty thought she could see a cloud
on Mrs. Sutton's brow whenever this happened; and dear as those
rides were to her, she avoided them whenever she could. Unhappily
(Frank did not consider it so), while out alone together one day,
Hetty's saddle-girth broke, and though she sprang quickly to the
ground, Frank's nerves were so unstrung, he declared, that he could
not at once repair the damage, but had to convince himself, by slow
degrees, that she really was not hurt or frightened. Consequently, it
was later than usual when they reached home; and Mother Sutton,
darting a quick look to see that the door had closed behind Frank,
who had explained the cause of delay, muttered something about
"cunning minxes, who had neither gratitude nor shame," and then
tramped out of the room, leaving Hetty with cheeks burning and
eyes strangely bright under the tears rising in them.
Next morning she made much ado over a sprained ankle, which was
not so painful as to keep her at home, but just bad enough to cause
her to ride slowly to school with Johnny and home again before
school-hours were fairly over. I fear that she was a "designing minx,"
for, if she managed, by keeping her room to evade Frank's
questioning glance and Mother Sutton's hostile looks, she managed
no less to escape an honor which, according to this good lady's
statement, corroborated by Lolita's more than usual tenderness,
Julian Selden had meant to confer upon her. But she could not stay
in her room forever; and Father Sutton dragged her out of it one
day, challenging her to tell the truth ("and shame the devil"), by
acknowledging that something had hurt her beside the sprained
ankle. Had Mrs. Sutton shown no spite openly against "the gal"
before, it broke out now, in little sharp speeches against women
"tryin' to work on the sympathy of foolish young men. Her boys, she
knew, couldn't never be ketched that way by no white-faced—"
"Will yer be still now!" thundered the old man, taking the pipe from
between his lips and pointing with it to Hetty, who at this moment
was really the white-faced thing the old lady had meant to call her.
"Johnny," said Hetty, next morning, on their way to school, "I think—
I'll go home when vacation begins, and—"
"Why, what d'you mean?" asked the boy, startled out of all proper
respect.
"Just what I say;" and she enumerated her reasons for considering it
her duty to return to her lonely sister and the six pining children;
and it was a matter of doubt whether Johnny's lips quivered more
during the recital, or Hetty's. But when the school-house was
reached, Johnny was a man again; and if he did blubber out loud
when he told his elder brother of it, late in the evening, down by the
big gate, nobody but Frank heard him, and his lips were rather white
when next he spoke.
"You asked me for that Mexican saddle of mine some time ago,
Johnny. You are welcome to it."
"I don't want no Mexican saddle," replied Johnny, in a surly tone,
and without grammar; but looking into his brother's face, he said,
"Thank you, Frank. I'd say you're 'bully,' only Hetty said it wasn't a
nice word."
In the course of the week Father Sutton, in his character as such,
and as school director, was made acquainted with Hetty's intention.
In both characters he protested at first, but yielded at last. He
walked out with "the gal" one evening, as though to take her over
the ranch for the last time, and then artfully dodged away when
Frank—by the merest accident—came to join them. Left alone with
this young man, Hetty trembled, as she had learned to tremble
under his mother's scowling looks and half-spoken sentences. He
spoke quietly, at first, of her going away; but her very quietness
seemed after a while to set him all on fire.
"Hetty," he cried, "are you then so anxious to go—so unwilling to
stay, even for a day, after the school closes? Is there nothing—is
there no one here you regret to leave behind you?"
Poor little Hetty! How they had praised her for her heroism once.
There was no praise due her then, as she had protested again and
again. Now she was the heroine, when she answered, though with
averted face and smothered voice, "Nothing—no one;" adding,
quickly, "you have all been so kind to me that naturally I shall feel
homesick for the Yedral Ranch, and shall be so glad to see any of
you when you come to the city."
Frank had heard "the tears in her voice," and though he turned from
her abruptly, it was not in anger, as she fancied.
"Father," he said, a day or two later, "I don't know but I'll take a run
over the mountains, now harvesting is over, and there seems
nothing particular for me to do."
"Please yourself and you'll please me, Frank," was the answer. "Got
any money? You kin git it when you want it."
Then there was nothing more said about the journey, and Frank,
making no further preparations, seemed to have forgotten all about
it.
When Hetty was lifted into the little wagon that took herself and
trunk to the big gate, she repeated her hope of sooner or later
greeting the members of the Sutton family in San Francisco.
"Not soon, I'm afeard, Miss Hetty; me an' father and Johnny never
goes to the city, and as for Frank—I reckon he'll want to git married
first, and bring Lolita 'long with him."
Martin, who was driving, probably knew the meaning of the fire in
the old man's eye, for he whipped up the horse and drove off, as
though "fearing to miss the stage," as he explained at the turn of
the road.
Altogether, George showed neither as much surprise nor pleasure as
Hetty had faintly expected him to evince. When they reached the
first town he came and stood by the open coach window, after the
customary halt, drawing on his gloves first, and then pointing out,
with great exactitude, where the old adobe tavern had formerly
stood, on the opposite side of the street.
During this interesting conversation, some tardy passengers came
out of the hotel, with hasty steps, and mounted to the top of the
stage with much hurried scrambling. Then George left Hetty's
window, mounted his throne, and drove on.
We need not say how Hetty's heart sank with the sinking sun; and
only when George came out of the station-house where they had
taken supper, ready and equipped for the night's drive, did a light
rise in her eyes.
"I thought you stopped at this station," she said, as he again leaned
at her window, while the same hasty steps and confused scrambling
on the top of the stage fell, half unconsciously, on her ear.
"Well—yes. As a general thing, I do. But me and Dick's changed off
to-night, so't I can see you into the cars to-morrow morning."
"How tired you will be," she remonstrated.
"Well—mebbe so. Howsomever, Miss Hetty, you didn't stop to think
whether you'd be tired when you started out to find help for me, last
New-Year's eve." And Hetty blushed, as she always did, when her
heroism was spoken of.
George's eyes did look heavy the next morning; but he still kept the
lines, lounging up to the coach-window about the time the stage
was ready to start, and always pointing out something of interest on
these occasions. Once, indeed, when she fancied that her ear caught
the sound of a familiar footfall on the porch of the tavern they were
about to leave, he was so anxious she should see the owl just
vanishing into the squirrel-hole, on the opposite side of the road,
that he laid his hand on her arm to insure her quick attention, just
as she was about to turn her head back in the direction of the porch.
Then came the usual climbing and scrambling overhead, and directly
George mounted, too, and drove on.
The shrill whistle of the locomotive seemed to cut right through
Hetty's heart; and the loneliness she had never felt away down the
country, now suddenly took possession of the girl's soul. No one
could have been more attentive than George; the best seat in the
cars was picked out for her; the daily papers laid beside her, and
then—then she was left alone. George only, of all her down-country
friends, had made the unconditional promise to visit her in San
Francisco. She was thinking of this after he had left her, and she sat
watching the cars filling with passengers for the city—travellers
gathered together here from watering-place and pleasure-resort,
from dairy-ranch and cattle-range. Was there another being among
these all as lonely as she? And she turned her face to the window,
and looked steadily over toward the hills, yellow and parched now, in
the late summer—so fresh and green from the winter's rains when
she had last seen them. It looked as if her life, too, were in the "sere
and yellow;" the heavy, throbbing pain that was in her heart and
rising to her throat—would it ever give place again to the bright
fancies she had indulged in when coming this way—oh! how many
weeks ago? She tried to count; but counting the weeks brought the
events of each in turn before her, and she desisted; she must keep a
calm face and a clear eye.
She heard the cry of the fruit-venders outside, and saw their baskets
laden with fruits, tempting and delicious, raised to the car-windows,
where passengers had signified their wish to purchase. Mechanically,
her eyes followed the movements of the young man in front of her.
Grapes, with the dew still on them; apples, with one red cheek, and
peaches with two; plums, larger than either, and far more luscious,
were transferred from the heavy basket into the lap of the lady
beside him—evidently his new-made wife—who said, "Thanks, dear,"
with such a happy, grateful smile, that Hetty grew quite envious. She
tried to think it was of the fruit; but pending the decision she laid
her head on the back of the seat in front of her, and before she
thought of what she was doing, the tears were trickling down her
cheeks. Then her shoulders began to jerk quite ridiculously, and she
was ready to die of shame, when a light hand was laid on them, and
her name was spoken.
"Hetty!" the voice said again; but she did not raise her head, only
answering, "Yes," as she would have done in a dream.
"Hetty!" once more, "see what I have brought you." Apples, and
peaches, and plums—all these things were showered into her lap,
and when she raised her head, she looked at them steadily a
moment, and then said, with a long breath, "Oh, Frank!" before she
turned to where he sat. As she stretched out both hands to meet
his, the fruit, now forgotten, fell plump, plump, to the floor, and
rolled all over the cars; and when the train moved slowly away from
the depot a little later, Hetty, looking up at the lady in front of her,
said to herself, that she envied her no longer—neither the apples nor
—. She made a full stop here; perhaps because of George's sudden
appearance, and the hilarity in which he and Frank indulged.
"Oh, Miss Hetty!" he laughed; "I couldn't make you see that owl this
morning, could I?"
"No; but I think I must have been as blind as an owl myself, not to
have seen whom you were hiding," she answered, taking the
contagion.
Again shrieked the locomotive, but not with the "heart-rending" cry
of a while ago; and George, bringing their hands quickly together in
his parting clasp, sprang from the cars and left Frank and Hetty
there.
Loud was the anger of good Mrs. Sutton on discovering that Frank
had accompanied Hetty to San Francisco. In vain Father Sutton
disclaimed all fore-knowledge of the young man's intention, and
asserted that Frank had never mentioned a tour to the city. Mrs.
Sutton said she knew the old man was in league with him. At the
end of a week Frank returned without so much as bringing the fur
sack as a peace-offering. In course of time he reconciled his mother
to some extent by again carrying messages to Lolita, and sometimes
bringing Lolita herself in return, just as in Hetty's time.
Autumn came; and still, to the determined schemer's dissatisfaction,
Frank had not yet secured the prize she so coveted for him. The
season brought with it many cares as well as pleasures to the
ranchero. At a rodeo, looked upon by the young people generally as
a pleasant entertainment, Frank was the admired of many eyes, as
his lasso unfailingly singled out the animal "in demand," among the
dense herds moving in a circle. The horse he rode was full of fire,
and more impetuous, if possible, than his rider; and Lolita, who was
among the guests at the Yedral Ranch, had never thought Frank so
handsome and so well worth winning before.
To Hetty the white walls and the spacious rooms of the grammar-
school, to which she had returned, seemed a prison and a
wilderness in one. Her sister's house, with the six young Tartars, was
more like Bedlam than ever; but Hetty had grown older and firmer,
and she declared, to her sister's amazement, that unless she could
withdraw herself from the mob unmolested, at her option, she
should seek a home with more congenial associates. The sister
opened her eyes wide, as if only now discovering that Hetty was full-
grown; and she assented silently.
First, after her return, letters from Frank lighted up her life at
intervals. But when the early rains of autumn, after an Indian
summer full of sunny days and glorious memories of vanished
springs, turned to the settled melancholy of "a wet winter," these
letters ceased, leaving in Hetty's existence a blank that nothing else
could fill. Christmas came, with its vacations and merry-makings,
and beside the dull, deep pain in Hetty's heart, there was still the
unselfish wish to give others pleasure, though she herself could
never again feel that glad emotion. From morn to night her deft
hands flew, sewing, stitching, sketching—busy always, yet never for
herself.
It was very near Christmas now—so near that Hetty, eager to have
all things ready for the joyous eve, had sat down to her work
without the usual care for neat appearance. Perhaps it was because
her curls were a little neglected, and her collar was not pinned on
with the usual precision, that her face looked worn this morning; her
eyes were languid, and the flush on her cheeks could not cover the
deficiency of flesh which became painfully visible.
Thus she sat, stitching, ever stitching. The silent parlor, with its
covered furniture and light carpeting, seemed the right place for
ghosts to flit through, and peer, mayhap, with dull, glazed eyes into
the fire, as Hetty caught herself just now. But she drove back the
ghosts—are they not always our own memories, woven out of
unfulfilled wishes, useless regrets, and profitless remorse?—and
hastily resumed her work. The ringing of the door-bell seemed so
much the doing of one of these ghosts, that she paid no attention to
it, but kept on stitching, quietly stitching. Directly the parlor-door
was thrown open, and the Mongolian servitor, looking with calm
indifference on the little streams of muddy water oozing at every
step from the boots of the new-comer, returned to the kitchen,
heedless, to all appearances, of the scream with which Hetty flew to
meet the stranger.
"George!" she cried, "oh! George!" and she clasped the damp arm of
the man, gotten up on the grizzly-bear pattern, as though there
could be no pleasure greater than this in all the world.
Though a man, George was wise enough to know that he was not
indebted to his personal attractions for this affectionate greeting; but
taking both her hands in his, he said, "Yes, Miss Hetty, I've come to
tell you all about it."
At the fall rodeo on the Yedral Ranch, Frank's horse had fallen,
covering its rider with its weighty body. He recovered from a death-
like swoon with wandering mind; and the spine being injured,
according to the doctor's statement, it seemed doubtful that he
would ever leave his bed, except as imbecile or cripple. Reason
returning, Frank felt that his friends' fears of his remaining a cripple
were not without foundation, and a hopeless gloom settled on his
spirit. Many a time, when George had made "fast time" and spent
the half-hour gained at Frank's bed, did Hetty's name rise to his lips;
but it was never pronounced. Only this: looking up out of deep
sunken eyes, one day, quite recently, Frank had said to him,
"George, I shall get well, and not be a cripple. If only—" "It's all
right," had been George's answer; and he had hurried from the
house as though charged with the most urgent commission.
After an hour's conversation, Hetty had only one question to ask.
Looking up with shy eagerness, she almost said below her breath,
"And Lolita?"
For answer, George took the flushed face between his hands.
"You've grown mighty thin, Miss Hetty," he simply said. Then he
continued, with great nonchalance, "Lolita got stuck after the new
schoolmaster—they've got a man in your place. But come, Miss
Hetty, you 'peared to me last New-Year's eve like an angel, in my
distress; suppose you do as much now for Frank Sutton. We can get
down there on New-Year's eve, and give you lots of time to spend
Christmas here first. What d'ye say?"
No lover could have pleaded more earnestly. All her objections were
overruled, and when at last she said, almost breathlessly, "Oh, but
his mother, George!" he answered, with all his honest heart: "It's my
firm belief, Miss Hetty, that you were cut out for a real hero-ine; and
a hero-ine you've got to be to the end of the chapter—which I don't
say but the last trial of your hero-ism will be greater than the first."
And sure enough, on New-Year's eve, came the rumbling of wheels
and the tramp of horses' hoofs close up to the veranda of the ranch-
house on the Yedral. None of the inmates seemed startled, though
none had expected company. Without a word Father Sutton sprang
to the door—alas! that the old man was swifter of foot now than the
young giant of a year ago—caught the lithe figure that sprang from
the stage in his arms and set her down, as Frank had done, in the
middle of the room. But she was not cold, dripping wet now, only
blinded by the light one moment, and the next on her knees by the
lounge, where a pale, haggard man lay stretched. He half raised
himself to catch her in his arms, and for a wonder did not sink back
with the moan that had become so painful to his father's ears. For
once Hetty had cast aside all timidity, and she looked up brightly into
Father Sutton's face, while one arm circled Frank's neck and the
other hand lay unresistingly in his.
"Hey!" shouted the old man; "now we know whose gal you are; I
used to call you mine once. Mother, get some supper; I reckon she is
wellnigh starved and perished with the cold. Lively, Johnny! bring
some more wood; Hetty'll stay for good, and you'll get time enough
to hang 'round the gal to-morrow."
And what a bright to-morrow it was! Such a New-Year's day had
never dawned on Yedral Ranch before. Every one seemed to have
found a treasure, even to Mrs. Sutton. Together with Hetty's trunk
had come a large, promising-looking box, and when Father Sutton
presented this to his better-half, she almost screamed—
"Oh, I know! it's my new fur sack!"
A WOMAN'S TREACHERY.
"How much you resemble Mrs. Arnold!" exclaimed the Doctor's wife,
after an hour's acquaintance, the day we reached Fort ——. It was
not the first time I had heard of my resemblance to this, to me,
unknown lady remarked on. A portion of the regiment of colored
troops to which Doctor Kline belonged, and which we met on their
way in to the States, as we were coming out, had been camped near
us one night; and a colored laundress, who had good-naturedly
come over to our tent to take the place of my girl, who was sick, had
broken into the same exclamation on first beholding me. Captain
Arnold belonged to the same regiment, and was expecting, like all
the volunteers then in the Territory, to be ordered home and
mustered out of service, as soon as the body of regular troops, to
which my husband belonged, could be assigned their respective
posts. Their expectations were not to be realized for some time yet;
and when I left the Territory, a year later, a part of these troops
were still on the frontier.
Fort —— was not our destination; to reach it, we should be obliged
to pass through, and stop for a day or two at, the very post of which
Captain Arnold had command—which would afford me excellent and
ample opportunity for judging of the asserted likeness between this
lady and myself. I must explain why we were, in a measure,
compelled to stop at Fort Desolation (we will call it so). It was
located in the midst of a desert—the most desolate and inhospitable
that can be imagined—in the heart of an Indian country, and just so
far removed from the direct route across the desert as to make it
impracticable to turn in there with a command, or large number of
soldiers; for which reason, troops crossing here always carried
water-barrels filled with them. A small party, however, such as ours
was then, could not with any safety camp out the one night they
must, despite the best ambulance-mules, pass on the desert.
With most pardonable curiosity, I endeavored to learn something
more of the woman who was so much like me in appearance; and I
began straightway to question Mrs. Kline about her. The impression
of a frank, open character, which this lady had made on me at first,
vanished at once when she found that Mrs. Arnold was to be made
the subject of conversation between us.
"Is she pretty?"
"Yes—quite so." Ahem! and looked like me. But my mother's saying,
that there might be a striking resemblance between a very
handsome and a very plain person, presented itself to my memory
like an uninvited guest, and I concluded not to fall to imagining vain
things on so slight a support.
"What kind of a man is Captain Arnold?"
"The most good-natured man in the world."
"Oh!" Something in the manner of her saying this in praise of
Captain Arnold made me think she wanted to say nothing further; so
I stopped questioning.
We left the Doctor and his wife early the next morning, and reached
Fort Desolation at night-fall. The orderly had preceded us a short
distance, and, when the ambulance stopped at the Captain's
quarters, Mrs. Arnold appeared on the threshold, holding a lantern in
her hand. She raised it, to let the light fall into the ambulance; and
as the rays fell on her own face, I could see that she looked like—a
sister I had. The Captain was absent, inspecting the picket-posts he
had established along the river, and would return by morning, Mrs.
Arnold said; and she busied herself with me in a pleasant, pretty
manner. She could not resemble me in height or figure, I said to
myself, for she was smaller and more delicately made; nor had any
one in our family such deep-blue eyes, save mother—we children
had to content ourselves with gray ones.
The night outside was dark and chilly; but in the Captain's house
there were light and warmth, and it was bright with the fires that
burned in the fireplaces of the different rooms—all opening one into
the other. I was forcibly struck with the difference between the
quarters at Fort —— and Mrs. Arnold's home at Fort Desolation.
Comforts (luxuries, in this country) of all kinds made it attractive:
bright carpets were on the floors here; while at the Doctor's quarters
at Fort ——, one was always reminded of cold feet and centipedes,
when looking at the naked adobe floors. Embroidered covers were
spread on the tables and white coverlets on the beds; while at the
Doctor's all these things were made hideous by hospital-linen and
gray blankets. Easy-chairs and lounges, manufactured from flour-
barrels, saw-bucks, and candle-boxes, were made gorgeous and
comfortable with red calico and sheep's-wool; but the crowning glory
of parlor, bed-room, and sitting-room was a dazzling toilet-set of
china—gilt-edged, and sprinkled with delicate bouquets of moss-
roses and foliage.
"Where did you get it?" I asked, in astonishment—not envy.
"Isn't it pretty?" she asked, triumphantly. "The Captain's
quartermaster, Lieutenant Rockdale, brought it from Santa Fé for
me, and paid, a mint of money for it, no doubt."
At the supper-table I saw Lieutenant Rockdale, who commanded the
post in the Captain's absence, being the only officer there besides
the Captain; and, as he messed with them altogether, I need not say
that the table was well supplied with all the delicacies that New York
and Baltimore send out to less highly favored portions of the
universe, in tin cans. Lieutenant Rockdale was a handsome man—a
trifle effeminate, perhaps, with languishing, brown eyes, and a soft
voice. He seemed delighted with our visit, and took my husband off
to his own quarters, while Mrs. Arnold and I looked over pictures of
her friends, over albums, and at all the hundred little curiosities
which she had accumulated while in the Territory. The cares of the
household seemed to sit very lightly on her; a negro woman,
Constantia, and a mulatto boy, of twelve or thirteen, sharing the
labor between them. The boy seemed to be a favorite with Mrs.
Arnold, though she tantalized and tormented him, as I afterwards
found she tormented and tantalized every living creature over which
she had the power.
I had noticed, while Constantia and Fred were clearing off the table,
that she had cut him a slice from a very choice cake, toward which
the child had cast longing looks. Placing it carefully on a plate, when
he had to leave it for a moment to do something his mistress had
bidden him, in the twinkling of an eye she had hidden it; and when
the boy missed it, she expressed her regret at his carelessness, and
artfully led his suspicions toward Constantia. Hearing him
whimpering and sniffling as he went back and forth between dining-
room and kitchen, his childish distress at losing the cake seemed to
afford her the same amusement that a stage-play would, and she
laughed till the tears rolled down her cheeks. Later, he was
summoned to replenish the fire; and, knowing the little darkey's
aversion for going out of the house bare-headed (he had an idea
that his cap could prevent the Indian arrows from penetrating his
skull), she hid the cap he had left in the adjoining room, and then
laughed immoderately at his terror on leaving the house without it.
The next morning, she led me out to the stables to show me her
horse—a magnificent, black animal, wild-eyed, with a restless, fretful
air. Crossing the space in front of the house, she called to a soldier
with sergeant-chevrons on his arms—a man with just enough of
negro blood in his veins to stamp him with the curse of his race.
"Harry!" she called to him, "Harry, come hold Black for me; I want to
give him a piece of sugar." She opened her hand to let him see the
pieces, and he touched his cap and followed us. He loosened the
halter and led the horse up to us, but the animal started back when
he saw Mrs. Arnold, and would not let her approach him. Harry
patted his neck and soothed him, and Mrs. Arnold holding the sugar
up to his view, the horse came to take it from her hand; but she
quickly clutched his lip with her fingers, and blew into his face till the
horse reared and plunged so that Harry could hold him no longer.
Laughing like an imp, she called to Harry:
"Get on him and hold him, if you cannot manage him in that way:
get on him anyhow, and let Mrs. —— see him dance."
The mulatto's flashing black eyes were bent on her with a singularly
reproachful look; but the next moment he was on the horse's back,
the horse snorting and jumping in a perfectly frantic manner.
When Mrs. Arnold had sufficiently recovered from her merriment,
she explained that the horse had not been ridden for a month; the
last time she had ridden him he had thrown her—she had pricked
him with a pin to urge him on faster.
About noon the Captain arrived; and I found him, as Mrs. Kline had
described, "the most good-natured man in the world," and, to all
appearances, loving his wife with the whole of his big heart. He was
big in stature, too, with broad shoulders, pleasant face, and cheerful,
ringing voice. The shaggy dog, who had slunk away from Mrs.
Arnold, came leaping up on his master when he saw him; the horse
he had ridden rubbed his nose against his master's shoulder before
turning to go into his stable, and Constantia and Fred beamed on
him with their white teeth and laughing eyes from the kitchen-door.
Later in the afternoon, he asked what I thought of his quarters, and
told me how hard his colored soldiers had worked to build the really
pretty adobe house in strict accordance with his wishes and
directions. But I could not quite decide whether he was more proud
of the house or of the affection his men all had for him. Then he told
me the story of almost every piece of furniture in the house; and,
moving from room to room, we came to where their bed stood.
Resting beside it was his carbine, which the orderly had brought in.
Taking it in his hand to examine it, he pointed it at his wife's head
with the air of a brigand, and uttered, in unearthly tones:
"Your money, or your life!"
With a quick, cat-like spring, she was by the bed, had thrust her
hands under the pillow, and the next instant was holding two
Derringers close to his breast. Throwing back her head, like a
heroine in velvet trousers on the stage, she returned, in the same
strain:
"I can play a hand at that game, too, and go you one better!"
She laughed as she said it—the laugh that she laughed with her
white teeth clenched—but there was a "glint" in her eye that I had
never seen in a blue eye before.
When once more on the way, my husband asked me how I liked
Mrs. Arnold. "Very well," said I; "but—," and I did not hesitate to tell
him of the peculiarities I had noticed about her. He himself was
charmed with her sprightliness, so he only responded with, "Pshaw!
woman!" after which I maintained an offended (he said, offensive)
silence on the subject.
Not quite four months later, my husband was recalled to Santa Fé,
and we again crossed the desert, with only three men as escort. I
had heard nothing from either Mrs. Arnold or the Captain in all this
time, for our post was farther out than theirs; indeed, so far out that
nothing belonging to the same military department passed by that
way. It was midsummer, and the dreary hills shutting in Fort
Desolation, and running down toward the river some distance back
of the place, were baked hard and black in the sun; the little stream
that had meandered along through the low inclosure of the fort in
winter time was now a mere bed of slime, and the plateaux, which
had been levelled for the purpose of erecting the Captain's house
and the commissary buildings on them, could not boast of a single
spear of grass or any other sign of vegetation. The Captain's house
lay on the highest of these plateaux; lower down, across the creek,
were the quartermaster and commissary buildings (here, too, were
Lieutenant Rockdale's quarters); and to the left, on the other side of
the men's quarters, was the guard-house—part jacal, part tent-cloth.
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