Title: Mayoclinic.org Online Services J2EE Application Architecture
1Mayoclinic.org Online Services J2EE Application
Architecture
- Jim Hale Jr.
- CFUG
- February 2008
2Why Learn About J2EE Architecture?
- ColdFusion and Java developers develop for the
same platform! - ColdFusion is not the best tool for every job
- Good design principles transcend programming
languages - Knowledge of technologies you dont foresee
yourself using can come in handy one day
Next High Level Diagram
3High Level Diagram
External data provider
Web services
WebSphere Application Server 6.0
Application database
Portal server WebSphere Portal Server 5.1
MS SQL Server 2000
Reporting server
Business Objects Enterprise XI
Intranet
Internet
firewall
all communication with backend systems must occur
via web services using SOAP
Next Architecture Goals
4Architecture Goals
- Use proven and popular solutions to problems
- Favor open source frameworks over homegrown ones
- Adhere to design patterns
- Minimize the amount of code to maintain
- Keep things as simple as possible, but no simpler
Next Software Layers
5Software Layers
Portlet View
Portlet Controller
Web services
Portlet Facade
Service
Data Access
Next Request Flow
6Request Flow
User is viewing information about a physician and
clicks the Edit button. The Edit Physician
page appears, displaying the physician data and
presenting the user with dropdown values to pick
from.
1
3
4
View Physician Page
5
Physician Service
Physician DAO
2
DB
Edit Physician Web Service
Edit Physician Controller
9
Dropdown Service
Dropdown DAO
Edit Physician Page
8
10
6
7
Next Frameworks
7Frameworks
Portlet View
PortletMVC
Portlet Controller
XFire / Axis
Web services
Spring Acegi
Portlet Facade
Service
Manager
Data Access
Hibernate
this will be replaced with an IBM or Java EE
solution when possible
Next What Is Hibernate?
8What Is Hibernate?
- Open source framework for dealing with databases
in an object oriented manner - Handles the mapping of resultsets to Java objects
- Attempts to keep applications database vendor
independent - Has support for caching query results and objects
Next Hibernate Example
9Hibernate Example
Java class
package edu.mayo.mypackage public class MyClass
private int id private String
descrip public int getId() // other getters
and setters
Hibernate mapping file
lt?xml version"1.0"?gt lt!DOCTYPE hibernate-mapping
SYSTEM "http//hibernate.sourceforge.net/hibernate
-mapping-3.0.dtd" gt lthibernate-mapping
package"edu.mayo.mypackage"gt ltclass
name"MyClass" table"tbl_mytable"gt ltid
name"id" type"int" column"my_id" /gt ltproperty
name"descrip" type"string" column"my_descrip"
length"50" /gt lt/classgt lt/hibernate-mappinggt
Code to update a row (when used with Spring)
MyClass mc getHibernateTemplate().getById(100)
mc.setDescrip(Some description) getHibernateTem
plate().save(mc)
Next Why Use Hibernate?
10Why Use Hibernate?
- Eliminates a lot of tedious SQL
- Very widely used
- Plenty of documentation and books available
- Part of the Java EE 5 specification
- Good integration with Spring
Next What Is Spring?
11What Is Spring?
- Open source framework that integrates various
frameworks and technologies into a single
platform - Configuration driven requires no Spring
specific code - Good support for aspect oriented programming
- Uses dependency injection to supply objects with
the objects they use at runtime
Next Spring Example
12Spring Example
public class MyService private Dao
dao public void setDao(Dao dao) this.dao
dao
lt?xml version"1.0" encoding"UTF-8"?gt lt!DOCTYPE
beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http//www.springframework.org/dtd/spring-beans.d
td"gt ltbeansgt ltbean idmyDao"
class"edu.mayo.mypackage.dao.MyDao /gt ltbean
idmyService" class"edu.mayo.mypackage.service.M
yService"gt ltproperty namedao" refmyDao"
/gt lt/beangt lt/beansgt
Next Why Use Spring?
13Why Use Spring?
- Eliminates a significant amount of plumbing code
- Proven powers French IRS site (34 million
transactions per year), FIFA web site (1 million
visitors per month). - Plenty of documentation and books available
- Spring concepts appear in Java EE 5 specification
- Ported to various development platforms
- Spring.NET
- ColdSpring
Next What Is XFire?
14What Is XFire?
- Allows you to publish and consume your Spring
managed service layer as web services without
writing any web service code or using any wizards - Generates XML schema for web services and complex
objects in the doc literal format - Project maintainers merged with another group,
now called CXF
Next XFire Example
15XFire Example
Server side Spring config file
ltbean id"personServiceImpl" class"edu.mayo.mos.s
ervice.impl.PersonServiceImpl" /gt
ltbean id"personService" class"org.codehaus.xfire
.spring.ServiceBean"gt ltproperty
name"serviceBean" ref"personServiceImpl"/gt
ltproperty name"serviceClass" value"edu.mayo.mos.
service.PersonService"/gt lt/beangt
Client side Spring config file
ltbean id"personServiceClient" class"org.codehaus
.xfire.spring.remoting.XFireClientFactoryBean"gt
ltproperty name"serviceClass"gt
ltvaluegtedu.mayo.mos.service.PersonServicelt/valuegt
lt/propertygt ltproperty name"wsdlDocumentU
rl"gt ltvaluegthttp//localhost9080/WebServices
/services/PersonService?wsdllt/valuegt
lt/propertygt lt/beangt
Sample client code
ApplicationContext context new
ClassPathXmlApplicationContext("wsclient.xml") Pe
rsonService psvc (PersonService)
context.getBean("personServiceClient")
Note this code is not necessary when used with
Spring MVC framework.
Next Why Use XFire?
16Why Use XFire?
- Eliminates all web service plumbing code
- Published web services are usable by other
technology platforms - Very easy to set up and use
- Downside Websphere Portal Server appeared to
have some issues with it - XFire is now being used on server side, while
Apache Axis is used as the client runtime on WPS - Either IBM or Java EE 5 web service stack will be
used in future
Next What Is PortletMVC?
17What Is PortletMVC?
- Open source portlet MVC framework distributed by
the Spring Web team - Adaptation of the Spring MVC framework for the
portal world - Very similar to Struts (with improvements)
- Runs in any JSR 168 compliant portal container
Next PortletMVC Example
18PortletMVC Example
Portlet Controller
public class MyController extends
AbstractController private PersonService
psvc public void setPersonService(PersonService
psvc) this.psvc psvc public
ModelAndView handleRenderRequestInternal(
RenderRequest request, RenderResponse response)
ModelAndView mav new ModelAndView(mypage)
Person p new Person() mav.addObject(person
, psvc.getPerson(p)) return mav
Controller Configuration
ltbean idmyController" classedu.mayo.mypackage.
controller.MyController"gt ltproperty
namepersonService" ref"personServiceClient
/gt lt/beangt ltbean id"portletModeParameterHandlerM
apping class"org.springframework.web.portlet.han
dler.PortletModeParameterHandlerMapping"gt
ltproperty name"portletModeParameterMap"gt
ltmapgt ltentry key"homePage"gtltref
bean"homePageController"/gtlt/entrygt
lt/mapgt lt/propertygt lt/beangt
Next Why Use PortletMVC?
19Why Use PortletMVC?
- Alternatives have problems
- JSF what IBM, Sun, etc. want developers using
- Very heavyweight solution
- Written with graphical IDEs in mind not very
flexible - Developers dont have positive things to say
about it - Struts most widely used MVC framework in Java
land - Not actively maintained anymore (although Struts
2 is coming) - Forces copying of data between Struts specific
classes and your backing objects - Input validation not as seamless as
implementations in JSF and PortletMVC - Interceptors offer same functionality as servlet
filters
Next What Is Acegi?
20What Is Acegi?
- Open source security framework written for Spring
- Complete security solution
- Authentication
- Authorization - URL, method / web service
invocation, web page sections - Data filtering
Next How Acegi Works
21How Acegi Works
- Developer writes one class which given a username
returns the permissions for that user - That class is registered with Acegi via a
configuration file - On user login that class is asked to supply user
permissions - Permissions are cached in user session by Acegi
- Permissions are then applied to Java methods,
URLs, and page sections as needed
Next Page Level Security
22Page Level Security
- Acegi comes with a JSTL tag library which can be
used to hide / show sections of web pages
Displaying a button only if user has permission
to use it
ltauthzauthorize ifAllGrantedcanEditDatagt ltbut
ton typebutton onclicklocation.hrefeditData
.htmgtEditlt/buttongt lt/authzgt
Displaying a message if the user does not have
permission to do something
ltauthzauthorize ifNotGrantedcanEditDatagt You
are not special enough to edit data. lt/authzgt
Next Why Use Acegi?
23Why Use Acegi?
- Single security manager for securing URLs, web
service methods, and sections of web pages - Very easy to set up and use (after the initial
learning curve) - Allows current user to temporarily impersonate
another user
Next ColdFusion Equivalents
24ColdFusion Equivalents
- ModelGlue - MVC framework for separating UI from
business logic - ColdSpring CF port of Spring for organizing the
dependencies between CFCs - Reactor ORM framework for working with database
records without writing tedious SQL statements - No need for a web service framework in CF, as
CFCs can be easily exposed as web services - Java EE 5 has similar ability
- No known equivalent for Acegi security framework