• No results found

Enterprise Java Web Application Frameworks & Sample Stack Implementation

N/A
N/A
Protected

Academic year: 2021

Share "Enterprise Java Web Application Frameworks & Sample Stack Implementation"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Enterprise Java Web

Application Frameworks &

Sample Stack Implementation

Mert ÇALI

Ş

KAN

[email protected] STM Inc.

(2)

Who am I?

The Software Plumber :)

SCJP certified dude bla bla...

Open Source Evangelist

Founder & Author of various Open Source Projects

Member of MyFaces Community
(3)

Agenda

The aim: Enterprise Java WebApp Framework

Which stack to choose?

The Stack
(4)

MVC pattern

Quality & Competency of “The Stack”

Performance & Scalability

Learning Curve & Development Speed !

don’t let cutting edge turn into bleeding edge...

release early & release often..!

Community Factor & Open Source support (forums-mailing lists & etc.)
(5)

Which stack to choose?

JSF WebWork Struts Spring MVC Tapestry Spring Guice Hibernate iBatis Toplink KODO EclipseLink Model/Persistence Layer picoContainer Controller/Dep.Inj. HiveMind XWork Apache CXF Spring WS Integration Apache Axis2 UI IDE Eclipse IntelliJ IDEA JDeveloper Wicket GWT NetBEANS Cocoon ZK Echo3
(6)

It’s nothing new!

not “yet another java framework”

It’s a stack demonstration with OSS

Released on 01.2009

http://code.google.com/p/mesir
(7)

DOMAIN MODEL

AddressBook Contact 1 0..* id text creationDate contacts id name email phone
(8)

THE STACK

VIEW CONTROLLER MODEL JSF FACELETS ORCHESTRA JPA HIBERNATE ENVERS SPRING H.VALIDATOR H.SEARCH MAVEN ECLIPSE with SecuRITY Apache CXF
(9)

JSF-1

A standard (v1.2_13 and v2.0.1 FCS)

A component oriented & event-driven framework

Binding makes JSF Powerful

Bind a bean’s variable to component

<h:inputText value=“#{person.name}” />

Bind a method to the action component

<h:commandButton

action=“#{personSavePage.savePerson}” />

Conversion & Validation

no hassle with java.util.Date

(10)

JSF-2

3rd Party Ajaxified Frameworks

PrimeFACES - Crazy Turks RichFACES - JBoss

IceFACES - Sun

ADFFaces - Oracle

IDE Support

(Eclipse - NetBeans - JDeveloper)

(11)

FACELETS

ViewHandler created for JSF

mixing JSF + JSP for JSF 1.x

well balanced HTML : xhtml

Templating
(12)

SPRING-1

Dependency Injection & IoC

with XML and annotations

JEE ( JMS, EJBs, JCA ...)

AOP

ORM Integration, DAO Support tx management, entityManager
(13)

SPRING-2

DAO Spring JDBC Transaction management ORM Hibernate JPA TopLink JDO OJB iBatis JEE JMX JMS JCA Remoting EJB Email AOP Spring AOP AspectJ Integration Web Spring WEB MVC Framework Integration Struts Tapestry JSF JSPs Velocity FreeMarker JasperReports Excel Spring Portlet MVC
(14)

SPRING-3

<context:property-placeholder location="classpath:application.properties"> ...

<context:component-scan base-package="tr.mesir" /> ...

<tx:annotation-driven /> ...

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">

<property name="driverClassName" value="${database.driver}"/>

<property name="url" value="${database.uri}"/>

<property name="username" value="${database.username}"/>

<property name="password" value="${database.password}"/> </bean>

...

<bean id="transactionManager"

class="org.springframework.orm.jpa.JpaTransactionManager">

(15)

SPRING-4

@Service("addressBookService")

public class AddressBookServiceImpl implements

AddressBookService { ...

@Autowired

private AddressBookDAO addressBookDAO; ...

}

@Repository

public class AddressBookDAOImpl implements AddressBookDAO { ...

@PersistenceContext

protected EntityManager entityManager; ...

(16)

MyFaces ORCHESTRA

Conversation Scoped beans &

Conversation Scoped Persistence Contexts LazyInitializationException or NonUniqueObjectException

(17)

JPA-1

Standard (Java EE 5.0)

object/relational mapping and persistent management interface

Support from different vendors

hibernate - toplink - eclipselink - kodo ...

(18)

JPA-2

@Entity

public class AddressBook extends BaseObject {

@Id

@GeneratedValue(strategy = GenerationType.AUTO)

private Long id;

@OneToMany(cascade={CascadeType.ALL})

@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)

private List<Contact> contacts = new ArrayList<Contact>();

(19)

JPA-3

public AddressBook loadById(Long id) {

return entityManager.find(AddressBook.class, id); }

public void save(AddressBook addressBook) { entityManager.persist(addressBook);

}

public List<String> findAllTitles() {

return entityManager.createQuery("select ab.title from

AddressBook ab").getResultList();

}

(20)

HIBERNATE-1

Object / Relational Mapping framework

No hassle with result set handling object

conversion and SQL, well almost for SQL :)

Support for any DB with dialects
(21)

Hibernate Search

Bringing full text search engine to the persistence domain model

e.g. : amazon search

Apache Lucene™ under the hood

Lucene Directory

File - DB - in mem

JPA Triggered Event System
(22)

H.S. - How To Use

Configuration

Transparent with JPA

(hibernate entity manager) (hibernate annotations)

Annotation Based @Indexed @Field(store, index) @IndexedEmbedded ...
(23)

H.S. - Example

@Entity

@Indexed

public class AddressBook extends BaseObject {

@Field(index=Index.TOKENIZED, store=Store.NO)

private String title;

@OneToMany(cascade={CascadeType.ALL})

@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)

@IndexedEmbedded

private List<Contact> contacts =

new ArrayList<Contact>(); ....

(24)

H.S. - Example

@SuppressWarnings("unchecked")

public List<AddressBook> findByWord(String searchWord) throws ParseException {

// Since contacts list is declared as @IndexedEmbedded inside AddressBook, // we can search through the name or email of a contact also.

MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] {

"title", "contacts.name", "contacts.email" }, new StandardAnalyzer());

Query query = parser.parse(searchWord);

FullTextQuery ftq = getFullTextEntityManager().createFullTextQuery(

query, AddressBook.class);

return ftq.getResultList();

(25)

HIBERNATE VALIDATOR-1

Reference implementation for JSR 303: Bean Validation

DRY (Don’t Repeat Yourself)

express your domain constraints once..! property2DDLSchema

annotation-based

@NotNull @NotEmpty @Length(min=, max=) ... @Email @Pattern @Valid ...

(26)

HIBERNATE VALIDATOR-2

@Field

@NotEmpty(message="Name should not be empty")

@Length(min=4, max=40)

private String name;

@Field

@NotEmpty(message="Email should not be empty")

@Email

(27)

HIBERNATE ENVERS-1

Versioning for JPA entities

A part of Hibernate with Hib.3.5

Simple to implement with annotations

@Audited ....

(28)

HIBERNATE ENVERS-2

Entities R e v i s i o n s id=”1”

data=”x” data=”p”id=”4”

id=”2” data=”a” id=”3” data=”x” id=”1” data=”y” id=”2” data=”b” id=”2”

(29)

HIBERNATE ENVERS-3

@Entity @Indexed

@Audited

public class Contact extends BaseObject {

@Field

@Versioned

private String name; }

(30)

Apache CXF-1

open-source services framework

annotation driven

JAX-WS & JAX-RS compliant

soap + rest
(31)

Apache CXF-2

@Component("addressBookWebService")

@WebService

public class AddressBookWebService {

@Autowired

private AddressBookService addressBookService; @WebMethod

public List<String> allAddressBookTitles() {

return addressBookService.findAllTitles(); } } spring configuration: <jaxws:endpoint id="addressBookWS" implementor="#addressBookWebService" address="/addressbook" />

(32)

Apache CXF-3

(33)

MAVEN

Stop “building the build” and focus on building the application...!

A uniform build system...

Project Object Model (POM)

Guidelines for best practices while doing development
(34)

MAVEN - The POM-1

<project ...>

<modelVersion>4.0.0</modelVersion> <groupId>tr.mc</groupId>

<artifactId>mesir</artifactId> <packaging>war</packaging>

<version>1.0-SNAPSHOT</version> <name>mesir</name>

<url>http://code.google.com/p/mesir</url>

<description>Skeleton project for java based web applications</description>

... ...

... ...

(35)

MAVEN - The POM-2

<dependencies> ...

<dependency>

<groupId>org.springframework</groupId> <artifactId>spring</artifactId>

<version>2.5.6</version> </dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId> <version>2.5.6</version>

<scope>test</scope> </dependency>

...

(36)

MAVEN - The POM-3

<repositories> <repository>

<id>mesir-repo</id>

<url>http://mesir.googlecode.com/svn/trunk/mavenrepo</url>

</repository> <repository>

<id>jboss</id>

<url>http://repository.jboss.com/maven2</url>

</repository> <repository>

<id>apache-snapshot</id>

<url>http://people.apache.org/repo/m2-snapshot-repository</url>

</repository> </repositories>

(37)

ECLIPSE-1

Universal toolset for Development

Open Source IDE

Extensible architecture based on plugins

Specified mostly on Java but development language is independent...

CDT - PHP - Cobol

Plugins used while developing mesir: subclipse
(38)

ECLIPSE-2

(39)

Thank you...

http://www.jroller.com/mert

http://code.google.com/p/mesir http://localhost:8080/mesir/ws/addressbook/allAddressBookTitles >http://mesir.googlecode.com/svn/trunk/mavenrepo http://repository.jboss.com/maven2</ http://people.apache.org/repo/m2-snapshot-repository</ http://www.jroller.com/mert http://www.twitter.com/mertcaliskan

References

Related documents

Comparative efficacy and acceptability of antidepressants, psychological interventions, and their combination for depressive disorder in children and adolescents: protocol for

In short, notwithstanding resistance and refreezing, the eventual outcome has been successful as the new accounting programme will satisfy the Accounting Department’s

Nevertheless, the past is rarely forgotten, and while in official narratives specific facts tend to be excluded or even denied, usually certain members of the society – mem-

Oleh yang demikian, adalah amat penting bagi sektor awam dan swasta untuk memilih corak pengagihan risiko yang sesuai dalam membuat keputusan yang

This chapter presents firstly the state of the art in maintenance support organization for offshore wind farms, and secondly summarizes the analytical model and the simulation

Penerapan Spatial Fuzzy C-Means pada segmentasi citra dan beberapa proses lainnya seperti cropping area objek, ekstraksi ciri warna HSV dan ekstraksi ciri tektur GLCM citra

The micro-chemical structure of long-term corrosion products on bronze swords buried at Lijiaba site (south- west China) has been investigated by Raman and XRF spectroscopies..

Increasing the cooking time from 60 to 120 min (decreasing residual lignin content) increased the values of modulus of elasticity, modulus of rupture, tensile strength, and