According to our earlier conversation I am following the below progression
to accomplish the project. Sorry for the lengthy email.

*Task1. Check whether the app in the tomcat webapps is jaggery app or not
before it gets deployed/initialized*

I trigger the BEFORE_START_EVENT by configuring the tomcat lifecycle
listener with context.xml in the tomcat. The context can listen to the
lifecycle listener by putting jar inside lib folder of tomcat. That jar
should contain the tomcat listener. Also we need to define that class in
the context.xml like below (For more details please refer this mail with
subject Tomcat Lifecycle listener how to.).

<Listener className="org.jaggery.tomcat.listener.TomcatListener" />

When an application is started to deploy BEFORE_START_EVENT will be
occurred. we check that event get the standard context of that event. To
find out whether it is a jaggery context or not we identify the
jaggery.conf in that app folder.

Code :

public void lifecycleEvent(LifecycleEvent event) {

        String type = event.getType();
        if (Lifecycle.BEFORE_START_EVENT.equals(type)) {
            LOGGER.log(Level.INFO, "BEFORE START EVENT triggered.");
            Lifecycle source = event.getLifecycle();

            if (source instanceof StandardContext) {

                StandardContext standardContext = (StandardContext) source;
                boolean exists = isJaggeryApp(standardContext);

                if (!exists) {
                    System.out.println("This is not a Jaggery app");
                } else {
                    System.out.println("This is a Jaggery app");
                }
            }
        }
    }

 public boolean isJaggeryApp(StandardContext standardContext) {

        String contextPath = standardContext.getPath();
        String catalinaPath = System.getProperty("catalina.base");

        try{
        File file = new File(catalinaPath + File.separator + "webapps" +
contextPath + File.separator + "jaggery.conf");
        boolean exists = file.exists();
        }
        catch (Exception e){
            e.printStackTrace();
        }

        if (!exists) {
            return false;
        } else {
            return true;
        }

    }

Output:

INFO: Deploying web application directory
/home/nasmin/tomcat/apache-tomcat-7.0.54/webapps/demo3
Jun 20, 2014 10:25:40 PM org.jaggery.tomcat.listener.TomcatListener
lifecycleEvent
INFO: BEFORE START EVENT triggered.
This is a Jaggery app

*Task2. How to put the jars in the tomcat that apps can see*

After finding the jaggery app in the tomcat we need to assign some jar
which will be required to get new jaggery engine. So we can put the in a
directory in the tomcat and we need to mention that in the
catalina.properties like below.

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.base}/jaggery/lib,${catalina.base}/jaggery/lib/*.jar,${catalina.home}/jaggery/lib,${catalina.home}/jaggery/lib/*.jar

*Task3. Register a jaggery servlet listener if it is a jaggery app *

Afterwards we need to register our jaggery servlet listener to the jaggery
app. I did by adding application listener to the jaggery standard context
and I added application paramaeter which we had in the web.xml. Here I got
an exception like below. Please advice on this.

Code:

standardContext.addApplicationListener("org.jaggeryjs.apps.JaggeryContextListener");

ApplicationParameter applicationParameter = new ApplicationParameter();
applicationParameter.setName("jaggery.initializer");
applicationParameter.setValue("server://engines/index.js");
standardContext.addApplicationParameter(applicationParameter);

ApplicationParameter applicationParameter1 = new ApplicationParameter();
applicationParameter1.setName("jaggery.development");
applicationParameter1.setValue("true");
standardContext.addApplicationParameter(applicationParameter1);

ApplicationParameter applicationParameter2 = new ApplicationParameter();
applicationParameter2.setName("jaggery.engine.pool.max.active");
applicationParameter2.setValue("5000");
standardContext.addApplicationParameter(applicationParameter2);

ApplicationParameter applicationParameter3 = new ApplicationParameter();
applicationParameter3.setName("jaggery.executor.pool.max");
applicationParameter3.setValue("5000");
standardContext.addApplicationParameter(applicationParameter3);

Output:

INFO: Deploying web application directory
/home/nasmin/tomcat/apache-tomcat-7.0.54/webapps/demo5
Jun 20, 2014 10:25:39 PM org.jaggery.tomcat.listener.TomcatListener
lifecycleEvent
INFO: BEFORE START EVENT triggered.
This is a Jaggery app
Jun 20, 2014 10:25:40 PM org.apache.catalina.core.StandardContext
listenerStart
SEVERE: Exception sending context initialized event to listener instance of
class org.jaggeryjs.apps.JaggeryContextListener
java.lang.NullPointerException
    at
org.jaggeryjs.apps.JaggeryContextListener.contextInitialized(JaggeryContextListener.java:27)
    at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
    at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
    at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
    at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
    at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Jun 20, 2014 10:25:40 PM org.apache.catalina.core.StandardContext
startInternal
SEVERE: Error listenerStart

I attached the tomcat directory structure for the jaggery app with this
email. Also we have a remaining task that we need put context parameters in
a separate property file and make it available for the app deployment. Here
I hard coded those parameters. Please advice on this issue.

Thanks in advance.
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to