Java EE 7 in Action
Java EE 7 in Action
Apr 8, 2015
Hirofumi Iwasaki
Financial Service Department, DU, Rakuten, Inc.
@HirofumiIwasaki #jdt65
Speaker Biography
Hirofumi Iwasaki
– Group Manager, Technology Manager
– Financial Service Department, Development Unit,
Rakuten, Inc.
Carrier
– 16 Years of experience in planning, designing and implementation of Japanese financial,
manufacturing and public enterprise system with emphasis in Java EE and .NET enterprise
middleware.
@HirofumiIwasaki #jdt65 2
JCP with Rakuten
@HirofumiIwasaki #jdt65 3
Update
Your Knowledge
JavaEE
of
To
@HirofumiIwasaki #jdt65
Agenda
1. Select the Java EE 7 based application server
@HirofumiIwasaki #jdt65 5
1. Select the Java EE 7 based
application server
To
@HirofumiIwasaki #jdt65
Java EE World and Others
App Google
Engine WebLogic World
Geronimo &
Compatible Group
Copy
Apache
Japan
Group
Group
JBoss World
@HirofumiIwasaki #jdt65 7
Details of Java EE Application Servers
@HirofumiIwasaki #jdt65 9
Summary: Select Your Appropriate Server
@HirofumiIwasaki #jdt65 10
2. Use modern IDE to build with
Maven instead of text editor
To
@HirofumiIwasaki #jdt65
In 1990’s – early 2000’s
*Is Japanese special habit not to use IDEs?
@HirofumiIwasaki #jdt65 12
We’re now living in 2010’s
*Is Japanese special habit not to use IDEs?
@HirofumiIwasaki #jdt65 13
Over 10,000 classes in real large systems
Crazy amount of
source codes!
@HirofumiIwasaki #jdt65 14
Manage tons of codes with modern IDE
@HirofumiIwasaki #jdt65 15
Summary: modern IDE for Java EE
@HirofumiIwasaki #jdt65 16
De-Facto standard building tool
@HirofumiIwasaki #jdt65 17
Three major IDEs support Maven in default setting
* *
“New Project” Dialogs:
@HirofumiIwasaki #jdt65 19
Summary: recommendation to make Java EE 7 project
To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7
@HirofumiIwasaki #jdt65 22
Selection of the front-end frameworks of server side Java
JavaServer Faces
– Genuine Java EE front-end framework
– Many additional components like “PrimeFaces”.
– View-based operation
Apache Struts
– 2000’s older front-end framework (especially 1.x)
– Many results in any industries
– Action-based operations
@HirofumiIwasaki #jdt65 23
struts-config.xml
1.x
ActionForm1 ActionForm2
- fields - fields
+ validate() + validate()
Action1 Action2
<<JSP>> <<JSP>> <<JSP>>
View1 + action() View 2 + action() View 3
@HirofumiIwasaki #jdt65 25
Paradigm Shift:
Action to Page
@HirofumiIwasaki #jdt65 26
Paradigm Changing - Simple
ActionForm1 ActionForm2
1.x - fields - fields
+ validate() + validate()
<<JSP>> Action1 <<JSP>> Action2 <<JSP>>
View1 + action() View 2 + action() View 3
Operate Build Operate Build
Action Next View Action Next View
Next Page
Initialization
Harmful No Compile,
JavaServer Dev. Procs Rapid Dev.
Facelet
Pages
Re-Deploy
Compile & Compile Real-time
Interpreting
Fix & Reload
Fix Java Servlet
Work
Work
Check
HTML HTML
Rendering Rendering
@HirofumiIwasaki #jdt65 29
HTML Friendly Tags
<input type="text"
jsfc="h:inputText"
name="id"
value="#{bean.property}" />
Nice Relationship
with HTML
Simplified
Design Tools
Java EE 7 (JSF 2.2)
<input type="text”
jsf:value="#{bean.property}" />
@HirofumiIwasaki #jdt65 30
Use HTML Friendly Tags
・・・
etc.
@HirofumiIwasaki #jdt65 31
Summary: Recommendation for the Java EE 7 Front-End
@HirofumiIwasaki #jdt65 32
4. Apply EJB for back-end framework
To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7
@HirofumiIwasaki #jdt65 34
RMI-IIOP Review: What’s EJB? Why EJB?
SOAP
REST
Web Socket
(BEGIN)
Client
EJB
EJB Database
(COMMIT)
1. Remote Invocation
2. Automatic Transaction Management
Activate
Instance
Pool EJB
EJB
EJB
EJB Client
EJB
3. Instance Pooling for Faster Operation
4. Security Management
@HirofumiIwasaki #jdt65 35
Forget about the past EJB blames of EJB 1.x & 2.x
in 2004
11 years ago!!
@HirofumiIwasaki #jdt65 36
EJB 3 and beyond – Improved dramatically
Other
@Stateless Instance
@Inject JPA
EJB
@EJB Database
EJB
1. Introduced Annotations, POJO
3. Entity Bean JPA
2. Introduced Injections
EJB
EJB ejb-jar.xml
Embedded Container
@HirofumiIwasaki #jdt65 38
Limitation: Don’t Use Lambda Parallel Stream inside of the EJB
Not worked.
“weblogic.ejb.container.compliance.
ComplianceException”
@HirofumiIwasaki #jdt65 39
Apply EJB for your enterprise logics
Apply me!
I’ll remotely
manage
transactions
@HirofumiIwasaki #jdt65 40
5. Consider remote connectivity
To
@HirofumiIwasaki #jdt65
RMI-IIOP Review: What’s EJB? Why EJB?
SOAP
REST
Web Socket
(BEGIN)
Client
EJB
EJB Database
(COMMIT)
1. Remote Invocation
2. Automatic Transaction Management
Activate
Instance
Pool EJB
EJB
EJB
EJB Client
EJB
3. Instance Pooling for Faster Operation
4. Security Management
@HirofumiIwasaki #jdt65 42
Supported protocols of Java EE 7 (EJB)
REST Java EE 6 @GET, @POST, (Nothing special) Work with JSON N/A
etc. or something
(string base)
Web Socket Java EE 7 @ServerEndpoint @ClientEndpoint Work with JSON N/A
with auto generate or something
(string base)
@HirofumiIwasaki #jdt65 43
For heavy transaction: consider RMI-IIOP
Global Transaction
Management Other
with XA Protocol System’s
EJB
AUTO
BEGIN
EJB
Client RMI-IIOP Session Bean Other
IIOP Enterprise
Information
Systems
AUTO
COMMIT
Database
@HirofumiIwasaki #jdt65 44
For light-weight usage: consider Web Socket + JSON
Ultra-Fast,
Ease of Dev.
AUTO
BEGIN
EJB
Client Web Socket Session Bean
AUTO
COMMIT
Database
Local Transaction
Management
@HirofumiIwasaki #jdt65 45
EJB Session Bean with RMI-IIOP and Web Socket
RMI-IIOP
Some Clients
EJB Transactional
Web Socket Processing
@Stateless
@Remote for RMI-IIOP
@ServerEndpoint(value = "/memberlogic") for Web Socket
public class MemberLogic implements MemberLogicRemote {
for RMI-IIOP
@OnMessage for Web Socket
public String register(String message, Session session) {
// WRITE TRANSACTIONAL LOGICS HERE!
return xxxx;
}
}
@HirofumiIwasaki #jdt65 46
Why do not use SOAP or REST?
SOAP REST
The improvements are almost stopped It does not have good support
in both specs and Java EE support. in Java EE, especially for client-side.
Heavy auto generating codes. No marshaling and unmarshaling
Buggy interoperability. support in Java EE.
Slower marshaling and unmarshaling. Slower protocol than web socket.
@HirofumiIwasaki #jdt65 47
Summary: Recommendation of Protocols
@HirofumiIwasaki #jdt65 48
6. Apply JPA for database persistence
To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7
@HirofumiIwasaki #jdt65 50
About JPA – Java Persistence API
@HirofumiIwasaki #jdt65 51
JPA – Simple Database Mapper
Auto Generate
One by One
Relational Database
(E-R Diagram) JPA Entity
With Bean Validation (Class Diagram)
@HirofumiIwasaki #jdt65 52
JPA – Simple Database Mapper
Auto CRUD
to Database
Access to RDB
JPA Entity
@HirofumiIwasaki #jdt65 53
JPA Custom Queries – JPQL and Criteria Query
JPQL:
public List<Member> findMemberByName(String name) {
String queryString = "SELECT a FROM Member m " +
"WHERE m.name = LOWER(:name)";
Query query = getEntityManager().createQuery(queryString);
query.setParameter("name", name);
List<Member> result = query.getResultList();
}
Criteria Query:
public List<Member> findMemberByName(String name) {
CriteriaBuilder builder = this.em.getCriteriaBuilder();
CriteriaQuery query = builder.createQuery();
Root<Member> member = query.from(Member.class);
query.select(member);
query.where(builder.equal(member.get(”name"), name));
List<Member> result = this.em.createQuery(query).getResultList();
}
@HirofumiIwasaki #jdt65 54
Why You Should Not Use Raw JDBC in Java EE?
Java EE Application
RAW
JNDI No Global Transaction
JTA Transaction ? No Connection Management
Management
Java VM
@HirofumiIwasaki #jdt65 55
Combination with EJB Session Bean
Business Logic
(no presentations)
Full automatic
transaction management Data Access
with EJB session bean JPA Call DBs
EJB
@HirofumiIwasaki #jdt65 56
Summary: Use JPA, Instead of Raw JDBC.
@HirofumiIwasaki #jdt65 57
7. Consider EE 8 for future-prove
To
@HirofumiIwasaki #jdt65
Beyond of the Java EE 7
Servlet 4.0
JSON-B 1.0
CDI 2.0
JMS 2.1
MVC 1.0
JSF 2.3
Java EE Management API 1.0
JSON-P 1.1
@HirofumiIwasaki #jdt65 59
Recommendation
Apply
Standard APIs
@HirofumiIwasaki #jdt65 60
Standardization History of Java EE
Project JPE
or earlier
J2EE 1.2
J2EE 1.3
J2EE 1.4
EJB/JTA/XA/IIOP
Servlet/JSP
JDBC
RMI
Java EE 5
JMS
Java EE 6
SOAP
JSF/Facelet
JPA
Java EE 7
Web Socket
REST
Java Batch
CDI
Java EE 8
MVC
…
@HirofumiIwasaki #jdt65 61
Terminated Technologies of Java EE
Project JPE
or earlier
J2EE 1.2
J2EE 1.4
JSP
JDBC
RMI
Java EE 5
JSP
JMS
Java EE 6
SOAP
JSF/Facelet
JPA
Java EE 7
Web Socket
REST
Java Batch
CDI
Java EE 8
MVC
EJB
@HirofumiIwasaki #jdt65 62
Summary
is the world
open specification De-Facto standard.
“Standard” has many
pros & cons, but it can keep
your assets and knowledge.
@HirofumiIwasaki #jdt65 63
standardization history:
• From vendor special functions
• From open source functions
Java EE 7 Updates:
Standardized and long term support
@HirofumiIwasaki #jdt65
Java EE has
many world-wide
people and company support.
your application will have
long-life guaranteed.
@HirofumiIwasaki #jdt65
Apply Java EE 7
today and
be
ready for EE 8.
@HirofumiIwasaki #jdt65
@HirofumiIwasaki #jdt65