Seven Points for Applying Java EE 7

67
@HirofumiIwasaki #jdt65 Seven Points for Applying Java EE 7 Apr 8, 2015 Hirofumi Iwasaki Financial Service Department, DU, Rakuten, Inc.

Transcript of Seven Points for Applying Java EE 7

@HirofumiIwasaki #jdt65

Seven Points for Applying Java EE 7

Apr 8, 2015Hirofumi IwasakiFinancial Service Department, DU, Rakuten, Inc.

@HirofumiIwasaki #jdt65 2

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 3

JCP with Rakuten

Rakuten Joined JCP as a member of “user company”.

@HirofumiIwasaki #jdt65

UpdateYour Knowledge

Java EETo7

of

@HirofumiIwasaki #jdt65 5

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

Agenda

@HirofumiIwasaki #jdt65

1. Select the Java EE 7 based application server

To7

@HirofumiIwasaki #jdt65 7

GlassFish &Compatible Group

WebLogic World

Geronimo &Compatible Group

JBoss World

Code

Sharing

BigCompetitor

JapanGroup

Com

petit

or

AppEngine

Copy

New

Nam

e

Compe

titor

of J

EE

Battle

Java EE World and Others

KoreaGroup

ApacheGroup

Google

@HirofumiIwasaki #jdt65 8

Details of Java EE Application Servers

Vendor App Server EE 1.4(2003-)

EE 5(2006-)

EE 6(2009-)

EE 7(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 available

@HirofumiIwasaki #jdt65 9

Commercial or Free?

Is heavily SLA required?

Is open source NOT required?

Is some support required?

YES NO

Select Commercial Products Select Free Products

Is there few initial cost limitation?

YES

YES NO YES

Is DIY not acceptable?

NO

NO

YESN

ONOYE

S

Is long running upgrading path required?

@HirofumiIwasaki #jdt65 10

Summary: Select Your Appropriate Server

Consider the policies for your application,

Determine the roadmap and resources,

Select the appropriate Java EE server.

@HirofumiIwasaki #jdt65

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

To7

@HirofumiIwasaki #jdt65 12

In 1990’s – early 2000’s

“Great Engineers” never use such IDEs!

Instead, they use text editor!

*Is Japanese special habit not to use IDEs?

@HirofumiIwasaki #jdt65 13

“Great Engineer” never use such IDEs!

Instead, use text editor!

We’re now living in 2010’s

NEVER

Apply the latest technologies!

*Is Japanese special habit not to use IDEs?

@HirofumiIwasaki #jdt65 14

Over 10,000 classes in real large systems

Crazy amount of source codes!

@HirofumiIwasaki #jdt65 15

Manage tons of codes with modern IDE

@HirofumiIwasaki #jdt65 16

Summary: modern IDE for Java EE

@HirofumiIwasaki #jdt65 17

De-Facto standard building tool

Determined with “pom.xml” Automatic library downloading Ease of use, script not supported

Determined with “build.gradle” Automatic library downloading Complex scripting supported

@HirofumiIwasaki #jdt65 18

Three major IDEs support Maven in default setting

*Additional plugin required

* *“New Project” Dialogs:

@HirofumiIwasaki #jdt65 19

“Special Project Files” are not required anymore with Maven

Maven Project are used by these three IDEs

@HirofumiIwasaki #jdt65 20

Summary: recommendation to make Java EE 7 project

Make project with ,

Enjoy programming with

(Choose anything you want)

@HirofumiIwasaki #jdt65

3. Apply JSF for front-end framework

To7

@HirofumiIwasaki #jdt65 23

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 24

<<JSP>>View1

<<JSP>>View 2

Action1

+ action()

<<JSP>>View 3

Action2

+ action()

ActionForm1- fields+ validate()

ActionForm2- fields+ validate()

OperateAction

Build Next View

OperateAction

BuildNext View

Per Action Operation

struts-config.xml1.x

@HirofumiIwasaki #jdt65 26

Paradigm Shift:Action to Page

@HirofumiIwasaki #jdt65 27

Paradigm Changing - Simple

<<JSP>>View1

<<JSP>>View 2

Action1

+ action()

<<JSP>>View 3

Action2

+ action()

ActionForm1- fields+ validate()

ActionForm2- fields+ validate()

OperateAction

Build Next View

OperateAction

BuildNext View

<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

1.x

@HirofumiIwasaki #jdt65 28

One Action Class

Paradigm Changing - Simple

Event Operation

Next PageInitialization

Backing Bean Action Method

Event Operation

Backing Bean @PostConstruct Method

Page Initialization

Sprit to Two Parts

@HirofumiIwasaki #jdt65 29

JSP vs. Facelet

JavaServerPages

Facelet

Compile

Java Servlet

Work

HTMLRendering

HTMLRendering

Real-timeInterpreting

&Work

No Compile,Rapid Dev.

Re-Deploy& Compile

HarmfulDev. Procs

Check

Fix Fix Reload

@HirofumiIwasaki #jdt65 30

HTML Friendly Tags

<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 #jdt65 31

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=“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 #jdt65

4. Apply EJB for back-end framework

To7

@HirofumiIwasaki #jdt65 35

Review: What’s EJB? Why EJB?

EJBClient

1. Remote Invocation

EJB

2. Automatic Transaction Management

Database

(BEGIN)

(COMMIT)

EJB

EJBEJB

EJB

InstancePool

Activate

3. Instance Pooling for Faster Operation

RMI-IIOPSOAPRESTWeb Socket

EJBClient

4. Security Management

@HirofumiIwasaki #jdt65 36

Forget about the past EJB blames of EJB 1.x & 2.x

in 200411 years ago!!

@HirofumiIwasaki #jdt65 37

Embedded Container

EJB 3 and beyond – Improved dramatically

EJB

1. Introduced Annotations, POJO

@Stateless

EJB

2. 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 #jdt65 38

POJO

Java EE ServerJava EE Server

Java Batch

How Design the Batch Logics?

Choice 1: Use EJB, Call via EJB Remote from Outside

EJBBatch

BatchKicker Call

Choice 2: Use Java Batch Framework,Call from Outside

BatchKicker Call

Choice 3: Don’t UseJava EE Server[NOT RECOMMENDED]

BatchKicker Call

Full automatic transaction,Able to use embedded server.

If the standard templates suitable for your app, try it.

Full manual transaction,management, and everything.

@HirofumiIwasaki #jdt65 39

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) withWebLogic Server 12.1 (yet Java EE 6)

Not worked.“weblogic.ejb.container.compliance.ComplianceException”

@HirofumiIwasaki #jdt65

5. Consider remote connectivity

To7

@HirofumiIwasaki #jdt65 42

Review: What’s EJB? Why EJB?

EJBClient

1. Remote Invocation

EJB

2. Automatic Transaction Management

Database

(BEGIN)

(COMMIT)

EJB

EJBEJB

EJB

InstancePool

Activate

3. Instance Pooling for Faster Operation

RMI-IIOPSOAPRESTWeb Socket

EJBClient

4. Security Management

@HirofumiIwasaki #jdt65 43

Supported protocols of Java EE 7 (EJB)

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 #jdt65 44

Global Transaction Managementwith XA Protocol

For heavy transaction: consider RMI-IIOP

EJBSession BeanClient RMI-IIOP

OtherSystem’s

EJB

Database

Other EnterpriseInformation

Systems

IIOP

RMI-IIOP

JDBC-XA

AUTOBEGIN

AUTOCOMMIT

@HirofumiIwasaki #jdt65 45

For light-weight usage: consider Web Socket + JSON

Local Transaction Management

EJBSession BeanClient Web Socket

Database

JDBC

AUTOBEGIN

AUTOCOMMIT

Ultra-Fast, Ease of Dev.

@HirofumiIwasaki #jdt65 46

EJB Session Bean with RMI-IIOP and Web Socket

@Stateless@Remote@ServerEndpoint(value = "/memberlogic")public class MemberLogic implements MemberLogicRemote {

@OnMessage public String register(String message, Session session) { // WRITE TRANSACTIONAL LOGICS HERE! return xxxx; }}

EJB

RMI-IIOP

Web Socket

Some ClientsTransactionalProcessing

for RMI-IIOPfor Web Socket

for RMI-IIOPfor Web Socket

@HirofumiIwasaki #jdt65 47

Why do not use SOAP or REST?

SOAP REST The improvements are almost stopped

in both specs and Java EE support. Heavy auto generating codes. Buggy interoperability. Slower marshaling and unmarshaling.

It does not have good support in Java EE, especially for client-side. No marshaling and unmarshaling

support in Java EE. Slower protocol than web socket.

@HirofumiIwasaki #jdt65 48

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

6. Apply JPA for database persistence

To7

@HirofumiIwasaki #jdt65 51

About JPA – Java Persistence API

Standardized

Java Persistence API(from Java EE 5)

@HirofumiIwasaki #jdt65 52

JPA – Simple Database Mapper

Relational Database(E-R Diagram)

One by One

JPA Entity(Class Diagram)

Auto Generate

With Bean Validation

@HirofumiIwasaki #jdt65 53

JPA – Simple Database Mapper

for CRUDJPA Entity

JPA Data Access Object (DAO)

Auto CRUD to Database

Auto Generate

Access to RDB

@HirofumiIwasaki #jdt65 54

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();}

JPA Custom Queries – JPQL and Criteria Query

JPQL:

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 55

JTA Transaction Management

Java EE Application

EJB Business Logic

Why You Should Not Use Raw JDBC in Java EE?

Java EE Application Server

Java VM

ConnectionPool

EJB ObjectPool

ThreadPool

Self-ManagedJDBC Connection

JPAEntity Manager

JNDI

JDBC Driver Manager

RAW

?

?No Global Transaction

No Connection Management

@HirofumiIwasaki #jdt65 56

Combination with EJB Session Bean

Business Logic(no presentations)

JPAEJB

DBs

JTA

Automatic Transaction

Call

Full automatic transaction managementwith EJB session bean

JPA entity managerautomatically jointhe CMT of EJB

Data Access

@HirofumiIwasaki #jdt65 57

Summary: Use JPA, Instead of Raw JDBC.

Apply JPA ordinarily,within the EJB Container

Managed Transaction (CMT)

@HirofumiIwasaki #jdt65

7. Consider EE 8 for future-prove

To7

@HirofumiIwasaki #jdt65 59

Beyond of the Java EE 7

CDI 2.0JSON-B 1.0

JMS 2.1

Ser

vlet

4.0

JAX

-RS

2.1

MVC 1.0JSF 2.3

Java EE Management API 1.0JSON-P 1.1

Java EE Security API 1.0

@HirofumiIwasaki #jdt65 60

Recommendation

Apply Standard APIs

@HirofumiIwasaki #jdt65 61

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 JP

A

JSF

/Facelet

RE

ST

CD

I

Java Batch

Project JPEor earlier

Web S

ocket

MV

C

Many Open Source Ideas

@HirofumiIwasaki #jdt65 62

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 JP

A

JSF

/Facelet

RE

ST

CD

I

Java Batch

Project JPEor earlier

Web S

ocket

EJB

Entity B

ean

JSP

MV

C

?

?

?

@HirofumiIwasaki #jdt65 63

Summary

is the worldopen specification De-Facto standard.

“Standard” has manypros & cons, but it can keep

your assets and knowledge.

@HirofumiIwasaki #jdt65

standardization history:• From vendor special functions• From open source functions

Java EE 7 Updates: Standardized and long term support

@HirofumiIwasaki #jdt65

Java EE hasmany world-wide

people and company support.your application will have

long-life guaranteed.

@HirofumiIwasaki #jdt65

Apply Java EE 7today and

be ready for EE 8.

@HirofumiIwasaki #jdt65

Q&A