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 <[email protected]>
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 <[email protected]>
> 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 <[email protected]>
>> 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
>>> [email protected]
>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>
>>>
>>
>>
>> --
>> Dilshan Edirisuriya
>> Senior Software Engineer - WSO2
>> Mob: + 94 777878905
>> http://wso2.com/
>>
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


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

Reply via email to