没有合适的资源?快使用搜索试试~ 我知道了~
首页Java EE 7开发指南:探索Java EE平台最新特性
《Java EE 7指南》是一份详尽的技术文档,面向Java EE 7平台的开发者提供全面的教育资源。发布于2013年6月,该版本的教程包含了Java Enterprise Edition 7(Java EE 7)的众多新特性和最佳实践,帮助开发者理解和掌握这一技术栈的最新进展。
Java EE 7是企业级Java应用开发的标准化框架,它集合了Java的服务器端技术和规范,如Servlet、JSP、EJB、JPA、JSF等,旨在简化企业级应用程序的开发和部署。这份教程覆盖了以下几个关键知识点:
1. **核心组件**:教程深入介绍了Java EE 7的核心组件,包括Servlet 3.1和JSP 2.3的增强特性,它们提供了更灵活、高性能的Web服务支持。此外,EJB 3.2作为企业级Bean的新版本,强调了轻量级和无侵入式编程模型。
2. **持久化与数据访问**:JPA 2.1是主要内容之一,它提供了强大的对象关系映射(ORM)功能,使得开发者可以更容易地管理数据库操作,实现对象持久化。
3. **安全性**:Java EE 7增强了安全模块,包括Java Authentication and Authorization Service (JAAS)和WebSocket的集成,以便更好地保护企业应用免受恶意攻击。
4. **Web服务与RESTful API**:教程详细解释了如何利用Java EE 7构建可扩展的Web服务,以及如何设计和实现RESTful API,以支持现代分布式系统架构。
5. **模块化和容器管理**:Java EE 7引入了模块化系统,使开发者能够按需选择和部署应用中的组件,提高了部署效率和资源利用率。
6. **开发工具与IDE集成**:教程还涵盖了如何在主流集成开发环境(IDE)如Eclipse和IntelliJ IDEA中有效地利用Java EE 7的特性,提高开发效率。
7. **兼容性与升级**:文档会提及Java EE 7与其他Java版本的兼容性,以及迁移策略,帮助开发者平稳过渡到新的技术栈。
8. **版权与许可**:请注意,该教程受Oracle或其关联公司的版权保护,并受到严格的使用和披露限制。未经许可,用户不得擅自复制、修改或公开传播软件及其文档。
阅读这份Java EE 7指导手册,开发者将能够深入理解Java EE 7的最新特性和最佳实践,从而更好地构建稳定、高效的企业级应用程序。同时,文档还强调了错误报告的重要性,确保了持续的技术更新和完善。
xvi
20.2.3 Retrieving Localized Messages....................................................................................... 20-3
20.3 Date and Number Formatting................................................................................................ 20-4
20.4 Character Sets and Encodings................................................................................................ 20-4
20.4.1 Character Sets.................................................................................................................... 20-4
20.4.2 Character Encoding.......................................................................................................... 20-5
Part IV Web Services
21 Introduction to Web Services
21.1 What Are Web Services?......................................................................................................... 21-1
21.2 Types of Web Services............................................................................................................. 21-1
21.2.1 "Big" Web Services............................................................................................................ 21-1
21.2.2 RESTful Web Services ...................................................................................................... 21-2
21.3 Deciding Which Type of Web Service to Use ...................................................................... 21-3
22 Building Web Services with JAX-WS
22.1 Creating a Simple Web Service and Clients with JAX-WS ................................................ 22-2
22.1.1 Requirements of a JAX-WS Endpoint............................................................................ 22-2
22.1.2 Coding the Service Endpoint Implementation Class .................................................. 22-3
22.1.3 Building, Packaging, and Deploying the Service......................................................... 22-4
22.1.3.1 To Build, Package, and Deploy the Service Using NetBeans IDE...................... 22-4
22.1.3.2 To Build, Package, and Deploy the Service Using Maven .................................. 22-4
22.1.4 Testing the Methods of a Web Service Endpoint......................................................... 22-4
22.1.4.1 To Test the Service without a Client....................................................................... 22-4
22.1.5 A Simple JAX-WS Application Client............................................................................ 22-5
22.1.5.1 Coding the Application Client................................................................................. 22-5
22.1.5.2 Running the Application Client .............................................................................. 22-6
22.1.6 A Simple JAX-WS Web Client ........................................................................................ 22-6
22.1.6.1 Coding the Servlet..................................................................................................... 22-6
22.1.6.2 Running the Web Client ........................................................................................... 22-8
22.2 Types Supported by JAX-WS................................................................................................. 22-8
22.2.1 Schema-to-Java Mapping................................................................................................. 22-9
22.2.2 Java-to-Schema Mapping................................................................................................. 22-9
22.3 Web Services Interoperability and JAX-WS....................................................................... 22-10
22.4 Further Information about JAX-WS .................................................................................... 22-10
23 Building RESTful Web Services with JAX-RS
23.1 What Are RESTful Web Services? ......................................................................................... 23-1
23.2 Creating a RESTful Root Resource Class.............................................................................. 23-2
23.2.1 Developing RESTful Web Services with JAX-RS ......................................................... 23-2
23.2.2 Overview of a JAX-RS Application................................................................................ 23-3
23.2.3 The @Path Annotation and URI Path Templates......................................................... 23-5
23.2.4 Responding to HTTP Methods and Requests .............................................................. 23-6
23.2.4.1 The Request Method Designator Annotations...................................................... 23-6
23.2.4.2 Using Entity Providers to Map HTTP Response and Request Entity Bodies... 23-8
23.2.5 Using @Consumes and @Produces to Customize Requests and Responses ........... 23-9
xvii
23.2.5.1 The @Produces Annotation...................................................................................... 23-9
23.2.5.2 The @Consumes Annotation.................................................................................. 23-10
23.2.6 Extracting Request Parameters..................................................................................... 23-11
23.3 Example Applications for JAX-RS....................................................................................... 23-14
23.3.1 Creating A Simple RESTful Web Service.................................................................... 23-14
23.3.1.1 To Create a RESTful Web Service Using NetBeans IDE.................................... 23-14
23.3.2 The rsvp Example Application..................................................................................... 23-15
23.3.2.1 Components of the rsvp Example Application................................................... 23-15
23.3.2.2 Running the rsvp Example Application............................................................... 23-16
23.3.3 Real-World Examples..................................................................................................... 23-17
23.4 Further Information about JAX-RS...................................................................................... 23-17
24 Accessing REST Resources with the JAX-RS Client API
24.1 Overview of the Client API .................................................................................................... 24-1
24.2 Creating a Basic Client Request using the Client API ........................................................ 24-1
24.2.1 Obtaining the Client Instance ......................................................................................... 24-2
24.2.2 Setting the Client Target.................................................................................................. 24-2
24.2.2.1 Setting Path Parameters in Targets......................................................................... 24-2
24.2.3 Invoking the Request ....................................................................................................... 24-3
24.3 Using the Client API in the JAX-RS Example Applications .............................................. 24-4
24.3.1 The Client API in the
rsvp
Example Application ........................................................ 24-4
24.3.2 The Client API in the
customer
Example Application................................................ 24-5
24.4 Advance Features of the Client API...................................................................................... 24-6
24.4.1 Configuring the Client Request...................................................................................... 24-6
24.4.1.1 Setting Message Headers in the Client Request.................................................... 24-6
24.4.1.2 Setting Cookies in the Client Request..................................................................... 24-7
24.4.1.3 Adding Filters to the Client...................................................................................... 24-7
24.4.2 Asynchronous Invocations in the Client API ............................................................... 24-8
24.4.2.1 Using Custom Callbacks in Asynchronous Invocations...................................... 24-9
25 JAX-RS: Advanced Topics and Example
25.1 Annotations for Field and Bean Properties of Resource Classes ...................................... 25-1
25.1.1 Extracting Path Parameters............................................................................................. 25-2
25.1.2 Extracting Query Parameters.......................................................................................... 25-2
25.1.3 Extracting Form Data....................................................................................................... 25-3
25.1.4 Extracting the Java Type of a Request or Response..................................................... 25-3
25.2 Validating Resource Data with Bean Validation................................................................. 25-4
25.2.1 Using Constraint Annotations on Resource Methods................................................. 25-4
25.2.2 Validating Entity Data ..................................................................................................... 25-5
25.2.3 Validation Exception Handling and Response Codes ................................................ 25-6
25.3 Subresources and Runtime Resource Resolution................................................................ 25-7
25.3.1 Subresource Methods....................................................................................................... 25-7
25.3.2 Subresource Locators ....................................................................................................... 25-7
25.4 Integrating JAX-RS with EJB Technology and CDI ............................................................ 25-8
25.5 Conditional HTTP Requests................................................................................................... 25-9
25.6 Runtime Content Negotiation.............................................................................................. 25-10
xviii
25.7 Using JAX-RS With JAXB ..................................................................................................... 25-11
25.7.1 Using Java Objects to Model Your Data...................................................................... 25-13
25.7.2 Starting from an Existing XML Schema Definition ................................................... 25-14
25.7.3 Using JSON with JAX-RS and JAXB ............................................................................ 25-16
25.8 The customer Example Application.................................................................................... 25-16
25.8.1 Overview of the customer Example Application....................................................... 25-17
25.8.2 The Customer and Address Entity Classes................................................................. 25-17
25.8.3 The CustomerService Class........................................................................................... 25-19
25.8.4 Using the JAX-RS Client in the CustomerBean Classes............................................ 25-21
25.8.5 Running the customer Example ................................................................................... 25-22
25.8.5.1 To Build, Package, and Deploy the customer Example Using NetBeans IDE 25-22
25.8.5.2 To Build, Package, and Deploy the customer Example Using Maven ............ 25-22
Part V Enterprise Beans
26 Enterprise Beans
26.1 What Is an Enterprise Bean?................................................................................................... 26-1
26.1.1 Benefits of Enterprise Beans............................................................................................ 26-1
26.1.2 When to Use Enterprise Beans........................................................................................ 26-2
26.1.3 Types of Enterprise Beans ............................................................................................... 26-2
26.2 What Is a Session Bean? .......................................................................................................... 26-2
26.2.1 Types of Session Beans..................................................................................................... 26-2
26.2.1.1 Stateful Session Beans............................................................................................... 26-2
26.2.1.2 Stateless Session Beans.............................................................................................. 26-3
26.2.1.3 Singleton Session Beans............................................................................................ 26-3
26.2.2 When to Use Session Beans............................................................................................. 26-3
26.3 What Is a Message-Driven Bean? .......................................................................................... 26-4
26.3.1 What Makes Message-Driven Beans Different from Session Beans?........................ 26-4
26.3.2 When to Use Message-Driven Beans............................................................................. 26-5
26.4 Accessing Enterprise Beans.................................................................................................... 26-5
26.4.1 Using Enterprise Beans in Clients .................................................................................. 26-6
26.4.1.1 Portable JNDI Syntax ................................................................................................ 26-6
26.4.2 Deciding on Remote or Local Access............................................................................. 26-7
26.4.3 Local Clients ...................................................................................................................... 26-7
26.4.3.1 Accessing Local Enterprise Beans Using the No-Interface View ....................... 26-8
26.4.3.2 Accessing Local Enterprise Beans That Implement Business Interfaces........... 26-8
26.4.4 Remote Clients .................................................................................................................. 26-9
26.4.5 Web Service Clients........................................................................................................ 26-10
26.4.6 Method Parameters and Access.................................................................................... 26-10
26.4.6.1 Isolation..................................................................................................................... 26-10
26.4.6.2 Granularity of Accessed Data................................................................................ 26-10
26.5 The Contents of an Enterprise Bean.................................................................................... 26-11
26.6 Naming Conventions for Enterprise Beans........................................................................ 26-11
26.7 The Lifecycles of Enterprise Beans...................................................................................... 26-11
26.7.1 The Lifecycle of a Stateful Session Bean...................................................................... 26-11
26.7.2 The Lifecycle of a Stateless Session Bean .................................................................... 26-12
26.7.3 The Lifecycle of a Singleton Session Bean................................................................... 26-13
xix
26.7.4 The Lifecycle of a Message-Driven Bean..................................................................... 26-13
26.8 Further Information about Enterprise Beans..................................................................... 26-14
27 Getting Started with Enterprise Beans
27.1 Creating the Enterprise Bean.................................................................................................. 27-1
27.1.1 Coding the Enterprise Bean Class .................................................................................. 27-1
27.1.2 Creating the converter Web Client................................................................................. 27-2
27.1.3 Running the converter Example..................................................................................... 27-3
27.1.3.1 To Run the converter Example in NetBeans IDE.................................................. 27-3
27.1.3.2 To Run the converter Example Using Maven ....................................................... 27-3
27.2 Modifying the Java EE Application....................................................................................... 27-4
27.2.1 To Modify a Class File...................................................................................................... 27-4
28 Running the Enterprise Bean Examples
28.1 The cart Example...................................................................................................................... 28-1
28.1.1 The Business Interface...................................................................................................... 28-2
28.1.2 Session Bean Class............................................................................................................ 28-2
28.1.2.1 Lifecycle Callback Methods ..................................................................................... 28-4
28.1.2.2 Business Methods...................................................................................................... 28-4
28.1.3 The @Remove Method ..................................................................................................... 28-5
28.1.4 Helper Classes................................................................................................................... 28-5
28.1.5 Running the cart Example............................................................................................... 28-5
28.1.5.1 To Run the cart Example Using NetBeans IDE..................................................... 28-6
28.1.5.2 To Run the cart Example Using Maven ................................................................. 28-6
28.2 A Singleton Session Bean Example: counter........................................................................ 28-7
28.2.1 Creating a Singleton Session Bean ................................................................................. 28-7
28.2.1.1 Initializing Singleton Session Beans........................................................................ 28-7
28.2.1.2 Managing Concurrent Access in a Singleton Session Bean................................. 28-8
28.2.1.3 Handling Errors in a Singleton Session Bean...................................................... 28-11
28.2.2 The Architecture of the counter Example ................................................................... 28-11
28.2.3 Running the counter Example ...................................................................................... 28-13
28.2.3.1 To Run the counter Example Using NetBeans IDE............................................ 28-13
28.2.3.2 To Run the counter Example Using Maven......................................................... 28-13
28.3 A Web Service Example: helloservice................................................................................. 28-14
28.3.1 The Web Service Endpoint Implementation Class .................................................... 28-14
28.3.2 Stateless Session Bean Implementation Class............................................................. 28-14
28.3.3 Running the helloservice Example............................................................................... 28-15
28.3.3.1 To Build, Package, and Deploy the helloservice Example Using NetBeans IDE........
28-15
28.3.3.2 To Build, Package, and Deploy the helloservice Example Using Maven........ 28-15
28.3.3.3 To Test the Service without a Client..................................................................... 28-15
28.4 Using the Timer Service........................................................................................................ 28-16
28.4.1 Creating Calendar-Based Timer Expressions............................................................. 28-16
28.4.1.1 Specifying Multiple Values in Calendar Expressions........................................ 28-17
28.4.2 Programmatic Timers..................................................................................................... 28-18
28.4.2.1 The @Timeout Method ........................................................................................... 28-18
xx
28.4.2.2 Creating Programmatic Timers............................................................................. 28-19
28.4.3 Automatic Timers ........................................................................................................... 28-20
28.4.4 Canceling and Saving Timers ....................................................................................... 28-20
28.4.5 Getting Timer Information............................................................................................ 28-21
28.4.6 Transactions and Timers................................................................................................ 28-21
28.4.7 The timersession Example............................................................................................. 28-21
28.4.8 Running the timersession Example.............................................................................. 28-23
28.4.8.1 To Run the timersession Example Using NetBeans IDE ................................... 28-24
28.4.8.2 To Build, Package, and Deploy the timersession Example Using Maven ...... 28-24
28.4.8.3 To Run the Web Client............................................................................................ 28-24
28.5 Handling Exceptions ............................................................................................................. 28-24
29 Using the Embedded Enterprise Bean Container
29.1 Overview of the Embedded Enterprise Bean Container.................................................... 29-1
29.2 Developing Embeddable Enterprise Bean Applications.................................................... 29-1
29.2.1 Running Embedded Applications.................................................................................. 29-2
29.2.2 Creating the Enterprise Bean Container........................................................................ 29-2
29.2.2.1 Explicitly Specifying Enterprise Bean Modules to be Initialized ....................... 29-3
29.2.3 Looking Up Session Bean References ............................................................................ 29-3
29.2.4 Shutting Down the Enterprise Bean Container............................................................ 29-3
29.3 The standalone Example Application................................................................................... 29-4
29.3.1 Runing the standalone Example Application in NetBeans IDE ................................ 29-5
29.3.2 Running the standalone Example Application using Maven .................................... 29-5
30 Using Asynchronous Method Invocation in Session Beans
30.1 Asynchronous Method Invocation........................................................................................ 30-1
30.1.1 Creating an Asynchronous Business Method .............................................................. 30-1
30.1.2 Calling Asynchronous Methods from Enterprise Bean Clients................................. 30-2
30.1.2.1 Retrieving the Final Result from an Asynchronous Method Invocation .......... 30-2
30.1.2.2 Cancelling an Asynchronous Method Invocation ................................................ 30-3
30.1.2.3 Checking the Status of an Asynchronous Method Invocation ........................... 30-3
30.2 The async Example Application ............................................................................................ 30-3
30.2.1 Architecture of the async Example Application .......................................................... 30-3
30.2.2 Running the async Example............................................................................................ 30-4
30.2.2.1 To Configure the Keystore and Truststore in GlassFish Server ......................... 30-4
30.2.2.2 To Run the async Example Application Using NetBeans IDE............................ 30-5
30.2.2.3 To Run the async Example Application Using Maven........................................ 30-6
Part VI Contexts and Dependency Injection for Java EE
31 Introduction to Contexts and Dependency Injection for Java EE
31.1 Getting Started.......................................................................................................................... 31-2
31.2 Overview of CDI...................................................................................................................... 31-3
31.3 About Beans.............................................................................................................................. 31-4
31.4 About CDI Managed Beans.................................................................................................... 31-4
31.5 Beans as Injectable Objects...................................................................................................... 31-5
剩余917页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2008-08-19 上传
2008-11-07 上传
2008-01-28 上传
2008-08-26 上传
点击了解资源详情
点击了解资源详情
commings_jj
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功