Developing Middleware in Java EE 8
Build robust middleware solutions using the latest technologies and trends
- 252 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Developing Middleware in Java EE 8
Build robust middleware solutions using the latest technologies and trends
About This Book
Use Java features such as JAX-RS, EJBs, and JPAs to build powerful middleware for newer architectures such as the cloudAbout This Bookā¢ Explore EJBs to build middleware solutions for enterprise and distributed applicationsā¢ Understand middleware designs such as event-based and message-driven web services ā¢ Learn to design and maintain large-scale systems and vendor disputesWho This Book Is ForEnterprise architects, designers, developers, and programmers who are interested in learning how to build robust middleware solutions for enterprise software will find this book useful. Prior knowledge of Java EE is essentialWhat You Will Learnā¢ Implement the latest Java EE 8 APIs and manage dependencies with CDI 2.0ā¢ Perform CRUD operations and access databases with JPA 2.1ā¢ Use bean validation API 2.0 to validate dataā¢ Develop business logic with EJB 3.2ā¢ Incorporate the REST architecture and RESTful API design patternsā¢ Perform serialization and deserialization on JSON documents using JSON-Bā¢ Utilize JMS for messaging and queuing models and securing applicationsā¢ Test applications using JUnit and Mockito and deploy them using DockerIn DetailMiddleware is the infrastructure in software based applications that enables businesses to solve problems, operate more efficiently, and make money. As the use of middleware extends beyond a single application, the importance of having it written by experts increases substantially. This book will help you become an expert in developing middleware for a variety of applications. The book starts off by exploring the latest Java EE 8 APIs with newer features and managing dependencies with CDI 2.0. You will learn to implement object-to-relational mapping using JPA 2.1 and validate data using bean validation. You will also work with different types of EJB to develop business logic, and with design RESTful APIs by utilizing different HTTP methods and activating JAX-RS features in enterprise applications. You will learn to secure your middleware with Java Security 1.0 and implement various authentication techniques, such as OAuth authentication. In the concluding chapters, you will use various test technologies, such as JUnit and Mockito, to test applications, and Docker to deploy your enterprise applications. By the end of the book, you will be proficient in developing robust, effective, and distributed middleware for your business.Style and approachLearn how to design and implement professional enterprise middleware solutions using the latest techniques and features provided by the Java EE 8 platform.
Frequently asked questions
Information
Accessing the Database with JPA 2.1
- Creating and using JPA entities
- Mapping entities to tables and columns
- Performing CRUD operations
- Mapping entity relationships
- Using the JPA query language and criteria APIs
- Mapping inheritance relationships
What's new in JPA 2.2?
- Stream query results
- Repeatable annotations
- Java 8 date and time support
- CDI support in converters
Architecture
- Persistence provider: A persistence provider is a JPA implementation provided by a vendor. As with most Java APIs, JPA is a standard API, where a set of different actual implementations are available from different vendors. The persistence provider means the vendor of the actual implementation we are using.
- Entities: An entity is a class that represents a domain object in our enterprise application. From a JPA perspective, an entity is represented with a table in the database, and an instance of this entity represents a record in that table.
- Entity managers: An entity manager is an object that represents a connection to a database, and contains all methods for the different operations that can be performed with the database, such as inserting a new record, retrieving a single record, performing advanced queries, and so on.
- Entity transaction: An entity transaction represents a database transaction that can be either committed or rolled back according to the application state. Any update operations (insert, update, delete) should be performed within the boundaries of an entity transaction.
- Query: As the name suggests, a query is an object that is used to perform a database query! In addition to the regular SQL, JPA provides a custom query language (called JPQL) that can be used to perform queries exactly like SQL, but with object-oriented concepts.
- Persistence unit: A persistence unit is a group of entities involved in a persistence context. A persistence unit is specified using a configuration file (persistence.xml), describing connection information, entities involved, and other useful configurations.
Writing your first JPA application
Step 1: Creating a data source
/WEB-INF/glassfish-resources.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> <resources> <jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="mysql_cinemasapp_rootPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false"> <property name="serverName" value="localhost"/> <property name="portNumber" value="3306"/> <property name="databaseName" value="cinemasapp"/> <property name="User" value="root"/> <property name="Password" value="root"/> <property name="URL" value="jdbc:mysql://localhost:3306/cinemasapp?zeroDateTimeBehavior=convertToNull"/> <property name="driverClass" value="com.mysql.jdbc.Driver"/> </jdbc-connection-pool> <jdbc-resource enabled="true" jndi-name="java:app/cinemasapp-ds" object-type="user" pool-name="mysql_cinemasapp_rootPool"/> </resources>
Step 2: Creating a persistence unit
/META-INF/persistence.xml <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="jpa-examplesPU" transaction-type="JTA"> <jta-data-source>java:app/cinemasapp-ds</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.schema-generation.database.action" value="create"/> </properties>
</persistence-unit> </persistence>
Step 3: Creating an entity class
Movie.java @Entity public class Movie { @Id @GeneratedValue private long id; private String title; public Movie() { } public long getId() { return id; } public void setId(long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } }
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- Packt Upsell
- Contributors
- Preface
- Delving into Java EE 8
- Dependency Injection Using CDI 2.0
- Accessing the Database with JPA 2.1
- Validating Data with Bean Validation 2.0
- Exposing Web Services with JAX-RS 2.1
- Manipulating JSON with JSON-B 1.0
- Communicating with Different Systems with JMS 2.0
- Sending Mails with JavaMail 1.6
- Securing an Application with Java Security 1.0
- Making Interactive Applications with WebSockets 1.1
- Other Books You May Enjoy