Hi Sagara,

Thanks for you guidance.
I have put a mail to [email protected] under the subject "WSO2 - TomEE
integration progress." regarding the progress. Please see my comments
Inline.


On Fri, May 16, 2014 at 7:41 PM, Sagara Gunathunga <[email protected]> wrote:

>
>
>
> On Fri, May 16, 2014 at 2:22 PM, Chamil Jeewantha <[email protected]> wrote:
>
>> The knowledge on TomEE architecture on  Tomcat is important to understand
>> how TomEE can be integrated to WSO2 AS.
>>
>> *What is OpenEJB & TomEE?*
>>
>> The OpenEJB and TomEE codes exist on the same code base. The OpenEJB code
>> provides the ejb and other j2ee support. The TomEE code is the integration
>> part that integrates openejb into Tomcat. The code base generates several
>> distributions Such as standalone TomEE, Standalone OpenEJB, OpenEJB-Lite,
>> TomEE war etc... A detailed  comparison can be found at [1]
>>
>> *TomEE on Tomcat*
>>
>> TomEE comes as a war file which can be deployed on Tomcat.
>>
>> To deploy TomEE on Tomcat:
>>
>>    1. Download TomEE war [2]
>>    2. put it in Tomcat's webapp directory.
>>    3. Start Tomcat
>>
>> Now the Tomcat is J2EE WP enabled.
>>
>> *How does it happen internally?*
>>
>> Lets look at the Important contents of TomEE war:
>>
>> TomEE.war
>>     | - libs    #contains all the lib files
>>     | - WEB-INF
>>             | - lib    #contains tomee-loader*.jar
>>             | - web.xml
>>
>> *TomEE initialization*
>>
>> There are three approaches of initializing TomEE on Tomcat.
>>
>> *Approach 1 - Loader Servlet*
>>
>>    - The web.xml file registers the LoaderServlet which is in the
>>    tomee-loader*.jar file.
>>
>> <servlet>
>>     <servlet-name>LoaderServlet</servlet-name>
>>     <servlet-class>org.apache.tomee.loader.LoaderServlet</servlet-class>
>>     <load-on-startup>1</load-on-startup>
>> </servlet>
>>
>>
>>    - The load-on-startup = 1 tells, please load this servlet on load.
>>    - The servlet then creates another WebappClassLoader (create mini
>>    webapp)
>>    - Loads tomee-loader.jar and openejb-loader.jar into new
>>    WebappClassLoader
>>    - Trigger the intialization process of TomEE within WebappClassLoader
>>    - The tomee-loader then do lots of background work and loads OpenEJB
>>    jars into Tomcat common classloader.
>>    - Initialization OpenEJB within Tomcat common class loader
>>
>> *Approach 2 - OpenEJBListener*
>>
>>    - The tomee-loader*.jar is copied into $CATALINA_HOME/lib directory
>>    - Register org.apache.tomee.loader.OpenEJBListener as a lifecycle
>>    listner in server.xml file
>>    - The lifecycle listener looks for the tomee webapp directory
>>    - It creates a new WebappClassLoader (Create a mini webapp)
>>    - Loads tomee-loader and openejb-loader jars to that webapp
>>    - trigger the tomee initialization process
>>    - The OpenEJB jar files are loaded into Tomcat common class loader by
>>    this mini Webapp
>>    - Initialize OpenEJB within common class loader
>>
>> *Approach 3 - TomEE libs in $CATALINA_HOME/libs direcotory*
>>
>>    - The TomEE/OpenEJB libraries are copied into $CATALINA_HOME/libs
>>    directory
>>    - Register org.apache.tomee.catalina.ServerListener in Tomcat
>>    server.xml
>>    - remove tomcat annotations-api.jar because it does not contain full
>>    set of j2ee annotations.
>>    - The TomEE/OpenEJB libs are already in catalina classloader
>>    - The ServerListener will trigger the TomEE initialization process
>>    within Tomcat common classloader
>>
>> In all the above approaches, They have loaded TomEE libs (and
>> dependencies) and initialized in Tomcat common Classloader
>>
>> TomEE Then registers a lifecycle listener which will be on alert for
>> WebApp loading.
>> TomEE will create a child container per webapp when its getting deployed.
>> This child container is the j2ee environment for the webapp.
>>
>>
>> *TomEE AS Integration*
>>
>> WSO2 AS uses Tomcat as the servlet container. TomEE has already put a big
>> effort to integrate OpenEJB to Tomcat. So reuse the TomEE code on AS is the
>> way to go.
>>
>> However, non of the above TomEE approaches directly work on AS due to its
>> architectural differences over vanilla Tomcat. The major problems found up
>> to now are:
>>
>>    - TomEE assumes classpath/URL class loading. AS has OSGI based own
>>    class loading mechanism
>>    - The TomEE requires full set of j2ee annotation support. The WSO2 AS
>>    is not bundled with the full set.
>>    - TomEE & WSO2 Webapp deployment incompatibilities.
>>    - TomEE uses its own Jar scanner, AS has its own Jar scanner.
>>    - ++
>>
>> In my POV there can be two types of problems.
>
> 1. In contrast to vanilla Tomcat in  AS Tomcat is deployed as OSGi service
> hence we have to modify some TomEE integration points to work under a OSGi
> run time.
>
+1 & this is done.

> When we integrate Tomcat with OSGi we ran into similar problems that's why
> you can see Carbon Jar scanner ,Carbon Classloaders etc. We are more or
> less aware of these generic issues and if you can elaborate more on case by
> case we can help.
>
+1 Now I am at a level of looking into JarScanner problems. Will elaborate
the problems once I understand them well. for now simply it doesn't work.

>
>
> 2. In AS we use Carbon deployers to deploy web applications instead of
> default Tomcat deployers, it seems TomEE also override default Tomcat
> deployers and take the deployment control. In this case we need to study
> TomEE deployment logic and  improve Carbon deployers accordingly.
>

>
>
>> *Architecture*
>>
>> Bundle all TomEE & OpenEJB jars as one single plugin (Orbit bundle) with
>> required tweaks on code.
>> Register Server lifecycle listener to trigger TomEE initialization when
>> server is getting started.
>> Modify the WSO2 AS WebappClassLoader, CarbonTomcatJarScanner etc... to
>> deal with OpenEJB
>>
>
> IMHO we need to start by improving web application deployers as it very
> clear that we can't use TomEE deployers.
>
It seems TomEE deployer is there to Deploy the OpenEJB containers. for now
they don't trouble.

>
>
>
>>
>> TomEE version we are working on : TomEE 1.6.0.1
>>
>> *Current Progress*
>>
>> With some of the code tweaks directly done on OpenEJB code the OpenEJB
>> jars have put into repository/components/dropins
>> Registered "ServerListener" lifecycle listener on catalina-server.xml
>> The openejb containers up are running on WSO2 AS.
>> The Webapp deployment listener registered by OpenEJB on WSO2 AS, creates
>> OpenEJB child container upon Webapp deployment
>> Gives some errors due to javax.annotation dependancy
>> Gives duplicate webapp error by CarbonTomcat.addWebApp method.
>>
>> *TODO:*
>>
>> Create one single OpenEJB bundle That can be deployed as a plugin
>> Fix JarScanner
>> Fix javax.annotation dependency problem
>> Solve the OpenEJB - CarbonTomcat.addWebApp problem
>> Fix the class loading problems
>> Samples :- Should be able to re-use TomEE samples.
>>
>
> +1
>
> Thanks !
>
>>
>>
>> [1] http://tomee.apache.org/comparison.html
>> [2] https://tomee.apache.org/downloads.html
>>
>>
>> --
>> K.D. Chamil Jeewantha
>> Associate Technical Lead
>> WSO2, Inc.;  http://wso2.com
>> Mobile: +94716813892
>>
>>
>
>
> --
> Sagara Gunathunga
>
> Senior Technical Lead; WSO2, Inc.;  http://wso2.com
> V.P Apache Web Services;    http://ws.apache.org/
> Linkedin; http://www.linkedin.com/in/ssagara
> Blog ;  http://ssagara.blogspot.com
>
>


-- 
K.D. Chamil Jeewantha
Associate Technical Lead
WSO2, Inc.;  http://wso2.com
Mobile: +94716813892
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to