5. Web Profile
• First Java EE profile to be defined
• A fully-functional, mid-size stack for modern web
application development
• Complete, but not the kitchen sink
6. Java EE 6 Web Profile Contents
JSF 2.0
JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0
Servlet 3.0
EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0
Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1
JPA 2.0 · JTA 1.1
7. Pluggability/Extensibility
• Focus on the web tier in this release
• Create a level playing field for third-party frameworks
• Simplify packaging of web applications
8. Modular Web Applications
•
•
•
•
•
•
Libraries can contain /META-INF/web-fragment.xml
web.xml is optional
@WebServlet, @WebFilter annotations
ServletContainerInitializer interface
Programmatic registration of components
Resource jars containing /META-INF/resources
9. Sample Web Fragment Descriptor
<web-fragment
version=”3.0”
xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<listener>
<listener-class>RequestListener</listener-class>
</listener>
</web-fragment>
10. JAX-RS 1.1
•
•
•
•
•
RESTful web services API
Already widely adopted
Really a general, high-level HTTP API
Annotation-based programming model
Programmatic API when needed
12. Bean Validation 1.0
• Integrated with JSF, JPA
• Declarative constraints using annotations
@NotNull
@Size(max=40) String address;
• Fully extensible: define your own constraints
@Email String recipient;
• Validator API for programmatic validation
validator.validate(obj) → Set<ConstraintViolation>
13. EJB 3.1
• @Singleton beans
• @Startup beans
• @Asynchronous invocations
@Asynchronous public Future<Integer> compute();
• Define EJBs directly inside a web application
• EJBContainer API works on Java SE
14. Adding an EJB to a Web Application
Before
BuyBooks.war
ShoppingCart
EJB Class
Now
ShoppingCart
EJB Class
ShoppingCart.jar
BuyBooks.ear
BuyBooks.war
15. Dependency Injection
• DI + CDI (JSR-330 + JSR-299)
• @Resource still around
@Resource DataSource myDB;
• Added @Inject annotation for typesafe injection
@Inject @LoggedIn User user;
• Automatic scope management (request, session, etc.)
• No configuration: beans discovered at startup
• Extensible via the BeanManager API
16. Dependency Injection Sample
@ApplicationScoped
public class CheckoutHandler {
@Inject
public CheckoutHandler(
@LoggedIn User user,
@Reliable @PayBy(CREDIT_CARD)
PaymentProcessor processor,
@Default ShoppingCart cart) {…}
}
Injection points identified by Qualifier + Type
@Default can be omitted
17. JSF 2.0
•
•
•
•
•
•
Facelet as a standard view declaration language
Composite components
Automatic discovery of component libraries
Programmatic and declarative Ajax support
System events
Validation out-of-the-box
18. Java EE 6 Platform
•
•
•
•
More powerful
More flexible
More extensible
Easier to use
http://java.sun.com/javaee
19.
20. What is GlassFish
• A Community
– Users, Partners, Testers, Developers
– Started in 2005 on http://java.net
• Application Server
– Enterprise Quality and Open Source (CDDL & GPL v2)
– Java EE 5 / 6 Reference Implementation
• Full Commercial Support from Oracle
– Not only a Reference Implementation
– Roadmap announced tomorrow regarding HA, Clustering...
21. GlassFish v3...
• The Java EE 6 spec, of course, and...
• Beyond the spec
– Fast, very fast, small, very small
– restart, btrace/dtrace, embedded, modularity, OSGi, RESTful
Admin,...
– Scripting: jRoR, Grails, and now Django
• Update Center: repository of new/updated bundles
• Tooling: Netbeans 6.8, IntelliJ,vi, and
– Eclipse 3.5, 3.6Mx
22. Modular and Dynamic
• Modular : OSGi: Equinox and Apache Felix
• But also Equinox or Static mode, thanks to HK2
– Yet very Fast !
• Painless Java EE 6 development
–
–
–
–
Via the new/easier APIs
Via better tools integration
Ultra fast Auto-deploy of all Java EE and static artifacts
Application runner
• java -jar glassfish.jar foo.war
23. Web Session Retention
• Deployment option to maintain stateful sessions across redeployments
– $ asadmin redeploy --properties keepSessions=true myapp.war
– Enabled by Default in Eclipse IDE
• For All sessions:
– Servlets, CDIs, Stateful EJBs,...
• Greatly simplifies the development paradigm
24. GlassFish and OSGi
• GlassFish runs on top of OSGi (Felix and Equinox)
– GlassFish ships with 200+ bundles
• Can use OSGi management tools (CLI or Web)
• Any OSGi bundle will run in GlassFish v3
– Drop it in domain1/autodeploy/bundles
– Can also asadmin deploy it using --type osgi
• Consume OSGi services via @Resource
@Resource (mappedName="MYPUREOSGISERVICE")
HelloService
myOSGiService;
• Web Application Bundle (WAB Support)
26. Integration with maven 2
• Java EE 6 APIs in Maven repository
– http://download.java.net/maven/2/javax/javaee-api/
– Stripped jars: very small <1Mb
– Not to be used for Testing
• GlassFish Embbeded can run via Maven
– mvn gf:run