Development Using Spring Roo

helpflightInternet και Εφαρμογές Web

10 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

106 εμφανίσεις

Rapid Server Side Java
Development Using Spring Roo
Christian Tzolov
Technical Lead,
TTSD, TomTom BV
12/05/2010
Agenda

TomTom Service & Delivery

Java Developer Productivity & Impediments

Demo
-
Traffic Information System

Aggregate data from an external
traffic service

Provide personalized traffic feeds in
HTML, XML and JSON formats

Portal Security

Portal UI Customization

Testing

Custom Roo Addon creation

Q&A
TomTom Service & Delivery

TomTom MapShare ™

Route Traces

TomTom Route Planner / HD Traffic
TomTom MapShare ™ Technology
http://www.tomtom.com/page/mapshare
TomTom Trace Data
1 data point == 1 pixel
TomTom Route Planner
http://routes.tomtom.com
Java Developer Productivity
“It is essential that most software projects fail.
No one need
ever again be embarrassed by participation in a failed
software project.
Rather they should be proud to have spared
society from yet another burden of complexity.

(An essay on computer productivity)
Java Development Toolchain

IDEs with refactoring capabilities
Eclipse/STS, Idea, Netbeans

IoC container
Spring, JEE

Dependency Management
Maven, Ivy, OSGi

Build Lifecycle Management
Maven, Ant

Continuous Integration
Hudson, Cruise Control

Deployment Management
Cloud/Datacenter APIs
Productivity Impediments

Time consuming to start new project

Verbose java code due to many frameworks
and conventions

No consistent view over the entire toolchain

Difficult to capture and reuse important
architectural decisions
Improved productivity,
No engineering trade
-
offs

Extensible, text
-
based RAD tool for Java and Spring applications.

Hybrid (Active + Passive) code generation

Conventions over Configuration

Encapsulate the best practices for Spring application

Java language and standard Java technologies only

Applied at development time only

No lock
-
in!
Demo:
Traffic Information System
Web Portal that provides customized traffic situation
information to the registered Users
Traffic Web Portal
-
Requirements
Web Portal for
Traffic Information
Management
Provides traffic feeds in human
readable
(
HTML
)
and XML and JSON formats
.
User can access his own feed only
!
Traffic
Information
Servic
Aggregate data from external
traffic information service
User
1
User
2
Admin
Manage portal users and
configure traffic feeds for them
User Interface (UI)
Web Controller
Application Layer
ORM
Database
Security
Environment

JDK 1.6

Eclipse/STS

MySQL (optional)
Aggregate data from an external
traffic service

JAXB2, XCJ

Spring Roo JAXB Add
-
on

Spring RestTemplate
Rest Client Implementation

Use REST API to query traffic information.
Contract First

Add JAXB/XCJ support for XML schema compilation (use JAXB
XSD Compiler roo add
-
on)
http://sourceforge.net/apps/trac/raddons/wiki/WikiStart#a1.JAXB2XSDcompileraddon

Use RestTemplate (Spring 3.0) to call REST services
http://static.springsource.org/spring/docs/3.0.x/spring
-
framework
-
reference/html/remoting.html#rest
-
resttemplate
roo
> jaxb xsd compiler setup

generateDirectory src/main/java
return
new
RestTemplate().getForObject(
“http://servername:port/service/{param1}/{param2}/.../{paramN}”,
TrafficSituation.
class
,
param1, param2 … paramN);
Traffic Query Service REST API
Service is used to query the traffic data using a SQL
-
like query
language
Component
Description
Example
hostName
The query server name
http://
xxxxxx
:yyyy/
query
The traffic query expression (SQL
-
like
syntax)
FROM NL LIMIT 10
API key
The authorizing API key
xxxxxx
-
yyyyyy
-
zzzzzz
{
hostName
}/tsq/traffic/query/{
query
}/en/xml/{
apiKey
}
XML response governed by the traffic.xsd
<c:forEach items="${trafficSituation.trafficList.trafficIncident}" var=
"trafficIncident"
>
<tr>
<td><c:out value="${
trafficIncident.locationDescription.country
}"/></td>
<td><c:out value="${
trafficIncident.locationDescription.roadNumber
}"/></td>
<td><c:out
value="${
trafficIncident.eventDescription.lengthAffectedMeters
}"/></td>
</tr>
</c:forEach>
Provide personalized traffic feeds in
HTML, XML and JSON formats

Spring MVC @Controller

Apache Tiles Layout

Content Types & Content Negotiation
Traffic Feed @Controller

Create TrafficController that uses TrafficRestService and
generates JSP content:

Add additional xml, json representations through the content
negotiation add
-
on:

Bind the TrafficSituation class to the content representation
configuration:
roo
> http resource representation setup
roo
> http resource add oxm
--
class com.tomtom.service.traffic.TrafficSituation
roo
> controller class
--
class ~.web.TrafficController
Portal Security

Spring Security 3.0
Apply Spring Security 3.0

Roo Security Add
-
on

Implement UserDetails

Customize UserDetailsService
public
class
GeeconUserDetailsService
implements
UserDetailsService {
@Override
public
UserDetails loadUserByUsername(String username)
throws
UsernameNotFoundException, DataAccessException {
return
(UserDetails) PortalUser.findPortalUsersByUsername(username).getSingleResult();
}
}
roo
> security setup
public class
PortalUser
implements
UserDetails {

@Override
public
Collection<GrantedAuthority> getAuthorities() {
return
Arrays.asList((GrantedAuthority) new GrantedAuthorityImpl("ROLE_XXX"));
}
}
Apply Spring Security 3.0

Use JSP security tags

Access user‟s details via the SpringSecurityContext
PortalUser portalUser = (PortalUser)
SecurityContextHolder
.
getContext
().getAuthentication().getPrincipal();
<xml xmlns:
sec
=
http://www.springframework.org/security/tags
>
<
sec
:authorize access="hasRole('ROLE_XXX')">

</
sec
:authorize>
Portal UI Customization

Spring JS

Dojo
Simple UI Customization

Application Logo
standard.css#background
-
image: url(
http://2010.geecon.org/images/menu/logo_haslo.png
);
Simple UI Customization

Dojo themes

Menu Look & Feel
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({
elementId :„
div_id_value
',
widgetType : 'dijit.TitlePane',
widgetAttrs : {title: '${
title_name
}„ }}));
</script>
In WEB
-
INF/layout/
default.jspx
replace
tundra
by
soria
.
More themes:
http://docs.dojocampus.org/dijit
-
themes
Testing

Integration Tests, Dod

Selenium UI tests
UI Testing
-
Selenium

Generate Selenium configuration:

Fix the selenium
-
maven
-
plugin version to 1.0.1

Start the application in tomcat (or Jetty) server

Run the test:
selenium test
--
controller ~.web.PortaluserController
mvn jetty:run
mvn selenium:selenese
Roo Add
-
ons
http://tzolov.blogspot.com/2010/05/spring
-
roo
-
addons
-
jaxb2
-
binding
-
and.html
1.0.2 Base Addons

Project
management
(like
project
creation,
dependency
management,
"perform"
commands)

General
type
management
(like
creation
of
types,
toString
method,
JavaBean
methods)

Persistence
(like
JPA
setup,
entities)

Field
management
(like
JSR
303
and
field
creation
with
JPA
compliance)

Dynamic
finders
(creation
of
finders
without
needing
to
write
the
JPA
-
QL
for
them)

JUnit
testing
(with
integration
and
mock
testing)

Spring
MVC
(including
URL
rewriting,
JSP
services,
controller
management)

Spring
Web
Flow

Spring
Security

Selenium
testing

Java
Message
Service
(JMS)

Simple
Mail
Transfer
Service
(SMTP)

Log
4
J
configuration
Resources
http://www.springsource.org/roo
Q&A