Sunteți pe pagina 1din 67

Seven Points for Applying Java EE 7

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.

 Opus, Lectures, etc.


– Conferences: JavaOne 2014, Oracle OpenWorld 2014, Java Day Tokyo 2014, JJUG CCC
Spring & Fall (2014), WebLogic roundtable (2012-2013), Rakuten Tech Conference (2014,
2013) etc.
– Magazine: @IT (2005-2010), CIO Magazine (2009), IT Architect (2005-2009), Web+DB
Press (2005), Java World (2001-2004), etc.

@HirofumiIwasaki #jdt65 2
JCP with Rakuten

Rakuten Joined JCP as a


member of “user company”.

@HirofumiIwasaki #jdt65 3
Update
Your Knowledge
JavaEE
of

To
@HirofumiIwasaki #jdt65
Agenda
1. Select the Java EE 7 based application server

2. Use modern IDE to build with Maven instead of text editor

3. Apply JSF for front-end framework

4. Apply EJB for back-end framework

5. Consider remote connectivity

6. Apply JPA for database persistence

7. Consider EE 8 for future-prove

@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

Korea GlassFish &


Group Compatible Group

Geronimo &
Compatible Group
Copy

Apache
Japan
Group
Group

JBoss World

@HirofumiIwasaki #jdt65 7
Details of Java EE Application Servers

Vendor App Server EE 1.4 EE 5 EE 6 EE 7


(2003-) (2006-) (2009-) (2013-)
Open Source GlassFish - 2.x 3.x 4.x
Oracle WebLogic 9.x 10.x 12.x - (Summer, 2015?)
IBM WebSphere 5.1 6.x, 7.x 8.x - (Summer, 2015?)
Red Hat JBoss 4.x 5.1 7.1 -
Red Hat WildFly - - - 8.0
Fujitsu Interstage 9.0,9.1 9.2,10.x,11.0 11.1 -
Apache Geronimo - 2.x 3.x -
Hitachi Cosminexus 7.x 8.x 9.x 10.0
TmaxSoft JEUS 5.0 6.0 7.0 8.0
Apache TomEE - - 1.x -

Few servers are


@HirofumiIwasaki #jdt65
available 8
Commercial or Free?
Is heavily
SLA required?

Is open source Is some support


NOT required? required?

Is there few initial Is long running Is DIY not acceptable?


cost limitation? upgrading path required?

Select Commercial Products Select Free Products

@HirofumiIwasaki #jdt65 9
Summary: Select Your Appropriate Server

Consider the policies for your application,

Determine the roadmap and resources,

Select the appropriate Java EE 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?

“Great Engineers” never


use such IDEs!
Instead, they use text editor!

@HirofumiIwasaki #jdt65 12
We’re now living in 2010’s
*Is Japanese special habit not to use IDEs?

“Great Engineer” never


use such IDEs!
NEVER
Instead, use text editor!

Apply the latest technologies!

@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

 Determined with “pom.xml”  Determined with “build.gradle”


 Automatic library downloading  Automatic library downloading
 Ease of use, script not supported  Complex scripting supported

@HirofumiIwasaki #jdt65 17
Three major IDEs support Maven in default setting

* *
“New Project” Dialogs:

@HirofumiIwasaki #jdt65 *Additional plugin required 18


“Special Project Files” are not required anymore with Maven

Maven Project are used by these three IDEs

@HirofumiIwasaki #jdt65 19
Summary: recommendation to make Java EE 7 project

Make project with ,

Enjoy programming with

(Choose anything you want)


@HirofumiIwasaki #jdt65 20
3. Apply JSF for front-end framework

To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7

Web Presentation Business Logic


(no presentations)
Data Access
JPA Call DBs
Call
JSF EJB Messaging
Call MQ
JMS
Rich Clients
Connection Other
Call
Call Automatic RMI-IIOP JAX Servers
Transaction EMail
JTA Call MTA
Java FX JavaMail

@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

Operate Build Operate Build


Action Next View Action Next View
Per Action Operation
@HirofumiIwasaki #jdt65 24
<Facelet> <Facelet> <Facelet>
View 1 View 2 View 3
Backing1 Backing2 Backing3
- fields - fields - fields
Front View + load() + load() + load()
& + action() + action() + action()
Backing Bean
Per View Operation

@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

<Facelet> <Facelet> <Facelet>


View 1 View 2 View 3
Backing1 Backing2 Backing3
- fields - fields - fields
Front View + load() + load() + load()
& Backing Bean + action() + action() + action()
@HirofumiIwasaki #jdt65 27
Paradigm Changing - Simple
One Action Class
Event Operation

Next Page
Initialization

Sprit to Two Parts

Event Operation Page Initialization

Backing Bean Backing Bean


Action Method @PostConstruct Method
@HirofumiIwasaki #jdt65 28
JSP vs. Facelet

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

Java EE 6 (JSF 2.1)

<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

HTML JSF 2.2 HTML Friendly Tags Older JSF Tags

<a> <a jsf:action=“#{cdi.prop}”>~~~</a> <h:commandLink>

<input type=“button”> <input type=“button” jsf:value=“#{cdi.prop}”/> <h:commandButton>


<input type=“submit”> <input type=“submit” jsf:value=“#{cdi.prop}”/>

<input type=“file”> <input type=“file” jsf:value=“#{cdi.prop}”/> <h:inputFile>

<input type=“hidden”> <input type=“hidden” jsf:value=“#{cdi.prop}”/> <h:inputHidden>

<input type=“password”> <input type=“password” jsf:value=“#{cdi.prop}”/> <h:inputSecret>

<textarea> <textarea jsf:value=“#{cdi.prop}”/> <h:inputTextArea>

<input type=“checkbox”> <input type=“checkbox” jsf:value=“#{cdi.prop}”/> <h:selectBooleanCheckbox>

・・・
etc.
@HirofumiIwasaki #jdt65 31
Summary: Recommendation for the Java EE 7 Front-End

Use For your web front-end,

Implement with Facelet,

Apply HTML-Friendly Tags for mark-up.

@HirofumiIwasaki #jdt65 32
4. Apply EJB for back-end framework

To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7

Web Presentation Business Logic


(no presentations)
Data Access
Call DBs
Call JPA
JSF EJB Messaging
Call MQ
JMS
Rich Clients
Connection Other
Call
Call Automatic RMI-IIOP JAX Servers
Transaction EMail
Java FX JTA Call MTA
JavaMail

@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

4. No Deployment Descriptor (optional)


5. Embedded EJB Container
@HirofumiIwasaki #jdt65
for Testing & etc. 37
How Design the Batch Logics?

Choice 1: Use EJB, Choice 2: Use Choice 3: Don’t Use


Call via EJB Remote Java Batch Framework, Java EE Server
from Outside Call from Outside [NOT RECOMMENDED]

Batch Batch Batch


Kicker Call EJB Kicker Call Java Batch Kicker Call POJO
Batch

Java EE Server Java EE Server

Full automatic transaction, If the standard templates Full manual transaction,


Able to use embedded server. suitable for your app, try it. management, and everything.

@HirofumiIwasaki #jdt65 38
Limitation: Don’t Use Lambda Parallel Stream inside of the EJB

Java EE 7 spec is not supported


Java SE 8 new functions.
Tested Fork/Join Framework
(basement of the parallel stream) with
WebLogic Server 12.1 (yet Java EE 6)

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)

Protocol Supported Annotation Client Stub Value Global


From Marshaling Transaction

RMI-IIOP J2EE 1.2 @Remote in Remote interface Auto XA Supported


remote interface with auto generate

SOAP Java EE 5 @WebService Auto generate in Auto N/A


development

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

Select the RMI-IIOP


for heavy transactional distributed systems.

Select the Web Socket


for system that requires light-weight and
faster speed.

@HirofumiIwasaki #jdt65 48
6. Apply JPA for database persistence

To
@HirofumiIwasaki #jdt65
Typical usage of Java EE 7

Web Presentation Business Logic


(no presentations)
Data Access
JPA Call DBs
Call
JSF EJB Messaging
Call MQ
JMS
Rich Clients
Connection Other
Call
Call Automatic RMI-IIOP JAX Servers
Transaction EMail
Java FX JTA Call MTA
JavaMail

@HirofumiIwasaki #jdt65 50
About JPA – Java Persistence API

Java Persistence API


(from Java EE 5)

@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

JPA Data Access Object (DAO)

@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

EJB Business Logic


JPA JDBC
Entity Manager Driver Manager

RAW
JNDI No Global Transaction
JTA Transaction ? No Connection Management
Management

Thread EJB Object Connection Self-Managed


?
Pool Pool Pool JDBC Connection

Java EE Application Server

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

JPA entity manager


Automatic automatically join
Transaction the CMT of EJB
JTA

@HirofumiIwasaki #jdt65 56
Summary: Use JPA, Instead of Raw JDBC.

Apply JPA ordinarily,


within the EJB Container
Managed Transaction (CMT)

@HirofumiIwasaki #jdt65 57
7. Consider EE 8 for future-prove

To
@HirofumiIwasaki #jdt65
Beyond of the Java EE 7

JAX-RS 2.1 Java EE Security API 1.0

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

EJB Entity Bean


J2EE 1.3

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

S-ar putea să vă placă și