Beginning Java EE 6 with GlassFish 3 (eBook)
536 Seiten
Apress (Verlag)
978-1-4302-2890-5 (ISBN)
Java Enterprise Edition (Java EE) continues to be one of the leading Java technologies and platforms from Oracle (previously Sun). Beginning Java EE 6 Platform with GlassFish 3, Second Edition is this first tutorial book on the final version of the Java EE 6 Platform.
Step by step and easy to follow, this book describes many of the Java EE 6 specifications and reference implementations, and shows them in action using practical examples. This book uses the new version of GlassFish 3 to deploy and administer the code examples.
Written by an expert member of the Java EE 6 specification request and review board in the Java Community Process (JCP), this book contains the best information possible, from an expert's perspective on enterprise Java technologies.
Antonio Goncalves is a senior software architect specializing in Java/Java EE. As a former BEA Systems consultant, he has expertise in application servers (Weblogic, JBoss, and GlassFish). He is the author of a Java EE 5 book in France and is also an Expert Member on Java EE 6, EJB 3.1, and JPA 2.0. He is the cofounder of the Paris Java User Group. For more, visit http://www.antoniogoncalves.org.
Java Enterprise Edition (Java EE) continues to be one of the leading Java technologies and platforms from Oracle (previously Sun). Beginning Java EE 6 Platform with GlassFish 3, Second Edition is this first tutorial book on the final version of the Java EE 6 Platform. Step by step and easy to follow, this book describes many of the Java EE 6 specifications and reference implementations, and shows them in action using practical examples. This book uses the new version of GlassFish 3 to deploy and administer the code examples. Written by an expert member of the Java EE 6 specification request and review board in the Java Community Process (JCP), this book contains the best information possible, from an expert s perspective on enterprise Java technologies.
Antonio Goncalves is a senior software architect specializing in Java/Java EE. As a former BEA Systems consultant, he has expertise in application servers (Weblogic, JBoss, and GlassFish). He is the author of a Java EE 5 book in France and is also an Expert Member on Java EE 6, EJB 3.1, and JPA 2.0. He is the cofounder of the Paris Java User Group. For more, visit http://www.antoniogoncalves.org.
Title Page 1
Copyright Page 2
Contents at a Glance 4
Table of Contents 5
Foreword 17
About the Author 18
About the Technical Reviewer 19
Acknowledgments 20
Preface 21
How Is This Book Structured? 21
Downloading and Running the Code 22
Contacting the Author 23
CHAPTER 1 Java EE 6 at a Glance 24
Understanding Java EE 24
A Bit of History 25
Standards 27
Architecture 27
Components 28
Containers 29
Services 29
Network Protocols 31
Packaging 32
Java Standard Edition 33
Java EE 6 Specifications 33
What’s New in Java EE 6? 35
Lighter 36
Pruning 36
Profiles 37
Easier to Use 38
Richer 39
More Portable 41
The CD-BookStore Application 41
Setting Up Your Environment 43
JDK 1.6 43
Maven 2 44
A Bit of History 44
Project Descriptor 45
Managing Artifacts 46
Project Modularity 47
Plug-ins and Life Cycle 48
Installation 49
Usage 49
JUnit 4 50
A Bit of History 50
How Does It Work? 50
Test Methods 53
Assert Methods 53
Fixtures 53
Launching JUnit 54
JUnit Integration 54
Derby 10.6 54
Installation 55
Usage 55
GlassFish v3.0.1 57
A Bit of History 57
GlassFish v3 Architecture 57
Update Center 59
GlassFish Subprojects 59
Administration 60
Admin Console 60
The asadmin CLI 61
Installing GlassFish 62
Summary 64
CHAPTER 2 Java Persistence 65
JPA Specification Overview 66
A Brief History of the Specification 66
What’s New in JPA 2.0? 67
Reference Implementation 67
Understanding Entities 68
Object-Relational Mapping 68
Querying Entities 70
Callbacks and Listeners 71
Putting it all Together 72
Writing the Book Entity 73
Writing the Main Class 74
Persistence Unit for the Main Class 75
Compiling with Maven 76
Running the Main Class with Derby 78
Writing the BookTest Class 79
Persistence Unit for the BookTest Class 81
Running the BookTest Class with Embedded Derby 82
Summary 82
CHAPTER 3 Object-Relational Mapping 83
How to Map an Entity 83
Configuration by Exception 85
Elementary Mapping 86
Tables 87
@Table 87
@SecondaryTable 88
Primary Keys 90
@Id and @GeneratedValue 90
Composite Primary Keys 91
@EmbeddedId 91
@IdClass 92
Attributes 94
@Basic 94
@Column 95
@Temporal 97
@Transient 98
@Enumerated 99
Access Type 100
Collection of Basic Types 103
Map of Basic Types 105
Mapping with XML 106
Embeddables 109
Access Type of an Embeddable Class 111
Relationship Mapping 113
Relationships in Relational Databases 114
Entity Relationships 115
Unidirectional and Bidirectional 116
@OneToOne Unidirectional 119
@OneToMany Unidirectional 122
@ManyToMany Bidirectional 126
Fetching Relationships 127
Ordering Relationships 129
@OrderBy 129
@OrderColumn 130
Inheritance Mapping 132
Inheritance Strategies 132
Single-Table-per-Class Hierarchy Strategy 133
Joined-Subclass Strategy 137
Table-per-Concrete-Class Strategy 138
Overriding Attributes 139
Type of Classes in the Inheritance Hierarchy 140
Abstract Entity 140
Nonentity 141
Mapped Superclass 142
Summary 143
CHAPTER 4 Managing Persistent Objects 144
How to Query an Entity 144
Entity Manager 148
Obtaining an Entity Manager 149
Persistence Context 151
Manipulating Entities 153
Persisting an Entity 155
Finding by ID 156
Removing an Entity 156
Orphan Removal 157
Synchronizing with the Database 158
Flushing Data 158
Refreshing an Entity 158
Content of the Persistence Context 159
Contains 159
Clear and Detach 159
Merging an Entity 160
Updating an Entity 161
Cascading Events 161
Cache API 163
JPQL 166
Select 167
From 169
Where 169
Binding Parameters 170
Subqueries 170
Order By 171
Group By and Having 171
Bulk Delete 171
Bulk Update 172
Queries 172
Dynamic Queries 175
Named Queries 176
Native Queries 179
Criteria API (or Object-Oriented Queries) 179
Type-Safe Criteria API 180
Concurrency 182
Versioning 184
Optimistic Locking 185
Pessimistic Locking 187
Summary 187
CHAPTER 5 Callbacks and Listeners 188
Entity Life Cycle 188
Callbacks 190
Listeners 193
Summary 198
CHAPTER 6 Enterprise Java Beans 199
Understanding EJBs 199
Types of EJBs 201
Anatomy of an EJB 201
EJB Container 203
Embedded Container 204
Dependency Injection and JNDI 205
Callback Methods and Interceptors 206
Packaging 206
EJB Specification Overview 207
History of the Specification 207
What’s New in EJB 3.1 208
EJB Lite 209
Reference Implementation 209
Putting It All Together 210
Writing the Book Entity 211
Writing the BookEJB Stateless Session Bean 211
Persistence Unit for the BookEJB 213
Writing the Main Class 214
Compiling and Packaging with Maven 214
Deploying on GlassFish 216
Running the Main Class with the Application Client Container 217
Writing the BookEJBTest Class 217
Summary 219
CHAPTER 7 Session Beans and the Timer Service 220
Session Beans 220
Stateless Beans 221
Stateful Beans 224
Singletons 226
Initialization 228
Chaining Singletons 229
Concurrency 230
Container-Managed Concurrency 230
Bean-Managed Concurrency 232
Concurrent Access Timeouts and Not Allowing Concurrency 232
Session Bean Model 233
Interfaces and Bean Class 233
Remote, Local, and No-Interface Views 234
Web Services Interface 236
Bean Class 236
Client View 237
@EJB 237
Portable JNDI Name 238
Session Context 240
Deployment Descriptor 241
Dependency Injection 242
Environment Naming Context 243
Asynchronous Calls 245
Embeddable Usage 247
The Timer Service 249
Calendar-Based Expression 250
Automatic Timer Creation 252
Programmatic Timer Creation 253
Summary 254
CHAPTER 8 Callbacks and Interceptors 256
Session Beans Life Cycle 256
Stateless and Singleton 256
Stateful 258
Callbacks 259
Interceptors 262
Around-Invoke Interceptors 263
Method Interceptors 266
Life-Cycle Interceptor 268
Chaining and Excluding Interceptors 269
Summary 271
CHAPTER 9 Transactions and Security 272
Transactions 272
ACID 273
Local Transactions 273
Distributed Transactions and XA 275
Transaction Support in EJB 278
Container-Managed Transactions 278
Marking a CMT for Rollback 282
Exception Handling 283
Bean-Managed Transactions 285
Security 287
Principals and Roles 287
Authentication and Authorization 288
Security Support in EJB 288
Declarative Security 289
Programmatic Security 292
Summary 294
CHAPTER 10 JavaServer Faces 295
Understanding JSF 296
FacesServlet and faces-config.xml 297
Pages and Components 297
Renderer 298
Converters and Validators 299
Managed Beans and Navigation 299
Ajax Support 300
Web Interface Specifications Overview 300
A Brief History of Web Interfaces 301
JSP 2.2, EL 2.2, and JSTL 1.2 301
JSF 2.0 301
What’s New in JSF 2.0 302
Reference Implementation 302
Putting It All Together 302
Writing the Book Entity 304
Writing the BookEJB 304
Writing the BookController Managed Bean 305
Writing the newBook.xhtml Page 306
Writing the listBooks.xhtml Page 308
Configuration with web.xml 310
Compiling and Packaging with Maven 311
Deploying on GlassFish 312
Running the Example 312
Summary 313
CHAPTER 11 Pages and Components 314
Web Pages 314
HTML 314
XHTML 316
CSS 318
DOM 320
JavaScript 321
Java Server Pages 323
Directive Elements 324
Scripting Elements 325
Action Elements 326
Putting It All Together 327
Expression Language 329
JSP Standard Tag Library 331
Core Actions 331
Formatting Actions 333
SQL Actions 334
XML Actions 336
Functions 338
Facelets 339
JavaServer Faces 340
Life Cycle 341
Standard HTML Components 343
Commands 343
Inputs 344
Outputs 345
Selections 346
Graphics 347
Grid and Tables 347
Error Messages 349
Miscellaneous 350
Templating 350
Resource Management 353
Composite Components 354
Implicit Objects 359
Summary 360
CHAPTER 12 Processing and Navigation 361
The MVC Pattern 361
FacesServlet 362
FacesContext 365
Faces Config 366
Managed Beans 367
How to Write a Managed Bean 367
Managed Bean Model 368
@ManagedBean 368
Scopes 369
@ManagedProperty 371
Life Cycle and Callback Annotations 372
Navigation 372
Message Handling 377
Conversion and Validation 379
Converters 379
Custom Converters 381
Validators 382
Custom Validators 383
Ajax 384
General Concepts 384
Support in JSF 386
Putting It All Together 388
Summary 392
CHAPTER 13 Sending Messages 393
Understanding Messages 393
JMS 394
MDB 394
Messaging Specification Overview 395
A Brief History of Messaging 395
JMS 1.1 395
EJB 3.1 395
Reference Implementation 396
How to Send and Receive a Message 396
Java Messaging Service 398
Point-to-Point 399
Publish-Subscribe 400
JMS API 401
Administered Objects 402
ConnectionFactory 402
Destination 403
Injection 403
Connection 405
Session 405
Messages 406
Header 406
Properties 408
Body 408
MessageProducer 408
MessageConsumer 410
Synchronous Delivery 410
Asynchronous Delivery 411
Selectors 413
Reliability Mechanisms 413
Setting Message Time-to-Live 414
Specifying Message Persistence 414
Controlling Acknowledgment 414
Creating Durable Subscribers 415
Setting Priorities 416
Message-Driven Beans 416
How to Write an MDB 416
MDB Model 417
@MessageDriven 418
@ActivationConfigProperty 418
Dependencies Injection 420
MDB Context 420
Life Cycle and Callback Annotations 421
MDB as a Consumer 421
MDB as a Producer 422
Transaction 423
Handling Exceptions 424
Putting It All Together 425
Writing the OrderDTO 425
Writing the OrderSender 425
Writing the OrderMDB 426
Compiling and Packaging with Maven 427
Creating the Administered Objects 429
Deploying the MDB on GlassFish 429
Running the Example 430
Summary 430
CHAPTER 14 SOAP Web Services 431
Understanding SOAP Web Services 431
XML 432
WSDL 433
SOAP 433
UDDI 433
Transport Protocol 434
SOAP Web Services Specification Overview 434
A Brief History of SOAP Web Services 434
Java EE Specifications 434
JAX-WS 2.2 435
Web Services 1.2 435
JAXB 2.2 435
WS-Metadata 2.0 435
JAXR 1.0 435
Reference Implementation 436
How to Invoke a SOAP Web Service 436
Java Architecture for XML Binding 438
Binding 439
Annotations 441
The Invisible Part of the Iceberg 444
WSDL 444
SOAP 447
Java API for XML-Based Web Services 448
JAX-WS Model 448
Web Service Endpoints 449
Annotations 449
@WebService 450
@WebMethod 451
@WebResult 451
@WebParam 452
@OneWay 452
All Together 452
Life Cycle and Callback 455
Web Service Context 456
Invoking a SOAP Web Service 456
Putting It All Together 458
Writing the CreditCard Class 458
Writing the CardValidator SOAP Web Service 458
Compiling and Packaging with Maven 459
Deploying on GlassFish 460
Writing the Web Service Consumer 462
Generating Consumer’s Artifacts and Packaging with Maven 463
Running the Main Class 465
Summary 466
CHAPTER 15 RESTful Web Services 467
Understanding RESTful Web Services 467
Resources and URIs 467
Representations 468
WADL 469
HTTP 469
Request and Response 469
HTTP Methods 471
GET 471
POST 471
PUT 471
DELETE 471
Others 472
Content Negotiation 472
Content Types 472
Status Codes 473
Caching and Conditional Requests 474
RESTful Web Services Specification 474
A Brief History of REST 475
JAX-RS 1.1 475
What’s New in JAX-RS 1.1? 475
Reference Implementation 476
The REST Approach 476
From the Web to Web Services 476
A Web-Browsing Experience 476
Uniform Interface 477
Addressability 477
Connectedness 478
Statelessness 479
Java API for RESTful Web Services 479
The JAX-RS Model 480
How to Write a REST Service 480
URI Definition 481
Extracting Parameters 483
Consuming and Producing Content Types 484
Entity Provider 487
Methods or the Uniform Interface 489
Contextual Information 490
Headers 490
Building URIs 491
Exception Handling 491
Life Cycle 492
Putting It All Together 493
Writing the Book Entity 493
Writing the BookResource 494
Header 494
Creating a New Book 494
Getting a Book by ID 495
Deleting a Book 496
Configuring Jersey 497
Compiling and Packaging with Maven 497
Deploying on GlassFish 498
Running the Example 499
Summary 500
Index 501
Erscheint lt. Verlag | 20.9.2010 |
---|---|
Zusatzinfo | 536 p. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► Java |
Mathematik / Informatik ► Informatik ► Theorie / Studium | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | Java • Java EE • JavaServer Faces • JSP • Navigation • Rest • Web Services |
ISBN-10 | 1-4302-2890-3 / 1430228903 |
ISBN-13 | 978-1-4302-2890-5 / 9781430228905 |
Haben Sie eine Frage zum Produkt? |
Größe: 4,2 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich