Upload
hirofumi-iwasaki
View
940
Download
1
Embed Size (px)
Citation preview
@HirofumiIwasaki #jdt2016_5A
Java EE 7 for Real Enterprise Systems実システムのための Java EE 7
May 24, 2016Hirofumi IwasakiFinancial Service Department, DU, Rakuten, Inc.
@HirofumiIwasaki #jdt2016_5A 2
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 3
On JavaOne 2015
Key Note Speech
Session "Real world batch processing using Java EE"
@HirofumiIwasaki #jdt2016_5A
Consider EE 8 for future-prove
@HirofumiIwasaki #jdt2016_5A
UpdateYour Knowledge
Java EE 7For8
of
@HirofumiIwasaki #jdt2016_5A 6
Beyond of the Java EE 7
CDI 2.0JSON-B 1.0
JMS 2.1
Serv
let 4
.0
JAX-R
S 2.1
MVC 1.0JSF 2.3
Java EE Management API 1.0JSON-P 1.1
Java EE Security API 1.0
@HirofumiIwasaki #jdt2016_5A 7
Recommendation
Apply Standard APIs
@HirofumiIwasaki #jdt2016_5A 8
Standardization History of Java EE
J2EE 1.2
J2EE 1.3
J2EE 1.4
Java EE 5
Java EE 6
Java EE 7
Java EE 8
JDB
C
EJB
/JTA/X
A/IIO
P
Servlet/JS
P
JMS
RM
I
SO
AP JPA
JSF/Facelet
RE
ST
CD
I
Java Batch
Project JPEor earlier
Web S
ocket
MV
C
…
Many Open Source Ideas
@HirofumiIwasaki #jdt2016_5A 9
Terminated Technologies of Java EE
J2EE 1.2
J2EE 1.3
J2EE 1.4
Java EE 5
Java EE 6
Java EE 7
Java EE 8
JDB
C
EJB
JSP JM
S
RM
I
SO
AP JPA
JSF/Facelet
RE
ST
CD
I
Java Batch
Project JPEor earlier
Web S
ocket
EJB
Entity B
ean
JSP
MV
C
…
?
?
?
Today's Big Topic 2EJB to CDI
Today's Big Topic 1
JSF 2.1 2.2
@HirofumiIwasaki #jdt2016_5A
Java EE 7, For Your Real Systems
@HirofumiIwasaki #jdt2016_5A 11
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
1999 2001 2003 2006 2009 2013
Java EE 7 Servers
J2EE 1.2 Servers
Pre-J2EE Serv
J2EE 1.3 Servers
J2EE 1.4 Servers
Java EE 5 Servers
Java EE 6 Servers
EOL Group,Start Migration Today!
2017?
Big Jump Required!
@HirofumiIwasaki #jdt2016_5A 13
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 14
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 15
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 16
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 17
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 18
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.
WebLogic EJB DD
@HirofumiIwasaki #jdt2016_5A
Web Front-End: JSF 2.1 2.2 for EE 7
@HirofumiIwasaki #jdt2016_5A 20
Rich Clients
Web Presentation Business Logic(no presentations)
Typical usage of Java EE 7
JPA
EJBJSF
DBs
Java FX JTA
Automatic Transaction
JMS MQ
ConnectionRMI-IIOP
OtherServers
EMailMTAJavaMail
JAX
Call
Call
Call
Call
Call
Call
Data Access
Messaging
@HirofumiIwasaki #jdt2016_5A 21
<Facelet>View 1
Backing1- fields+ load()+ action()
<Facelet>View 2
Backing2- fields+ load()+ action()
<Facelet>View 3
Backing3- fields+ load()+ action()
Front View&
Backing Bean
Almost no changed in big architecture view
in EE 6 (JSF 2.1) to EE 7 (JSF 2.2).
@HirofumiIwasaki #jdt2016_5A 22
<Facelet>View 1
Backing1- fields+ load()+ action()
Front View&
Backing Bean
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 normal HTML elements.
2. JSF original backing bean tonormal CDI.
@HirofumiIwasaki #jdt2016_5A 23
HTML Friendly Markups
<input type="text” jsf:value="#{bean.property}" />
Java EE 7 (JSF 2.2)
Java EE 6 (JSF 2.1)
Simplified
<input type="text" jsfc="h:inputText" name="id" value="#{bean.property}" />
Nice Relationshipwith HTML
Design Tools
@HirofumiIwasaki #jdt2016_5A 24
HTML Friendly Markups
HTML JSF 2.2 HTML Friendly Tags Older JSF Tags
<a> <a jsf:action=“#{cdi.prop}”>~~~</a> <h:commandLink>
<input type=“button”><input type=“submit”>
<input type=“button” jsf:value=“#{cdi.prop}”/><input type=“submit” jsf:value=“#{cdi.prop}”/>
<h:commandButton>
<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 #jdt2016_5A 25
Java EE 6: Cannot Access from Outside to JSF Managed Bean
Filter FacesServlet
PhaseListeners
Facelet
Facelet
Facelet
@View Scoped
@View Scoped
@View Scoped
ManagedBean
@SessionScoped
Java EE 6 (JSF 2.1)
JSF Managed BeanWorld
Cannot Access!
Why??
@HirofumiIwasaki #jdt2016_5A 26
Java EE 6: Cannot Use ViewScoped CDIs, or Use JSF Backing Bean
Filter FacesServlet
PhaseListeners
Facelet
Facelet
Facelet
CDIdon't have
@View Scoped
CDIdon't have
@View Scoped
CDIdon't have
@View ScopedManaged
Bean@Session
Scoped
Java EE 6 (JSF 2.1)
CDI WorldOK!
Cannot Use "View Scoped"Why??
@HirofumiIwasaki #jdt2016_5A 27
Java EE 7: All Integrated CDI with JSF
Filter FacesServlet
PhaseListeners
Facelet
Facelet
Facelet
New CDI@ViewScoped
New CDI@ViewScoped
New CDI@ViewScoped
CDI@Session
Scoped
Java EE 7 (JSF 2.2)
CDI WorldOK!
OK!
Perfect!
@HirofumiIwasaki #jdt2016_5A 28
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.
28
@HirofumiIwasaki #jdt2016_5A 29
Summary: Recommendation for the Java EE 7 Front-End
Use For your web front-end,
Apply HTML-Friendly Markups.
Implement with Facelet,
@HirofumiIwasaki #jdt2016_5A
Back-End: EJB to CDI for future prove
@HirofumiIwasaki #jdt2016_5A 31
Rich Clients
Web Presentation Business Logic(no presentations)
Typical usage of Java EE 7
JPA
EJBJSFDBs
Java FX JTA
Automatic Transaction
JMS MQ
ConnectionRMI-IIOP
OtherServers
EMailMTAJavaMail
JAX
Call
Call
Call
Call
Call
Call
Data Access
Messaging
@HirofumiIwasaki #jdt2016_5A 32
Java EE 6: What’s EJB? Why EJB? – The Core of Java EE
EJBClient
1. Remote Invocation
EJB
2. Automatic Transaction Management
Database
(BEGIN)
(COMMIT)
EJBEJB
EJB
EJB
InstancePool
Activate
3. Instance Pooling for Faster Operation
RMI-IIOPSOAPRESTWeb Socket
EJBClient
4. Security Management
@HirofumiIwasaki #jdt2016_5A 33
Embedded Container
Java EE 6: EJB 3 and beyond – Improved dramatically
EJB
1. Introduced Annotations, POJO
@Stateless
EJB2. Introduced Injections
@Inject@EJB
OtherInstance
ejb-jar.xml
4. No Deployment Descriptor (optional)
EJB EJB
5. Embedded EJB Container for Testing & etc.
JPADatabase
3. Entity Bean JPA
@HirofumiIwasaki #jdt2016_5A 34
On Java EE 8 and Beyond: EJB to CDI
Why EJB should go out?1. Super old implementation in each Java
EE compliant application server.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.
Good-bye guys…
@HirofumiIwasaki #jdt2016_5A 35
Java EE 7 - EJB to CDI: Supporting half functions
EJB↓
CDIClient
1. Remote Invocation
EJB↓
CDI
2. Automatic Transaction Management
Database
(BEGIN)
(COMMIT)
EJBEJB
EJB
EJB
InstancePool
Activate
3. Instance Pooling for Faster Operation
RMI-IIOPSOAPRESTWeb Socket
EJBClient
4. Security Management
Notsupported Not
supported
@HirofumiIwasaki #jdt2016_5A 36
Supported protocols of Java EE 7 in CDI
Protocol Supported From
Annotation Client Stub Value Marshaling Global Transaction
RMI-IIOP J2EE 1.2 @Remote in remote interface
Remote interface with auto generate
Auto XA Supported
SOAP Java EE 5 @WebService Auto generate in development
Auto N/A
REST Java EE 6 @GET, @POST, etc. (Nothing special) Work with JSONor something(string base)
N/A
Web Socket Java EE 7 @ServerEndpoint @ClientEndpoint with auto generate
Work with JSONor something(string base)
N/A
@HirofumiIwasaki #jdt2016_5A 37
NOT SUPPORTED:Global Transaction Managementwith XA Protocol
Java EE 7 - Limitation of CDI: RMI-IIOP with XA is not supported
CDIClient REST, Web Socket
OtherSystem’s
EJB
Database
Other EnterpriseInformation
Systems
IIOP
RMI-IIOP
JDBC-XA
AUTOBEGIN
AUTOCOMMIT
Notsupported
Notsupported
@HirofumiIwasaki #jdt2016_5A 38
EE7 - Limitation of CDI: For light-weight usage, or simplified architecture
Local Transaction Management
CDIClient REST, Web Socket
Database
JDBC
AUTOBEGIN
AUTOCOMMIT
Enough for almost small architecture.
OtherSystem
REST
* No XA
@HirofumiIwasaki #jdt2016_5A
How to convert EJB to CDI
For From (EJB) To (CDI)Declaration @Stateless @Dependent
@TransactionalInjection @EJB @InjectTransaction control @TransactionAttibute
(TransactionAttibuteType.REQUIRES_NEW)
@Transactional (Transactional.TxType.REQUIRES_NEW)
Self transaction management
@TransactionManagement(TransactionManagementType.BEAN)
(delete)
Transaction rollback @ApplicationException(rollback = true)
@Transactional(rollbackOn = Exception.class)
Remote protocol @WebServices, @GET or @POST,@ServerEndpoint, or@Remote in remote interface,
@WebServices, @GET, @POST or@ServerEndpoint
@HirofumiIwasaki #jdt2016_5A 40
EJB to CDI Code – Super Simple CaseFrom (EJB CMT Session Bean) To (CDI)
And delete ejb-jar.xml (and weblogic-ejb-jar.xml etc.),
@HirofumiIwasaki #jdt2016_5A 41
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.
41
@HirofumiIwasaki #jdt2016_5A 42
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 43
Summary
is the worldopen specification De-Facto standard.
“Standard” has manypros & cons, but it can keep
your assets and knowledge.
@HirofumiIwasaki #jdt2016_5A
Java EE hasmany world-wide
people and company support.your application will have
long-life guaranteed.
@HirofumiIwasaki #jdt2016_5A
Apply Java EE 7today and
be ready for EE 8.
@HirofumiIwasaki #jdt2016_5A
Q&A