ebook img

www.it-ebooks - Amazon Web Services PDF

359 Pages·2013·9.24 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview www.it-ebooks - Amazon Web Services

www.it-ebooks.info www.it-ebooks.info Programming Grails Burt Beckwith www.it-ebooks.info Programming Grails by Burt Beckwith Copyright © 2013 Burt Beckwith. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editors: Mike Loukides and Meghan Blanchette Indexer: Judy McConville Production Editor: Kristen Borg Cover Designer: Karen Montgomery Copyeditor: Absolute Services, Inc Interior Designer: David Futato Proofreader: Linley Dolby Illustrator: Robert Romano May 2013: First Edition Revision History for the First Edition: 2013-04-22: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449323936 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Programming Grails, the image of an Antarctic giant petrel, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-32393-6 [LSI] www.it-ebooks.info Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi 1. Introduction to Groovy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Installing Groovy 1 Groovy Console 2 Optional Typing 3 Collections and Maps 4 Properties 5 Using the AST Browser 7 Decompiling with JD-GUI 8 Decompiling with javap 8 Closures 8 Interface Coercion 11 Programmatic Closures 11 Owner, Delegate, and this 12 Groovy’s Contributions in the War Against Verbosity 13 Constructors 14 Checked Exceptions 15 Groovy Truth 15 Semicolons 16 Optional Return 16 Scope 16 Parentheses 16 Default Imports 16 Differences Between Java and Groovy 17 Array Initialization 17 in and def Keywords 17 do/while Loops 17 for Loops 17 iii www.it-ebooks.info Annotations 18 Groovy Equality 18 Multimethod Dispatch 18 Groovy Strings 19 Static this 20 The Groovy JDK (GDK) 21 DefaultGroovyMethods and InvokerHelper 21 Metaprogramming and the MOP 21 Adding Methods 22 Intercepting Method Calls 23 Operators 26 Null-Safe Dereference 26 Elvis 26 Spread 27 Spaceship 27 Field Access 28 as 28 in 28 Method Reference 29 Overload Your Operators 29 Being Too Groovy 31 def Considered Harmful 31 Closures Versus Methods 32 TypeChecked, CompileStatic, and invokedynamic 33 2. Grails Internals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Installing Grails 38 Creating an Application 38 The Grails Command Line 39 IDE Support 41 Plugins 42 Optional Plugins 43 Core Plugins 45 Conventions 57 Controller and View Conventions 57 Service Conventions 60 Domain Class Conventions 61 More Information 65 3. Persistence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Data Mapping 67 Nonpersistent Domain Classes 69 iv | Table of Contents www.it-ebooks.info Data Validation 69 Custom Validation 72 Extreme Custom Validation 74 Validation Plugins 75 Friendly Error Messages 75 Blanks Versus Nulls 76 Transients 77 Mapping Collections 78 Querying 80 Saving, Updating, and Deleting 82 NoSQL Support 84 4. Spring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Inversion of Control and Dependency Injection 85 Complex Dependency Configuration Using Spring SpEL 86 Manually Injecting Dependencies at Runtime 87 Bean Scopes 87 Transactional Services 88 @Transactional 89 Transaction Proxies 90 Transaction Utility Methods 93 Bean Life Cycles and Interfaces 94 Bean Postprocessors 95 A Groovier Way 96 Bean Aliases 97 Internationalization 98 Resources 98 Resource Dependency Injection 99 ResourceLocator 100 Data Binding and Validation 101 Data Binding 101 Validation 102 Database Persistence 102 Thread-Local Holders 103 JdbcTemplate 103 Other Database Support 104 Spring MVC 104 Filters 105 Using Spring MVC Controllers 106 Remoting 107 Client Access 108 JMS 110 Table of Contents | v www.it-ebooks.info EJBs 110 JMX 110 Email 111 Cache Abstraction 111 5. Hibernate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Mapping Domain Classes 113 Dialects 115 Dialect Autodetection 116 Dialect Customization 116 Hibernate Without GORM 118 hibernate.cfg.xml 118 HibernateUtil 119 Author 120 Book 120 Experimenting with the APIs 121 The Session 123 withSession 124 withNewSession 124 Open Session in View 124 Disabling OSIV 125 Custom User Types 126 Optimistic and Pessimistic Locking 129 Accessing the Session’s Connection 130 schema-export 130 SQL Logging 131 Proxies 133 equals, hashCode, and compareTo 134 Caching 135 Examples 136 Caching API 139 Query Caching Considered Harmful? 140 HQL 141 executeQuery 141 Query Syntax 142 Report Queries 143 Aggregate Functions 144 Expressions 145 Collections 145 Collections Performance 145 The Solution 146 Session.createFilter() 147 vi | Table of Contents www.it-ebooks.info Custom Configurations 148 Mapping Views and Subselect Classes 150 Subselect Domain Classes 152 Selecting with a POGO 153 get(), load(), and read() 154 get() 154 load() 154 read() 156 Performance 156 Caching 156 Lazy Loading 157 Transactional Write-Behind 158 6. Integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 JMS 159 XA Support with the Atomikos Plugin 163 Mail 167 Sending Email 168 Sending Email Asynchronously 171 Sending Email from Log4j 172 Testing 174 SOAP Web Services 174 The Server Application 175 The Client Application 176 TCPMon 179 REST 180 TCPMon 187 JMX 188 7. Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 External config Files 191 Loading the Configuration 193 Partitioning Config Files 194 Splitting resources.groovy 195 Modularizing Within resources.groovy 196 Environment-Specific Spring Beans 198 Beans Closures in Config.groovy 201 Options for BuildConfig.groovy 201 Adding Additional Source Folders 202 Extra Folders Under grails-app 203 8. Plugins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Table of Contents | vii www.it-ebooks.info Creating a Plugin 205 Initial Steps 206 The Plugin Descriptor 209 Metadata 209 Life Cycle Callbacks 213 Splitting Applications into Plugins 218 Inline Plugins 218 Building and Releasing 219 Automated Testing 219 Running the Tests 224 Custom Plugin Repositories 224 Plugin Documentation 226 Custom Artifacts 227 Some Notes on Plugin Development Workflow 232 9. Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 OWASP 235 A1: Injection 235 A2: Cross-Site Scripting (XSS) 238 A3: Broken Authentication and Session Management 241 A4: Insecure Direct Object References 242 A5: Cross-Site Request Forgery 244 A6: Security Misconfiguration 245 A7: Insecure Cryptographic Storage 246 A8: Failure to Restrict URL Access 248 A9: Insufficient Transport Layer Protection 248 A10: Unvalidated Redirects and Forwards 249 Security Plugins 250 spring-security-core 250 Other Plugins and Libraries 254 AntiSamy 254 ESAPI 254 HDIV 254 General Best Practices 255 10. The Cloud. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Cost Savings 262 What You Give Up 262 Cloud Foundry 263 Database Applications 263 Scaling 269 NoSQL, RabbitMQ, and Searchable 270 viii | Table of Contents www.it-ebooks.info

Description:
gramming Groovy, Second Edition by Venkat Subramaniam (Pragmatic Programmers) and Groovy in Action, Second Edition by Dierk König et al. (Manning),
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.