Anda di halaman 1dari 46

Java EE 7 for Real Enterprise Systems

実システムのためのJava EE 7

May 24, 2016


Hirofumi Iwasaki
Financial Service Department, DU, Rakuten, Inc.

@HirofumiIwasaki #jdt2016_5A
Speaker Biography

 Hirofumi Iwasaki
– Group Manager, Technology Manager
– Financial Service Department, Development Unit, Rakuten, Inc.

 Carrier
– 17 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 2015, 2014, Oracle OpenWorld 2014, Java Day Tokyo
2015, 2014, JJUG CCC Spring & Fall (2014), WebLogic roundtable (2012-
2013), Rakuten Tech Conference 2015 – 2013, etc.
– Book: デベロッパーのキャリアと働き方を語ろうVol.1 (2016)
– Magazine: 日経コンピュータ 2015年8月号 @IT (2005-2010), CIO Magazine
(2009), IT Architect (2005-2009), Web+DB Press (2005), Java World (2001-
2004), etc.

@HirofumiIwasaki #jdt2016_5A 2
On JavaOne 2015

Key Note Speech

Session "Real world batch processing using Java EE"


@HirofumiIwasaki #jdt2016_5A 3
Consider EE 8 for future-prove

@HirofumiIwasaki #jdt2016_5A
Update
Your Knowledge
JavaEE 7
of

For
@HirofumiIwasaki #jdt2016_5A
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 #jdt2016_5A 6
Recommendation

Apply
Standard APIs
@HirofumiIwasaki #jdt2016_5A 7
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 #jdt2016_5A 8
Terminated Technologies of Java EE
Project JPE
or earlier

J2EE 1.2
Today's

EJB Entity Bean


J2EE 1.3 Big Topic 1
JSF 2.1  2.2 Today's
J2EE 1.4 Big Topic 2

JSP
EJB to CDI
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 #jdt2016_5A 9
Java EE 7, For Your Real Systems

@HirofumiIwasaki #jdt2016_5A
Basic Strategy for Applying Java EE 7

 Continuous upgrading recommended.


– J2EE 1.2  1.3  1.4  Java EE 5  6  7 (on every two – four years)
– Wait migrations until the application server matured.
 Big jump: huge risk
– Some APIs were already terminated completely.
 EJB Entity Bean (1.1, 2.x)
 Older deployment descriptor (XML files) DTD or XML schema.
– Some Application servers were already terminated or stopped development.
 Silverstream
 Macromedia JRun
 Oracle Application Server (Orion, iAS, OC4J)
 Netscape (iPlanet) Application Server
 JOnAS
 Apache Geronimo

@HirofumiIwasaki #jdt2016_5A 11
Pre-J2EE Serv

J2EE 1.2 Servers

J2EE 1.3 Servers

J2EE 1.4 Servers

Java EE 5 Servers

Java EE 6 Servers

Java EE 7 Servers

1999 2001 2003 2006 2009 2013 2017?


@HirofumiIwasaki #jdt2016_5A
Update Your Systems Based on Java EE 6 to EE 7

 Typical Java EE 6 system configuration (2009 - )


– Oracle WebLogic 12.1, IBM WebSphere 8.x, JBoss 6, 7, other minor products.
– JDK 7  JDK 8 (super small jump).
– No need to migrate, super easy, just try it.
 Web front-end
– JSF 2.1 or Struts 2.x based  JSF 2.2 (jump!)
 From Struts 2, complete rewrite required from action to page.
 From JSF 2.1, apply HTML friendly markups, change backing bean to CDI (see next
chapter for more details)
 Back-end
– EJB 3 session bean  CDI 1.1 (jump!)
 If you use RMI-IIOP (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 Change EJB annotations to CDI annotations. (See more details on next chapter)
– JPA 2.0  JPA 2.1 (super small change)
 Almost no changed.

@HirofumiIwasaki #jdt2016_5A 13
Update Your Systems Based on Java EE 5 to EE 7

 Typical Java EE 5 system configuration (2006 - )


– Oracle WebLogic 10.x, 11, IBM WebSphere 7, JBoss 5.1, other minor products.
– JDK 6  JDK 8 (super small jump).
– Complete EOL, start migration today!
 Web front-end
– JSF 1.2 or Struts 2.x based  JSF 2.2 (jump!)
 From Struts 2, complete rewrite required from action to page.
 From JSF 1.2, apply Facelet instead of JSP, change backing bean to CDI (see next chapter
for more details)
 Back-end
– EJB 3 session bean  CDI 1.1 (jump!)
 If you use RMI-IIOP (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 Change EJB annotations to CDI annotations. (See more details on next chapter)
– JPA 1.0  JPA 2.1 (small jump!)
 Consider apply "PESSIMISTIC_READ" for "FOR UPDATE" SQL locking.

@HirofumiIwasaki #jdt2016_5A 14
Update Your Systems Based on J2EE 1.4 to EE 7

 Typical J2EE 1.4 system configuration (2003 - )


– BEA WebLogic 8.1, 9, IBM WebSphere 5.1, 6.x, JBoss 4.3, other minor products.
– JDK 1.4  JDK 8 (big jump!) , apply annotations.
– Complete EOL, start migration today!
 Web front-end
– Struts 1.x based  JSF 2.2 (big jump!)
 Complete rewrite required.
 Back-end
– EJB 2.1 session bean or Spring framework 1.x  CDI 1.1 (big jump!)
 If you use RMI-IIOP (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 ejb-jar.xml or applicationContext.xml  CDI annotations, remove home interface, etc.
– EJB 2.1 entity bean (CMP) or Hibernate 2.x, 3.x  JPA 2.1 (big jump from EJB!)
 Regenerate from RDB as "Entity" completely.
 From EJB, ejb-jar.xml  persistence.xml, EJB home interface  entity manager, etc.
 From Hibernate, small changes.

@HirofumiIwasaki #jdt2016_5A 15
Update Your Systems Based on J2EE 1.3 to EE 7

 Typical J2EE 1.3 system configuration (2001 - )


– BEA WebLogic 7.0, IBM WebSphere 5.0, other minor products.
– JDK 1.3, 1.4  JDK 8 (big jump!) , apply annotations.
– Complete EOL, start migration today!
 Web front-end
– Struts 1.x based  JSF 2.2 (big jump!)
 Complete rewrite required.
 Back-end
– EJB 2.0 session bean  CDI 1.1 (big jump!)
 If you use RMI-IIOP (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 ejb-jar.xml  CDI annotations, remove home & remote interface, etc.
– EJB 2.0 entity bean (CMP)  JPA 2.1 (big jump!)
 Regenerate from RDB as "Entity" completely.
 ejb-jar.xml  persistence.xml, change home interface to DAO.
 EJB home interface  entity manager, etc.

@HirofumiIwasaki #jdt2016_5A 16
Update Your Systems Based on J2EE 1.2 to EE 7

 Typical J2EE 1.2 system configuration (1999 - )


– BEA WebLogic 5.1, 6.0, 6.1, IBM WebSphere 4.0, other minor products.
– JDK 1.1, 1.2, 1.3  JDK 8 (big jump!) , apply collection framework, annotations.
– Complete EOL, start migration today!
 Web front-end
– Struts 1.x based  JSF 2.2 (big jump!)
 Complete rewrite required.
 Back-end
– EJB 1.1 session bean  CDI 1.1 (big jump!)
 If you use RMI-IIOP (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 ejb-jar.xml  CDI annotations, remove home & remote interface, etc.
– EJB 1.1 entity bean (CMP)  JPA 2.1 (big jump!)
 Regenerate from RDB as "Entity" completely.
 ejb-jar.xml  persistence.xml, change home interface to DAO.
 EJB home interface  entity manager, etc.

@HirofumiIwasaki #jdt2016_5A 17
Update Your Systems Based on pre-J2EE Era to EE 7

 Typical pre-J2EE 1.2 system configuration (1997 - )


– WebLogic Tengah 3.0, 4.51, Netscape Application Server (Kiva), IBM WebSphere 3.5,
Apache HTTPD + Apache JServ, other minor products.
– JDK 1.1  JDK 8 (super big jump!), apply collection framework, annotations.
– Perfect EOL, start migration today!
 Web front-end
– WebLogic JHTML, Netscape Application Builder (NAB)-based, JavaSoft Servlet 2.0, etc.
 JSF 2.2 (ultra big jump!)
 Complete rewrite required.
 Back-end
– WebLogic EJB, EJB 1.0 session bean  CDI 1.1 (big jump!)
 If you use T3 (with XA) for remote connection, consider apply EJB 3.2 instead of CDI.
 Almost all codes are usable, but need rewritten using JPA for data persistence.
 Deployment descriptor (prop)  CDI annotations, etc.
– WebLogic EJB, EJB 1.0 entity bean  JPA 2.1 (ultra big jump!)
 Regenerate from RDB completely.
 Deployment descriptor (prop)  persistence.xml
 EJB home interface  EntityManager, etc.

@HirofumiIwasaki #jdt2016_5A 18
WebLogic EJB DD
Web Front-End: JSF 2.1  2.2 for EE 7

@HirofumiIwasaki #jdt2016_5A
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 #jdt2016_5A 20
Almost no changed in big
architecture view
in EE 6 (JSF 2.1) to EE 7 (JSF 2.2).

<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

@HirofumiIwasaki #jdt2016_5A 21
Two big changes:
1. HTML friendly markup in Facelet
2. JSF backing bean to CDI

1. HTML friendly markup


<h:xxxxxx> JSF special element to
<Facelet> normal HTML elements.
View 1
Backing1
- fields 2. JSF original backing bean to
Front View + load()
& + action() normal CDI.
Backing Bean

@HirofumiIwasaki #jdt2016_5A 22
HTML Friendly Markups

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 #jdt2016_5A 23
HTML Friendly Markups

HTML JSF 2.2 HTML Friendly Tags Older JSF Tags

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

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


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

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


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

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


type=“checkbox”> ・・・ box>

etc.
@HirofumiIwasaki #jdt2016_5A 24
Java EE 6: Cannot Access from Outside to JSF Managed Bean

Java EE 6 (JSF 2.1)

Facelet @View
Scoped
Faces Phase
Filter
Servlet Listeners

Facelet @View
Scoped

Facelet @View
Scoped
Managed
Bean
@Session
Scoped
Cannot Access! JSF Managed Bean
World
@HirofumiIwasaki #jdt2016_5A 25
Java EE 6: Cannot Use ViewScoped CDIs, or Use JSF Backing Bean

Java EE 6 (JSF 2.1)

Cannot Use "View Scoped"


CDI
Facelet don't have
@View
Faces Phase Scoped
Filter
Servlet Listeners
CDI
Facelet don't have
@View
Scoped
CDI
Facelet don't have
@View
Managed Scoped
Bean
@Session
Scoped
OK!
CDI World
@HirofumiIwasaki #jdt2016_5A 26
Java EE 7: All Integrated CDI with JSF
Java EE 7 (JSF 2.2)
OK!

New CDI
Facelet @View
Faces Phase Scoped
Filter
Servlet Listeners
New CDI
Facelet @View
Scoped

New CDI
Facelet @View
Scoped
CDI
@Session
Scoped

OK! CDI World


Perfect!
@HirofumiIwasaki #jdt2016_5A 27
Consideration Points for Applying CDI in JSF Backing Bean

 Now CDI can be accessible on Filter.


– Consider applying @ApplicationScoped, @SessionScoped for some hacking techs.

 Migration from raw static objects to @ApplicationScoped CDI bean


– For easy management especially for controlling initialization timing.

 Migration from raw HttpSession to @SessionScoped CDI bean


– Don't use both HttpSession and @SessionScoped for avoiding confusing on production.
– Apply @SessionScoped only for managing session data.

 Migration from JSF management bean @ViewScoped to CDI @ViewScoped


– Same name but in different package (javax.faces.view.ViewScoped)
– Just change the package import from javax.faces.bean.ViewScoped.

@HirofumiIwasaki #jdt2016_5A 28 28
Summary: Recommendation for the Java EE 7 Front-End

Use For your web front-end,

Implement with Facelet,

Apply HTML-Friendly Markups.

@HirofumiIwasaki #jdt2016_5A 29
Back-End: EJB to CDI for future prove

@HirofumiIwasaki #jdt2016_5A
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 #jdt2016_5A 31
Java EE 6: What’s EJB? Why EJB? – The Core of Java EE
RMI-IIOP
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 #jdt2016_5A 32
Java EE 6: 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 #jdt2016_5A
for Testing & etc. 33
On Java EE 8 and Beyond: EJB to CDI

 Why EJB should go out?


1. Super old implementation in each Java
Good-bye EE compliant application server.
guys… 2. Old-style pre-compile required, need
much time to deploy.
3. Ultra tight related with EJB container,
difficult to test easily (although using EJB
embedded server).
4. Decreasing RMI-IIOP (T3) protocol users,
less compliant with CORBA specs.
5. Duplicated specification with latest CDI
with directly supported automatic
transaction with JTA specifications.

@HirofumiIwasaki #jdt2016_5A 34
RMI-IIOP Java EE 7 - EJB to CDI: Supporting half functions
SOAP
REST
Web Socket
EJB (BEGIN)
Client
↓ EJB
CDI ↓ Database
CDI (COMMIT)
1. Remote Invocation
2. Automatic Transaction Management
Activate
Instance
Pool EJB
EJB
Not
supported Not
EJB
EJB Client supported
EJB
3. Instance Pooling for Faster Operation
4. Security Management
@HirofumiIwasaki #jdt2016_5A 35
Supported protocols of Java EE 7 in CDI

Protocol Supported Annotation Client Stub Value Marshaling Global


From Transaction

RMI-IIOP J2EE 1.2 @Remote in remote Remote interface with Auto XA Supported
interface auto generate

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


development

REST Java EE 6 @GET, @POST, etc. (Nothing special) Work with JSON N/A
or something
(string base)

Web Socket Java EE 7 @ServerEndpoint @ClientEndpoint with Work with JSON N/A
auto generate or something
(string base)

@HirofumiIwasaki #jdt2016_5A 36
Java EE 7 - Limitation of CDI: RMI-IIOP with XA is not supported

NOT SUPPORTED:
Global Transaction Other
Management System’s
with XA Protocol
EJB
AUTO
BEGIN Not
CDI supported
Other
Client REST, Web Socket Enterprise
IIOP
Information
Systems
AUTO
COMMIT Not
supported

Database

@HirofumiIwasaki #jdt2016_5A 37
EE7 - Limitation of CDI: For light-weight usage, or simplified architecture

Enough for almost small architecture.

AUTO
BEGIN
CDI
Client REST, Web Socket Other
REST
System
* No XA
AUTO
COMMIT

Database
Local Transaction
Management
@HirofumiIwasaki #jdt2016_5A 38
How to convert EJB to CDI
For From (EJB) To (CDI)
Declaration @Stateless @Dependent
@Transactional
Injection @EJB @Inject
Transaction control @TransactionAttibute @Transactional
(TransactionAttibuteType (Transactional.TxType
.REQUIRES_NEW) .REQUIRES_NEW)
Self transaction @TransactionManagement( (delete)
management TransactionManagementType.BEAN)
Transaction rollback @ApplicationException( @Transactional(
rollback = true) rollbackOn = Exception.class)
Remote protocol @WebServices, @WebServices,
@GET or @POST, @GET, @POST or
@ServerEndpoint, or @ServerEndpoint
@Remote in remote interface,
@HirofumiIwasaki #jdt2016_5A
EJB to CDI Code – Super Simple Case
From (EJB CMT Session Bean) To (CDI)

And delete ejb-jar.xml (and weblogic-ejb-jar.xml etc.),


@HirofumiIwasaki #jdt2016_5A 40
Consideration Points for Applying CDI

 Merging JSF backing bean (CDI) view with business logics (CDI)
– Logically acceptable, but some difficulty for managing.
 Difficult to visualize transaction boundary with @Transactional.
 Super tight relationship between view and logics - Less code reusability.
– Not recommended for enterprise production, just apply for quick prototyping only.

 Incompatible points
– RMI-IIOP (or T3) with XA (global transaction)
 Keep using EJB remote interface on communication point only.
 Plan to change other lightweight protocol like REST+JSON.
– EJB Timer
 Change other products like job scheduler like IBM Tiboli, HITACHI JP1, etc.
– Asynchronous operations (@Asynchronous, or EJB Message-Driven bean with JMS)
 Wait next CDI spec (on EE 8), or keep using EJB.

@HirofumiIwasaki #jdt2016_5A 41 41
Summary: EJB to CDI

Apply simplified architecture,


use CDI with JTA automatic transaction
management.
Migrate EJB to CDI as applying easy replacement
rules.
Recognize incompatible points,
check EE 8 spec candidate,
design your next app.

@HirofumiIwasaki #jdt2016_5A 42
Summary

is the world
open specification De-Facto standard.
“Standard” has many
pros & cons, but it can keep
your assets and knowledge.
@HirofumiIwasaki #jdt2016_5A 43
Java EE has
many world-wide
people and company support.
your application will have
long-life guaranteed.

@HirofumiIwasaki #jdt2016_5A
Apply Java EE 7
today and
be
ready for EE 8.
@HirofumiIwasaki #jdt2016_5A
@HirofumiIwasaki #jdt2016_5A

Anda mungkin juga menyukai