[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wsf-c-dev
Subject:    Re: [Dev] GSoC Project - Progress on the Apache Tomcat based runtime implementation for Jaggery.js
From:       Mohamed Nasmin <nasmin1990 () gmail ! com>
Date:       2014-06-30 18:52:39
Message-ID: CAP_P8r3n2x01utx-DOjnPaDVJ=xBJhQS0BEN+G3oJK+KC3Aoxg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


After some reading I found the above null pointer comes when we adding the
context listener BEFORE_START_EVENT occurs. So I changed the event to
STARTING. Now without any error the jaggery context listener added to the
standard context.

But when access the sample tomgery application through URL I got this
error. When I debug this[1] I found appConfigs is null. But could not find
how it happened. Thanks in advance.

*Code : *

protected void service(HttpServletRequest request,
                           HttpServletResponse response) throws
ServletException, IOException {
        JaggeryAppConfigs appConfigs =
JaggeryAppConfigs.getInstance(request.getServletContext());
        request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
        AsyncContext asyncCtx = request.startAsync();
        asyncCtx.addListener(new JaggeryAsyncListener());
        asyncCtx.setTimeout(appConfigs.getServletTimeout());
        appConfigs.getServletExecutor().execute(new
JaggeryAsyncRequestProcessor(asyncCtx));
    }

*Exception :*

java.lang.NullPointerException
	org.jaggeryjs.apps.JaggeryAsyncServlet.service(JaggeryAsyncServlet.java:23)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

[1]
https://github.com/ruchiraw/jaggery/blob/master/components/jaggery-core/org.jaggeryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryAsyncServlet.java



On Sun, Jun 22, 2014 at 5:54 AM, Chamil Jeewantha <chamil@wso2.com> wrote:

> Hi Nasmin,
> 
> the Null Pointer Exception (NPE) comes from the line
> 
> registration.setAsyncSupported(true);
> 
> Which means "registration" object is null. The responsible line of
> assigning this variable is the line 25.
> 
> ServletRegistration.Dynamic registration = servletContext.addServlet(
> JaggeryAsyncServlet.NAME, JaggeryAsyncServlet.class);
> 
> servletContext.addServlet javadoc[1] says,
> 
> a ServletRegistration object that may be used to further configure the registered \
> servlet, or *null** if this ServletContext already contains a complete \
> ServletRegistration for the given **servletName* 
> For this case you can start debug by two points.
> 
> 1. debug JaggeryContextListener
> 2. Debug with tomcat source - servletContext.addServlet method to see why it \
> returns null here. 
> 
> [1] http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addServlet(java.lang.String, \
> java.lang.Class) 
> 
> 
> On Sat, Jun 21, 2014 at 10:08 PM, Mohamed Nasmin <nasmin1990@gmail.com>
> wrote:
> 
> > Hi,
> > 
> > @Ruchira
> > I will debug the jars that we use in the tomgery app deployment and
> > update with the results.
> > 
> > @Dilshan
> > I am using that JaggeryContextListener in a jar which is created by
> > Ruchira. You can find the source code of that jar here[1].
> > 
> > @Dakshika
> > With the integration with JSR-223, Jaggery will use Nashorn from JDK8
> > onwards and will fallback to JDK's embeded Rhino version with JDK7 or
> > below. With the above Jaggery core minimisations, a Jaggery app can be even
> > deployed on top of tomcat, subjecting to a WEB-INF directory which contains
> > jaggery core jars and web.xml. For more details please refer this link[2].
> > 
> > [1]
> > https://github.com/ruchiraw/jaggery/blob/master/components/jaggery-core/org.jaggeryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryContextListener.java
> >  [2] http://osdir.com/ml/carbon-wso2-architecture/2014-06/msg00000.html
> > 
> > 
> > On Sat, Jun 21, 2014 at 9:46 PM, Dilshan Edirisuriya <dilshan@wso2.com>
> > wrote:
> > 
> > > Hi,
> > > 
> > > Whats there at line 27 of JaggeryContextListener.java? Where can we find
> > > the source for this?
> > > 
> > > Regards,
> > > 
> > > Dilshan
> > > 
> > > 
> > > On Sat, Jun 21, 2014 at 1:31 PM, Mohamed Nasmin <nasmin1990@gmail.com>
> > > wrote:
> > > 
> > > > 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
> > > > Dev@wso2.org
> > > > http://wso2.org/cgi-bin/mailman/listinfo/dev
> > > > 
> > > > 
> > > 
> > > 
> > > --
> > > Dilshan Edirisuriya
> > > Senior Software Engineer - WSO2
> > > Mob: + 94 777878905
> > > http://wso2.com/
> > > 
> > 
> > 
> > _______________________________________________
> > Dev mailing list
> > Dev@wso2.org
> > http://wso2.org/cgi-bin/mailman/listinfo/dev
> > 
> > 
> 
> 
> --
> K.D. Chamil Jeewantha
> Associate Technical Lead
> WSO2, Inc.;  http://wso2.com
> Mobile: +94716813892
> 
> 


[Attachment #5 (text/html)]

<div dir="ltr"><div><div>After some reading I found the above null pointer comes when \
we adding the context listener BEFORE_START_EVENT occurs. So I changed the event to \
STARTING. Now without any error the jaggery context listener added to the standard \
context. <br> <br></div>But when access the sample tomgery application through URL I \
got this error. When I debug this[1] I found appConfigs is null. But could not find \
how it happened. Thanks in advance.<br><br></div><b>Code : </b><br> \
<div><div><br>protected void service(HttpServletRequest request,<br>                  \
HttpServletResponse response) throws ServletException, IOException {<br>              \
JaggeryAppConfigs appConfigs = \
JaggeryAppConfigs.getInstance(request.getServletContext());<br>  \
request.setAttribute(&quot;org.apache.catalina.ASYNC_SUPPORTED&quot;, true);<br>      \
AsyncContext asyncCtx = request.startAsync();<br>               \
asyncCtx.addListener(new JaggeryAsyncListener());<br>               \
asyncCtx.setTimeout(appConfigs.getServletTimeout());<br>  \
appConfigs.getServletExecutor().execute(new \
JaggeryAsyncRequestProcessor(asyncCtx));<br>       }<br><br></div><div><b>Exception \
:</b><br><br><pre>java.lang.NullPointerException  \
org.jaggeryjs.apps.JaggeryAsyncServlet.service(JaggeryAsyncServlet.java:23)  \
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)  \
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)</pre>[1] <a \
href="https://github.com/ruchiraw/jaggery/blob/master/components/jaggery-core/org.jagg \
eryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryAsyncServlet.java">https://github.c \
om/ruchiraw/jaggery/blob/master/components/jaggery-core/org.jaggeryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryAsyncServlet.java</a><br>
 </div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, \
Jun 22, 2014 at 5:54 AM, Chamil Jeewantha <span dir="ltr">&lt;<a \
href="mailto:chamil@wso2.com" target="_blank">chamil@wso2.com</a>&gt;</span> \
wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr">Hi Nasmin,<div><br></div><div>the Null \
Pointer Exception (NPE) comes from the line</div><div><br></div><div> <span \
style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">registration</span><span \
style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap">.</span><span \
style="color:teal;font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;text-align:start;white-space:pre-wrap">setAsyncSupported</span><span \
style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap">(</span><span \
style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap;background-color:rgb(255,255,255)">true</span><span \
style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap">);</span><br>


</div><div><span style="font-weight:bold;color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap"><br></span></div><div><font \
color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace"><span \
style="font-size:12px;line-height:18px;white-space:pre-wrap">Which means \
&quot;registration&quot; object is null. The responsible line of assigning this \
variable is the line 25.</span></font></div>

<div><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, \
monospace"><span style="font-size:12px;line-height:18px;white-space:pre-wrap"><br></span></font></div><div><pre \
style="overflow:auto;margin-top:0px;margin-bottom:0px"> <div \
style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px"><span>ServletRegistration</span><span \
style="font-weight:bold">.</span><span style="color:teal">Dynamic</span> \
<span>registration</span> <span style="font-weight:bold">=</span> \
<span>servletContext</span><span style="font-weight:bold">.</span><span \
style="color:teal">addServlet</span><span style="font-weight:bold">(</span></div>

<div style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px"> \
<span>JaggeryAsyncServlet</span><span style="font-weight:bold">.</span><span \
style="color:teal">NAME</span><span style="font-weight:bold">,</span> \
<span>JaggeryAsyncServlet</span><span style="font-weight:bold">.</span><span \
style="color:teal">class</span><span style="font-weight:bold">);</span></div>

<div style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px"><span \
style="font-weight:bold"><br> </span></div><div \
style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px">servletContext.addServlet \
javadoc[1] says,</div>

<div style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px"><br></div><div \
style="color:rgb(51,51,51);font-family:Consolas,&#39;Liberation \
Mono&#39;,Menlo,Courier,monospace;font-size:12px;line-height:18px;padding-left:10px;min-height:18px">


<span style="color:rgb(0,0,0);font-family:&#39;Times New \
Roman&#39;;font-size:medium;line-height:normal;white-space:normal">a \
ServletRegistration object that may be used to further configure the registered \
servlet, or  </span><tt \
style="color:rgb(0,0,0);line-height:normal;white-space:normal"><b>null</b></tt><span \
style="color:rgb(0,0,0);font-family:&#39;Times New \
Roman&#39;;font-size:medium;line-height:normal;white-space:normal"><b>  if this \
ServletContext already contains a complete ServletRegistration for the given  \
</b></span><tt style="color:rgb(0,0,0);line-height:normal;white-space:normal"><b>servletName</b></tt><br>


</div><br>For this case you can start debug by two points.<br><br>1. debug \
JaggeryContextListener<br>2. Debug with tomcat source - servletContext.addServlet \
method to see why it returns null here.<br><br><br>[1] <a \
href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addServlet(java.lang.String" \
target="_blank">http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addServlet(java.lang.String</a>, \
java.lang.Class)</pre>

</div></div><div class="gmail_extra"><div><div class="h5"><br><br><div \
class="gmail_quote">On Sat, Jun 21, 2014 at 10:08 PM, Mohamed Nasmin <span \
dir="ltr">&lt;<a href="mailto:nasmin1990@gmail.com" \
target="_blank">nasmin1990@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br></div>@Ruchira <br>I will \
debug the jars that we use in the tomgery app deployment and update with the \
results.<br>

<br></div>@Dilshan <br>I am using that JaggeryContextListener in a jar which is \
created by Ruchira. You can find the source code of that jar here[1].<br> \
<br>@Dakshika <br>With the integration with JSR-223, Jaggery will use Nashorn from \
JDK8 onwards and will fallback to JDK&#39;s embeded Rhino version with JDK7 or below. \
With the above Jaggery core minimisations, a Jaggery app can be even  deployed on top \
of tomcat, subjecting to a WEB-INF directory which  contains jaggery core jars and \
web.xml. For more details please refer this link[2].<br><br>[1] <a \
href="https://github.com/ruchiraw/jaggery/blob/master/components/jaggery-core/org.jaggeryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryContextListener.java" \
target="_blank">https://github.com/ruchiraw/jaggery/blob/master/components/jaggery-cor \
e/org.jaggeryjs.apps/src/main/java/org/jaggeryjs/apps/JaggeryContextListener.java</a><br>



[2] <a href="http://osdir.com/ml/carbon-wso2-architecture/2014-06/msg00000.html" \
target="_blank">http://osdir.com/ml/carbon-wso2-architecture/2014-06/msg00000.html</a><br></div><div><div><div \
class="gmail_extra"> <br><br><div class="gmail_quote">On Sat, Jun 21, 2014 at 9:46 \
PM, Dilshan Edirisuriya <span dir="ltr">&lt;<a href="mailto:dilshan@wso2.com" \
target="_blank">dilshan@wso2.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hi,<br><br>Whats there at line 27 of \
JaggeryContextListener.java? Where can we find the source for this?<br>


<br>Regards,<br><br>Dilshan<br><div></div></div><div class="gmail_extra"><br><br><div \
class="gmail_quote"><div><div> On Sat, Jun 21, 2014 at 1:31 PM, Mohamed Nasmin <span \
dir="ltr">&lt;<a href="mailto:nasmin1990@gmail.com" \
target="_blank">nasmin1990@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">


<div><div>
<div dir="ltr">According to our earlier conversation I am following the below \
progression to accomplish the project. Sorry for the lengthy \
email.<br><div><div><br><b>Task1. Check whether the app in the tomcat webapps is \
jaggery app or not before it gets deployed/initialized</b><br>





<br>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.).<br>





<br>&lt;Listener className=&quot;org.jaggery.tomcat.listener.TomcatListener&quot; \
/&gt;<br><br></div><div>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.<br>





<br></div><div>Code :<br><br>public void lifecycleEvent(LifecycleEvent event) \
{<br><br>               String type = event.getType();<br>               if \
(Lifecycle.BEFORE_START_EVENT.equals(type)) {<br>                       \
LOGGER.log(Level.INFO, &quot;BEFORE START EVENT triggered.&quot;);<br>





                       Lifecycle source = event.getLifecycle();<br><br>               \
if (source instanceof StandardContext) {<br><br>                               \
StandardContext standardContext = (StandardContext) source;<br>                       \
boolean exists = isJaggeryApp(standardContext);<br>





<br>                               if (!exists) {<br>                                 \
System.out.println(&quot;This is not a Jaggery app&quot;);<br>                        \
} else {<br>                                       System.out.println(&quot;This is a \
Jaggery app&quot;);<br>





                               }<br>                       }<br>               }<br>  \
}<br><br>  public boolean isJaggeryApp(StandardContext standardContext) {<br><br>     \
String contextPath = standardContext.getPath();<br>               String catalinaPath \
= System.getProperty(&quot;catalina.base&quot;);<br>





               <br>               try{<br>               File file = new \
File(catalinaPath + File.separator + &quot;webapps&quot; + contextPath + \
File.separator + &quot;jaggery.conf&quot;);<br>               boolean exists = \
file.exists();<br>               }<br>





               catch (Exception e){<br>                       \
e.printStackTrace();<br>               }<br><br>               if (!exists) {<br>     \
return false;<br>               } else {<br>                       return true;<br>   \
}<br><br>       }<br></div>




<div>
<br></div><div>Output:<br><br>INFO: Deploying web application directory \
/home/nasmin/tomcat/apache-tomcat-7.0.54/webapps/demo3<br>Jun 20, 2014 10:25:40 PM \
org.jaggery.tomcat.listener.TomcatListener lifecycleEvent<br>INFO: BEFORE START EVENT \
triggered.<br>





This is a Jaggery app<br></div><div>
<br><b>Task2. How to put the jars in the tomcat that apps can \
see</b><br><br></div><div>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.<br>





<br>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</div>






<div><br><b>Task3. Register a jaggery servlet listener if it is a jaggery app

</b><br><br></div><div>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.<br>





<br></div><div>Code:<br><br>standardContext.addApplicationListener(&quot;org.jaggeryjs.apps.JaggeryContextListener&quot;);<br><br>ApplicationParameter \
applicationParameter = new \
ApplicationParameter();<br>applicationParameter.setName(&quot;jaggery.initializer&quot;);<br>






applicationParameter.setValue(&quot;server://engines/index.js&quot;);<br>standardContext.addApplicationParameter(applicationParameter);<br><br>ApplicationParameter \
applicationParameter1 = new \
ApplicationParameter();<br>applicationParameter1.setName(&quot;jaggery.development&quot;);<br>






applicationParameter1.setValue(&quot;true&quot;);<br>standardContext.addApplicationParameter(applicationParameter1);<br><br>ApplicationParameter \
applicationParameter2 = new \
ApplicationParameter();<br>applicationParameter2.setName(&quot;jaggery.engine.pool.max.active&quot;);<br>






applicationParameter2.setValue(&quot;5000&quot;);<br>standardContext.addApplicationParameter(applicationParameter2);<br><br>ApplicationParameter \
applicationParameter3 = new \
ApplicationParameter();<br>applicationParameter3.setName(&quot;jaggery.executor.pool.max&quot;);<br>






applicationParameter3.setValue(&quot;5000&quot;);<br>standardContext.addApplicationParameter(applicationParameter3);<br><br></div><div>Output:<br><br>INFO: \
Deploying web application directory \
/home/nasmin/tomcat/apache-tomcat-7.0.54/webapps/demo5<br>





Jun 20, 2014 10:25:39 PM org.jaggery.tomcat.listener.TomcatListener \
lifecycleEvent<br>INFO: BEFORE START EVENT triggered.<br>This is a Jaggery app<br>Jun \
20, 2014 10:25:40 PM org.apache.catalina.core.StandardContext listenerStart<br>





SEVERE: Exception sending context initialized event to listener instance of class \
org.jaggeryjs.apps.JaggeryContextListener<br>java.lang.NullPointerException<br>       \
at org.jaggeryjs.apps.JaggeryContextListener.contextInitialized(JaggeryContextListener.java:27)<br>






       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)<br> \
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)<br> \
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)<br>





       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)<br> \
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)<br>       \
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)<br>





       at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)<br> \
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)<br> \
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)<br>





       at java.util.concurrent.FutureTask.run(FutureTask.java:262)<br>       at \
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)<br>   \
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)<br>






       at java.lang.Thread.run(Thread.java:744)<br><br>Jun 20, 2014 10:25:40 PM \
org.apache.catalina.core.StandardContext startInternal<br>SEVERE: Error \
listenerStart<br><br></div><div>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. <br>





<br>Thanks in advance.<br></div></div></div>
<br></div></div><div>_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@wso2.org" target="_blank">Dev@wso2.org</a><br>
<a href="http://wso2.org/cgi-bin/mailman/listinfo/dev" \
target="_blank">http://wso2.org/cgi-bin/mailman/listinfo/dev</a><br> \
<br></div></blockquote></div><span><font color="#888888"><br><br clear="all"><br>-- \
<br><div dir="ltr">Dilshan Edirisuriya<br>Senior Software Engineer - WSO2<br>Mob: <a \
href="tel:%2B%2094%20777878905" value="+94777878905" target="_blank">+ 94 \
777878905</a><br>


<a href="http://wso2.com/" target="_blank">http://wso2.com/</a><br></div>

</font></span></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@wso2.org" target="_blank">Dev@wso2.org</a><br>
<a href="http://wso2.org/cgi-bin/mailman/listinfo/dev" \
target="_blank">http://wso2.org/cgi-bin/mailman/listinfo/dev</a><br> \
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br></div></div><div \
dir="ltr"><span style="color:rgb(136,136,136)">K.D. Chamil Jeewantha</span><br \
style="color:rgb(136,136,136)"><font color="#888888">Associate Technical \
Lead</font><div>

<span style="color:rgb(136,136,136)">WSO2, Inc.;    </span><a href="http://wso2.com/" \
style="color:rgb(17,85,204)" target="_blank">http://wso2.com</a><br \
style="color:rgb(136,136,136)"><font color="#888888">Mobile: <a \
href="tel:%2B94716813892" value="+94716813892" \
target="_blank">+94716813892</a></font><br style="color:rgb(136,136,136)">

<br></div></div>
</div>
</blockquote></div><br></div>



_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic