From the heavy weight authors of Wiley, on Java EE side Murat Yener with Professional Java EE Design Patterns (http://www.amazon.com/Professional-JavaEE-Design-Patterns-Murat/dp/111884341X) and on Spring side Mert Caliskan with Professional Spring (http://www.amazon.com/Beginning-Spring-Mert-Caliskan/dp/1118892925). The talk will expose good, bad and the ugly sides of both Java EE and Spring by hands on illustration of creating a crud app from scratch. Both speakers will introduce best parts of their platform on demos meanwhile point out weaknesses of the opponent. Both platforms will demonstrate their strengths on best practices, tool support, 3rd party libraries, community support and design patterns. Get ready for a family size huge fun while watching two most commonly used platform on Java.
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
jDays2015 - JavaEE vs. Spring Smackdown
1. Java EE vs. Spring
Smackdown
Mert Çalışkan, @mertcal
MuratYener, @yenerm
2. • MuratYener
• 10+Years of Java & Mobile
• Coder @ intel.com
• Google Developer Expert (Android)
• Profile available @
tr.linkedin.com/in/muratyener
• @yenerm
The Fighters
• Mert Çalışkan
• 10+Years of Enterprise Java
• Coder @ t2.com.tr
• Oracle Java Champion
• Profile available @
tr.linkedin.com/in/mertcaliskan
• @mertcal
3. • MuratYener
• 10+Years of Java & Mobile
• Coder @ intel.com
• Google Developer Expert (Android)
• Profile available @
tr.linkedin.com/in/muratyener
• @yenerm
The Fighters
• Mert Çalışkan
• 10+Years of Enterprise Java
• Coder @ t2.com.tr
• Oracle Java Champion
• Profile available @
tr.linkedin.com/in/mertcaliskan
• @mertcal
4. The Books that started it all…
http://amazon.com/author/murat http://amazon.com/author/mert
5. or DOYOU NEED SPECIAL
ABILITIES?
IS JAVA EE ENOUGH?
Come to the Spring Side..!
6. Current Trend on Java EE and Spring Framework
http://www.google.com/trends/explore#q=Java%20EE%2C%20Spring%20Framework
7. in 2 versions, one with Java EE 7 and one with Spring 4!
So we created a Sample Application named
8. No project, server, framework or even a POJO has been harmed
during the preparation on this talk.
Still we’re professionals so don’t try this at home (but you may
do try at work…)
Disclaimer
9. This talk is fiction, we are not messengers of either platform. We
both used each framework in a project at some point in our lifes
and we reserve to switch sides at any time in future.
Still for the sake of our book sells, we encourage you to pick the
best side and stick with it forever!
Disclaimer II
12. Spring
• Started with aim for simplifying J2EE
• Based on POJO programming model
• Offered DI instead of JNDI
• Enabled use of lightweight web servers instead of heavy J2EE server
13. JavaEE7 Spring
CDI Spring IoC
Interceptor Spring AOP AspectJ
JPA Persistence
Dependency Injection
AOP
JPA JDBC
UIJSF 2 Spring MVC JSF 2
WSJAX-WSJAX-RS
Spring MVC
REST Support
Security Spring Security
Contract-first
SOAP WS
TestingN/A Spring Testing
Java EE
Security
EJB
15. Setup
IDE: NetBeans 8.0.2 Intellij IDEA 14 Ultimate
Server: Payara Payara
On IDEA, Mert needed to register
glassfish-resources.xml file with command:
./asadmin add-resources ~/path-to-file/glassfish-resources.xml
and then start derby DB with
./asadmin start-database
and then connect to the sample Db with ij.sh as:
ij> connect 'jdbc:derby://localhost:1527/sample;create=true’
SpringJavaEE
16. ‘0’
config
Configuration
• Context configuration file (either as an
XML file or a Java class) is needed to
bootstrap the application.
• With Spring MVC, the location of the
configuration file is provided to the
Dispatcher Servlet definition in
web.xml.
• It’s also possible to provide multiple
configuration files and they will be
merged prior to context initialization.
SpringJavaEE
32. @Transactional
• @Transactional under package
javax.transaction
• With Java EE7 enables transactions in
CDI methods as well as EJB methods.
• isolation levels supported: REQUIRED,
REQUIRES_NEW, MANDATORY,
SUPPORTS, NOT_SUPPORTED, NEVER
• EJB3 impl come with JTA configured by
default.
• No readOnly transaction support
• @Transactional under package
org.springframework.transaction.annotat
ion
• Spring handled transactions with this
annotation since v1.2
• Isolation levels supported: Java EE ones
+ NESTED.
• Transaction manager should be
configured in order to handle JTA
@Transactional(readOnly = true)
SpringJavaEE7
33. AOP and Caching
• ServletFilter
• @WebFilter (Servlet 3.0)
• @Interceptor, @AroundInvoke
• @PostConstruct, @PreDestroy
• Spring provides AOP with proxy
pattern at runtime.
• It employs AspectJ annotations for
configuration (but not doing compile
time weaving…only runtime)
• Spring Caching offers an abstraction on
3rd party cache providers like Ehcache,
Hazelcast, Guava and etc.
• Complies with Pointcut designators
like, within(), execution(), bean(),
@annotation() and others.
SpringJavaEE7
34. JavaEE - Method Execution Time Logging
@Interceptor
public class LogInterceptor {
@AroundInvoke
public Object doSecurityCheck(InvocationContext context) throws Exception{
long startTime = System.nanoTime();
String className =context.getMethod().getDeclaringClass().getCanonicalName();
String methodName = context.getMethod().getName();
Object execution= context.proceed()
long elapsedTime = System.nanoTime() - startTime;
Logger.getLogger("LOG").info("Execution of " + className + "#" + methodName +
" ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");
return execution;
}
@PostConstruct
public void onStart(){
Logger.getLogger("SecurityLog").info(“Activating");
}
@PreDestroy
public void onShutdown(){
Logger.getLogger("SecurityLog").info(“Deactivating");
}
}
35. Spring - Method Execution Time Logging
@Component
@Aspect
public class ExecutionTimeLogging {
@Around("within(com.devchronicles..*)")
public Object profile(ProceedingJoinPoint pjp) throws Throwable {
long startTime = System.nanoTime();
String className = pjp.getTarget().getClass().getCanonicalName();
String methodName = pjp.getSignature().getName();
Object output = pjp.proceed();
long elapsedTime = System.nanoTime() - startTime;
System.out.println("Execution of " + className + "#" + methodName +
" ended in " + new BigDecimal(elapsedTime).divide(new BigDecimal(1000000)) + " milliseconds");
return output;
}
}
36. Security
• Declarative: (basic, form based, digest, client,
mutual)
• via resources: resource/pattern/role
• via annotations: @HttpMethodConstraint,
@HttpConstraint, @ServletSecurity
• Programmatic: request.login(userName,
password);
• Message Security: via header in SOAP
messages
• JAAS & web.xml security
• Alternatively..Apache Shiro
• Provides w/ subproject Spring Security
• Supports several different authentication
methods
login form–based authentication, authentication with X509 user
certificates, LDAP authentication,Windows authentication over
legacy NTLM or Kerberos methods,
basic and digest authentications.
• Separation of auth. methods from user
repositories i.e.: form-based auth from active
directory or a DB.
• Supports SSO w/ CAS, OpenID, SiteMinder,
and OAuth
• Guest login & built-in remember-me support
• HTTP/HTTPS support
JavaEE7 Spring
42. Testing
• JUnit
• OpenEJB Container (one line)
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
• Embedded Glasfish Container
• Arquillian container tests
• JUnit + TestNG
• Offers integration testing support
w/out the need of deploying app w/
Spring Testing.
• Offers Servlet API mock objects like
MockHttpServletRequest, MockHttpServletResponse,
MockHttpSession and others.
• Testing REST services is easy with the
builder API.
• Bean Profiling allows us to differentiate
DB connections for in DEV (derby) or
in TEST (hsqldb)
JavaEE7 Spring
43. Java EE - REST Service Testing
• JUnit
• Mockito
• Simple, just like Java SE
47. Release Timeline
10.2006
v2 v2.5
11.2007 12.2009 12.2011 12.2012 12.2013 09.2014 06.2015
v3 v3.1 v3.2 v4 v4.1 v4.2
Spring
Java EE
05.1998
JPE J2EE 1.2
12.1999 09.2001 11.2003 5.2006 12.2009 06.2013 Q3 2016
J2EE 1.3 J2EE 1.4 Java EE 5 Java EE 6 Java EE 7 Java EE 8
slowest iteration, biggest change!
48. FinalVerdict
•Spring is cool and so is Java EE.
•They are providing the best of breed (v4 & EE7) same motto,
different underlying infra.
•Java EE is standards designator, if you are starting a new
project, better to stick w/ the standards.
•If you are into sub-projects of Spring, like -data, -social, -batch,
and others like security, leverage the use of Spring.
•We are using both and we’re both happy :)
49. All sources are available under
•JavaEE7Version:
https://github.com/yenerm/FightClub
•SpringVersion:
https://github.com/mulderbaba/FightClub