Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Java EE 6 Cookbook for Securing, Tuning, and Extending Enterprise Applications pdf
Nội dung xem thử
Mô tả chi tiết
Java EE 6 Cookbook
for Securing,
Tuning, and
Extending Enterprise
Applications
Packed with comprehensive recipes to secure, tune, and
extend your Java EE applications
Mick Knutson
PUBLISHING
professional expertise distilled
BIRMINGHAM - MUMBAI
Java EE 6 Cookbook for Securing, Tuning,
and Extending Enterprise Applications
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.
First published: June 2012
Production Reference: 1180612
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84968-316-6
www.packtpub.com
Cover Image by Jackson Myers ([email protected])
Credits
Author
Mick Knutson
Reviewers
Antonio Gomes Rodrigues
Manjeet Singh Sawhney
Deepak Vohra
Acquisition Editor
Andrew Duckworth
Lead Technical Editor
Andrew Duckworth
Technical Editors
Merin Jose
Conrad Sardinha
Mehreen Shaikh
Copy Editor
Insiya Morbiwala
Project Coordinator
Theresa Chettiar
Proofreader
Joanna McMahon
Indexer
Hemangini Bari
Graphics
Valentina D'silva
Manu Joseph
Production Coordinator
ArvindKumar Gupta
Cover Work
ArvindKumar Gupta
About the Author
Mick Knutson, with nearly two decades of experience working in the IT industry in various
roles as Enterprise technology consultant, Java Architect, project leader, Engineer, Designer
and Developer, has gained a wide variety of experience in disciplines including Java EE,
Web Services, Mobile Computing, and Enterprise Integration Solutions.
Over the course of his career, Mr. Knutson has enjoyed long-lasting partnerships with
many of the most recognizable names in the Health Care, Financial, Banking, Insurance,
Manufacturing, Telecommunications, Utilities, Product Distribution, Industrial, and Electronics
industries employing industry-standard full software lifecycle methodologies, including the
Rational Unified Process (RUP), Agile, SCRUM, and Extreme Programming (XP).
Mr. Knutson has led training courses and book publishing engagements, authored technical
white papers, and presented at seminars worldwide. As an active blogger and Tweeter, Mr.
Knutson has also been inducted in the prestigious DZone.com "Most Valuable Blogger" (MVB)
group, and can be followed at http://baselogic.com, http://dzone.com/users/
mickknutson and http://twitter.com/mickknutson.
Mr. Knutson is exceptional at team building and motivating both at a peer-to-peer level and in
a leadership role. He demonstrates excellent communications skills and the ability to adapt to
all environments and cultures with ease.
Mr. Knutson is President of BASE Logic, Inc., a software consulting firm focusing on
Java-related technologies and development practices, and training for enterprise development.
Mr. Knutson has been a strategic member of Comcast, for Wayne Ramprashad, helping
to design and deploy the next generation IVR to align the One Customer Experience and
deflect millions in quarterly operational costs. This opportunity helped foster many real world
challenges and solutions used indirectly in many of the recipes included in this book.
Acknowledgement
There were several individuals and companies that offered great support in the creation of
this book. Rich Highland, Claus Ibsen, and Jonathan Anstey of FuseSource. Atlassian supplied
a license of Clover for code coverage. Eviware supported many recipes with a license of
soapUI Pro. Jetbrains supplied a license of IntelliJ IDEA editor. MadeForNet supplied a license
of HTTP Debugger. Vandyke Software supplied licenses for SecureCRT and SecureFX. YourKit
supplied a license for the YourKit profiler.
Visual Paradigm assisted me with the use of their UML modeling suite that was instrumental
in writing this book, as well as a powerful tool I have recommended and used on many
projects to describe, design and detail all aspects of the software development lifecycle.
Bhavin Parikh assisted in many of the soapUI recipes in this book. Mr. Parikh is a
Senior Consultant and Scrum Master, currently employed at Valtech and has more than
13 years of extensive software development experience in OOP, Java, J2EE, web services,
database, and various middleware and enterprise technologies. Mr. Parikh holds a Master's
degree in Computer Science from Penn State University, and he spoke on data mining at the
13th International Conference on Intelligent and Adaptive Systems and Software Engineering.
Jim Leary of CloudBees assisted with Jenkins and cloud deployment recipes. Mr. Leary has
over 30 years of experience in the information technology field. Over half his career has
involved working with web-based technologies across a wide swath of frameworks, platforms,
and languages. He has held positions as a software developer, manager and architect in a
variety of industries including high technology, financial services and energy.
Shawn Northart assisted in Munin and firewall recipes. Mr. Northart moved to San Jose in
2003 after serving various technical support and system administration roles for several
ISPs in and around Sacramento. In managed hosting, he honed his system administration
skills working with Apache, PHP, and MySQL on the FreeBSD and Linux platforms. He has also
worked extensively with designing, implementing, and tuning web-server farms, both large and
small, for a number of high-traffic websites.
Justin Zealand assisted with the iOS section in Chapter 6, Enterprise Mobile Device
Integration. Justin is an independent contractor with over a decade of programming
experience in Java-based web systems and more recently native mobile platforms,
including iOS and Android. Justin has worked at major companies across a wide range
of industries and across many Internet technology disciplines.
Friends and family: I would like to thank my mother for teaching me how to work hard and
how one must sometimes make sacrifices to achieve one's goals. I would like to thank my
father for giving me the motivation to persevere against all odds. This book would not have
been possible without the support of all of my friends throughout the entire process.
About the Reviewers
Antonio Gomes Rodrigues earned his Master's degree at the University of Paris VII
in France. Since then, he has worked at various companies with Java EE technologies in
the roles of developer, technical leader, technical manager of offshore projects, and
performance expert.
He is currently working on performance problems in Java EE applications, in a
specialized company.
I would like to thank my wife Aurélie for her support.
Manjeet Singh Sawhney currently works for a major IT services, business solutions, and
outsourcing company in London (UK) as an Information Management Consultant. Previously, he
has worked for other global organizations in various technical roles, including Java development
and technical solutions consulting. Even though Manjeet has worked across a range of
programming languages and technologies, his core language is Java. During his postgraduate
studies, he also worked as a Student Tutor for one of the top 100 universities in the world where
he was teaching Java to undergraduate students and marked exams and project assignments.
Manjeet acquired his professional experience by working on several mission-critical projects
serving clients in the Financial Services, Telecommunications, Manufacturing, and Public Sector.
I am very thankful to my parents, my wife Jaspal and my son Kohinoor for
their encouragement and patience as reviewing this book took some of my
weekends from the family.
Deepak Vohra is a consultant and a principal member of the NuBean.com software
company. Deepak is a Sun Certified Java Programmer and Web Component Developer,
and has worked in the fields of XML and Java programming, and J2EE for over five years.
Deepak is the co-author of the Apress book Pro XML Development with Java Technology and
was the technical reviewer for the O'Reilly book WebLogic: The Definitive Guide. Deepak was
also the technical reviewer for the Course Technology PTR book Ruby Programming for the
Absolute Beginner, and the technical editor for the Manning Publications book Prototype and
Scriptaculous in Action.
Deepak is also the author of the Packt Publishing books JDBC 4.0 and Oracle JDeveloper for
J2EE Development, Processing XML documents with Oracle JDeveloper 11g, and EJB 3.0
Database Persistence with Oracle Fusion Middleware 11g.
www.PacktPub.com
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files
available? You can upgrade to the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@
packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library.
Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
f Fully searchable across every book published by Packt
f Copy and paste, print and bookmark content
f On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib
today and view nine entirely free books. Simply use your login credentials for immediate access.
Instant Updates on New Packt Books
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter,
or the Packt Enterprise Facebook page.
Table of Contents
Preface 1
Chapter 1: Out with the Old, In with the New 7
Introduction 7
Pruning old APIs 8
In with the new 13
Implementing Java Contexts and Dependency Injection (CDI) 14
Understanding the EJB 3.1 specification 17
Understanding the JPA 2.0 specification 21
Understanding the JAX-RS 1.1 specification 25
Understanding the Servlet 3.0 specification 27
Understanding the WebBeans 1.0 specification 30
Understanding the JSF 2.0 specification 30
Understanding Bean Validation 32
Understanding profiles 34
Chapter 2: Enterprise Persistence 37
Introduction 37
Understanding @CollectionTable 38
Auditing previous JPA Operations 42
Auditing historical JPA Operations 44
Profiling and testing JPA Operations 53
Chapter 3: Security 65
Introduction 65
Performing authentication in Java EE 68
Authorization in Java EE 77
Enforcing security in Enterprise Applications 80
Programmatic security and annotations in Java EE 84
Securely signing JAR artefacts 89
Configuring Linux firewall rules 93
ii
Table of Contents
Securely obfuscating Java byte-code 101
Minification and obfuscation of web resources 108
Chapter 4: Enterprise Testing Strategies 115
Introduction 115
Remote debugging of Java EE applications 116
Testing JPA with DBUnit 120
Using Mock objects for testing 130
Testing HTTP endpoints with Selenium 143
Testing JAX-WS and JAX-RS with soapUI 152
Chapter 5: Extending Enterprise Applications 169
Introduction 169
Integrating Groovy into Enterprise Applications 170
Integrating Jython into Enterprise Applications 178
Integrating Scala into Enterprise Applications 181
Weaving AspectJ advice into Enterprise Applications 184
Weaving AspectJ advice into existing libraries 187
Adding advice with CDI Decorators 190
Adding advice with CDI Interceptors 194
Chapter 6: Enterprise Mobile Device Integration 201
Introduction 201
Evaluating mobile framework projects 202
Native application considerations 209
Leveraging mobile design tools 215
Testing mobile-web applications with online emulators 223
Setting up a local Apache environment 228
Native SDK development considerations 236
Chapter 7: Deployment and Configuration 239
Introduction 239
Java EE configuration with CDI 240
Java EE configuration with Groovy 244
Enabling remote JMX on Tomcat server 248
Enabling JMX over SSL on Tomcat server 256
Enabling remote JMX on GlassFish server 260
Enabling JMX over SSL on GlassFish server 268
Using JRebel for rapid redeployment 273
Managing VisualVM application repository configuration 281
Chapter 8: Performance and Debugging 285
Introduction 285
Profiling memory with jVisualVM 286
iii
Table of Contents
Using jstatd to enable Visual GC 293
Profiling applications with Netstat 299
Profiling TCP connections with TCPMon 307
Monitoring application and server performance with Munin 310
Debugging HTTP connections with HTTP Debugger 316
Index 323