4 Replies Latest reply on Feb 6, 2012 6:48 AM by Jeremy Whiting

    NameNotFoundException lookup during an asynchronous WebService call.

    Jeremy Whiting Expert

      Hi,

       

      I have a JEE5 specification application that is throwing a NameNotFoundException. I have created a sample application that replicates the issue.

       

      It seems the naming context is not available for a WebService method when it has been invoked asynchronously. The WebService web method is annotated with @OneWay.

      The callee code goes into the WS stack. The WS stack recognises the call is async and put the invocation onto a work queue.

      When the worker queue task is taken off later, the web method call is invoked. But without the jndi context populated with bound objects.

       

      This is the Web Service. The web service calls a class that performs a JNDI call.

       

      package org.jboss.performance.jndi.test.ws;

       

      import java.util.logging.Logger;

       

      import javax.jws.Oneway;

      import javax.jws.WebService;

       

      import org.jboss.performance.jndi.test.lookup.StaticInit;

       

      @WebService

         (

               serviceName="StaticService"

         )

      public class StaticService implements IStatic{

       

         private static Logger logger = Logger.getLogger(StaticService.class.getName());

        

         @Oneway

         public void doIt() {

            new StaticInit();// this will load the class

         }

      }

       

      This is the class it calls.

       

      public class StaticInit {

       

         public static int NET_SEGMENT_SIZE_MIN = -1;

         public static int NET_SEGMENT_SIZE_MAX = -1;

         static

         {

            synchronized (StaticInit.class) {

               try

               {

                  Context ic = new InitialContext();

                  NET_SEGMENT_SIZE_MIN = ((Integer)ic.

                          lookup("java:comp/env/supplier.payloadsize.min")).

                       intValue();

                  NET_SEGMENT_SIZE_MAX = ((Integer)ic.

                       lookup("java:comp/env/supplier.payloadsize.max")).

                             intValue();

               }

               catch(NamingException ex)

               {

                     ex.printStackTrace();

               }

            }

         }

      }

       

      This is the web.xml file. And it is in the WEB-INF directory this time

       

      <web-app xmlns="http://java.sun.com/xml/ns/javaee"

          version="2.5"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

       

        <display-name>jndi lookup test</display-name>

       

       

        <env-entry>

                  <description>This entry should be bound to the

                  java comp namespace.</description>

                  <env-entry-name>supplier.payloadsize.min</env-entry-name>

                  <env-entry-type>java.lang.Integer</env-entry-type>

                  <env-entry-value>32</env-entry-value>

            </env-entry>

            <env-entry>

                  <description>This env entry is to set the thread keep alive time (in seconds) for threads in the delivery scheduler thread pool </description>

                  <env-entry-name>supplier.payloadsize.max</env-entry-name>

                  <env-entry-type>java.lang.Integer</env-entry-type>

                  <env-entry-value>64</env-entry-value>

            </env-entry>

      </web-app>

       

       

      The JNDI lookup causes this exception stack trace.

       

      18:47:59,263 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (Thread-6 (group:HornetQ-client-global-threads-1571378648)) Creating Service {http://ws.test.jndi.performance.jboss.org/}StaticService from WSDL: http://burtha02-wireless:8080/envEntryEmulatorSampleWeb/StaticService?wsdl

      18:52:54,945 ERROR [stderr] (default-workqueue-1) javax.naming.NameNotFoundException: java:comp/env/supplier.payloadsize.min

      18:52:54,947 ERROR [stderr] (default-workqueue-1)     at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:95)

      18:52:54,947 ERROR [stderr] (default-workqueue-1)     at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:213)

      18:52:54,947 ERROR [stderr] (default-workqueue-1)     at javax.naming.InitialContext.lookup(InitialContext.java:409)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at org.jboss.performance.jndi.test.lookup.StaticInit.<clinit>(StaticInit.java:44)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at org.jboss.performance.jndi.test.ws.StaticService.doIt(StaticService.java:20)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at java.lang.reflect.Method.invoke(Method.java:616)

      18:52:54,948 ERROR [stderr] (default-workqueue-1)     at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:169)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:117)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at java.util.concurrent.FutureTask.run(FutureTask.java:166)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)

      18:52:54,949 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:232)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.interceptor.OneWayProcessorInterceptor$1.run(OneWayProcessorInterceptor.java:130)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$2.run(AutomaticWorkQueueImpl.java:353)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

      18:52:54,950 ERROR [stderr] (default-workqueue-1)     at java.lang.Thread.run(Thread.java:636)

       

      Is there something extra I should be doing to establish the jndi context ?

       

      Regards,

      Jeremy