4 Replies Latest reply on Oct 5, 2011 4:14 AM by lieshoff

    NoInitialCOnceptException when calling session bean from client

    deryaaltuntas

      I have created one enterprise application with EJB and WEB project.

      Then I added one EJB3 Session Bean class named FileManagerBean with remote and local interface interface.

      Now I am trying to call moveFolder business method of this bean.I have deployed succefully.But I run test

      class, NoInıtıalContextException occures.I do not find look up name for my EJBProject.Maybe my problem is this.

      I am setting InitialContext in client.(May be port number is wrong)

      I am sending All classes, persistence.xml file and print of JNDI data source of  JMX console.

      Please look at my problem

      javax.naming.NoInitialContextException

       

       

      : Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

       

      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)

      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)

      at javax.naming.InitialContext.lookup(InitialContext.java:392)

      at com.siemens.SessionBeanFileManager.Test.Test.doTest(Test.java:34)

      at com.siemens.SessionBeanFileManager.Test.Test.main(Test.java:26)

       

       

      TEST CLASS

      package com.siemens.SessionBeanFileManager.Test;

       

       


      import java.io.FileNotFoundException;
      import java.io.IOException;
      import java.util.Properties;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.resource.spi.SecurityException;
      import com.siemens.SessionBean.FileManager.FileManagerBean;
      import com.siemens.SessionBean.FileManager.FileManagerBeanRemote;

      public class Test {

      /**
        * @param args
        */
      public Test() {
      }

       

      public static void main(String[] args) throws FileNotFoundException, IOException, SecurityException{
        Test searchFacadeTest = new Test();
        searchFacadeTest.doTest();
      }


      public void doTest() throws FileNotFoundException, IOException{
        try {

         InitialContext jndiContext = new InitialContext();
         FileManagerBeanRemote fileManager= (FileManagerBeanRemote)jndiContext.lookup("SiguardEJB/EJB3/FileManagerBean/remote");
         fileManager.moveFile("C:\\test.txt", "C:\\Documents and Settings\\tr1a6358\\bowling.txt");
        }
        catch (Exception e) {
         e.printStackTrace();
        }
      }
           // developed for JBoss only. this is vender dependency
           public static Context getInitialContext( ) throws javax.naming.NamingException {
            Properties p = new Properties( );
            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            return new javax.naming.InitialContext(p);
           }

      }

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • 1. Re: NoInitialCOnceptException when calling session bean from client
          deryaaltuntas

          Now I am not getting NoInitialContext Exception after adding jbossall-client.jar to class path.Now my code hangs up in lookup method.

          No response comes.Only below is written to console.

           

          23:58:57,268 DEBUG TimedSocketFactory:87 - createSocket, hostAddr: localhost/127.0.0.1, port: 1098, localAddr: null, localPort: 0, timeout: 0

           

          I think may be my port number can be wrong.I have checked in name-Servicing of JMX console.It seems 1098.May be I am setting

          wrong port.Please look at attachment.

          Other possibility is wrong lookup name.(JNDI name)(FileManagerBean/local").I am also sending JNDI namespace.

          Please help me .I can not see why I am wrong.

           

           

            * @param args
            */
          public Test() {
          }


          public static void main(String[] args) throws FileNotFoundException, IOException, SecurityException{
            Test searchFacadeTest = new Test();
            searchFacadeTest.doTest();
          }


          public void doTest() throws FileNotFoundException, IOException{
            try {

             Context jndiContext = getInitialContext();
             FileManagerBeanRemote fileManager= (FileManagerBeanRemote)jndiContext.lookup("FileManagerBean/local");
             //fileManager.moveFile("C:\\test.txt", "C:\\Documents and Settings\\tr1a6358\\bowling.txt");
            }
            catch (Exception e) {
             e.printStackTrace();
            }
          }

          // developed for JBoss only. this is vender dependency
          public static Context getInitialContext( ) throws javax.naming.NamingException {
            Properties p = new Properties( );
            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            p.put(Context.PROVIDER_URL, "jnp://localhost:1098");
            Context context = new InitialContext(p);
            return context;
          }

          }

           

           

           

           

           

           

           

          • 2. Re: NoInitialCOnceptException when calling session bean from client
            jaikiran

            The port number to use is 1099 and not 1098. Also, if you want to get started, take a look at these tutorials http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/index.html

            • 3. Re: NoInitialCOnceptException when calling session bean from client
              deryaaltuntas

              I have succeed to call remote ınterface from client.

              Context jndiContext = getInitialContext();

              FileManagerBeanRemote fileManager= (FileManagerBeanRemote)jndiContext.lookup("FileManagerBean/remote");

              fileManager.moveFile("C:\\Documents and Settings\\tr1a6358\\Desktop\\jar-versions.xml", "C:\\Documents and Settings\\tr1a6358\\jar-versions.xml");

               

              Now I want to learn how can I local ınterface from client.Above method does not work.Could you please give an example

               

              I concluded from reading that local session bean is useful, ıf I call one session bean from another bean.Another bean must implement local interface.

              Is it correct?

              • 4. Re: NoInitialCOnceptException when calling session bean from client
                lieshoff

                In bean class you have added the right annotation in local interface? To lookup a local interface new IntialContext().lookup("...") is enough, you don't must pass context properties like provider url and so on.