Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Apache TomEE - Tomcat with a kick

27,221 views

Published on

An OpenEJB presentation on "Apache TomEE"

TomEE aims to provide a fully certified Java EE 6 Web profile stack based on Tomcat, allowing you to use Java EE features in your lightweight Tomcat applications.

A stack that's assembled and maintained by the Apache OpenEJB project

Published in: Technology
  • Be the first to comment

Apache TomEE - Tomcat with a kick

  1. 1. Apache TomEE Tomcat with a kick About Apache TomEE David Blevins Jonathan Gallimore dblevins@apache.org [email_address] @dblevins @jongallimore * Original Slides modified a little to make the document self-contained
  2. 2. In this presentation we will introduce and demonstrate Apache TomEE… And show how you can leverage all the additional features available in the JavaEE 6 platform, without having to move away from Tomcat. Intro Welcome to Apache TomEE – Tomcat with a kick.
  3. 3. The slides are from Jonathan Gallimore and David Belvins’ presentation @JAX London, Spring 2011. You can watch the video here Meta
  4. 4. So, what is Apache TomEE? In short, its a stack that's assembled and maintained by the Apache OpenEJB project. TomEE aims to provide a fully certified Java EE 6 Web profile stack based on Tomcat, allowing you to use Java EE features in your lightweight Tomcat applications. Talk
  5. 5. Apache TomEE: Overview <ul><li>Java EE 6 Web Profile certification in progress </li></ul><ul><li>Apache TomEE Includes support for: </li></ul><ul><ul><li>Servlet 3.0 (Apache Tomcat) </li></ul></ul><ul><ul><li>JPA 2.0 (Apache OpenJPA) </li></ul></ul><ul><ul><li>JSF 2.0 (Apache MyFaces) </li></ul></ul><ul><ul><li>CDI 1.0 (Apache OpenWebBeans) </li></ul></ul><ul><ul><li>EJB 3.1 (Apache OpenEJB) </li></ul></ul><ul><ul><li>JMS (Apache ActiveMQ) </li></ul></ul><ul><ul><li>Webservices (Apache CXF) </li></ul></ul>
  6. 6. Although TomEE is assembled by the OpenEJB team, its based on a number of different Apache projects shown on the previous slide. You may be familiar with or using some of these projects already. Even if you're not using EJBs in your projects, Apache TomEE still provides a range of functionality you may find useful. Side-note
  7. 7. Apache TomEE: Philosophy <ul><li>Preserve Tomcat  </li></ul><ul><ul><li>Leverage Tomcat JNDI, Security, everything </li></ul></ul><ul><li>Get more, don't give up anything </li></ul><ul><ul><li>Add the extras without removing anything </li></ul></ul><ul><li>Lightweight </li></ul><ul><ul><li>Just 38MB zip </li></ul></ul><ul><ul><li>Runs with no extra memory requirements </li></ul></ul><ul><li>No need to learn new server environment </li></ul><ul><li>Existing IDE tools for Tomcat should also work with TomEE </li></ul>
  8. 8. Obviously there are a number of different Java EE servers available today, and a number of open source offerings. How is TomEE different from other implementations? Well, we take a different approach to building the server – many implementations will use Tomcat to provide a servlet features, and will strip it down and embed it in their own server. TomEE does the opposite – OpenEJB and all the other components are embedded into Tomcat , and nothing is taken away. Talk ..Contd in next slide Question
  9. 9. This offers a number of advantages: Firstly, TomEE is able to leverage all the functionality that Tomcat provides, such as JNDI and security. Secondly, TomEE is still lightweight – the zip is around 37MB, and does not have any additional memory requirements over Tomcat to run. Finally, the environment will be completely familiar to existing Tomcat users, meaning that your existing tooling should still work. For example, there isn't a TomEE Eclipse plugin or Netbeans plugin – the existing out-of-the-box plugins for Tomcat 7 also work with TomEE. Talk So what do we get ?
  10. 10. Apache TomEE: History <ul><li>Predates Java EE 6 Web Profile </li></ul><ul><li>Integration approach inspired by OpenEJB's embeddable nature </li></ul><ul><li>Previously known as OpenEJB-Tomcat integration </li></ul><ul><li>Also available as a drop-in-war for Tomcat 5.5 - 7.0 </li></ul><ul><li>Origin of EE 6 &quot; EJBs in .wars &quot; feature </li></ul>
  11. 11. Although we're introducing Apache TomEE as a new bundle, it has actually been around for a while, first making an appearance in 2006, and was inspired by OpenEJB's embeddable nature. Previously it has been known as the “OpenEJB-Tomcat integration”, and was (and still is) available as a drop-in .war file for any version of Tomcat back to 5.5. In addition to the drop-in .war , TomEE is now available as a pre-built bundle which requires no installation or configuration. Also worth mentioning, Apache TomEE is actually the origin of the “ EJBs in war files ” that is new in the JavaEE 6 specification. David, our PMC chair, participates in the JCP that provides the EJB specification and has done since EJB 2.1. Talk
  12. 12. Apache TomEE: Getting started <ul><li>Very simple installation: </li></ul><ul><ul><li>Obtain bundle and unzip OR </li></ul></ul><ul><ul><li>Deploy openejb.war into an existing Tomcat installation and run through a simple wizard </li></ul></ul><ul><li>Sample application included in bundle </li></ul><ul><li>Additional lib folder in $CATALINA_BASE/webapps/openejb/lib </li></ul><ul><li>Dashboard available at http://localhost:8080/openejb </li></ul>
  13. 13. - bin – untouched, shell scripts have the usual options - conf – server.xml is the same, one extra listener. Can configure ports, hosts, engines, threadpools etc in here. Extra file openejb.xml – this is where most TomEE configuration happens – this is where global resources are defined. Tomcat-users.xml – we use Tomcat security. - logs – untouched – extra file openejb.log ends up in here, useful for troubleshooting (rarely, we hope!) - webapps – works the same way as it does for Tomcat. Drop your directories/wars in here! Also supports EAR files too. … contd in next slide A peek Apache TomEE: Folder Structure
  14. 14. Set of Tomcat apps, plus two extras: Ejb-examples – sample application from OpenEJB repository. Simple example showing a few JavaEE features – not very functional, but useful for testing. OpenEJB – where the magic happens. Note extra lib directory, some jars can be swapped out. Provides a dashboard to test the setup and examine the JNDI tree. A peek Apache TomEE: Folder Structure
  15. 15. Apache TomEE: Moviefun example <ul><li>Movie fun sample – available from OpenEJB SVN repository:  </li></ul><ul><li>http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/webapps/moviefun/ </li></ul><ul><li>Or at github https://github.com/apache/openejb/tree/trunk/openejb3/examples/webapps/moviefun </li></ul><ul><li>Simple example demonstrating: </li></ul><ul><ul><li>Servlet @EJB injection </li></ul></ul><ul><ul><li>Bean lookup from a JSP </li></ul></ul><ul><ul><li>Dependency injection with JSF ManagedBean </li></ul></ul><ul><ul><li>Persistence with JPA 2 </li></ul></ul><ul><ul><li>Notifications via JMS </li></ul></ul><ul><ul><li>Webservice support </li></ul></ul><ul><ul><li>Stateless EJB with no-interface view </li></ul></ul>Samples
  16. 16. One thing that might have struck you during the demo, is that we unzipped TomEE, deployed and used a database-based web application, all without doing any configuration at all – not even specifying a database to use. TomEE will use some default resources specified in conf/openejb.xml , including HSQLDB as a default datasource, which is why we didn't need to configure a database for the moviefun example. This is great for development, but you might want to use a different database in production , for example, MySQL. To do this we just need to add the MySQL connector jar to the Tomcat/lib folder, and add a datasource resource for the persistence context. Side-note
  17. 17. The openejb.xml file is very easy to configure . Its an XML/properties format. The xml tags match the annotations you'd use for dependency inject (for example @Resource) and type matches the simple name of the object type. Side-note
  18. 18. Apache TomEE: Configuration <ul><li>Resources configured in $CATALINA_BASE/conf/openejb.xml </li></ul><ul><li>Simple XML + properties format </li></ul><ul><li>Tags match Annotation names </li></ul><ul><li>«Resource id=&quot;moviesDatabase&quot; type=&quot;DataSource&quot;» </li></ul><ul><li>@Resource DataSource moviesDatabase </li></ul><ul><li>Drop drivers in tomcat.home/lib </li></ul>
  19. 19. ApacheTomEE: Security <ul><li>Uses Tomcat's Security Realm </li></ul><ul><li>Extra TomEE layer adds support for </li></ul><ul><ul><li>JAAS </li></ul></ul><ul><ul><li>JACC </li></ul></ul><ul><ul><li>WS Security </li></ul></ul><ul><li>Supports any org.apache.catalina.Realm implementation </li></ul><ul><li>E.g. add users to $CATALINA_BASE/conf/tomcat-users.xml </li></ul><ul><li>Alternatively use login.config to provide your own security module </li></ul>
  20. 20. Rather than providing its own security implementation, TomEE makes full use of the security features that are part of Tomcat. Any Catalina realm is supported or you can provide your own security module using the login.config file. Talk ApacheTomEE: Security
  21. 21. For example, to add some simple security to the moviefun application, all we would need to do is: 1. Add some users to the tomcat-users.xml file 2. Add the necessary @DefineRoles and @RolesAllowed annotations on MoviesImpl 3. Add some security config to do HTTP Basic authentication to web.xml Webservice security is also looked after – username/password based security (HTTP basic, or WS-Security) uses the same Tomcat security. Certificate based security is also available. Samples are available to demonstrate this. Talk ApacheTomEE: Security
  22. 22. Apache TomEE: JPA <ul><li>All persistence.xml files found and deployed </li></ul><ul><li>Connection persistence.xml values filled in automatically </li></ul><ul><ul><li>jta-data-source </li></ul></ul><ul><ul><li>non-jta-data-source </li></ul></ul><ul><li>Servlets, ManagedBeans, Session Beans, etc now use </li></ul><ul><ul><li>@PersistenceUnit EntityManagerFactory emf; </li></ul></ul><ul><ul><li>@PersistenceContext EntityManager em; </li></ul></ul><ul><li>OpenJPA included, easy to remove </li></ul><ul><li>Hibernate used in many Apache TomEE installs </li></ul><ul><li>EclipseLink also works </li></ul>
  23. 23. By default, persistence in TomEE is taken care of by Apache OpenJPA. TomEE will deploy any persistence.xml files automatically. As well session EJBs, persistence units can also be injected into servlets and managed beans as well. Other JPA providers can also be used in TomEE, hibernate is particularly popular. Side-note
  24. 24. Apache TomEE: Transactions <ul><li>Connection pooling is Transaction aware </li></ul><ul><ul><li>Everyone in same transaction, shares same connection </li></ul></ul><ul><li>Servlets, ManagedBeans, etc. can start transactions </li></ul><ul><ul><li>@Resource UserTransaction transaction; </li></ul></ul><ul><li>No need for EJBs to use transactions </li></ul>
  25. 25. TomEE provides transaction support. Even if you aren't using EJBs, simply inject an UserTransaction @Resource into your servlets or MangedBeans. What’s cool ? Apache TomEE: Transactions
  26. 26. Apache TomEE: JMS <ul><li>Resources configured in $CATALINA_BASE/conf/openejb.xml (Connection Factory, Topics, Queues) </li></ul><ul><li>By default ActiveMQ listens for connections on port 61616 </li></ul><ul><li>Resources can be injected into Servlets etc via </li></ul><ul><ul><li>@Resource ConnectionFactory connectionFactory; </li></ul></ul><ul><ul><li>@Resource Queue queue; </li></ul></ul><ul><ul><li>@Resource Topic topic; </li></ul></ul><ul><li>Example functionality in the Moviefun / monitor example </li></ul>
  27. 27. Apache TomEE: Web Services <ul><li>Use @Webservice on either </li></ul><ul><ul><li>POJO </li></ul></ul><ul><ul><li>Session Bean </li></ul></ul><ul><li>CXF & Web Service plumbing happens automatically </li></ul><ul><li>Accessible via: http://localhost:8080/Movies?wsdl </li></ul><ul><li>Web Service Security supported </li></ul><ul><li>Web Service Clients also work </li></ul><ul><ul><li>@WebServiceRef CalculatorWs service; </li></ul></ul><ul><li>Sample webservice client: get-movies.pl and delete-movie.pl </li></ul>
  28. 28. Apache TomEE: EJB Client <ul><li>HTTP can be used for EJB remote communication (http://localhost:8080/openejb/ejb) </li></ul><ul><li>Great for firewalled systems </li></ul><ul><li>User/Pass supplied with InitialContext params </li></ul><ul><li>HTTP or HTTPS </li></ul>… Contd in next slide
  29. 29. EJBs deployed in TomEE can also be accessed remotely using an EJB client. One nice feature of this is that TomEE uses HTTP/HTTPS as the protocol, so your rich applications can connect directly to EJBs without needing other firewall ports to be opened up. As long as you include the openejb-client jar in your client application, nothing else is needed. If you need to secure your EJBs, you can pass a username and password in the InitialContext properties. Sample (client) code below: Talk Apache TomEE: EJB Client
  30. 30. Apache TomEE: Functional Testing <ul><li>T7MP Maven plugin can use TomEE as a server </li></ul><ul><ul><li>Run your application embedded in your Maven build </li></ul></ul><ul><ul><li>Provides an isolated environment </li></ul></ul><ul><ul><li>Very useful for functional tests, combined with HtmlUnit or Selenium </li></ul></ul><ul><ul><li>Example integration test in the moviefun project </li></ul></ul>
  31. 31. Finally – if you're into functional testing, I wanted to demonstrate a technique I have used. OpenEJB's embeddable nature makes it great for testing EJBs in a junit test. You can take this one step further and use Apache TomEE with the Maven T7MP plugin. This allows you to start a TomEE instance (well, Tomcat 7 with the OpenEJB war) for your test run. Combined with an in-memory database and something like Selenium or HtmlUnit, you can run your application completely embedded within your Maven build, allowing you to run your tests completely in isolation of your development environment. This technique can be useful in providing a consistent environment for tests, and not having to worry about different setups between developer machines. Talk
  32. 32. Thanks! OpenEJB Home Apache TomEE Getting Involved: Users mailing list Dev mailing list Follow us on Facebook / Twitter Check the next slides for Web Profile Cert status
  33. 33. Web Profile Certification Status <ul><li>We can't say (that’s the law) </li></ul><ul><li>Work being done on Amazon EC2, using </li></ul><ul><li>T1.Micro Linux images, lots of them </li></ul><ul><li>100 going at once! </li></ul><ul><li>Each has 613MB memory max </li></ul><ul><li>Though we still run with default memory options (64MB) </li></ul><ul><li>It's quick! </li></ul><ul><li>Will be Cloud certified! </li></ul><ul><li>Wish we could show you the setup (sorry, also the rules) </li></ul>
  34. 34. I previously mentioned that Apache TomEE is aiming to be a certified web profile implementation. Work on the certification process is underway. Unfortunately we can't say what the status of the work is at the moment, as its subject to a non-disclosure agreement. We do have an interesting setup to run the TCK tests against TomEE , using lots of instances on the Amazon EC2 cloud. Again, unfortunately, we can't show you the setup, which is a shame, as it allows us to run the necessary tests very quickly, giving us fast feedback. Talk
  35. 35. Thanks !

×